So, I want my Update function in my Physics class to be pretty powerful, perhaps I'm asking too much, but I want it to loop through a box of objects that are currently in play (for instance, a pong ball and two paddles to start). I want it to perform collision checks between all relevant objects, keeping in mind ultimately I plan on having more than just a pong ball and two paddles. It seems overkill for pong, yes this I know, but I'm looking at the future.
Hmmm, I think this is the most I can write before field testing this thing.
I would love if anyone with half an idea of what I'm trying to do could point out any obvious logical errors that I'm missing!
This is the function
This is the Renderable_Object classCode:void Physics::Update(std::vector<Renderable_Object*> & Game_Objects) { for (int i = 0; i++ i < Game_Objects.end()) { if (Game_Objects[i]->isPhysical) { for (int j = 0; j++; j < Game_Objects.end()) { if (i == j) { j++; } else if (Game_Objects[i]->AABB) { if (Game_Objects[j]->isPhysical) { if (Game_Objects[j]->AABB) { if(collision2d(Game_Objects[i]->getMinimum(), Game_Objects[i]->getMaximum(), Game_Objects[j]->getMinimum(), Game_Objects[j]->getMaximum())) { //do stuff } else { j++; } } else { if(planeIntersection2d(Game_Objects[j], Game_Objects[i]->getLocation())) { //do other stuff } else { j++; } } } else { j++; } } } } else { i++; } } }
Code:class Renderable_Object { public: Renderable_Object(float minX, float minY, float maxX, float maxY, float posX, float posY, bool visible, bool physical) { d_min.x = minX; d_min.y = minY; d_max.x = maxX; d_max.y = maxY; position.x = posX; position.y = posY; isVisible = visible; isPhysical = physical; velocity.x = 0; velocity.y = 0; } Vector2 & getVelocity() { return velocity; } void setVelocity(float x, float y) { velocity.x = x; velocity.y = y; } Vector2 & getLocation() { return position; } Vector2 & getMinimum() { return d_min; } Vector2 & getMaximum() { return d_max; } private: Vector2 position; Vector2 velocity; Vector2 d_min; Vector2 d_max; bool isPhysical; // does this object use collision at all? bool isVisible; // render this object? bool AABB; //compatible with AABB collision detection };