51 lines
1.7 KiB
C++
51 lines
1.7 KiB
C++
// Copyright (c) 2023 Dominic Masters
|
|
//
|
|
// This software is released under the MIT License.
|
|
// https://opensource.org/licenses/MIT
|
|
|
|
#include "TriggerController2D.hpp"
|
|
|
|
using namespace Dawn;
|
|
|
|
TriggerController2D::TriggerController2D(SceneItem *i) : SceneItemComponent(i) {
|
|
|
|
}
|
|
|
|
std::vector<SceneItemComponent*> TriggerController2D::getDependencies() {
|
|
return {
|
|
(this->collider = this->item->getComponent<Collider2D>())
|
|
};
|
|
}
|
|
|
|
bool_t TriggerController2D::getCollidingResult(Collider2D* movingObject) {
|
|
assertNotNull(this->collider, "TriggerController2D::getCollidingResult: Collider cannot be null");
|
|
assertNotNull(movingObject, "TriggerController2D::getCollidingResult: Moving object cannot be null");
|
|
|
|
switch(movingObject->getColliderType()) {
|
|
case COLLIDER2D_TYPE_BOX: {
|
|
auto box1 = dynamic_cast<BoxCollider*>(movingObject);
|
|
assertNotNull(box1, "TriggerController2D::getCollidingResult: Moving object is not a BoxCollider");
|
|
|
|
// Box VS ?
|
|
switch(collider->getColliderType()) {
|
|
case COLLIDER2D_TYPE_BOX: {
|
|
auto box2 = dynamic_cast<BoxCollider*>(collider);
|
|
assertNotNull(box2, "TriggerController2D::getCollidingResult: Collider is not a BoxCollider");
|
|
return boxIsBoxColliding(
|
|
physics3Dto2D(box1->transform->getWorldPosition()), box1->min, box1->max,
|
|
physics3Dto2D(box2->transform->getWorldPosition()), box2->min, box2->max
|
|
);
|
|
}
|
|
|
|
default: {
|
|
assertUnreachable("TriggerController2D::getCollidingResult: Collider type not implemented");
|
|
}
|
|
}
|
|
}
|
|
|
|
default: {
|
|
assertUnreachable("TriggerController2D::getCollidingResult: Moving object type not implemented");
|
|
return false;
|
|
}
|
|
}
|
|
} |