Hi there im trying to convert screen coords to game coords or wold space coords...
Here is my rendering function
[Source]
glViewport(0,0,CurrentWidth,CurrentHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45,1,1.0f,250.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(Cx,Cy,Cz);
glRotatef(Rx,1,0,0);
glRotatef(Ry,0,1,0);
glRotatef(Rz,0,0,1);
glTranslatef(float(map.Width) / -2.0f,float(map.Height) / -2.0f,0);
mouseCursor = CalculateMouse(); // Grab Mouse Position
... Then the map is rendered and the MousePointer's Position
... that is aquired
[/Source]
[Source]
CVector3 CalculateMouse()
{
POINT mouse; // Stores The X And Y Coords For The Current Mouse Position
GLint viewport[4]; // Viewport Constraints
GLdouble modelview[16]; // Model View Matrix
GLdouble projection[16]; // Project Matrix
GLfloat winX, winY, winZ; // Windows X,Y,Z (Positions)
GLdouble posX=0, posY=0, posZ=0; // World or (Identity) for the Positions
glGetIntegerv(GL_VIEWPORT, viewport); // Retrieves The Viewport Values (X, Y, Width, Height)
glGetDoublev(GL_MODELVIEW_MATRIX, modelview); // Retrieve The Modelview Matrix
glGetDoublev(GL_PROJECTION_MATRIX, projection); // Retrieve The Projection Matrix
GetCursorPos(&mouse); // Gets The Current Cursor Coordinates (Mouse Coordinates)
ScreenToClient(hWnd, &mouse);
winX = (float)mouse.x; // Holds The Mouse X Coordinate
winY = (float)viewport[3] - (float)mouse.y; // Holds The Mouse Y Coordinate
// Get Distance of Point under Mouse Icon
glReadPixels(winX, int(winY), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ);
mouseDistance = winZ;
// And Now Finaly We Use UnProject (which is basically like using the inverse matrix)
gluUnProject( winX, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ);
return CVector3(posX,posY,posZ);
};
[/Source]
SO the PosX,PosY,PosZ i get back from this GetMouse function
is always as far away from the Camera/Rendered Position as possible...
In a sense you could say WinZ is always == FarPlane
if any1 can help i will appreciate it