Basic hit detection

This commit is contained in:
2023-03-21 14:42:54 -07:00
parent 3a790e57c9
commit 978c420046
20 changed files with 343 additions and 41 deletions

View File

@@ -9,6 +9,8 @@
#include "scene/Scene.hpp"
#include "scene/components/physics/3d/Collider3D.hpp"
#include "scene/components/physics/3d/CubeCollider.hpp"
#include "scene/components/physics/2d/Collider2D.hpp"
#include "scene/components/physics/2d/BoxCollider.hpp"
using namespace Dawn;
@@ -162,4 +164,40 @@ void Scene::debugHitboxes() {
}
++itColliders;
}
auto colliders2d = this->findComponents<Collider2D>();
auto itColliders2 = colliders2d.begin();
while(itColliders2 != colliders2d.end()) {
auto c = *itColliders2;
switch(c->getColliderType()) {
case COLLIDER2D_TYPE_BOX:
auto asBox = dynamic_cast<BoxCollider*>(c);
this->debugLine({
.v0 = glm::vec3(asBox->min.x, 0, asBox->min.y),
.v1 = glm::vec3(asBox->max.x, 0, asBox->min.y),
.color = COLOR_BLUE,
.transform = c->transform->getWorldTransform()
});
this->debugLine({
.v0 = glm::vec3(asBox->max.x, 0, asBox->min.y),
.v1 = glm::vec3(asBox->max.x, 0, asBox->max.y),
.color = COLOR_BLUE,
.transform = c->transform->getWorldTransform()
});
this->debugLine({
.v0 = glm::vec3(asBox->max.x, 0, asBox->max.y),
.v1 = glm::vec3(asBox->min.x, 0, asBox->max.y),
.color = COLOR_BLUE,
.transform = c->transform->getWorldTransform()
});
this->debugLine({
.v0 = glm::vec3(asBox->min.x, 0, asBox->max.y),
.v1 = glm::vec3(asBox->min.x, 0, asBox->min.y),
.color = COLOR_BLUE,
.transform = c->transform->getWorldTransform()
});
break;
}
++itColliders2;
}
}