devdept

02-03-2010, 04:54 AM

Hi All,

As you all know if you have the model close to the origin you see it perfectly:

http://www.devdept.com/close.gif

But when it is very far from the origin you see it like:

http://www.devdept.com/far.gif

This issue can be easily fixed doing:

glMatrix(PROJECTION);

glLoadIdentity();

glPerspective(...);

glMatrix(MODELVIEW);

glLoadIdentity();

>>>>>>>>>>>>>> glTranslate(-1000000, -1000000, 0) // moves the model onto the origin

gluLookAt(...);

But what happen when you do screen to client conversion like:

gluUnProject(mousePos.X, height - mousePos.Y, 0, modelViewMatrix, projectionMatrix, viewport, P0.X, P0.Y, P0.Z);

gluUnProject(mousePos.X, height - mousePos.Y, 1, modelViewMatrix, projectionMatrix, viewport, P1.X, P1.Y, P1.Z);

intPoint = LinePlaneIntersection(P0, P1, planeEquation)

We get the wrong 3D point right?

Shall we use the following solution or a better/more accurate approach exists?

gluUnProject(mousePos.X, height - mousePos.Y, 0, modelViewMatrix, projectionMatrix, viewport, P0.X, P0.Y, P0.Z);

gluUnProject(mousePos.X, height - mousePos.Y, 1, modelViewMatrix, projectionMatrix, viewport, P1.X, P1.Y, P1.Z);

intPoint = LinePlaneIntersection(P0, P1, planeEquation)

intPoint.X += 1000000; // moves the 3D point back to the actual position

intPoint.Y += 1000000;

Thanks,

Alberto

As you all know if you have the model close to the origin you see it perfectly:

http://www.devdept.com/close.gif

But when it is very far from the origin you see it like:

http://www.devdept.com/far.gif

This issue can be easily fixed doing:

glMatrix(PROJECTION);

glLoadIdentity();

glPerspective(...);

glMatrix(MODELVIEW);

glLoadIdentity();

>>>>>>>>>>>>>> glTranslate(-1000000, -1000000, 0) // moves the model onto the origin

gluLookAt(...);

But what happen when you do screen to client conversion like:

gluUnProject(mousePos.X, height - mousePos.Y, 0, modelViewMatrix, projectionMatrix, viewport, P0.X, P0.Y, P0.Z);

gluUnProject(mousePos.X, height - mousePos.Y, 1, modelViewMatrix, projectionMatrix, viewport, P1.X, P1.Y, P1.Z);

intPoint = LinePlaneIntersection(P0, P1, planeEquation)

We get the wrong 3D point right?

Shall we use the following solution or a better/more accurate approach exists?

gluUnProject(mousePos.X, height - mousePos.Y, 0, modelViewMatrix, projectionMatrix, viewport, P0.X, P0.Y, P0.Z);

gluUnProject(mousePos.X, height - mousePos.Y, 1, modelViewMatrix, projectionMatrix, viewport, P1.X, P1.Y, P1.Z);

intPoint = LinePlaneIntersection(P0, P1, planeEquation)

intPoint.X += 1000000; // moves the 3D point back to the actual position

intPoint.Y += 1000000;

Thanks,

Alberto