Getting view near and far planes through ruby?
-
Is there any way of getting the near and far planes of the view through ruby?
-
Not that I know of. Unless you can determine how to calculate them. I think you can check them against the data shown in that PC only camera stats window (I forget the command to call that up though). I wouldn't even being to know how to approach that though.
-
Ok, so ... does anyone know how to calculate them?
-
I haven't done much work with perspective projection, or the view object, but my first impression would be that the near plane would be normal to camera.direction and go through the point returned by camera.target, then the far plane would have the same normal and be translated in the direction of that vector by the distance returned by the camera.focal_length method. If that's correct, then the calculation should be straightforward.
-
When you say 'plane' do you mean the actual plane defined by [point,vector] ?
The near plane - the screen center can be found from
point=model.active_view.camera.eye
and
vector=model.active_view.camera.target.vector_to(model.active_view.camera.eye)
The far plane ? you could do something similar with the target point ??
IF you want to find the 'corners' of the 'screen' that's a different matter... involving fov etc ???
-
If you want worldspace near and far plane distances, just project the Model bounding box onto the lookat vector
lookat = Sketchup.active_model.active_view.camera.target - Sketchup.active_model.active_view.camera.eye
then project each corner of the model bounding box on this line. So:
for i in 0...8
#enumerate all the corners
x = i & 1 != 0 ? Sketchup.active_model.bounds.min[0] : Sketchup.active_model.bounds.max[0]
y = i & 2 != 0 ? Sketchup.active_model.bounds.min[1] : Sketchup.active_model.bounds.max[1]
z = i & 4 != 0 ? Sketchup.active_model.bounds.min[2] : Sketchup.active_model.bounds.max[2]build a corner point to test
c = Geom::Point3d.new(x,y,z)
how far a long the line of sight it is
d = lookat.dot(c - Sketchup.active_model.active_view.camera.eye)
track minimum and maximum value of d
end
Advertisement