Screen to world Offset?


#1

Hi I need to draw a point on the Cplane under the mouse… but the routine I grabbed from the samples has a big offset?

        class CustomConduit : DisplayConduit
    {
        protected override void PostDrawObjects(DrawEventArgs e)
        {
            RhinoView view = RhinoDoc.ActiveDoc.Views.ActiveView;
            var P = Cursor.Position;
            Transform xform = view.ActiveViewport.GetTransform(CoordinateSystem.Screen, CoordinateSystem.Camera);
            Point3d world_point = new Point3d(P.X, P.Y, 0.0);
            world_point.Transform(xform);
            e.Display.DrawPoint(world_point, Color.DarkRed);
        }
    }

and this is what I am getting? How can I get a point directly under my mouse

I am not using any kind of GET, I need this outside of any of those routines.


(Dale Fugier) #2

Hi @ChristopherBotha,

This:

Transform xform = view.ActiveViewport.GetTransform(
  CoordinateSystem.Screen, 
  CoordinateSystem.Camera
);

should be this:
Transform xform = view.ActiveViewport.GetTransform( CoordinateSystem.Screen, CoordinateSystem.World // << );

– Dale


#3

Hi Dale.

Exact same offset. Except only in one window.


(Steve Baer) #4

Change
RhinoView view = RhinoDoc.ActiveDoc.Views.ActiveView;
to
RhinoViewport viewport = e.Viewport;

The proper viewport is passed to the conduit for each viewport being drawn.

You also need to make the change that Dale suggested.


#5

Thanks. Will give that a whirl!


#6

nope, same offset using this code.


(Steve Baer) #7

Ah, Cursor.Position is in screen coordinates, not to local client coordinates of your window.

Call
P = view.ParentView.ScreenToClient§;

to convert the screen point


#8

That fixed it up, thank you!


#9

Ha! Was going for an implementation of Zbrush LazyMouse for freehand sketching… remember to turn off overrides before exiting a command :wink:

(lazyMouse working great though, thanks for the help.