Jump to content

  • Log In with Google      Sign In   
  • Create Account


Best way to store collision detection BBs


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 MrKyleMann175   Members   -  Reputation: 104

Like
0Likes
Like

Posted 23 May 2014 - 07:59 AM

Hi, okay so ive got got a 3d game with a lot of wall and objects that i want to have collision detection and resolution with, so far ive been using bounding boxes like this:

 

        //Right bunker wall
        if(playerX > nuclearBunkerX + 7 && playerX < nuclearBunkerX + 8
        && playerY > nuclearBunkerY - 8 && playerY < nuclearBunkerY + 6
        && playerZ > nuclearBunkerZ - 3 && playerZ < nuclearBunkerZ + 16.3)
        {
            playerWallCollisionResolution();
        }

 

but having all these bounding boxes takes up a lot of space meaning it takes me longer to find different parts of code, has anyone got any ways that they use bounding boxes while still being able to keep the BBs from filling up my code, for example maybe i could have a text file that i read in to my program that contains all the BBs and then have a for loop running through them? has anyone done it and been successful doing it this way?

 

Thanks :)



Sponsor:

#2 Waterlimon   Crossbones+   -  Reputation: 2456

Like
7Likes
Like

Posted 23 May 2014 - 08:17 AM

It doesnt really need to be a text file if you can just separate the bounding box definition code to its own source/header file, or wherever that information can be hidden without getting on the way.

 

How is your game structured? The example you posted has some magic numbers (which should probably be defined elsewhere, maybe not in a separate text file but elsewhere in the codebase), doesnt have any vector class or bounding box class to make the operations neater, and the check against a single object in the scene has been hardcoded.

 

-Make a Vector class to represent positions, so you dont have to do everything 3 times once for each dimension.

-Make a bounding box class to represent bounding boxes for the same reason

(So you can do if (nuclearBunkerBB.contains(player.position)) to check if the player is in the box)

-Try to abstract the collision code such that all objects are treated equal if possible. Most objects probably behave pretty much the same regarding collision, so you can have a vector<Collider> which you loop over to check for collisions. If you need object specific collision responses, you can give each Collider a callback function or something similiar which allows you to implement these custom behaviors.

-Define the magic numbers and such so that the logic isnt filled with them. This is somewhere where you define what a nuclearbunker is, or what a player is. These definitions can be loaded from disk, or they can be defined in code (Eg you could do something like have a vector of object types, each one identified by some enum, and each object type tells its dimensions and any other relevant information)


o3o


#3 Irlan   Members   -  Reputation: 1454

Like
0Likes
Like

Posted 26 May 2014 - 01:54 PM

Search for AABB Collision Detection. The Real Time Collision Detection's book goes deep on the subject.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS