Implementing panning functionality programmatically

I am implementing ‘Pan’ routine. I convert mouse point location to world coordinates and I update camera location based on the previous and next point using world coordinates However, in order to make it work properly it looks like I need to rotate camara or the viewport to keep proper angle based on the camera movement (target should stay perpendicular to the projection surface).Otherwise when panning object it will be viewed from a different angle if I only move the camera. It is hard to notice when the object is away from the camera but if I am close, object is loosing its orientation. Here is the framgment of my code:

double factor = -1.0 ;

            double x = factor * (current.X - previous.X) + Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.MainViewport.CameraLocation.X;
            double y = factor * (current.Y - previous.Y) + Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.MainViewport.CameraLocation.Y;
            double z = factor * (current.Z - previous.Z) + Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.MainViewport.CameraLocation.Z;

            Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.MainViewport.SetCameraLocation(new Rhino.Geometry.Point3d(x, y, z), true);
            Rhino.RhinoDoc.ActiveDoc.Views.RedrawEnabled = true;

I am trying to figure out if I can apply rotation using Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.MainViewport.Rotate() (what angle, what vector and rotation point) to keep the target at the same angle towards the camera when camera is moving, so it works exactly like in the Rhino application.

Did anyone implemented panning functionality programatically? Please let me know if anybody has some suggestions.

Thanks,

Jacek

If you were using C++, you’d just call CRhinoViewport::MouseLateralDolly and pass in your 2- 2D screen points. But I don’t see this function exposed in RhinoCommon yet. Since there is quite a bit of work to Pan like Rhino does, I’ve added a request to expose this functionality.

http://mcneel.myjetbrains.com/youtrack/issue/RH-30186

Hi Jacek,

The YouTrack item I referenced above has been implemented.

New functionality has been added to RhinoCommon, in the Rhino WIP, that makes it fairly easy to pan a viewport.

Rhino.Display.RhinoViewport.MouseLateralDolly

– Dale

1 Like