From cdd9a7e353d218d6a33c493ebfd361f6b25164fe Mon Sep 17 00:00:00 2001 From: HumanoidSandvichDispenser Date: Sun, 1 Mar 2026 12:17:53 -0800 Subject: [PATCH] Add bounding box for selected entity --- as4/as4.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/as4/as4.cpp b/as4/as4.cpp index 54eb2ec..68e02ba 100644 --- a/as4/as4.cpp +++ b/as4/as4.cpp @@ -20,7 +20,7 @@ #define SKYBOX_IMPLEMENTATION #include "skybox.hpp" -void DrawBoundedModel(raylib::Model &model, auto transformer) { +void DrawBoundedModel(raylib::Model &model, bool drawBoundingBox, auto transformer) { // store the original transform to apply a different transform to the // model without affecting the next time we draw raylib::Matrix oldTransform = model.GetTransform(); @@ -40,7 +40,9 @@ void DrawBoundedModel(raylib::Model &model, auto transformer) { auto box = model.GetTransformedBoundingBox(); // draw the bounding box of the model using raylib's built in function - DrawBoundingBox(box, raylib::Color::White()); + if (drawBoundingBox) { + DrawBoundingBox(box, raylib::Color::White()); + } // restore the model's transform to its original state so that the next time we // draw the model, it doesn't have the previous transform applied to it @@ -110,11 +112,11 @@ int main() { std::vector entities; - Entity &ePenguin = entities.emplace_back(); - ePenguin.model = &penguin; + Entity &p1 = entities.emplace_back(); + p1.model = &penguin; - Entity &eEagle = entities.emplace_back(); - eEagle.model = &eagle; + Entity &p2 = entities.emplace_back(); + p2.model = &penguin; // penguin physics raylib::Vector3 position = { 0, 0, 0 }; @@ -201,10 +203,13 @@ int main() { ground.Draw({ 0, 0, 0 }, 1.0f, raylib::Color::White()); - for (Entity &e : entities) { + for (size_t i = 0; i < entities.size(); ++i) { + Entity &e = entities[i]; e.position += from_magnitude_and_heading(e.speed, e.heading) * dt; - DrawBoundedModel(*e.model, [&e](raylib::Matrix transform) { + bool drawBox = (int)i == selectedIdx; + + DrawBoundedModel(*e.model, drawBox, [&e](raylib::Matrix transform) { return transform .RotateY(e.heading) .Scale(40, 40, 40)