Dawn/archive/physics_components/2d/TriggerController2D.cpp

51 lines
1.8 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(std::weak_ptr<SceneItem> i) : SceneItemComponent(i) {
}
std::vector<std::shared_ptr<SceneItemComponent>> TriggerController2D::getDependencies() {
return {
(this->collider = this->item.lock()->getComponent<Collider2D>())
};
}
bool_t TriggerController2D::getCollidingResult(std::shared_ptr<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 = std::static_pointer_cast<BoxCollider>(movingObject);
assertNotNull(box1, "TriggerController2D::getCollidingResult: Moving object is not a BoxCollider");
// Box VS ?
switch(collider->getColliderType()) {
case COLLIDER2D_TYPE_BOX: {
auto box2 = std::static_pointer_cast<BoxCollider>(collider);
assertNotNull(box2, "TriggerController2D::getCollidingResult: Collider is not a BoxCollider");
return boxIsBoxColliding(
physics3Dto2D(box1->item.lock()->getWorldPosition()), box1->min, box1->max,
physics3Dto2D(box2->item.lock()->getWorldPosition()), box2->min, box2->max
);
}
default: {
assertUnreachable("TriggerController2D::getCollidingResult: Collider type not implemented");
}
}
}
default: {
assertUnreachable("TriggerController2D::getCollidingResult: Moving object type not implemented");
return false;
}
}
}