I am attempting to convert from my object coordiantes to screen coordinates.
Below is my current process. I am not getting the answers i am expecting. I seem to get clip coordinates that area much larger than 1. like -60.0 sometimes. mostly always bigger than 1/-1.
I beleive the process goes like:
ObjVector * ModelView Matrix * Projection Matrix * Perspective Divide = screen coordinates in +/-1 form. then i adjust per resolution.
the following code does that minus the perspective divide, i think
float modelview[16], proj[16];
float inV[16];//THIS HOLDS MY OBJECT COORDINATES
//load the Matrix
glMatrixMode(GL_MODELVIEW);
glGetFloatv(GL_MODELVIEW_MATRIX, (GLfloat*)&modelview);
//LOAD AND GET PROJECTION MATRIX
glMatrixMode(GL_PROJECTION);
glGetFloatv(GL_PROJECTION_MATRIX, (GLfloat*)&proj);
//load modelview matrix AGAIN
glMatrixMode(GL_MODELVIEW);
//copy matrix by pushing
glPushMatrix();
//MULTIPLY MODELVIEW MATRX WITH PROJECTION MATRIX
glMultMatrixf((GLfloat*)&proj);
//SET THE VECTOR CONTAINING MY OBJECT COORDINATES, REST
//IS FILLED WITH ZEROS. i KNOW I CAN LEAVE IT AS A 4X1 VEC.
inV[0] = x;
inV[1] = y;
inV[2] = z;
inV[3] = 1.0;
for(int i=4;i<16;i++)inV[i]=0;//FILL IN ZEROS
//MULTIPLY OBJECT VECOTR/MATRIX. SHOULD GIVE ME CLIP COORDINATES?
glMultMatrixf((GLfloat*)&inV);
//SAVE THE RESULT TO A MATRIX
glGetFloatv(GL_MODELVIEW_MATRIX, (GLfloat*)matrix);
//restore model view matrix by popping
glPopMatrix();
I think my “matrix” float[16] should hold my clipping coordinates?? matrix[0] and matrix[1] are supposed to be between +/-1.0 and should hold the x,y after i do a perspective divide?
Isnt the perspective divide (w) a 1 since i set my 4th parameter(inV[3]) of my object vector to a 1?
I apprciate any help
thanks