Mouse position

Greetings,
I want to get the position of the mouse inside the rhino viewport as a Point3d without using the getpoint method. Actually, I want to track the mouse all the time. Would you mind to help me find a solution?
Thanks

I assume you are working with RhinoCommon: in that case, you want to use the MouseCallback class. For documentation, see
https://developer.rhino3d.com/api/RhinoCommon/html/T_Rhino_UI_MouseCallback.htm

Thanks for the response. Yes, I am using rhino common and C#. I have already visited this class, but I did not understand how to get the position of the mouse in the viewport. I think this class is used to add more functionality to the mouse. I also found a method called : ClientToWorld(). Do you have any suggestion on how to use this method?

I was able to Trackdown the solution to this point:

    System.Drawing.Point screenPos = System.Windows.Forms.Cursor.Position;
    Rhino.RhinoDoc doc = Rhino.RhinoDoc.ActiveDoc;
    RhinoView view = doc.Views.ActiveView;
    Line line = view.ActiveViewport.ClientToWorld(screenPos);
    Plane cplane = view.ActiveViewport.ConstructionPlane();
    double t;
    Rhino.Geometry.Intersect.Intersection.LinePlane(line, cplane, out t);
    A = line.PointAt(t);

The problem is that there This is not the absolute position in top view. So this is the question: How can i get the absolute postition?MouseTracker.gh (10.4 KB)
Second, this is in 2D how can i get the 3d position?

you’ll need “screen to client” and “client to world”.

1 Like

Thanks that solved the 2D. I’ll attach the solution.

MouseTracker.gh (3.9 KB)

1 Like

for “3d” you need to do a raycast.Have a look at Intersect namespace or Ray class

1 Like

If you have a reference to the view port, you can use the frustum line. This is a line in world (model) coordinates that originates from the screen point. See this method and its overrides:
https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_DocObjects_ViewportInfo_GetFrustumLine_1.htm

1 Like

Thankyou all, I used GetFrustumLine() and it workes perfectly for my task.

2 Likes