Add bounding box for selected entity
parent
c02cb4ca20
commit
cdd9a7e353
21
as4/as4.cpp
21
as4/as4.cpp
|
|
@ -20,7 +20,7 @@
|
||||||
#define SKYBOX_IMPLEMENTATION
|
#define SKYBOX_IMPLEMENTATION
|
||||||
#include "skybox.hpp"
|
#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
|
// store the original transform to apply a different transform to the
|
||||||
// model without affecting the next time we draw
|
// model without affecting the next time we draw
|
||||||
raylib::Matrix oldTransform = model.GetTransform();
|
raylib::Matrix oldTransform = model.GetTransform();
|
||||||
|
|
@ -40,7 +40,9 @@ void DrawBoundedModel(raylib::Model &model, auto transformer) {
|
||||||
auto box = model.GetTransformedBoundingBox();
|
auto box = model.GetTransformedBoundingBox();
|
||||||
|
|
||||||
// draw the bounding box of the model using raylib's built in function
|
// 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
|
// 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
|
// draw the model, it doesn't have the previous transform applied to it
|
||||||
|
|
@ -110,11 +112,11 @@ int main() {
|
||||||
|
|
||||||
std::vector<Entity> entities;
|
std::vector<Entity> entities;
|
||||||
|
|
||||||
Entity &ePenguin = entities.emplace_back();
|
Entity &p1 = entities.emplace_back();
|
||||||
ePenguin.model = &penguin;
|
p1.model = &penguin;
|
||||||
|
|
||||||
Entity &eEagle = entities.emplace_back();
|
Entity &p2 = entities.emplace_back();
|
||||||
eEagle.model = &eagle;
|
p2.model = &penguin;
|
||||||
|
|
||||||
// penguin physics
|
// penguin physics
|
||||||
raylib::Vector3 position = { 0, 0, 0 };
|
raylib::Vector3 position = { 0, 0, 0 };
|
||||||
|
|
@ -201,10 +203,13 @@ int main() {
|
||||||
|
|
||||||
ground.Draw({ 0, 0, 0 }, 1.0f, raylib::Color::White());
|
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;
|
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
|
return transform
|
||||||
.RotateY(e.heading)
|
.RotateY(e.heading)
|
||||||
.Scale(40, 40, 40)
|
.Scale(40, 40, 40)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue