I’m not 100% sure I’m following here (just taking a quick break from a dumb compiler problem), but this is the code I use to get the mouse position on a 3D plane, the function needs to be called AFTER you set the camera transform.

```
// ----------------------------------------------------------------------------------------------------------------------
//
// Get's the 3d position of the mouse on the plane
// y=0 and puts it in the vector mousePosOnPlane
//
void ASeasonSpring::getMousePosOnPlane(int x, int y)
{
glGetFloatv(GL_MODELVIEW_MATRIX, tmpModelView);
glGetFloatv(GL_PROJECTION_MATRIX, tmpProjection);
glGetIntegerv(GL_VIEWPORT, tmpViewport);
float dx, dy, dz = 0.0;
int ry = tmpViewport[3] - y - 1;
gluES::gluUnProject( x, ry, 0.0,
tmpModelView, tmpProjection, tmpViewport,
&dx, &dy, &dz);
mouseRayPosition.x = dx;
mouseRayPosition.y = dy;
mouseRayPosition.z = dz;
dx = dy = dz = 0.0;
gluES::gluUnProject( x, ry, 1.0,
tmpModelView, tmpProjection, tmpViewport,
&dx, &dy, &dz);
mouseRayVector.x = dx;
mouseRayVector.y = dy;
mouseRayVector.z = dz;
mouseRayVector -= mouseRayPosition;
mouseRayVector.Normalize();
// pre calc this ??
CVector planeNormal = CVector(0.0, 1.0, 0.0);
CVector pointOnPlane = CVector(-1.0, 0.0, 0.0);
float planeDistance = PlaneDistance(&planeNormal, &pointOnPlane);
//printf(">>>%f\n", planeDistance);
float tmpDist = RayIntersectPlane(&planeNormal, planeDistance, &mouseRayPosition, &mouseRayVector);
//printf("%f\n", tmpDist);
oldMousePosOnPlane.x = mousePosOnPlane.x;
oldMousePosOnPlane.y = mousePosOnPlane.y;
oldMousePosOnPlane.z = mousePosOnPlane.z;
mousePosOnPlane = mouseRayPosition + (mouseRayVector * tmpDist);
}
```

this is in the .h file:

```
CVector mousePosOnPlane;
CVector oldMousePosOnPlane;
CVector mouseRayPosition;
CVector mouseRayVector;
GLfloat tmpModelView[16];
GLfloat tmpProjection[16];
GLint tmpViewport[4];
```

mousePosOnPlane will end up with the position of the mouse on a plane with Y up.

/A

[/code]