summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornobytesgiven <[email protected]>2022-10-26 20:16:35 +0300
committerGitHub <[email protected]>2022-10-26 19:16:35 +0200
commit51138175078e56d22aee7703d083708df683cac5 (patch)
tree6c241987acdd57835f29852b2c09e79c45557d5c
parent28e8b2add38098aee2b55243af4f3a62f2cd60c4 (diff)
downloadraylib-51138175078e56d22aee7703d083708df683cac5.tar.gz
raylib-51138175078e56d22aee7703d083708df683cac5.zip
Improved billboards example, highlighting rotation and draw order (#2779)
* Improved billboards example, highlighting rotation and draw order * changes to conform to the raylib conventions * NOW it conforms Co-authored-by: nobytesgiven <[email protected]>
-rw-r--r--examples/models/models_billboard.c39
1 files changed, 35 insertions, 4 deletions
diff --git a/examples/models/models_billboard.c b/examples/models/models_billboard.c
index 68a24e6a..0b5a42d5 100644
--- a/examples/models/models_billboard.c
+++ b/examples/models/models_billboard.c
@@ -12,6 +12,7 @@
********************************************************************************************/
#include "raylib.h"
+#include "raymath.h"
//------------------------------------------------------------------------------------
// Program main entry point
@@ -33,11 +34,28 @@ int main(void)
camera.fovy = 45.0f;
camera.projection = CAMERA_PERSPECTIVE;
- Texture2D bill = LoadTexture("resources/billboard.png"); // Our texture billboard
- Vector3 billPosition = { 0.0f, 2.0f, 0.0f }; // Position where draw billboard
+ Texture2D bill = LoadTexture("resources/billboard.png"); // Our billboard texture
+ Vector3 billPositionStatic = { 0.0f, 2.0f, 0.0f }; // Position of billboard
+ Vector3 billPositionRotating = { 1.0f, 2.0f, 1.0f };
+ // Entire billboard texture, source is used to take a segment from a larger texture.
+ Rectangle source = { 0.0f, 0.0f, (float)bill.width, (float)bill.height };
+
+ // NOTE: Billboard locked on axis-Y
+ Vector3 billUp = { 0.0f, 1.0f, 0.0f };
+
+ // Rotate around origin
+ // Here we choose to rotate around the image center
+ // NOTE: (-1, 1) is the range where origin.x, origin.y is inside the texture
+ Vector2 rotateOrigin = { 0.0f };
SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode
+ // Distance is needed for the correct billboard draw order
+ // Larger distance (further away from the camera) should be drawn prior to smaller distance.
+ float distanceStatic;
+ float distanceRotating;
+
+ float rotation = 0.0f;
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@@ -47,6 +65,9 @@ int main(void)
// Update
//----------------------------------------------------------------------------------
UpdateCamera(&camera);
+ rotation += 0.4f;
+ distanceStatic = Vector3Distance(camera.position, billPositionStatic);
+ distanceRotating = Vector3Distance(camera.position, billPositionRotating);
//----------------------------------------------------------------------------------
// Draw
@@ -59,8 +80,18 @@ int main(void)
DrawGrid(10, 1.0f); // Draw a grid
- DrawBillboard(camera, bill, billPosition, 2.0f, WHITE);
-
+ // Draw order matters!
+ if (distanceStatic > distanceRotating)
+ {
+ DrawBillboard(camera, bill, billPositionStatic, 2.0f, WHITE);
+ DrawBillboardPro(camera, bill, source, billPositionRotating, billUp, (Vector2) {1.0f, 1.0f}, rotateOrigin, rotation, WHITE);
+ }
+ else
+ {
+ DrawBillboardPro(camera, bill, source, billPositionRotating, billUp, (Vector2) {1.0f, 1.0f}, rotateOrigin, rotation, WHITE);
+ DrawBillboard(camera, bill, billPositionStatic, 2.0f, WHITE);
+ }
+
EndMode3D();
DrawFPS(10, 10);