67 lines
1.5 KiB
C++
67 lines
1.5 KiB
C++
// Copyright (c) 2023 Dominic Masters
|
|
//
|
|
// This software is released under the MIT License.
|
|
// https://opensource.org/licenses/MIT
|
|
|
|
#include "Collider2D.hpp"
|
|
#include "BoxCollider.hpp"
|
|
|
|
using namespace Dawn;
|
|
|
|
Collider2D::Collider2D(SceneItem *i) : SceneItemComponent(i) {
|
|
|
|
}
|
|
|
|
bool_t Collider2D::getCollidingResult(
|
|
glm::vec2 movement,
|
|
Collider2D *other,
|
|
glm::vec2 &normal,
|
|
float_t &entryTime,
|
|
float_t &exitTime,
|
|
glm::vec2 &entryPoint,
|
|
glm::vec2 &exitPoint
|
|
) {
|
|
assertNotNull(other);
|
|
if(movement.x == 0 && movement.y == 0) return false;
|
|
|
|
auto localPos = this->transform->getLocalPosition();
|
|
glm::vec2 myPos(localPos.x, localPos.z);
|
|
|
|
|
|
// Check what THIS is
|
|
switch(this->getColliderType()) {
|
|
case COLLIDER2D_TYPE_BOX: {
|
|
auto box1 = dynamic_cast<BoxCollider*>(this);
|
|
assertNotNull(box1);
|
|
|
|
// Box VS ?
|
|
switch(other->getColliderType()) {
|
|
case COLLIDER2D_TYPE_BOX: {
|
|
auto box2 = dynamic_cast<BoxCollider*>(other);
|
|
assertNotNull(box2);
|
|
auto localPos2 = box2->transform->getLocalPosition();
|
|
glm::vec2 otherPos(localPos2.x, localPos2.z);
|
|
|
|
return boxCheckCollision(
|
|
myPos, box1->min, box1->max,
|
|
otherPos, box2->min, box2->max,
|
|
movement,
|
|
normal, entryTime, exitTime, entryPoint, exitPoint
|
|
);
|
|
}
|
|
|
|
default: {
|
|
assertUnreachable();
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
|
|
default: {
|
|
assertUnreachable();
|
|
}
|
|
}
|
|
|
|
assertUnreachable();
|
|
return false;
|
|
} |