Jump to content
  • Advertisement
Sign in to follow this  

Problem recalculating AABB

This topic is 5406 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
Apply exactly the same translations to your bounding box (ie yoiur min max variables) as you do to the model.

Share this post

Link to post
Share on other sites
You are accessing the wrong indices. OpenGL store matrices in column-major format:
 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.


Share this post

Link to post
Share on other sites
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:


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 )


// Apply Translation
glTranslatef( 0.0f, 0.0f, 10.0f);

// Recalculate the min and max Vektor of the aabb

// Draw the object

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 ?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!