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.
Here is what I have so far: It's a rough start, a lot of holes, and very incomplete.
void Physics::Update(std::vector<Renderable_Object*> & Game_Objects)
{
for (int i = 0; i++ i < Game_Objects.end())
{
for (int j = 0; j++; j < Game_Objects.end())
{
if (i == j){ j++; }
if (Game_Objects->AABB)
{
if (Game_Objects[j]->AABB)
{
if(collision2d(Game_Objects->getMinimum(), Game_Objects->getMaximum(),
Game_Objects[j]->getMinimum(), Game_Objects[j]->getMaximum()))
{
reverse_x_velocity(Game_Objects->getVelocity());
}
}
}
}
}
}
Here is my renderable object abstraction: Also pretty basic, probably not pretty, but functional at this point.
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
};
Does this look like a right step in the direction I'm trying to go? Any tips or hints?