Hi, I’m continuing a thread on textRendering here, since it’s morphed into a question about how to project world co-ordinates into screen co-ordinates.
I am trying to make sense of the gluProject method. My object’s coordinates are set to (0f, 0f, 0f) and I am getting this output from my function below.
window_coords x/y/z = -0.6213202977855181/-0.4142135216304729/ 4.000000059008596
How do I interpret this? I was expecting pixel values! And how do I interpret the z value?
In case this is useful info:
My screen size is 600px/400px.
I am setting perspective like so : glu.gluPerspective(45,(float)width/height,1,100);
My camera is at (0f,0f,0f)
I am calling a glTranslate(0f,0f,-10f) before drawing my square at coords (0f,0f,0f);
public void getScreenCoordsForObject(GL gl, GLU glu, Coord c)
{
double modelview[] = new double[16];
double projection[] = new double[16];
int viewport[] = new int[4];
double windowCoords[] = new double[3];
gl.glGetDoublev(GL.GL_MODELVIEW_MATRIX, modelview, 0);
gl.glGetDoublev(GL.GL_PROJECTION_MATRIX, projection, 0);
gl.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0);
glu.gluUnProject(c.x, c.y, c.z,
modelview, 0,
projection, 0,
viewport, 0,
windowCoords, 0);
System.out.println("window_coords x/y/z = " + windowCoords[0] + "/" + windowCoords[1] + "/ " + windowCoords[2]);
}
Thanks, spiraljetty