Hi, I was wondering if there was an easy way to access the results of a OpenGL transformation. I’m trying to determine if two objects on screen are coincident with each other, and I can’t find an easy way to determine screen coordinates for both objects. One of the objects is stationary and the other moves up and down on the Y axis and spins on the Z.

Thanks,

poemind

if you just want the transformed coordinates of
a node on the screen, google for gluProject.

If you want to check if the objects intersect in the screen and need to now the intersection you can use the stencil buffer for that.
Set the stencil operation (with glStencilOp) to GL_REPLACE and use 1 for the value (you may use other values depending of whether or not that conflicts with your use of the stencil buffer)and draw the first object. Then set the stencil operation to GL_OR and the value to 2. Draw the second object.
The objects intersect where the stencil buffer contains the value 3.
To get the intersection set the stencil function (with glStencilFunc) to GL_EQUAL and the reference value to 3. Then draw to the back buffer (make sure it is cleared!) something that fills the entire screen and use glReadPixels to get the intersection

It seems to me that you are wondering how to get actual/world space coordinate of transformed objects. if that so, than here are the solution.

``````float x,y,z;//original coordinates
float newX, newY, newZ;//storage for transformed vertices

float m;//storage for homogenous transformation matrices

//put all your transformations here

glGetFloatv(GL_MODELVIEW_MATRIX, m);//get current homogenous transformation matrices

//manually transform the vertices and put it in new*
newX = m* x + m*y + m*z + m;
newY = m* x + m*y + m*z + m;
newZ = m* x + m*y + m*z + m;

``````

basically, what we did was querying opengl modelview matrices(which is a 4 by 4 matrices represented as array of 16 floats in top down order) after it was multiplied with transformations. we use this matrices to manually compute our desired vertices transformation(by multiplying 4 by 4(transformation matrices) with 4 by 1(vertex as (x,y,z,1)) matrices). i did not use shortcuts/leet code for making it easier to understand.

hope this helps

You can try my glhlib.

It has a whole series of functions for matrix operations and vertex transform.

Matrix ops:

glhTranslatef2
glhScalef2
glhFrustumf2
glhOrthof2
glhMergedFrustumf2
glhLookAtf2
glhMultMatrixf2
glhQuickInvertMatrixf2
glhInvertMatrixf2
glhTransposeMatrixf2
and others

Vertex :

glhProjectf_2
glhProjectf_3
glhUnProjectf_2
glhUnProjectf_3
glhProjectf_SSE_Aligned_2
glhProjectf_SSE_Aligned_WarmCache_2
glhMultiplyMatrixByVector4by4f_1
glhMultiplyMatrixByVector4by4f_SSE_Aligned_WarmCache_1
and others

http://www.geocities.com/vmelkon/glhlibrary.html