Reverse operation of view.screen_coords
-
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 witheye.x=eye.x+10
andtarget.x=target.x+10
... it should pan the camera by 10 to the right etc... -
<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?
-
@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 witheye.x=eye.x+10
andtarget.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.
-
-
@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. -
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 ?
-
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 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.
-
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 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
-
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
-
Ah, yes! Of course - no need to pick anything. I forgot that the ray contained a point that could be used directly.
-
Two brains are better than one [at least our combined IQs add up to around the average!!]
-
I've already determined that my brain is on timeshare lease...
-
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
-
"Sl-eep"..?
-
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
-
I added some 'ruby' tags to make it clearer...
I hope this is not ALL of the code...
Have you set theview
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....... -
@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.
-
@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
Advertisement