i have a small problem that i’m stuck on, i’m trying to get the 3d coordinates of the place i click on in a 3d world with the mouse, i have tried a few methods but haven’t been able to get any good results
currently i do
public void get3dCoord(int mouseX, int mouseY) {
GLU.gluUnProject( mouseX, mouseY, getZDepthAtOrigin(), getModelviewMatrixA(), getProjectionMatrixA(), getViewportA(), result);
}
public float getZDepthAtOrigin()
{
float[] resultf = new float[3];
project( 320, 240, 0, resultf);
return ((int)(resultf[2] * 1000F)) / 1000f; // truncate to 4 decimals
}
i use gluLookAt to move the camera around the 3d world
GLU.gluLookAt(camX, camY, camZ, // camera pos
320, 240, 0, // camera target
tiltX, tiltY, tiltZ); // camera tilt
with the code above i’ve been able to get ok results from the mouse when camX is at 320, camY is at 240 and camZ is changed to zooms in and out but when i change camX, or camY, the point where the mouse should be on the 3d world map starts going off, what is the correct way to do this?
to add to the problem i also have a 3d height map, i was wondering if there is a good way to get the 3d point on where the pointer clicks as done in games such as c&c: generals, tribal trouble:), dawn of war etc
thanks
