Jump to content
  • Advertisement
Sign in to follow this  
neo187

AABB Bounding Box collision help!

This topic is 2569 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

Hello there.... this is driving me kind of nuts.... I am trying to create an algorithm that returns pointers to all the game objects whose bounding box is inside a big bounding box around the character (so that on those I can perform more accurate collision checks)....

The way I am doing it is by using a BoundingBox struct with a Min and a Max vector of, respectively, the bottom left vertex and the top right..... This is all Axis alligned....

The algorithm for returning the Min and Max is working fine since I am drawing wireframe boxes around the objects using them, and they all look ok.... But this algorithm to check for how many object boxes collide with the character viewing box just gives me random results.... This is it:



void World::findVisibleObjects(){

// clear the vector
visibleObjects.clear();

//for all the game objects in the scene
for(int i = 0; i < gameObjects.size(); i++){
if(((viewingVolume.max.x >= gameObjects.at(i).bb.min.x)
&& (viewingVolume.max.y >= gameObjects.at(i).bb.min.y)
&& (viewingVolume.max.z >= gameObjects.at(i).bb.min.z)) ||
((viewingVolume.min.x <= gameObjects.at(i).bb.max.x)
&& (viewingVolume.min.y <= gameObjects.at(i).bb.max.y)
&& (viewingVolume.min.z <= gameObjects.at(i).bb.max.z))){

//place a pointer to the object in the visibleObjects vector
visibleObjects.push_back(&gameObjects.at(i));
}
}
}


Now when I return the visibleObjects.size() I get very random results, even when the wireframe boxes clearly collide on screen....

Am I doing something wrong?

Help!

P.S.
This is OpenGL by the way, if it has any relevance...

Share this post


Link to post
Share on other sites
Advertisement
You aret esting their minimum point as less than your view volume maximum point. you OR this set of object with those that have their maximum point greater thatn your view volume minimum point.

lets think abot the first part. so they pass since their min is less than view.max. well that's true, but what about their max vs your min? you only tested them against the one corner, you didn't actually see if they were bound within the box or interected. same applies to the test on the other side of the OR. what you probably end up with is having nearly everything pass through as visible.

you could add a faster test using spheres first.

Share this post


Link to post
Share on other sites

You aret esting their minimum point as less than your view volume maximum point. you OR this set of object with those that have their maximum point greater thatn your view volume minimum point.

lets think abot the first part. so they pass since their min is less than view.max. well that's true, but what about their max vs your min? you only tested them against the one corner, you didn't actually see if they were bound within the box or interected. same applies to the test on the other side of the OR. what you probably end up with is having nearly everything pass through as visible.

you could add a faster test using spheres first.


spheres, it's what I am currently trying to do and it's driving me nuts... I am trying to test for intersection between a ray and a sphere... I gave full details of how i am trying to implement it here, maybe you can help me?

http://www.gamedev.net/topic/614299-mouse-to-ray-sphere-collision-detection-help/

I managed to resolve the bounding box check using this code (but yes basically the issue was what you pointed out):




for(int i = 0; i < gameObjects.size(); i++){
if(!((viewingVolume.min.x >= gameObjects.at(i).bb.max.x) || (viewingVolume.max.x <= gameObjects.at(i).bb.min.x)
|| (viewingVolume.min.y >= gameObjects.at(i).bb.max.y) || (viewingVolume.max.y <= gameObjects.at(i).bb.min.y)
|| (viewingVolume.min.z >= gameObjects.at(i).bb.max.z) || (viewingVolume.max.z <= gameObjects.at(i).bb.min.z)))
{

//setDebugText("inside box!!!!");
visibleObjects.push_back(&gameObjects.at(i));
}
}
}


Thanks for the hint!

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!