sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Reverse operation of view.screen_coords

    Scheduled Pinned Locked Moved Developers' Forum
    30 Posts 5 Posters 744 Views 5 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • TIGT Offline
      TIG Moderator
      last edited by

      If you get the view.camera, get its .eye and .target and change these points 'in tandem', then apply them to a new/updated camera etc then the view should 'pan'...
      [I put that very simplistically but you ought to get the idea]
      So with eye.x=eye.x+10 and target.x=target.x+10 ... it should pan the camera by 10 to the right etc...

      TIG

      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        <span class="syntaxdefault">ray </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> view</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">pickray</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> x</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> y </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">result </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">raytest</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> ray </span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span>
        

        ?

        But, may I ask why you want to perform such pan?

        Thomas Thomassen — SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply Reply Quote 0
        • thomthomT Offline
          thomthom
          last edited by

          @tig said:

          If you get the view.camera, get its .eye and .target and change these points 'in tandem', then apply them to a new/updated camera etc then the view should 'pan'...
          [I put that very simplistically but you ought to get the idea]
          So with eye.x=eye.x+10 and target.x=target.x+10 ... it should pan the camera by 10 to the right etc...

          He's trying to figure out how much he has to move the camera in order for it to shift by the size of the viewport.

          Thomas Thomassen — SketchUp Monkey & Coding addict
          List of my plugins and link to the CookieWare fund

          1 Reply Last reply Reply Quote 0
          • TIGT Offline
            TIG Moderator
            last edited by

            How about https://developers.google.com/sketchup/docs/ourdoc/inputpoint#position ?

            TIG

            1 Reply Last reply Reply Quote 0
            • thomthomT Offline
              thomthom
              last edited by

              @tig said:

              How about https://developers.google.com/sketchup/docs/ourdoc/inputpoint#position ?

              Doesn't that risk it snapping to nearby geometry? That's why I was thinking a raytest would be safest as it would not be affected by inference.

              Thomas Thomassen — SketchUp Monkey & Coding addict
              List of my plugins and link to the CookieWare fund

              1 Reply Last reply Reply Quote 0
              • TIGT Offline
                TIG Moderator
                last edited by

                He can specify the view's inputpoint by using screen-coordinates (x,y) ?
                And then get the inputpoint's position as a 3dPoint ??

                That way he can get the screen width as with y at 0, and x at 0 and screen-width, gives two points - he can get the distance between them, then that's the amount to shunt the camera's eye/target across to pan a whole screen in the x-direction ?

                TIG

                1 Reply Last reply Reply Quote 0
                • TIGT Offline
                  TIG Moderator
                  last edited by

                  This 'proof of concept' pans the whole screen to the right [in plan is easiest to see...]

                  def pan_whole_screen_to_the_right()
                    model=Sketchup.active_model
                    view=model.active_view
                    ip0=view.inputpoint(0,0)
                    ip1=view.inputpoint(view.vpwidth,0)
                    p0=ip0.position
                    p1=ip1.position
                    dis=p0.distance(p1)
                    cam=view.camera
                    eye=cam.eye
                    tar=cam.target
                    upp=cam.up
                    eye.x=eye.x+dis
                    tar.x=tar.x+dis
                    cam.set(eye,tar,upp)
                  end
                  

                  Obviously you can make a more flexible method which could pan right/left and up/down as desired...

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • thomthomT Offline
                    thomthom
                    last edited by

                    @tig said:

                    He can specify the view's inputpoint by using screen-coordinates (x,y) ?
                    And then get the inputpoint's position as a 3dPoint ??

                    But my concern was that InputPoint will return a 3D point affected by inference, ie it snaps to mid points or something, based onthe 2D point.

                    Thomas Thomassen — SketchUp Monkey & Coding addict
                    List of my plugins and link to the CookieWare fund

                    1 Reply Last reply Reply Quote 0
                    • TIGT Offline
                      TIG Moderator
                      last edited by

                      I see the point. 😒
                      Here's a fuller version that avoids that [can you think of a better way?]

                      def pan_whole_screen_to_the_right()
                        model=Sketchup.active_model
                        ents=model.entities
                        ants=model.active_entities
                        pants=ents.to_a+ants.to_a
                        hidn=pants.uniq.find_all{|e|not e.hidden?}
                        model.start_operation('pants')
                        hidn.each{|e|e.hidden=true}
                        hgeo=model.rendering_options["DrawHidden"]
                        model.rendering_options["DrawHidden"]=false
                        view=model.active_view
                        ip0=view.inputpoint(0,0)
                        ip1=view.inputpoint(view.vpwidth,0)
                        p0=ip0.position
                        p1=ip1.position
                        dis=p0.distance(p1)
                        cam=view.camera
                        eye=cam.eye
                        tar=cam.target
                        upp=cam.up
                        eye.x=eye.x+dis
                        tar.x=tar.x+dis
                        cam.set(eye,tar,upp)
                        hidn.each{|e|e.hidden=false}
                        model.rendering_options["DrawHidden"]=hgeo
                        model.commit_operation
                      end
                      

                      TIG

                      1 Reply Last reply Reply Quote 0
                      • thomthomT Offline
                        thomthom
                        last edited by

                        @tig said:

                        Here's a fuller version that avoids that [can you think of a better way?] [code]def pan_whole_screen_to_the_right()

                        http://forums.sketchucation.com/viewtopic.php?f=180&t=44290#p394956

                        Thomas Thomassen — SketchUp Monkey & Coding addict
                        List of my plugins and link to the CookieWare fund

                        1 Reply Last reply Reply Quote 0
                        • TIGT Offline
                          TIG Moderator
                          last edited by

                          Therefore we can substitute
                          p0=view.pickray(0,0)[0] p1=view.pickray(view.vpwidth,0)[0]
                          and get a simpler method because the ray's point doesn't get influenced by inferences and is made on the picture-plane, as it were...

                          def pan_whole_screen_to_the_right()
                            model=Sketchup.active_model
                            view=model.active_view
                            p0=view.pickray(0,0)[0]
                            p1=view.pickray(view.vpwidth,0)[0]
                            dis=p0.distance(p1)
                            cam=view.camera
                            eye=cam.eye
                            tar=cam.target
                            upp=cam.up
                            eye.x=eye.x+dis
                            tar.x=tar.x+dis
                            cam.set(eye,tar,upp)
                          end
                          

                          😄

                          TIG

                          1 Reply Last reply Reply Quote 0
                          • thomthomT Offline
                            thomthom
                            last edited by

                            Ah, yes! Of course - no need to pick anything. I forgot that the ray contained a point that could be used directly.

                            Thomas Thomassen — SketchUp Monkey & Coding addict
                            List of my plugins and link to the CookieWare fund

                            1 Reply Last reply Reply Quote 0
                            • TIGT Offline
                              TIG Moderator
                              last edited by

                              Two brains are better than one [at least our combined IQs add up to around the average!!]
                              😆

                              TIG

                              1 Reply Last reply Reply Quote 0
                              • thomthomT Offline
                                thomthom
                                last edited by

                                I've already determined that my brain is on timeshare lease... 😒

                                Thomas Thomassen — SketchUp Monkey & Coding addict
                                List of my plugins and link to the CookieWare fund

                                1 Reply Last reply Reply Quote 0
                                • J Offline
                                  jpark
                                  last edited by

                                  TIG and thomthom,

                                  Do you guys ever sleep!!??
                                  You gave me a plenty of assignment for the weekend; to digest all that you posted.

                                  For your info, I am attempting to model a 'plan viewer' for blueprints which will become framework for architectural components

                                  Thanks guys

                                  John

                                  1 Reply Last reply Reply Quote 0
                                  • thomthomT Offline
                                    thomthom
                                    last edited by

                                    "Sl-eep"..? 😕

                                    Thomas Thomassen — SketchUp Monkey & Coding addict
                                    List of my plugins and link to the CookieWare fund

                                    1 Reply Last reply Reply Quote 0
                                    • J Offline
                                      jpark
                                      last edited by

                                      Just finished reading up on view.pickray method and ran TIG's sample code. At first glance it should have worked but does not. In executing each line, I find that p0 and p1 return same value as camera eye position. See Ruby Console responses below:

                                      p0=view.pickray(0,0)[0] Point3d(3255.11, 1479.16, 8761.61) p1=view.pickray(view.vpwidth,0)[0] Point3d(3255.11, 1479.16, 8761.61) p2=view.pickray(0,view.vpheight)[0] Point3d(3255.11, 1479.16, 8761.61) p3=view.pickray(view.vpwidth,view.vpheight)[0] Point3d(3255.11, 1479.16, 8761.61) cam=Sketchup.active_model.active_view.camera #<Sketchup::Camera:0x7ce5de0> cam.eye Point3d(3255.11, 1479.16, 8761.61) cam.target Point3d(3255.11, 1479.16, 127.281) cam.up Vector3d(0, 1, 0)

                                      How could this be? I thought I understood pickray method but NOT

                                      Off the topic note: where can I find instruction on how to annotate posting w/ codes, images, smiles, etc ...

                                      John

                                      1 Reply Last reply Reply Quote 0
                                      • TIGT Offline
                                        TIG Moderator
                                        last edited by

                                        I added some 'ruby' tags to make it clearer...

                                        I hope this is not ALL of the code...
                                        Have you set the view and so on earlier ?
                                        IF so... you don't use
                                        cam=Sketchup.active_model.active_view.camera
                                        but
                                        cam=view.camera
                                        ???
                                        My code is a working example.......

                                        TIG

                                        1 Reply Last reply Reply Quote 0
                                        • Dan RathbunD Offline
                                          Dan Rathbun
                                          last edited by

                                          @jpark said:

                                          Off the topic note: where can I find instruction on how to annotate posting w/ codes, images, smiles, etc ...

                                          There is a "hard to find" link on each message "POST A REPLY" page, in the right column, beneath the "Smilies" list.

                                          Notice how the line "BBCode is ON" has a link ??

                                          It leads you to a user guide for the code tags.

                                          Most of these usable tags have toolbar button "inserters" already set up for you to use. You just click the button, it inserts the tag. and positions the cursor between the tags so you can type text (or paste text,) into them.

                                          I'm not here much anymore.

                                          1 Reply Last reply Reply Quote 0
                                          • J Offline
                                            jpark
                                            last edited by

                                            @dan rathbun said:

                                            There is a "hard to find" link on each message "POST A REPLY" page, in the right column, beneath the "Smilies" list.

                                            Now I'm enlightened 😍 Thanks Dan

                                            @tig said:

                                            I hope this is not ALL of the code...

                                            No this is an output of individual Ruby Console execution. This is my attempt to debug each line of your sample code to check each variable's current value. Programming is my hobby and I just picked up Sketchup and Ruby couple of months ago so I have a lot to learn.

                                            Back to pickray method - All screen postions (ie p0, p1, p2, and p3) return different value yet pickray method of these points return identical 3D point as camera eye position but with different vector. How come?

                                            John

                                            1 Reply Last reply Reply Quote 0
                                            • 1
                                            • 2
                                            • 1 / 2
                                            • First post
                                              Last post
                                            Buy SketchPlus
                                            Buy SUbD
                                            Buy WrapR
                                            Buy eBook
                                            Buy Modelur
                                            Buy Vertex Tools
                                            Buy SketchCuisine
                                            Buy FormFonts

                                            Advertisement