Camera space question
-
view.camera.xaxis
view.camera.yaxis
view.camera.zaxisgive you the camera space frame. (xaxis is left/right, yaxis is up/down, zaxis is along camera dir).
-
Thanks, I've come that far. It's how to use those that I can't figure out.
Here is an example of what I want to do.
I have a position (a point3d) that I want to transform a distance of x-length, y-length and z-length in the camera space coordinate system.
How do I set it up?
-
I think you may be looking too deeply. How would you do it in model space?
-
In "world space" I do it:
newPos = Geom::Point3d.new(pos.x+Xdist, pos.y+Ydist, pos.z+Zdist)
pos = newPos -
This might work...
xdist = 10 pos = Geom;;Point3d.new(0,0,0) camera_axis = Sketchup.active_model.active_view.camera.xaxis camera_axis.length = xdist newPos = pos + camera_axis
-
Ah, ok. So you need to transform your x-length,y-length,z-length into world space.
camera_space_translation = Geom::Vector3d.new(xDist,yDist,zDist)
then
world_space_translation = Geom::Vector3d.new(view.camera.xaxis.dot(camera_space_translation),
view.camera.yaxis.dot(camera_space_translation),
view.camera.zaxis.dot(camera_space_translation))(do whatever with world_space_translation)
BTW This is just a long hand vector-matrix multiply.
-
Adam,
Is your method different than using the Transformarion.axis, which is a
@unknownuser said:
method is used to create a Transformation that goes from world coordinates to an arbitrary coordinate system
Is the result the same? I could use a course on 3d mathematics, particularly as it applies in SketchUp.
-
No different. Just wasn't sure whether you can get the camera matrix as a whole, so thought it just as easy to do 3 dot products. (And we do just want a 3x3 tranform here).
-
-
First, sorry for not getting back earlier. Its been kind of hectic here.
Thanks for answering but I still have problems.
Adam, your way gives relly weird results. Either there is something wrong with your method or (more possibly) there is something wrong with me.
When using your method and just translating the xDist it gets a transform also in th z axis and if I use the value 100 as xDist it gets moved a distance of 2540 mm?Part of the code:
camSpaceTranslation = Geom;;Vector3d.new(xDist, yDist, zDist) worldSpaceTranslation = Geom;;Vector3d.new(camera.xaxis.dot(camSpaceTranslation), camera.yaxis.dot(camSpaceTranslation), camera.zaxis.dot(camSpaceTranslation)) newEye = eye + worldSpaceTranslation newTarget = target + worldSpaceTranslation eye = newEye target = newTarget camera = camera.set(eye, target, up)
Once more to clearify what I'm after:
Moving along world axes is working but I want to numerically move the camera eye point and target point (the target shall just move the same amount as the eye) in the cameras sightline*(in/out),*left/right and up/down.
Any thoughts? -
And how many millimeters in an inch (the native units of Sketchup) are there?
@pixero said:
First, sorry for not getting back earlier. Its been kind of hectic here.
When using your method and just translating the xDist it gets a transform also in th z axis and if I use the value 100 as xDist it gets moved a distance of 2540 mm?
-
25.4mm to an inch.
-
@adamb said:
And how many millimeters in an inch (the native units of Sketchup) are there?
The "native" unit of mySketchUp is centimetre. -
?
model = Sketchup.active_model c = model.active_view.camera eye = c.eye up = c.up target = c.target xaxis = c.xaxis yaxis = c.yaxis zaxis = c.zaxis model.entities.add_cpoint eye model.entities.add_cpoint target model.entities.add_text("eye", eye) model.entities.add_text("target", target) distance = 12 newEye = eye.offset(xaxis, distance) model.entities.add_cpoint newEye model.entities.add_text("newEye", newEye) newTarget = target.offset(xaxis, distance) model.entities.add_cpoint newTarget model.entities.add_text("newTarget", newTarget) c.set(newEye, newTarget, up)
-
Might I suggest AddPages as a reference script? It adds pages (scenes) orthographically (based on user-supplied x, y, and z offsets). If I understand the gist of the discussion, then AddPages has at its heart the transformation code in question.
-
Thanks all for helping!
Now I got it working the way I want.
I'll be back when the script is done. -
See this thread: http://www.sketchucation.com/forums/scf/viewtopic.php?f=153&t=1528&p=41330#p41330
And once more, thanks for helping!
Advertisement