sum1stolemyname
sum1stolemyname

Reputation: 4550

Howto convert transformed coordinates to world coordinates in OpenGL?

I have a transformation set up in Opengl like this:

glPushMatrix(); 
glTranslated(pntPos.X(), pntPos.Y(), pntPos.Z());
glRotated(dx, 1, 0, 0);
glRotated(dy, 0, 1, 0);
glRotated(dz, 0, 0, 1);

//I use this to Render a freely placeable textbox in 3d 
//space which is based on the FTGL-Toolkit [1] (for TTF support).

m_FTLayout.Render(m_wcCaption, m_iCaptionSize);
glPopMatrix();

This works as expected.

However, i would like to calculate the 3d-Boundingbox wich bounds my text in word space. I know the coordinates of this bounding-box relative to my GL-Transformation.

But i have a hard time calculating their world coordinates from these. Could you give me some insight on how to retrieve the respective World coordinates of the four vertexes in the bounding Box?

[1] http://sourceforge.net/projects/ftgl/

Upvotes: 0

Views: 1190

Answers (1)

Bahbar
Bahbar

Reputation: 18015

The simplest way is to ask the GL what its current modelview matrix is glGetFloatv(GL_MODELVIEW_MATRIX, m), and transform your bounding box vertices by the resulting matrix.

             m[0]  m[4]  m[8]  m[12]     v[0]
             m[1]  m[5]  m[9]  m[13]     v[1]
     M(v) =  m[2]  m[6]  m[10] m[14]  X  v[2]
             m[3]  m[7]  m[11] m[15]     v[3]

That will give you the view-space 4-D homogeneous position of your vertex.

Or, you could compute the modelview yourself, based on the math that is available in the man pages of glTranslated and glRotated

Upvotes: 3

Related Questions