diff --git a/examples/models/models_directional_billboard.c b/examples/models/models_directional_billboard.c index 125a76dfa..533d6f5d6 100644 --- a/examples/models/models_directional_billboard.c +++ b/examples/models/models_directional_billboard.c @@ -18,6 +18,7 @@ #include "raylib.h" #include "raymath.h" +#include //------------------------------------------------------------------------------------ // Program main entry point @@ -68,9 +69,15 @@ int main(void) } // Reset frame index to zero on overflow - if (anim >= 4) + if (anim >= 4) anim = 0; + + // Find the current direction frame based on the camera position to the billboard object + float dir = (float)floor(((Vector2Angle((Vector2){ 2.0f, 0.0f }, (Vector2){ camera.position.x, camera.position.z })/PI)*4.0f) + 0.25f); + + // Correct frame index if angle is negative + if (dir < 0.0f) { - anim = 0; + dir = 8.0f - (float)abs((int)dir); } //---------------------------------------------------------------------------------- @@ -83,15 +90,6 @@ int main(void) BeginMode3D(camera); DrawGrid(10, 1.0f); - - // Find the current direction frame based on the camera position to the billboard object - float dir = (float)floor(((Vector2Angle((Vector2){ 2.0f, 0.0f }, (Vector2){ camera.position.x, camera.position.z })/PI)*4.0f) + 0.25f); - - // Correct frame index if angle is negative - if (dir < 0.0f) - { - dir = 8.0f - (float)abs((int)dir); - } // Draw billboard pointing straight up to the sky, rotated relative to the camera and offset from the bottom DrawBillboardPro(camera, skillbot, (Rectangle){ 0.0f + (anim*24.0f), 0.0f + (dir*24.0f), 24.0f, 24.0f }, Vector3Zero(), (Vector3){ 0.0f, 1.0f, 0.0f }, Vector2One(), (Vector2){ 0.5f, 0.0f }, 0, WHITE);