[C++] Collision Handling

Started by
1 comment, last by Dawoodoz 12 years, 6 months ago
I guess a few things to start off with, I'm using C++.

Alright, I have this class called ObjectHandler, which pretty much handles all the game objects. A game Object is defined as anything with a loop() and render() function as well as collision functions. The ObjectHandler stores all the Objects in a vector that when you call the ObjectHandler's loop() or render() functions it then calls every Objects loop() or render() functions.

Now, when calling the loop command the ObjectHandler gives itself to the object (like calling Object.loop(ObjectHandler this) so that the Object can use the ObjectHandler to check collisions with all other objects. The problem here is that if I call the ObjectHandler for a collision check I cannot check for specific subclasses of Object without creating separate functions and separate vectors.

So for a gist here's some psuedocode for what I want to do:



bool ObjectHandler::collision(class x)

{

for(int i=0;i<ObjVect.size;i++)

{

if(ObjVect could be considered an x && ObjVect->collision())

{

return true;

}

}

return false;

}



Now of course collision would have a few more variables to pass in, but I believe this gets the point across of what I want to do.

Now I hear there is an easy way of doing this in C#, but I also hear that if you ever have to call a function to tell if a certain object is a certain class then you have design flaws. So I'm wondering if doing it like this is a major flaw in design and would be greatful if you could point me towards some faqs or give some advice if you believe that is the case.
Advertisement
http://t-machine.org...lopment-part-1/

You should put a representation of all objects that can collide in a seperate container and use that container for your collision code, not ObjVec.
Static - Static
Do nothing to save 99% of the time

Dynamic - Static
Use a grid or tile array

Dynamic - Dynamic
Use heap sort with the X dimension before letting each item test collisions to the neighbours.
Continue in each direction until the biggest item would not collide from that distance using the fact that abs(X) <= sqrt(X^2 + Y^2 + Z^2).

This topic is closed to new replies.

Advertisement