Doing Collision management

I have made a Collider class.

It has Three overlap bool functions for rectangle vs rectangle overlaping, rectangle vs circle overlaping and circle vs circle overlapping.

The mathematics is not that difficult when you have the seperating axis theorem and the basic knowlage of a simple circle and a rectangle.

The rectangle vs rectangle one checks to see if there is overlapping by the x-axis of the rectangle’s extension, width and height. Then it checks if it is ovelapping the y-axis. (seperating axes theorem)

RectVSRect

The circle vs circle checks it’s radius to decide wheter it’s overlaping or not.
CircleVsCircle

the circle vs rectangle was a litte trickyer to figure out. I Think I got it right though, same idea as rectangle vs rectangle only this time the other rectangle is a circle.

RectVsCircle

I Do NOT know if they work. I have not been able to try them yet!!!!!!!!!!!!!!!!!!!!!!!!

Then I started a Little bit on the CollisionManger class.

I wanted to use a vectorarray with pointers to colliders(the class I just did) so I made one. Then I figured I’d like to add some Colliders to it… This is where it become difficult for me. I dont exactly know how I want to do it yet. But what I did was an Attach function that takes a Collider pointer as a parameter and push it into the vector Array.

void CollisionManager::AttachCollider(Collider* p_collider)
{
m_axColliders.push_back(p_collider);
}

Besides from that, it has a constructor (currently not doing anything) and a cleanup iterating through the Collider vector and deletes the elements.

void CollisionManager::Cleanup()
{
auto it = m_axColliders.begin();
while (it != m_axColliders.end())
{
delete (*it);
it++;
}
m_axColliders.clear();
}

My thoughts on having a vector with colliders are simply I can check collisions with every collider at one Place and do the right things to them when they happen. I am not doing anything more tonihgt because I am not sure if I shold have two types of vectors. one for rectangular ones and one for the circles. I am leaning on the desition not to do that. Because my colliders have overloaded constructors, one taking in 2 Vector2f’s, position and extension. The other takes in a float called radius… hmm, maybe I should let that one have a position as well..

Any way, the Idea was to have both circle colliders and rectangle colliders. And since they are defined as either one or the other when you create them it should be enough to have only one vector for them.. But then the checking of collision types will be pretty tough. at least for me. Yeah, time to sleep. Just spamming my mind about this a Little bit. Good for reflectiong over the work, I’ve found.

laters.

Leave a comment