Parameters for gluUnProject are:
GLdouble winX,
GLdouble winY,
GLdouble winZ,
const GLdouble model,
const GLdouble proj,
const GLint view,

When you declare the variables ojbX, objY, objZ before you pass them to the function what type do they have to be?

I have tried:

Gldouble objX; etc.
GLdouble *objX; and neither work.

Your code should look something like this.

GLdouble objX, objY, objX;

gluUnproject( …, &objX, &objY, &objZ );

Thanks that worked.

Question? I am using glut and using the mouseFunc to get the winX,winY. Then I call gluUnProject and move and object to objX, objY, objZ.

But the GLUT mouseFunc doesn’t provide a z parameter…or does it? Anyway anytime I move my object to the coords generated from gluUnProject the z is always 0. As initialed.

How should I get around this so that the object doesn’t always end up right in front of the camera? (due to the z position of 0.)

Forget that above. I don’ think that unProject does what I think it does.

You will have to supply a value for winz that maps to 3D space (0 - 1 inclusive). However, its best to unproject to both the near and far plane, and use the resulting line to intersect with your object (Terrain in this case) and get your z value. There’s more in this advance forum topic Selecting Vetrices . The last part gives code you can adapt.