Project 2D screen point to 3D plane

Hello community.

Today, I'm trying to create a custom manipulator and I'd like to know if there is a way to project a 2D point (mouse position) to a 3D point that is on a specific plane (using gp_Pln for example) regardless of the camera eye direction.

I know the "Convert" function of the view but there is nothing to convert the 2D point on a custom plane.

Thank you for your answers ;)

gkv311 n's picture

What do you mean 'project 2D point on the screen to 3D space regardless camera eye direction'? That makes no sense to me - camera eye direction and vertical axis are defining the very coordinates system of this 2D space relative to 3D space.

Guillaume CHAFFAROD's picture

Thank you and sorry for my bad explaination.

I have a 3D view. On this view, I have a virtual 3D plane defined by a point and its normal.

I'd just like to know where is my mouse cursor on this plane, using the mouse coordinates and the plane definition (using a gp_Pln for example).

gkv311 n's picture

You may use IntAna_IntConicQuad to find intersection between line gp_Line and plane gp_Pln.

int theX = ..., theY = ...;
Handle(V3d_View) theView = ...;
gp_Pln thePln = ...;
...
Graphic3d_Vec3d aPnt, aProj;
theView->ConvertWithProj (theX, theY, aPnt.x(), aPnt.y(), aPnt.z(), aProj.x(), aProj.y(), aProj.z());
gp_Line aLine (gp_Pnt (aPnt.x(), aPnt.y(), aPnt.z()), gp_Dir (aProj.x(), aProj.y(), aProj.z()));
IntAna_IntConicQuad anIntTool (aLine, thePln, Precision::Angular(), Precision::Intersection());
if (!anIntTool.IsDone() || anIntTool.IsParallel() || anIntTool.NbPoints() < 1) { error }
gp_Pnt aProjPnt = anIntTool.Point(1);

Or you may use picking information, if your plane is defined by AIS interactive object.

Guillaume CHAFFAROD's picture

My plane is virtual and there is no interactive object to define it, but I'm interest on how to do that :)