diff --git a/engine/samples/collisions/main.cpp b/engine/samples/collisions/main.cpp index 201ae59544..29632e91cf 100644 --- a/engine/samples/collisions/main.cpp +++ b/engine/samples/collisions/main.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -61,7 +62,7 @@ static void addColliders(Write state, Commands commands) { state->a = commands.create() .add(Collider{}) - .add(BoxCollisionShape{}) + .add(CapsuleCollisionShape{{0.5F, 1.0F}}) .add(LocalToWorld{}) .add(Position{glm::vec3{0.0F, 0.0F, -2.0F}}) .add(Rotation{}) @@ -111,7 +112,8 @@ static void updateCollided(Query> query, Write state, Read { for (auto [entity, collider] : query) { - for (const auto& [collider1, collider2] : collisions->candidates(BroadPhaseCollisions::CollisionType::BoxBox)) + for (const auto& [collider1, collider2] : + collisions->candidates(BroadPhaseCollisions::CollisionType::BoxCapsule)) { if (collider1 == entity || collider2 == entity) { @@ -122,11 +124,11 @@ static void updateCollided(Query> query, Write state, Read } } -static void render(Query, Read, Read> query) +static void render(Query, Read> query) { - for (auto [entity, localToWorld, collider, shape] : query) + for (auto [entity, localToWorld, collider] : query) { - cubos::core::gl::Debug::drawWireBox(shape->box, localToWorld->mat * collider->transform); + cubos::core::gl::Debug::drawWireBox(collider->localAABB.box(), localToWorld->mat * collider->transform); cubos::core::gl::Debug::drawWireBox(collider->worldAABB.box(), glm::translate(glm::mat4{1.0}, collider->worldAABB.center()), glm::vec3{1.0, 0.0, 0.0}); diff --git a/engine/src/cubos/engine/collisions/broad_phase.cpp b/engine/src/cubos/engine/collisions/broad_phase.cpp index d2bc7df613..fa53ee1263 100644 --- a/engine/src/cubos/engine/collisions/broad_phase.cpp +++ b/engine/src/cubos/engine/collisions/broad_phase.cpp @@ -21,8 +21,19 @@ void setupNewBoxes(Query, Write> query, Write< void setupNewCapsules(Query, Write> query, Write collisions) { - (void)query; - (void)collisions; + for (auto [entity, shape, collider] : query) + { + if (collider->fresh) + { + collisions->addEntity(entity); + + collider->localAABB = shape->capsule.aabb(); + + collider->margin = 0.0F; + + collider->fresh = false; + } + } } void updateAABBs(Query, Write> query)