Jump to content
  • Advertisement
Sign in to follow this  
Vexator

computing min/max values for bounding boxes that are not centered around the origin

This topic is 4491 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! i'm working on frustum culling atm. to ge the minimum and maximum values for my bounding boxes, i compare all x, y, and z elements of the vertices against my min/max values. if the current element is less than the min value, the min value is set to this element - the same for the max values: Vector3D kMinimum = Vector3D( 0.0f, 0.0f, 0.0f ); Vector3D kMaximum = Vector3D( 0.0f, 0.0f, 0.0f ); for( unsigned int i = 0; i < m_uiVertexCount; i++ ) { if( m_pkVertices.x < kMinimum.x ) kMinimum.x = m_pkVertices.x; if( m_pkVertices.y < kMinimum.y ) kMinimum.y = m_pkVertices.y; if( m_pkVertices.z < kMinimum.z ) kMinimum.z = m_pkVertices.z; if( m_pkVertices.x > kMaximum.x ) kMaximum.x = m_pkVertices.x; if( m_pkVertices.y > kMaximum.y ) kMaximum.y = m_pkVertices.y; if( m_pkVertices.z > kMaximum.z ) kMaximum.z = m_pkVertices.z; } m_kBoundingBox.SetMinimum( kMinimum ); m_kBoundingBox.SetMaximum( kMaximum ); this works fine if the model is centered around the origin, but if a model is for example shifted up, so that it's only on the positive y-axes, the resulting bounding box is too big. so instead of setting my min/max values to zero at initialisation, i set them to the first vertex positions: Vector3D kMinimum = m_pkVertices[0]; Vector3D kMaximum = m_pkVertices[0]; this works in most cases, but there are still exceptions.. is there a better way? thanks in advance!

Share this post


Link to post
Share on other sites
Advertisement
Someone may correct me, but I believe your doing this the right way. The main thing is to make sure the object is centered on it local space orign and then translated to world space.

Share this post


Link to post
Share on other sites

I don't see any problem with the code.

Vector3D kMinimum = m_pkVertices[0];
Vector3D kMaximum = m_pkVertices[0];

This is definetely the right way.

Can you describe the occuring problem ?

Cheers

Share this post


Link to post
Share on other sites
i had a situation when it caused problems, but i can't reproduce it anymore, mpfh.. well i'll leave it at that for the moment, if you say it's the way it's done :) thank you! ah another question: how to handle rotation with axis aligned boxes? my frustum culling check only checks unrotated boxes; so far i'm simply checking if any of the eight corners is inside the frustum.

bool Frustum::IsInside( const BoundingBox &box )
{
const Vector3D kMinimum = box.GetMinimum()+box.GetTranslation();
const Vector3D kMaximum = box.GetMaximum()+box.GetTranslation();

for( unsigned int i = 0; i < 6; i++ )
{
if( (m_kPlanes.x*kMinimum.x+m_kPlanes.y*kMinimum.y+m_kPlanes.z*kMinimum.z+m_kPlanes.w) >= 0.0f )
continue;
if( (m_kPlanes.x*kMaximum.x+m_kPlanes.y*kMinimum.y+m_kPlanes.z*kMinimum.z+m_kPlanes.w) >= 0.0f )
continue;
if( (m_kPlanes.x*kMaximum.x+m_kPlanes.y*kMinimum.y+m_kPlanes.z*kMaximum.z+m_kPlanes.w) >= 0.0f )
continue;
if( (m_kPlanes.x*kMinimum.x+m_kPlanes.y*kMinimum.y+m_kPlanes.z*kMaximum.z+m_kPlanes.w) >= 0.0f )
continue;
if( (m_kPlanes.x*kMinimum.x+m_kPlanes.y*kMaximum.y+m_kPlanes.z*kMinimum.z+m_kPlanes.w) >= 0.0f )
continue;
if( (m_kPlanes.x*kMaximum.x+m_kPlanes.y*kMaximum.y+m_kPlanes.z*kMinimum.z+m_kPlanes.w) >= 0.0f )
continue;
if( (m_kPlanes.x*kMaximum.x+m_kPlanes.y*kMaximum.y+m_kPlanes.z*kMaximum.z+m_kPlanes.w) >= 0.0f )
continue;
if( (m_kPlanes.x*kMinimum.x+m_kPlanes.y*kMaximum.y+m_kPlanes.z*kMaximum.z+m_kPlanes.w) >= 0.0f )
continue;

return false;
}

return true;
}

Share this post


Link to post
Share on other sites
Quote:
Original post by Vexator
i had a situation when it caused problems, but i can't reproduce it anymore, mpfh.. well i'll leave it at that for the moment, if you say it's the way it's done :) thank you! ah another question: how to handle rotation with axis aligned boxes? my frustum culling check only checks unrotated boxes; so far i'm simply checking if any of the eight corners is inside the frustum.
The 'eight corners' test isn't the most efficient form of this test, nor is it completely accurate. Google 'frustum aabb intersection' and you'll find better algorithms.

As for oriented objects, the easiest thing to do is to simply size the original AABB so that it contains the object fully regardless of orientation. It will of course not be as tight fitting, but for frustum culling purposes that should be ok.

Share this post


Link to post
Share on other sites
ok and how would i have to resize them? all i got are the maximum/minimum extents, how can i get the extents of the rotated model?

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!