Problem recalculating AABB
Hi everyone In my ( very ) little 3D engine i use AABBs, which are represented by a minimal and a maximal Vector of the object they surround. CVector3 m_vMin; Cvector3 m_vMax; As long an object is centered around the origin, the corresponding bounding Box is drawn correctly. However, if i translate the object via glTranslatef ( 0.0f, 0.0f, 10.0f ) the Bounding Box is still drawn as if the object was around the origin. The Bounding Box doesn't get translated. In order to translate the min and max Vectors, i call glGetFloatv (GL_MODELVIEW_MATRIX, mvMatrix); and then i add the 4th row of the given matrix to m_vMin and m_vMax ( mvMatrix Indices 3,7 and 11 ). Am i using the wrong matrix ? Because, if i start my debugger with a breakpoint directly after the above "glGetFloatv" call, i can see that the forth row of mvMatrix is ( 0,0,0,1 ). Shouldn't it be something like ( 0,0,10,1 ) o_0 ? The results i get when i use rotation are even more weird .... I guess i am making a terrible obvious mistake. But which one ? Thanks for any help.
You are accessing the wrong indices. OpenGL store matrices in column-major format:
So you actually want indices 12, 13 and 14, not 3, 7, and 11.
Enigma
0 4 8 12 1 5 9 13 2 6 10 14 3 7 11 15
So you actually want indices 12, 13 and 14, not 3, 7, and 11.
Enigma
Thanks for the answers ! I actually assumed that opengl Matrices are row-major matrices. However, it still doesn't work right, and i think it has something to do with the order i call the commands
Here is how i do it:
renderscene
{
glLoadIdentity();
gluLookAt( g_Camera.m_vPosition.x , g_Camera.m_vPosition.y , g_Camera.m_vPosition.z,
g_Camera.m_vView.x , g_Camera.m_vView.y , g_Camera.m_vView.z ,
g_Camera.m_vUp.x , g_Camera.m_vUp.y , g_Camera.m_vUp.z );
/* draw the AABB of the object, according to the transformed coordinates,
* which were calculated by the last object.m_AABB.recalculate call ( see below )
*/
object.m_AABB.draw();
// Apply Translation
glTranslatef( 0.0f, 0.0f, 10.0f);
// Recalculate the min and max Vektor of the aabb
object1.m_AABB.recalculate();
// Draw the object
object.draw();
SDL_GL_SwapBuffers( );
}
The AABB isn't drawn were it should: It moves as i move the camera. Any hints ? How are you doing AABB recalculation after an object transformation ?
Here is how i do it:
renderscene
{
glLoadIdentity();
gluLookAt( g_Camera.m_vPosition.x , g_Camera.m_vPosition.y , g_Camera.m_vPosition.z,
g_Camera.m_vView.x , g_Camera.m_vView.y , g_Camera.m_vView.z ,
g_Camera.m_vUp.x , g_Camera.m_vUp.y , g_Camera.m_vUp.z );
/* draw the AABB of the object, according to the transformed coordinates,
* which were calculated by the last object.m_AABB.recalculate call ( see below )
*/
object.m_AABB.draw();
// Apply Translation
glTranslatef( 0.0f, 0.0f, 10.0f);
// Recalculate the min and max Vektor of the aabb
object1.m_AABB.recalculate();
// Draw the object
object.draw();
SDL_GL_SwapBuffers( );
}
The AABB isn't drawn were it should: It moves as i move the camera. Any hints ? How are you doing AABB recalculation after an object transformation ?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement