Add bounding box for selected entity
parent
c02cb4ca20
commit
cdd9a7e353
19
as4/as4.cpp
19
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
|
||||
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<Entity> 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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue