Get mouse position in active viewport + cplane coords


#1

How to get the 2d - relative to the viewport windows and 3d coordinates of the active cplane?

Reason why would be custom object creation (not get, set style, but rather a scatter painter or similar)
the 2d would be to interact with Hud-style displayconduit elements.
(rhino5, c#, or similar)
Thanks!


(Menno Deij - van Rijswijk) #2
AFAIK there is no example in C# but you would need the Viewport.GetPickTransform() if I'm not mistaken. (see below)

(Dale Fugier) #3

To transform a 2-D screen point to a 3-D world xy-plane point, you can do something like this:

Rhino.Display.RhinoView view = doc.Views.ActiveView;
Rhino.Geometry.Transform xform = view.ActiveViewport.GetTransform(
    Rhino.DocObjects.CoordinateSystem.Screen, 
    Rhino.DocObjects.CoordinateSystem.World
    );
Rhino.Geometry.Point3d world_point = new Rhino.Geometry.Point3d(
    screen_point.X, 
    screen_point.Y, 
    0.0
    );
world_point.Transform(xform);

#4

i don’t really understand what you mean dale, but i think i figured it out more or less:

RhinoView view = doc.Views.ActiveView;
RhinoViewport vp = view.ActiveViewport;

System.Drawing.Point p = vp.ScreenToClient(Cursor.Position);
Line l = vp.ClientToWorld(p); // this gives a point exactly over the cursor

I didn’t figure out yet what defines the depth of the point, but its a good start - and i think the code from dale could be the next step to bring the point to a plane

edit: just realized that my initial post was a bit vague on what i wanted to achieve: to get the coordinates that are shown in the lower left corner of rhino


(Dale Fugier) #6

This is exactly what my sample code shows how to do…