Hello everyone!
Is there a way to get the zoom ratio of the viewport?
Or I want to know the distance from the camera to the world plane XY
(Suppose the camera is on top)
C++
Thanks!
This isn’t C++, but it still might help you:
The world Z coordinate of the camera location is the distance from the world XY plane. Use absolute value if you want a positive distance for a location under the plane.
I found this one before, but it doesn’t seem to work. Zoom the view (middle mouse button), and its value is still the same.
ON_3dPoint pt = doc->ActiveView()->ActiveViewport().VP().CameraLocation(); double test = ON_Plane::World_xy.DistanceTo(pt); RhinoApp().Print(L"%f\n",test);
Is my thinking wrong? I want to get the zoom value of the view.
Is the middle mouse button set for Zoom or ZoomLens? Zoom moves the camera. ZoomLens changes the focal length.
The Lens value does change.
doc->ActiveView()->ActiveViewport().VP().GetCamera35mmLensLength(&lens_Length);
However, the value of the focal length will vary according to the size of the subject.
Rhino viewports do not have a “zoom value.” Why do you need this?
Thanks,
– Dale
Thank you,Dale.
I want to determine whether the distance between two points is within a fixed screen coordinate distance.
Maybe I will convert these points to screen coordinates, and the calculation will be a bit simpler.
Yes, I would think so.
I have not tested this. But this should do it.
/// <summary>
/// Returns the screen distance, in pixels, between two 3D points.
/// </summary>
/// <param name="view">The view to evaluate the points.</param>
/// <param name="point0">The first 3D point.</param>
/// <param name="point1">The second 3D point.</param>
/// <returns>The screen distance in pixels.</returns>
static int RhScreenDistance(
const CRhinoView& view,
ON_3dPoint point0,
ON_3dPoint point1
)
{
ON_Xform world_to_screen;
view.ActiveViewport().VP().GetXform(ON::world_cs, ON::screen_cs, world_to_screen);
ON_2dPoint screen_point0 = world_to_screen * point0;
ON_2dPoint screen_point1 = world_to_screen * point1;
return (int)screen_point0.DistanceTo(screen_point1);
}
– Dale
It is perfect, thank you again sincerely!