Getting x,y,z Co Ordinates

Hi
How to get the x,y,z Co-ordinate corresponding to mouse pointer's posn in OCC Screen..

Thanks...

Mikael Aronsson's picture

Depends on what you want, the mouse coordinate has no Z value, so to transform the mouse position to a 3D coordinate you need to know where in 3D space the mouse cursor is located, the only possible way to do this in a simple way is if you have a shape under the mouse cursor that you can map to cursor to and transform the "hit" to a 3D point.

Sharjith Naramparambath's picture

Hi,
You can search for one of the functions named..

gp_Pnt ConvertClickToCoordinate(int x, int y, Handle(V3D_View) aView)

View or Viewer I am not sure.

in the mfc sample files of V3d Viewer that helps to map the mouse x and y coordinates and gives a gp_Pnt in 3D space of the viewer.

Regards
N. Sharjith

Marco Matt's picture

I use the following code

gp_Pnt OCCContext::to3DPoint(const QPoint & point)
{
// Make a plane perpendicular to the projection orientation.
gp_Dir proj_orientation = get3DViewProjection();
gp_Pln view_plane = gp_Pln(gp_Pnt (0, 0, 0), proj_orientation);
// Convert the 2d point into a 3d point.
Standard_Real xp, yp, zp;
get3DView()->Convert(point.x(), point.y(), xp, yp, zp);
gp_Pnt converted_pnt(xp, yp, zp);
// Project the converted point in the plane.
gp_Pnt2d projected_pnt = ProjLib::Project(view_plane, converted_pnt);
// Get a 3d point from this 2d point.
gp_Pnt p3D = ElSLib::Value (projected_pnt.X(), projected_pnt.Y(), view_plane);
return p3D;
}

gp_Dir OCCContext::get3DViewProjection()
{
Standard_Real x_ori, y_ori, z_ori;
get3DView()->Proj(x_ori, y_ori, z_ori);
gp_Dir proj_orientation(x_ori, y_ori, z_ori);
return proj_orientation;
}

Selahattin BABADAĞ's picture

Impossible, impossible, impossible ... its impossible to convert the mouse coordinates to world coordinates in 3d view with opencascade , i searched all internet all resources but result is negative :((

Is there a way?