Exemplo n.º 1
0
bool Collider::Collide(Collider* a, Collider* b)
{
    ColliderType typeA = a->GetColliderType();
    ColliderType typeB = b->GetColliderType();

    //Big nasty if/else for deciding which collision function to use
    if (typeA == CT_RECT && typeB == CT_RECT)									//Rectangle - Rectangle
        return CollideRectRect((RectangleCollider*)a, (RectangleCollider*)b);

    else if (typeA == CT_CIRCLE && typeB == CT_CIRCLE)							//Circle - Circle
        return CollideCircleCircle((CircleCollider*)a, (CircleCollider*)b);

    else if (typeA == CT_POLYGON && typeB == CT_POLYGON)						//Polygon - Polygon
        return CollidePolygonPolygon((PolygonCollider*)a, (PolygonCollider*)b);

    else if (typeA == CT_RECT && typeB == CT_CIRCLE)							//Rectangle - Circle
        return CollideRectCircle((RectangleCollider*)a, (CircleCollider*)b);
    else if (typeA == CT_CIRCLE && typeB == CT_RECT)
        return CollideRectCircle((RectangleCollider*)b, (CircleCollider*)a);

    else if (typeA == CT_RECT && typeB == CT_POLYGON)							//Rectangle - Polygon
        return CollideRectPolygon((RectangleCollider*)a, (PolygonCollider*)b);
    else if (typeA == CT_POLYGON && typeB == CT_RECT)
        return CollideRectPolygon((RectangleCollider*)b, (PolygonCollider*)a);

    else if (typeA == CT_CIRCLE && typeB == CT_POLYGON)							//Circle - Polygon
        return CollideCirclePolygon((CircleCollider*)a, (PolygonCollider*)b);
    else if (typeA == CT_POLYGON && typeB == CT_CIRCLE)
        return CollideCirclePolygon((CircleCollider*)b, (PolygonCollider*)a);

    // Unhandled case
    return false;
}
Exemplo n.º 2
0
	bool Collider::Collide(Collider* a, Collider* b, CollisionData *collisionData)
	{
		ColliderType typeA = a->GetColliderType();
		ColliderType typeB = b->GetColliderType();

		//Big nasty if/else for deciding which collision function to use
		if (typeA == CT_RECT && typeB == CT_RECT)									//Rectangle - Rectangle
			return CollideRectRect((RectangleCollider*)a, (RectangleCollider*)b, collisionData);

		else if (typeA == CT_CIRCLE && typeB == CT_CIRCLE)							//Circle - Circle
			return CollideCircleCircle((CircleCollider*)a, (CircleCollider*)b, collisionData);

		else if (typeA == CT_POLYGON && typeB == CT_POLYGON)						//Polygon - Polygon
			return CollidePolygonPolygon((PolygonCollider*)a, (PolygonCollider*)b, collisionData);

		else if (typeA == CT_RECT && typeB == CT_CIRCLE)							//Rectangle - Circle
			return CollideRectCircle((RectangleCollider*)a, (CircleCollider*)b, collisionData);
		else if (typeA == CT_CIRCLE && typeB == CT_RECT)
			return CollideRectCircle((RectangleCollider*)b, (CircleCollider*)a, collisionData);

		else if (typeA == CT_RECT && typeB == CT_POLYGON)							//Rectangle - Polygon
			return CollideRectPolygon((RectangleCollider*)a, (PolygonCollider*)b, collisionData);
		else if (typeA == CT_POLYGON && typeB == CT_RECT)
			return CollideRectPolygon((RectangleCollider*)b, (PolygonCollider*)a, collisionData);

		else if (typeA == CT_CIRCLE && typeB == CT_POLYGON)							//Circle - Polygon
			return CollideCirclePolygon((CircleCollider*)a, (PolygonCollider*)b, collisionData);
		else if (typeA == CT_POLYGON && typeB == CT_CIRCLE)
			return CollideCirclePolygon((CircleCollider*)b, (PolygonCollider*)a, collisionData);

		else if (typeA == CT_CIRCLE && typeB == CT_PATH)
			return CollideCirclePath((CircleCollider*)a, (PathCollider*)b, collisionData);
		else if (typeA == CT_PATH && typeB == CT_CIRCLE)
			return CollideCirclePath((CircleCollider*)b, (PathCollider*)a, collisionData);

		else if ((typeA == CT_RECT && typeB == CT_PATH) || (typeA == CT_PATH && typeB == CT_RECT))
		{
			Debug::Log("Warning: Collisions between Rectangle and Path not yet supported.");
		}
		else
		{
			Debug::Log("Warning: Unhandled collider pair.");
		}

		// Unhandled case
		return false;
	}