Getting wrong X,Y,Z coordinates

I can get (x, y, z) via gp_Pnt ConvertClickToCoordinate(int x, int y, Handle(V3D_View) aView) when using Projection_Orthographic projection type.

But the result is wrong when using Projection_Perspective projection type.

Anyone there has any idea to fix it?

Kirill Gavrilov's picture

There is no ConvertClickToCoordinate() function in OCCT - how it looks?

Shen Tung Huang's picture

Hi Kirill

This function is in the Viewer3dView class from Viewer3d project of mfc sample.

There's the code

gp_Pnt ConvertClickToPoint(Standard_Real x, Standard_Real y, Handle(V3d_View) aView)
	Standard_Real XEye,YEye,ZEye,XAt,YAt,ZAt;
	gp_Pnt EyePoint(XEye,YEye,ZEye);
	gp_Pnt AtPoint(XAt,YAt,ZAt);

	gp_Vec EyeVector(EyePoint,AtPoint);
	gp_Dir EyeDir(EyeVector);

	gp_Pln PlaneOfTheView = gp_Pln(AtPoint,EyeDir);
	Standard_Real X,Y,Z;
	gp_Pnt ConvertedPoint(X,Y,Z);
	gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project(PlaneOfTheView,ConvertedPoint);
	gp_Pnt ResultPoint = ElSLib::Value(ConvertedPointOnPlane.X(),
	return ResultPoint;

When using Projection_Orthographic projection type, I can get the point via cursor.

But when using Projection_Perspective projection type, the result point is far away from the cursor.

I got different result in two projection types of the code below