From dd89bc99a722a4fecf589f9feedd4e6563b1848f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Fonseca?= Date: Wed, 4 Oct 2023 21:58:20 +0100 Subject: [PATCH 1/9] refactor(collisions): separate collider from shapes --- .../include/cubos/engine/collisions/aabb.hpp | 4 +- .../cubos/engine/collisions/collider.hpp | 23 +++++++++ .../cubos/engine/collisions/colliders/box.hpp | 31 ------------ .../engine/collisions/colliders/capsule.hpp | 25 ---------- .../cubos/engine/collisions/shapes/box.hpp | 24 ++++++++++ .../engine/collisions/shapes/capsule.hpp | 17 +++++++ engine/samples/collisions/main.cpp | 18 +++---- .../cubos/engine/collisions/broad_phase.cpp | 48 ++++++++++++------- .../cubos/engine/collisions/broad_phase.hpp | 32 ++++++------- engine/src/cubos/engine/collisions/plugin.cpp | 13 +++-- 10 files changed, 128 insertions(+), 107 deletions(-) create mode 100644 engine/include/cubos/engine/collisions/collider.hpp delete mode 100644 engine/include/cubos/engine/collisions/colliders/box.hpp delete mode 100644 engine/include/cubos/engine/collisions/colliders/capsule.hpp create mode 100644 engine/include/cubos/engine/collisions/shapes/box.hpp create mode 100644 engine/include/cubos/engine/collisions/shapes/capsule.hpp diff --git a/engine/include/cubos/engine/collisions/aabb.hpp b/engine/include/cubos/engine/collisions/aabb.hpp index 4ab19b2572..c6de91c36b 100644 --- a/engine/include/cubos/engine/collisions/aabb.hpp +++ b/engine/include/cubos/engine/collisions/aabb.hpp @@ -13,9 +13,9 @@ namespace cubos::engine { - /// @brief Component which stores the AABB of an entity with a collider component. + /// @brief AABB of a collider. /// @ingroup collisions-plugin - struct [[cubos::component("cubos/aabb", VecStorage)]] ColliderAABB + struct ColliderAABB { /// @brief Minimum point of the diagonal of the AABB. glm::vec3 min = glm::vec3{-INFINITY}; diff --git a/engine/include/cubos/engine/collisions/collider.hpp b/engine/include/cubos/engine/collisions/collider.hpp new file mode 100644 index 0000000000..7c83eb2a6b --- /dev/null +++ b/engine/include/cubos/engine/collisions/collider.hpp @@ -0,0 +1,23 @@ +/// @file +/// @brief Component @ref cubos::engine::Collider. +/// @ingroup collisions-plugin + +#pragma once + +#include + +#include + +namespace cubos::engine +{ + /// @brief Component which adds a collider to an entity. + /// @ingroup collisions-plugin + struct [[cubos::component("cubos/collider", VecStorage)]] Collider + { + glm::mat4 transform{1.0F}; ///< Transform of the collider. + + bool fresh = true; ///< Whether the collider is fresh. This is an hack and should be done in ECS. + ColliderAABB localAABB; ///< Local space AABB of the collider. + ColliderAABB worldAABB; ///< World space AABB of the collider. + }; +} // namespace cubos::engine diff --git a/engine/include/cubos/engine/collisions/colliders/box.hpp b/engine/include/cubos/engine/collisions/colliders/box.hpp deleted file mode 100644 index 24fce6a979..0000000000 --- a/engine/include/cubos/engine/collisions/colliders/box.hpp +++ /dev/null @@ -1,31 +0,0 @@ -/// @file -/// @brief Component @ref cubos::engine::BoxCollider. -/// @ingroup collisions-plugin - -#pragma once - -#include - -namespace cubos::engine -{ - /// @brief Component which adds a box collider to an entity. - /// - /// - Convex: For any 2 points inside the shape, the line segment connecting those points lies - /// inside the shape. - /// - Positive margin: Requires a positive margin to round off sharp corners. Defined in - /// physics-space units. - /// - /// @ingroup collisions-plugin - struct [[cubos::component("cubos/box_collider", VecStorage)]] BoxCollider - { - glm::mat4 transform{1.0F}; ///< Transform of the collider. - cubos::core::geom::Box shape; ///< Box shape of the collider. - - /// @brief Margin of the collider. Needed for collision stability. - /// - /// The collider margin avoids collision errors by rounding off sharp corners. It is - /// absolute so the collider's transform won't affect it. Shouldn't be changed without good - /// reason, as it's preferable to scale down the collider to account for it. - float margin = 0.04F; - }; -} // namespace cubos::engine diff --git a/engine/include/cubos/engine/collisions/colliders/capsule.hpp b/engine/include/cubos/engine/collisions/colliders/capsule.hpp deleted file mode 100644 index a8a696ab84..0000000000 --- a/engine/include/cubos/engine/collisions/colliders/capsule.hpp +++ /dev/null @@ -1,25 +0,0 @@ -/// @file -/// @brief Component @ref cubos::engine::CapsuleCollider. -/// @ingroup collisions-plugin - -#pragma once - -#include - -#include - -namespace cubos::engine -{ - /// @brief Component which adds a capsule collider to an entity. - /// - /// - Convex: For any 2 points inside the shape, the line segment connecting those points lies - /// inside the shape. - /// - Zero margin: No margin is needed, since the shape has no sharp corners. - /// - /// @ingroup collisions-plugin - struct [[cubos::component("cubos/capsule_collider", VecStorage)]] CapsuleCollider - { - glm::mat4 transform{1.0F}; ///< Transform of the collider. - cubos::core::geom::Capsule shape; ///< Capsule shape of the collider. - }; -} // namespace cubos::engine diff --git a/engine/include/cubos/engine/collisions/shapes/box.hpp b/engine/include/cubos/engine/collisions/shapes/box.hpp new file mode 100644 index 0000000000..d41c1cca33 --- /dev/null +++ b/engine/include/cubos/engine/collisions/shapes/box.hpp @@ -0,0 +1,24 @@ +/// @file +/// @brief Component @ref cubos::engine::BoxCollisionShape. +/// @ingroup collisions-plugin + +#pragma once + +#include + +namespace cubos::engine +{ + /// @brief Component which adds a box collision shape to an entity, used with a collider component. + /// @ingroup collisions-plugin + struct [[cubos::component("cubos/box_collision_shape", VecStorage)]] BoxCollisionShape + { + cubos::core::geom::Box shape; ///< Box shape. + + /// @brief Margin of the collider. Needed for collision stability. + /// + /// The collider margin avoids collision errors by rounding off sharp corners. It is + /// absolute so the collider's transform won't affect it. Shouldn't be changed without good + /// reason, as it's preferable to scale down the collider shape to account for it. + float margin = 0.04F; + }; +} // namespace cubos::engine diff --git a/engine/include/cubos/engine/collisions/shapes/capsule.hpp b/engine/include/cubos/engine/collisions/shapes/capsule.hpp new file mode 100644 index 0000000000..b0285801fb --- /dev/null +++ b/engine/include/cubos/engine/collisions/shapes/capsule.hpp @@ -0,0 +1,17 @@ +/// @file +/// @brief Component @ref cubos::engine::CapsuleCollisionShape. +/// @ingroup collisions-plugin + +#pragma once + +#include + +namespace cubos::engine +{ + /// @brief Component which adds a capsule collision shape to an entity, used with a collider component. + /// @ingroup collisions-plugin + struct [[cubos::component("cubos/capsule_collision_shape", VecStorage)]] CapsuleCollisionShape + { + cubos::core::geom::Capsule shape; ///< Capsule shape. + }; +} // namespace cubos::engine diff --git a/engine/samples/collisions/main.cpp b/engine/samples/collisions/main.cpp index 222b498bea..fd71a01883 100644 --- a/engine/samples/collisions/main.cpp +++ b/engine/samples/collisions/main.cpp @@ -6,8 +6,9 @@ #include #include -#include +#include #include +#include #include #include #include @@ -60,7 +61,7 @@ static void init(Commands commands, Write input, Write cam static void addColliders(Write state, Commands commands) { state->a = commands.create() - .add(BoxCollider{}) + .add(BoxCollisionShape{}) .add(LocalToWorld{}) .add(Position{glm::vec3{0.0F, 0.0F, -2.0F}}) .add(Rotation{}) @@ -68,7 +69,7 @@ static void addColliders(Write state, Commands commands) state->aRotationAxis = glm::sphericalRand(1.0F); state->b = commands.create() - .add(BoxCollider{}) + .add(BoxCollisionShape{}) .add(LocalToWorld{}) .add(Position{glm::vec3{0.0F, 0.0F, 2.0F}}) .add(Rotation{}) @@ -105,7 +106,7 @@ static void updateTransform(Write state, Read input, Queryvec += glm::vec3{0.0F, 0.0F, -0.01F}; } -static void updateCollided(Query> query, Write state, Read collisions) +static void updateCollided(Query> query, Write state, Read collisions) { for (auto [entity, collider] : query) { @@ -120,12 +121,13 @@ static void updateCollided(Query> query, Write state, R } } -static void render(Query, Read, Read> query) +static void render(Query, Read, Read> query) { - for (auto [entity, localToWorld, collider, aabb] : query) + for (auto [entity, localToWorld, collider, shape] : query) { - cubos::core::gl::Debug::drawWireBox(collider->shape, localToWorld->mat * collider->transform); - cubos::core::gl::Debug::drawWireBox(aabb->box(), glm::translate(glm::mat4{1.0}, aabb->center()), + cubos::core::gl::Debug::drawWireBox(shape->shape, 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 f83586ddb3..9e81e893ac 100644 --- a/engine/src/cubos/engine/collisions/broad_phase.cpp +++ b/engine/src/cubos/engine/collisions/broad_phase.cpp @@ -1,14 +1,24 @@ #include "broad_phase.hpp" +using cubos::engine::ColliderAABB; + using CollisionType = BroadPhaseCollisions::CollisionType; -void updateBoxAABBs(Query, Read, Write> query) +void updateBoxAABBs(Query, Read, Write> query) { - for (auto [entity, localToWorld, collider, aabb] : query) + for (auto [entity, localToWorld, shape, collider] : query) { + if (collider->fresh) + { + glm::vec3 diag[2]; + shape->shape.diag(diag); + collider->localAABB = ColliderAABB{diag[0], diag[1]}; + collider->fresh = false; + } + // Get the 4 points of the collider. glm::vec3 corners[4]; - collider->shape.corners4(corners); + collider->localAABB.box().corners4(corners); // Pack the 3 points of the collider into a matrix. auto points = glm::mat4{glm::vec4{corners[0], 1.0F}, glm::vec4{corners[1], 1.0F}, glm::vec4{corners[2], 1.0F}, @@ -30,22 +40,21 @@ void updateBoxAABBs(Query, Read, Writemargin}; + max += glm::vec3{shape->margin}; // Set the AABB. - aabb->max = translation + max; - aabb->min = translation - max; + collider->worldAABB = ColliderAABB{translation - max, translation + max}; } } -void updateCapsuleAABBs(Query, Read, Write> query, +void updateCapsuleAABBs(Query, Read, Read> query, Write collisions) { (void)query; (void)collisions; } -void updateMarkers(Query> query, Write collisions) +void updateMarkers(Query> query, Write collisions) { // TODO: This is parallelizable. for (glm::length_t axis = 0; axis < 3; axis++) @@ -54,10 +63,10 @@ void updateMarkers(Query> query, Write std::sort( collisions->markersPerAxis[axis].begin(), collisions->markersPerAxis[axis].end(), [axis, &query](const BroadPhaseCollisions::SweepMarker& a, const BroadPhaseCollisions::SweepMarker& b) { - auto [aAABB] = query[a.entity].value(); - auto [bAABB] = query[b.entity].value(); - auto aPos = a.isMin ? aAABB->min : aAABB->max; - auto bPos = b.isMin ? bAABB->min : bAABB->max; + auto [aCollider] = query[a.entity].value(); + auto [bCollider] = query[b.entity].value(); + auto aPos = a.isMin ? aCollider->worldAABB.min : aCollider->worldAABB.max; + auto bPos = b.isMin ? bCollider->worldAABB.min : bCollider->worldAABB.max; return aPos[axis] < bPos[axis]; }); } @@ -106,7 +115,7 @@ CollisionType getCollisionType(bool box, bool capsule) return CollisionType::CapsuleCapsule; } -void findPairs(Query, OptRead, Read> query, +void findPairs(Query, OptRead, Read> query, Write collisions) { collisions->clearCandidates(); @@ -115,10 +124,10 @@ void findPairs(Query, OptRead, ReadsweepOverlapMaps[axis]) { - auto [box, capsule, aabb] = query[entity].value(); + auto [box, capsule, collider] = query[entity].value(); for (auto& other : overlaps) { - auto [otherBox, otherCapsule, otherAabb] = query[other].value(); + auto [otherBox, otherCapsule, otherCollider] = query[other].value(); // TODO: Should this be inside the if statement? auto type = getCollisionType(box || otherBox, capsule || otherCapsule); @@ -126,19 +135,22 @@ void findPairs(Query, OptRead, ReadoverlapsY(*otherAabb) && aabb->overlapsZ(*otherAabb)) + if (collider->worldAABB.overlapsY(otherCollider->worldAABB) && + collider->worldAABB.overlapsZ(otherCollider->worldAABB)) { collisions->addCandidate(type, {entity, other}); } break; case 1: // Y - if (aabb->overlapsX(*otherAabb) && aabb->overlapsZ(*otherAabb)) + if (collider->worldAABB.overlapsX(otherCollider->worldAABB) && + collider->worldAABB.overlapsZ(otherCollider->worldAABB)) { collisions->addCandidate(type, {entity, other}); } break; case 2: // Z - if (aabb->overlapsX(*otherAabb) && aabb->overlapsY(*otherAabb)) + if (collider->worldAABB.overlapsX(otherCollider->worldAABB) && + collider->worldAABB.overlapsY(otherCollider->worldAABB)) { collisions->addCandidate(type, {entity, other}); } diff --git a/engine/src/cubos/engine/collisions/broad_phase.hpp b/engine/src/cubos/engine/collisions/broad_phase.hpp index acb1520180..856bef9e09 100644 --- a/engine/src/cubos/engine/collisions/broad_phase.hpp +++ b/engine/src/cubos/engine/collisions/broad_phase.hpp @@ -5,10 +5,10 @@ #include -#include #include -#include -#include +#include +#include +#include #include using cubos::core::ecs::Commands; @@ -17,38 +17,38 @@ using cubos::core::ecs::Query; using cubos::core::ecs::Read; using cubos::core::ecs::Write; -using cubos::engine::BoxCollider; +using cubos::engine::BoxCollisionShape; using cubos::engine::BroadPhaseCollisions; -using cubos::engine::CapsuleCollider; -using cubos::engine::ColliderAABB; +using cubos::engine::CapsuleCollisionShape; +using cubos::engine::Collider; using cubos::engine::LocalToWorld; -/// @brief Adds collision tracking to all new entities with colliders. -template -void trackNewEntities(Query, OptRead> query, Write collisions, +/// @brief Adds collider to all new entities with collision shape. +template +void trackNewEntities(Query, OptRead> query, Write collisions, Commands commands) { - // TODO: This query should eventually be replaced by Query, Without> + // TODO: This is a bit of a hack. We should detect newly added colliders instead of using them as a marker. - for (auto [entity, collider, aabb] : query) + for (auto [entity, shape, aabb] : query) { if (!aabb) { - commands.add(entity, ColliderAABB{}); + commands.add(entity, Collider{}); collisions->addEntity(entity); } } } /// @brief Updates the AABBs of all box colliders. -void updateBoxAABBs(Query, Read, Write> query); +void updateBoxAABBs(Query, Read, Write> query); /// @brief Updates the AABBs of all capsule colliders. -void updateCapsuleAABBs(Query, Read, Write> query, +void updateCapsuleAABBs(Query, Read, Read> query, Write collisions); /// @brief Updates the sweep markers of all colliders. -void updateMarkers(Query> query, Write collisions); +void updateMarkers(Query> query, Write collisions); /// @brief Performs a sweep of all colliders. void sweep(Write collisions); @@ -58,5 +58,5 @@ void sweep(Write collisions); /// @details /// TODO: This query is disgusting. We need a way to find if a component is present without reading it. /// Maybe something like Commands but for reads? -void findPairs(Query, OptRead, Read> query, +void findPairs(Query, OptRead, Read> query, Write collisions); \ No newline at end of file diff --git a/engine/src/cubos/engine/collisions/plugin.cpp b/engine/src/cubos/engine/collisions/plugin.cpp index 0c04f3838b..ba3d66e0e9 100644 --- a/engine/src/cubos/engine/collisions/plugin.cpp +++ b/engine/src/cubos/engine/collisions/plugin.cpp @@ -1,4 +1,3 @@ -#include #include #include @@ -10,13 +9,13 @@ void cubos::engine::collisionsPlugin(Cubos& cubos) cubos.addResource(); - cubos.addComponent(); - cubos.addComponent(); - cubos.addComponent(); + cubos.addComponent(); + cubos.addComponent(); + cubos.addComponent(); - cubos.system(trackNewEntities).tagged("cubos.collisions.aabb.missing"); - cubos.system(trackNewEntities).tagged("cubos.collisions.aabb.missing"); - cubos.tag("cubos.collisions.aabb.missing").before("cubos.collisions.aabb"); + cubos.system(trackNewEntities).tagged("cubos.collisions.missing"); + cubos.system(trackNewEntities).tagged("cubos.collisions.missing"); + cubos.tag("cubos.collisions.missing").before("cubos.collisions.aabb"); cubos.system(updateBoxAABBs).tagged("cubos.collisions.aabb"); cubos.system(updateCapsuleAABBs).tagged("cubos.collisions.aabb"); From 4f7e5a26a0ab3ea250166a1b67a18cf5296ae7fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Fonseca?= Date: Wed, 4 Oct 2023 22:27:05 +0100 Subject: [PATCH 2/9] refactor(collisions): shape agnostic aabb update --- .../cubos/engine/collisions/collider.hpp | 5 ++++ .../cubos/engine/collisions/shapes/box.hpp | 7 ------ engine/samples/collisions/main.cpp | 3 ++- .../cubos/engine/collisions/broad_phase.cpp | 24 +++++++++++-------- .../cubos/engine/collisions/broad_phase.hpp | 16 +++++++------ engine/src/cubos/engine/collisions/plugin.cpp | 15 ++++++------ 6 files changed, 38 insertions(+), 32 deletions(-) diff --git a/engine/include/cubos/engine/collisions/collider.hpp b/engine/include/cubos/engine/collisions/collider.hpp index 7c83eb2a6b..8d3d7f30c8 100644 --- a/engine/include/cubos/engine/collisions/collider.hpp +++ b/engine/include/cubos/engine/collisions/collider.hpp @@ -19,5 +19,10 @@ namespace cubos::engine bool fresh = true; ///< Whether the collider is fresh. This is an hack and should be done in ECS. ColliderAABB localAABB; ///< Local space AABB of the collider. ColliderAABB worldAABB; ///< World space AABB of the collider. + + /// @brief Margin of the collider. + /// + /// When the collider shape has sharp edges, a margin is needed. + float margin = 0.0F; }; } // namespace cubos::engine diff --git a/engine/include/cubos/engine/collisions/shapes/box.hpp b/engine/include/cubos/engine/collisions/shapes/box.hpp index d41c1cca33..ed5049f9a3 100644 --- a/engine/include/cubos/engine/collisions/shapes/box.hpp +++ b/engine/include/cubos/engine/collisions/shapes/box.hpp @@ -13,12 +13,5 @@ namespace cubos::engine struct [[cubos::component("cubos/box_collision_shape", VecStorage)]] BoxCollisionShape { cubos::core::geom::Box shape; ///< Box shape. - - /// @brief Margin of the collider. Needed for collision stability. - /// - /// The collider margin avoids collision errors by rounding off sharp corners. It is - /// absolute so the collider's transform won't affect it. Shouldn't be changed without good - /// reason, as it's preferable to scale down the collider shape to account for it. - float margin = 0.04F; }; } // namespace cubos::engine diff --git a/engine/samples/collisions/main.cpp b/engine/samples/collisions/main.cpp index fd71a01883..94c07e02b1 100644 --- a/engine/samples/collisions/main.cpp +++ b/engine/samples/collisions/main.cpp @@ -114,6 +114,7 @@ static void updateCollided(Query> query, Write state, Read { if (collider1 == entity || collider2 == entity) { + CUBOS_WARN("Collision detected!"); state->collided = true; break; } @@ -148,7 +149,7 @@ int main() cubos.startupSystem(addColliders); cubos.system(updateTransform).before("cubos.transform.update"); - cubos.system(updateCollided).tagged("updated").after("cubos.collisions"); + cubos.system(updateCollided).tagged("updated").after("cubos.collisions.broad"); cubos.system(render).after("updated"); cubos.run(); diff --git a/engine/src/cubos/engine/collisions/broad_phase.cpp b/engine/src/cubos/engine/collisions/broad_phase.cpp index 9e81e893ac..811fa6b509 100644 --- a/engine/src/cubos/engine/collisions/broad_phase.cpp +++ b/engine/src/cubos/engine/collisions/broad_phase.cpp @@ -4,9 +4,9 @@ using cubos::engine::ColliderAABB; using CollisionType = BroadPhaseCollisions::CollisionType; -void updateBoxAABBs(Query, Read, Write> query) +void setupBoxAABBs(Query, Write> query) { - for (auto [entity, localToWorld, shape, collider] : query) + for (auto [entity, shape, collider] : query) { if (collider->fresh) { @@ -15,7 +15,18 @@ void updateBoxAABBs(Query, Read, WritelocalAABB = ColliderAABB{diag[0], diag[1]}; collider->fresh = false; } + } +} + +void setupCapsuleAABBs(Query, Write> query) +{ + (void)query; +} +void updateAABBs(Query, Write> query) +{ + for (auto [entity, localToWorld, collider] : query) + { // Get the 4 points of the collider. glm::vec3 corners[4]; collider->localAABB.box().corners4(corners); @@ -40,20 +51,13 @@ void updateBoxAABBs(Query, Read, Writemargin}; + max += glm::vec3{collider->margin}; // Set the AABB. collider->worldAABB = ColliderAABB{translation - max, translation + max}; } } -void updateCapsuleAABBs(Query, Read, Read> query, - Write collisions) -{ - (void)query; - (void)collisions; -} - void updateMarkers(Query> query, Write collisions) { // TODO: This is parallelizable. diff --git a/engine/src/cubos/engine/collisions/broad_phase.hpp b/engine/src/cubos/engine/collisions/broad_phase.hpp index 856bef9e09..6596b6d1c8 100644 --- a/engine/src/cubos/engine/collisions/broad_phase.hpp +++ b/engine/src/cubos/engine/collisions/broad_phase.hpp @@ -30,9 +30,9 @@ void trackNewEntities(Query, OptRead> query, WriteaddEntity(entity); @@ -40,12 +40,14 @@ void trackNewEntities(Query, OptRead> query, Write, Read, Write> query); +/// @brief Setups the AABBs of all box colliders. +void setupBoxAABBs(Query, Write> query); -/// @brief Updates the AABBs of all capsule colliders. -void updateCapsuleAABBs(Query, Read, Read> query, - Write collisions); +/// @brief Setups the AABBs of all capsule colliders. +void setupCapsuleAABBs(Query, Write> query); + +/// @brief Updates the AABBs of all colliders. +void updateAABBs(Query, Write> query); /// @brief Updates the sweep markers of all colliders. void updateMarkers(Query> query, Write collisions); diff --git a/engine/src/cubos/engine/collisions/plugin.cpp b/engine/src/cubos/engine/collisions/plugin.cpp index ba3d66e0e9..d483bf409b 100644 --- a/engine/src/cubos/engine/collisions/plugin.cpp +++ b/engine/src/cubos/engine/collisions/plugin.cpp @@ -15,15 +15,16 @@ void cubos::engine::collisionsPlugin(Cubos& cubos) cubos.system(trackNewEntities).tagged("cubos.collisions.missing"); cubos.system(trackNewEntities).tagged("cubos.collisions.missing"); - cubos.tag("cubos.collisions.missing").before("cubos.collisions.aabb"); + cubos.tag("cubos.collisions.missing").before("cubos.collisions.aabb.setup"); - cubos.system(updateBoxAABBs).tagged("cubos.collisions.aabb"); - cubos.system(updateCapsuleAABBs).tagged("cubos.collisions.aabb"); - cubos.tag("cubos.collisions.aabb").after("cubos.transform.update"); + cubos.system(setupBoxAABBs).tagged("cubos.collisions.aabb.setup"); + cubos.system(setupCapsuleAABBs).tagged("cubos.collisions.aabb.setup"); + cubos.system(updateAABBs) + .after("cubos.collisions.aabb.setup") + .after("cubos.transform.update") + .before("cubos.collisions.broad.markers"); - cubos.system(updateMarkers).tagged("cubos.collisions.broad.markers").after("cubos.collisions.aabb"); + cubos.system(updateMarkers).tagged("cubos.collisions.broad.markers"); cubos.system(sweep).tagged("cubos.collisions.broad.sweep").after("cubos.collisions.broad.markers"); cubos.system(findPairs).tagged("cubos.collisions.broad").after("cubos.collisions.broad.sweep"); - - cubos.tag("cubos.collisions.broad").before("cubos.collisions"); } From e10a607f8d3cd4df0c0e46f475e31f95fa577ae6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Fonseca?= Date: Wed, 4 Oct 2023 22:51:41 +0100 Subject: [PATCH 3/9] refactor(collision): remove trackNewEntities --- .../cubos/engine/collisions/collider.hpp | 5 ++-- engine/samples/collisions/main.cpp | 3 +- .../cubos/engine/collisions/broad_phase.cpp | 10 +++++-- .../cubos/engine/collisions/broad_phase.hpp | 28 ++++--------------- engine/src/cubos/engine/collisions/plugin.cpp | 10 ++----- 5 files changed, 22 insertions(+), 34 deletions(-) diff --git a/engine/include/cubos/engine/collisions/collider.hpp b/engine/include/cubos/engine/collisions/collider.hpp index 8d3d7f30c8..c16ad9e6f2 100644 --- a/engine/include/cubos/engine/collisions/collider.hpp +++ b/engine/include/cubos/engine/collisions/collider.hpp @@ -16,13 +16,14 @@ namespace cubos::engine { glm::mat4 transform{1.0F}; ///< Transform of the collider. - bool fresh = true; ///< Whether the collider is fresh. This is an hack and should be done in ECS. ColliderAABB localAABB; ///< Local space AABB of the collider. ColliderAABB worldAABB; ///< World space AABB of the collider. /// @brief Margin of the collider. /// /// When the collider shape has sharp edges, a margin is needed. - float margin = 0.0F; + float margin; + + bool fresh = true; ///< Whether the collider is fresh. This is an hack and should be done in ECS. }; } // namespace cubos::engine diff --git a/engine/samples/collisions/main.cpp b/engine/samples/collisions/main.cpp index 94c07e02b1..459442276b 100644 --- a/engine/samples/collisions/main.cpp +++ b/engine/samples/collisions/main.cpp @@ -61,6 +61,7 @@ static void init(Commands commands, Write input, Write cam static void addColliders(Write state, Commands commands) { state->a = commands.create() + .add(Collider{}) .add(BoxCollisionShape{}) .add(LocalToWorld{}) .add(Position{glm::vec3{0.0F, 0.0F, -2.0F}}) @@ -69,6 +70,7 @@ static void addColliders(Write state, Commands commands) state->aRotationAxis = glm::sphericalRand(1.0F); state->b = commands.create() + .add(Collider{}) .add(BoxCollisionShape{}) .add(LocalToWorld{}) .add(Position{glm::vec3{0.0F, 0.0F, 2.0F}}) @@ -114,7 +116,6 @@ static void updateCollided(Query> query, Write state, Read { if (collider1 == entity || collider2 == entity) { - CUBOS_WARN("Collision detected!"); state->collided = true; break; } diff --git a/engine/src/cubos/engine/collisions/broad_phase.cpp b/engine/src/cubos/engine/collisions/broad_phase.cpp index 811fa6b509..e8d959fe47 100644 --- a/engine/src/cubos/engine/collisions/broad_phase.cpp +++ b/engine/src/cubos/engine/collisions/broad_phase.cpp @@ -4,23 +4,29 @@ using cubos::engine::ColliderAABB; using CollisionType = BroadPhaseCollisions::CollisionType; -void setupBoxAABBs(Query, Write> query) +void setupNewBoxes(Query, Write> query, Write collisions) { for (auto [entity, shape, collider] : query) { if (collider->fresh) { + collisions->addEntity(entity); + glm::vec3 diag[2]; shape->shape.diag(diag); collider->localAABB = ColliderAABB{diag[0], diag[1]}; + + collider->margin = 0.04F; + collider->fresh = false; } } } -void setupCapsuleAABBs(Query, Write> query) +void setupNewCapsules(Query, Write> query, Write collisions) { (void)query; + (void)collisions; } void updateAABBs(Query, Write> query) diff --git a/engine/src/cubos/engine/collisions/broad_phase.hpp b/engine/src/cubos/engine/collisions/broad_phase.hpp index 6596b6d1c8..51b8789b65 100644 --- a/engine/src/cubos/engine/collisions/broad_phase.hpp +++ b/engine/src/cubos/engine/collisions/broad_phase.hpp @@ -23,28 +23,12 @@ using cubos::engine::CapsuleCollisionShape; using cubos::engine::Collider; using cubos::engine::LocalToWorld; -/// @brief Adds collider to all new entities with collision shape. -template -void trackNewEntities(Query, OptRead> query, Write collisions, - Commands commands) -{ - // TODO: This is a bit of a hack. We should detect newly added colliders instead of using them as a marker. +/// @brief Setups new box colliders. +void setupNewBoxes(Query, Write> query, Write collisions); - for (auto [entity, shape, collider] : query) - { - if (!collider) - { - commands.add(entity, Collider{}); - collisions->addEntity(entity); - } - } -} - -/// @brief Setups the AABBs of all box colliders. -void setupBoxAABBs(Query, Write> query); - -/// @brief Setups the AABBs of all capsule colliders. -void setupCapsuleAABBs(Query, Write> query); +/// @brief Setups new capsule colliders. +void setupNewCapsules(Query, Write> query, + Write collisions); /// @brief Updates the AABBs of all colliders. void updateAABBs(Query, Write> query); @@ -61,4 +45,4 @@ void sweep(Write collisions); /// TODO: This query is disgusting. We need a way to find if a component is present without reading it. /// Maybe something like Commands but for reads? void findPairs(Query, OptRead, Read> query, - Write collisions); \ No newline at end of file + Write collisions); diff --git a/engine/src/cubos/engine/collisions/plugin.cpp b/engine/src/cubos/engine/collisions/plugin.cpp index d483bf409b..2fda8b64c0 100644 --- a/engine/src/cubos/engine/collisions/plugin.cpp +++ b/engine/src/cubos/engine/collisions/plugin.cpp @@ -13,14 +13,10 @@ void cubos::engine::collisionsPlugin(Cubos& cubos) cubos.addComponent(); cubos.addComponent(); - cubos.system(trackNewEntities).tagged("cubos.collisions.missing"); - cubos.system(trackNewEntities).tagged("cubos.collisions.missing"); - cubos.tag("cubos.collisions.missing").before("cubos.collisions.aabb.setup"); - - cubos.system(setupBoxAABBs).tagged("cubos.collisions.aabb.setup"); - cubos.system(setupCapsuleAABBs).tagged("cubos.collisions.aabb.setup"); + cubos.system(setupNewBoxes).tagged("cubos.collisions.setup"); + cubos.system(setupNewCapsules).tagged("cubos.collisions.setup"); cubos.system(updateAABBs) - .after("cubos.collisions.aabb.setup") + .after("cubos.collisions.setup") .after("cubos.transform.update") .before("cubos.collisions.broad.markers"); From d8b5c31a3b0c3e82d5c5737c5b2f249d1877eaf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Fonseca?= Date: Thu, 5 Oct 2023 00:20:15 +0100 Subject: [PATCH 4/9] refactor(geom): move aabb to core::geom --- core/include/cubos/core/geom/aabb.hpp | 114 ++++++++++++++++++ core/include/cubos/core/geom/capsule.hpp | 11 ++ .../include/cubos/engine/collisions/aabb.hpp | 92 -------------- .../cubos/engine/collisions/collider.hpp | 6 +- .../cubos/engine/collisions/shapes/box.hpp | 4 +- .../engine/collisions/shapes/capsule.hpp | 4 +- engine/samples/collisions/main.cpp | 3 +- .../cubos/engine/collisions/broad_phase.cpp | 15 +-- 8 files changed, 139 insertions(+), 110 deletions(-) create mode 100644 core/include/cubos/core/geom/aabb.hpp delete mode 100644 engine/include/cubos/engine/collisions/aabb.hpp diff --git a/core/include/cubos/core/geom/aabb.hpp b/core/include/cubos/core/geom/aabb.hpp new file mode 100644 index 0000000000..6164839118 --- /dev/null +++ b/core/include/cubos/core/geom/aabb.hpp @@ -0,0 +1,114 @@ +/// @file +/// @brief Component @ref cubos::core::geom::AABB. +/// @ingroup core-geom + +#pragma once + +#include + +#include + +namespace cubos::core::geom +{ + /// @brief Represents an axis-aligned bounding box. + /// @ingroup core-geom + struct AABB + { + /// @brief Diagonal of the AABB. + glm::vec3 diag[2] = {glm::vec3{-INFINITY}, glm::vec3{INFINITY}}; + + /// @brief Minimum point of the AABB. + /// @return Minimum point of the AABB. + glm::vec3 min() const + { + return diag[0]; + } + + /// @brief Maximum point of the AABB. + /// @return Maximum point of the AABB. + glm::vec3 max() const + { + return diag[1]; + } + + /// @brief Sets the minimum point of the AABB. + /// @param min Minimum point of the AABB. + void min(const glm::vec3& min) + { + diag[0] = min; + } + + /// @brief Sets the maximum point of the AABB. + /// @param max Maximum point of the AABB. + void max(const glm::vec3& max) + { + diag[1] = max; + } + + /// @brief Gets a @ref Box representation of the AABB. + /// @return @ref Box representation. + Box box() const + { + auto size = max() - min(); + return Box{size / 2.0F}; + } + + /// @brief Gets the center of the AABB. + /// @return Center of the AABB. + glm::vec3 center() const + { + return (min() + max()) / 2.0F; + } + + /// @brief Checks if the AABB overlaps with another AABB on the X axis. + /// @param other Other AABB. + /// @return Whether the AABBs overlap. + bool overlapsX(const AABB& other) const + { + return min().x <= other.max().x && max().x >= other.min().x; + } + + /// @brief Checks if the AABB overlaps with another AABB on the Y axis. + /// @param other Other AABB. + /// @return Whether the AABBs overlap. + bool overlapsY(const AABB& other) const + { + return min().y <= other.max().y && max().y >= other.min().y; + } + + /// @brief Checks if the AABB overlaps with another AABB on the Z axis. + /// @param other Other AABB. + /// @return Whether the AABBs overlap. + bool overlapsZ(const AABB& other) const + { + return min().z <= other.max().z && max().z >= other.min().z; + } + + /// @brief Checks if the AABB overlaps with another AABB. + /// @param other Other AABB. + /// @return Whether the AABBs overlap. + bool overlaps(const AABB& other) const + { + return overlapsX(other) && overlapsY(other) && overlapsZ(other); + } + }; +} // namespace cubos::core::geom + +namespace cubos::core::data::old +{ + inline void serialize(Serializer& ser, const core::geom::AABB& aabb, const char* name) + { + ser.beginObject(name); + ser.write(aabb.min(), "min"); + ser.write(aabb.max(), "max"); + ser.endObject(); + } + + inline void deserialize(Deserializer& des, core::geom::AABB& aabb) + { + des.beginObject(); + des.read(aabb.diag[0]); + des.read(aabb.diag[1]); + des.endObject(); + } +} // namespace cubos::core::data::old diff --git a/core/include/cubos/core/geom/capsule.hpp b/core/include/cubos/core/geom/capsule.hpp index 8b777f13f8..ec967b9a2a 100644 --- a/core/include/cubos/core/geom/capsule.hpp +++ b/core/include/cubos/core/geom/capsule.hpp @@ -6,6 +6,7 @@ #include #include +#include namespace cubos::core::geom { @@ -30,6 +31,16 @@ namespace cubos::core::geom { return length + 2.0F * radius; } + + /// @brief Computes the local AABB of the capsule. + /// @return Local AABB of the capsule. + AABB aabb() const + { + AABB aabb; + aabb.min({-radius, -radius, -radius}); + aabb.max({radius, radius + length, radius}); + return aabb; + } }; } // namespace cubos::core::geom diff --git a/engine/include/cubos/engine/collisions/aabb.hpp b/engine/include/cubos/engine/collisions/aabb.hpp deleted file mode 100644 index c6de91c36b..0000000000 --- a/engine/include/cubos/engine/collisions/aabb.hpp +++ /dev/null @@ -1,92 +0,0 @@ -/// @file -/// @brief Component @ref cubos::engine::ColliderAABB. -/// @ingroup collisions-plugin - -#pragma once - -#include - -#include -#include -#include -#include - -namespace cubos::engine -{ - /// @brief AABB of a collider. - /// @ingroup collisions-plugin - struct ColliderAABB - { - /// @brief Minimum point of the diagonal of the AABB. - glm::vec3 min = glm::vec3{-INFINITY}; - - /// @brief Maximum point of the diagonal of the AABB. - glm::vec3 max = glm::vec3{INFINITY}; - - /// @brief Gets a @ref core::geom::Box representation of the AABB. - /// @return @ref core::geom::Box representation. - core::geom::Box box() const - { - auto size = max - min; - return core::geom::Box{size / 2.0F}; - } - - /// @brief Gets the center of the AABB. - /// @return Center of the AABB. - glm::vec3 center() const - { - return (min + max) / 2.0F; - } - - /// @brief Checks if the AABB overlaps with another AABB on the X axis. - /// @param other Other AABB. - /// @return Whether the AABBs overlap. - bool overlapsX(const ColliderAABB& other) const - { - return min.x <= other.max.x && max.x >= other.min.x; - } - - /// @brief Checks if the AABB overlaps with another AABB on the Y axis. - /// @param other Other AABB. - /// @return Whether the AABBs overlap. - bool overlapsY(const ColliderAABB& other) const - { - return min.y <= other.max.y && max.y >= other.min.y; - } - - /// @brief Checks if the AABB overlaps with another AABB on the Z axis. - /// @param other Other AABB. - /// @return Whether the AABBs overlap. - bool overlapsZ(const ColliderAABB& other) const - { - return min.z <= other.max.z && max.z >= other.min.z; - } - - /// @brief Checks if the AABB overlaps with another AABB. - /// @param other Other AABB. - /// @return Whether the AABBs overlap. - bool overlaps(const ColliderAABB& other) const - { - return overlapsX(other) && overlapsY(other) && overlapsZ(other); - } - }; -} // namespace cubos::engine - -namespace cubos::core::data::old -{ - inline void serialize(Serializer& ser, const engine::ColliderAABB& aabb, const char* name) - { - ser.beginObject(name); - ser.write(aabb.min, "min"); - ser.write(aabb.max, "max"); - ser.endObject(); - } - - inline void deserialize(Deserializer& des, engine::ColliderAABB& aabb) - { - des.beginObject(); - des.read(aabb.min); - des.read(aabb.max); - des.endObject(); - } -} // namespace cubos::core::data::old diff --git a/engine/include/cubos/engine/collisions/collider.hpp b/engine/include/cubos/engine/collisions/collider.hpp index c16ad9e6f2..c9b609f7bf 100644 --- a/engine/include/cubos/engine/collisions/collider.hpp +++ b/engine/include/cubos/engine/collisions/collider.hpp @@ -6,7 +6,7 @@ #include -#include +#include namespace cubos::engine { @@ -16,8 +16,8 @@ namespace cubos::engine { glm::mat4 transform{1.0F}; ///< Transform of the collider. - ColliderAABB localAABB; ///< Local space AABB of the collider. - ColliderAABB worldAABB; ///< World space AABB of the collider. + core::geom::AABB localAABB{}; ///< Local space AABB of the collider. + core::geom::AABB worldAABB{}; ///< World space AABB of the collider. /// @brief Margin of the collider. /// diff --git a/engine/include/cubos/engine/collisions/shapes/box.hpp b/engine/include/cubos/engine/collisions/shapes/box.hpp index ed5049f9a3..01e6268a51 100644 --- a/engine/include/cubos/engine/collisions/shapes/box.hpp +++ b/engine/include/cubos/engine/collisions/shapes/box.hpp @@ -8,10 +8,10 @@ namespace cubos::engine { - /// @brief Component which adds a box collision shape to an entity, used with a collider component. + /// @brief Component which adds a box collision shape to an entity, used with a @ref Collider component. /// @ingroup collisions-plugin struct [[cubos::component("cubos/box_collision_shape", VecStorage)]] BoxCollisionShape { - cubos::core::geom::Box shape; ///< Box shape. + cubos::core::geom::Box box; ///< Box shape. }; } // namespace cubos::engine diff --git a/engine/include/cubos/engine/collisions/shapes/capsule.hpp b/engine/include/cubos/engine/collisions/shapes/capsule.hpp index b0285801fb..9a62f15bf5 100644 --- a/engine/include/cubos/engine/collisions/shapes/capsule.hpp +++ b/engine/include/cubos/engine/collisions/shapes/capsule.hpp @@ -8,10 +8,10 @@ namespace cubos::engine { - /// @brief Component which adds a capsule collision shape to an entity, used with a collider component. + /// @brief Component which adds a capsule collision shape to an entity, used with a @ref Collider component. /// @ingroup collisions-plugin struct [[cubos::component("cubos/capsule_collision_shape", VecStorage)]] CapsuleCollisionShape { - cubos::core::geom::Capsule shape; ///< Capsule shape. + cubos::core::geom::Capsule capsule; ///< Capsule shape. }; } // namespace cubos::engine diff --git a/engine/samples/collisions/main.cpp b/engine/samples/collisions/main.cpp index 459442276b..201ae59544 100644 --- a/engine/samples/collisions/main.cpp +++ b/engine/samples/collisions/main.cpp @@ -4,7 +4,6 @@ #include #include -#include #include #include #include @@ -127,7 +126,7 @@ static void render(Query, Read, Readshape, localToWorld->mat * collider->transform); + cubos::core::gl::Debug::drawWireBox(shape->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 e8d959fe47..d2bc7df613 100644 --- a/engine/src/cubos/engine/collisions/broad_phase.cpp +++ b/engine/src/cubos/engine/collisions/broad_phase.cpp @@ -1,7 +1,5 @@ #include "broad_phase.hpp" -using cubos::engine::ColliderAABB; - using CollisionType = BroadPhaseCollisions::CollisionType; void setupNewBoxes(Query, Write> query, Write collisions) @@ -12,9 +10,7 @@ void setupNewBoxes(Query, Write> query, Write< { collisions->addEntity(entity); - glm::vec3 diag[2]; - shape->shape.diag(diag); - collider->localAABB = ColliderAABB{diag[0], diag[1]}; + shape->box.diag(collider->localAABB.diag); collider->margin = 0.04F; @@ -60,8 +56,9 @@ void updateAABBs(Query, Write> query) max += glm::vec3{collider->margin}; // Set the AABB. - collider->worldAABB = ColliderAABB{translation - max, translation + max}; - } + collider->worldAABB.min(translation - max); + collider->worldAABB.max(translation + max); + }; } void updateMarkers(Query> query, Write collisions) @@ -75,8 +72,8 @@ void updateMarkers(Query> query, Write coll [axis, &query](const BroadPhaseCollisions::SweepMarker& a, const BroadPhaseCollisions::SweepMarker& b) { auto [aCollider] = query[a.entity].value(); auto [bCollider] = query[b.entity].value(); - auto aPos = a.isMin ? aCollider->worldAABB.min : aCollider->worldAABB.max; - auto bPos = b.isMin ? bCollider->worldAABB.min : bCollider->worldAABB.max; + auto aPos = a.isMin ? aCollider->worldAABB.min() : aCollider->worldAABB.max(); + auto bPos = b.isMin ? bCollider->worldAABB.min() : bCollider->worldAABB.max(); return aPos[axis] < bPos[axis]; }); } From daf9917ae56265188e3e420b3cdd1d1ec5d9dafb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Fonseca?= Date: Thu, 5 Oct 2023 00:20:38 +0100 Subject: [PATCH 5/9] docs(engine): better explain margin --- engine/include/cubos/engine/collisions/collider.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/engine/include/cubos/engine/collisions/collider.hpp b/engine/include/cubos/engine/collisions/collider.hpp index c9b609f7bf..013334db67 100644 --- a/engine/include/cubos/engine/collisions/collider.hpp +++ b/engine/include/cubos/engine/collisions/collider.hpp @@ -22,6 +22,7 @@ namespace cubos::engine /// @brief Margin of the collider. /// /// When the collider shape has sharp edges, a margin is needed. + /// The plugin will set it based on the shape associated with the collider. float margin; bool fresh = true; ///< Whether the collider is fresh. This is an hack and should be done in ECS. From ec61e500bc352380669d90e6bcf925eef6ee94b8 Mon Sep 17 00:00:00 2001 From: Ricardo Antunes Date: Tue, 3 Oct 2023 23:23:38 +0100 Subject: [PATCH 6/9] docs(cubos): add mising docs --- engine/include/cubos/engine/cubos.hpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/engine/include/cubos/engine/cubos.hpp b/engine/include/cubos/engine/cubos.hpp index 8795511fb7..419083659c 100644 --- a/engine/include/cubos/engine/cubos.hpp +++ b/engine/include/cubos/engine/cubos.hpp @@ -22,7 +22,8 @@ namespace cubos::engine struct DeltaTime { DeltaTime(float value); - float value; + + float value; ///< Time in seconds. }; /// @brief Resource used as a flag to indicate whether the main loop should stop running. @@ -33,7 +34,8 @@ namespace cubos::engine struct ShouldQuit { ShouldQuit(bool value); - bool value; + + bool value; ///< Whether the main loop should stop running. }; /// @brief Resource which stores the command-line arguments. @@ -44,7 +46,8 @@ namespace cubos::engine struct Arguments { Arguments(std::vector value); - const std::vector value; + + const std::vector value; ///< Command-line arguments. }; /// @brief Used to chain configurations related to tags. From c547dce0d12868460b5d2d5057e0d66e2cbcfbcb Mon Sep 17 00:00:00 2001 From: roby2014 Date: Wed, 4 Oct 2023 14:33:14 +0100 Subject: [PATCH 7/9] fix(misc): fixed `.clang-format` --- .clang-format | 1 - 1 file changed, 1 deletion(-) diff --git a/.clang-format b/.clang-format index e17cdc3bd9..aa33d224f3 100644 --- a/.clang-format +++ b/.clang-format @@ -1,7 +1,6 @@ --- BasedOnStyle: Microsoft NamespaceIndentation: All -SortIncludes: 'false' IndentWidth: 4 AccessModifierOffset: -4 DerivePointerAlignment: false From 4d8f377545151c5f4bfcc0d443ea170a549b91c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Fonseca?= Date: Thu, 5 Oct 2023 09:24:18 +0100 Subject: [PATCH 8/9] fix(geom): use vec3.hpp instead of glm.hpp --- core/include/cubos/core/geom/aabb.hpp | 2 +- core/include/cubos/core/geom/box.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/include/cubos/core/geom/aabb.hpp b/core/include/cubos/core/geom/aabb.hpp index 6164839118..98e145df91 100644 --- a/core/include/cubos/core/geom/aabb.hpp +++ b/core/include/cubos/core/geom/aabb.hpp @@ -4,7 +4,7 @@ #pragma once -#include +#include #include diff --git a/core/include/cubos/core/geom/box.hpp b/core/include/cubos/core/geom/box.hpp index 9745020181..54c1b197a1 100644 --- a/core/include/cubos/core/geom/box.hpp +++ b/core/include/cubos/core/geom/box.hpp @@ -4,7 +4,7 @@ #pragma once -#include +#include #include #include From 9eeda4110338adfba3c46f6ac138e3cbc447f845 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Fonseca?= Date: Thu, 5 Oct 2023 09:43:42 +0100 Subject: [PATCH 9/9] fix(geom): replace INFINITY by numeric_limits --- core/include/cubos/core/geom/aabb.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/include/cubos/core/geom/aabb.hpp b/core/include/cubos/core/geom/aabb.hpp index 98e145df91..64bb8a77f0 100644 --- a/core/include/cubos/core/geom/aabb.hpp +++ b/core/include/cubos/core/geom/aabb.hpp @@ -15,7 +15,8 @@ namespace cubos::core::geom struct AABB { /// @brief Diagonal of the AABB. - glm::vec3 diag[2] = {glm::vec3{-INFINITY}, glm::vec3{INFINITY}}; + glm::vec3 diag[2] = {glm::vec3{-std::numeric_limits::infinity()}, + glm::vec3{-std::numeric_limits::infinity()}}; /// @brief Minimum point of the AABB. /// @return Minimum point of the AABB.