Hi,
i want to be able to “Drag and Drop” a Sphere im my App.
So, I get the Mouse-Coordinates with :
void GetMouseCoord(int PosX, int PosY) {
GLdouble PosZ ;
GLdouble objx, objy, objz;
GLint viewport[4];
GLdouble modelMatrix[16];
GLdouble projMatrix[16];
glReadPixels(PosX, PosY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &PosZ);
glGetIntegerv(GL_VIEWPORT, viewport);
glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix);
glGetDoublev(GL_PROJECTION_MATRIX, projMatrix);
gluUnProject((GLdouble)PosX, (GLdouble)PosY, PosZ, modelMatrix, projMatrix, viewport, &objx, &objy, &objz);
Move_Obj_X = (objx) ;
Move_Obj_Y = -(objy) ;
Move_Obj_Z = (objz) ;
}
This work’s fine, but the Cordiantes are somekind of “wrong”.
When i move the Sphere to the Move_Obj_X,
Move_Obj_Y and Move_Obj_Z _ Coordiantes,
this point is far away from the mouse.
When i zoomed out the Scene (changing the Z-Value of the Camera), evrything is messed up, too
I want to have my Object exactly, where the Mouse-Cursor is…
Can Anyone help me ???