aboutsummaryrefslogtreecommitdiff
path: root/raylib/rmodels.c
diff options
context:
space:
mode:
authorUneven Prankster <unevenprankster@protonmail.com>2023-08-12 11:28:17 -0300
committerUneven Prankster <unevenprankster@protonmail.com>2023-08-12 11:28:17 -0300
commita2cb2ee59296e466bab94d9a96c331648ef212b0 (patch)
tree56739fa9b47cc8c22cef4515a6d3012f52f26127 /raylib/rmodels.c
parent5baf08556afa833d609a1ea667e7bbdeee7f1f8f (diff)
Merged some new goodies from raylib repo
Diffstat (limited to 'raylib/rmodels.c')
-rw-r--r--raylib/rmodels.c45
1 files changed, 32 insertions, 13 deletions
diff --git a/raylib/rmodels.c b/raylib/rmodels.c
index 49f9226..8c7e088 100644
--- a/raylib/rmodels.c
+++ b/raylib/rmodels.c
@@ -3492,7 +3492,7 @@ void DrawBillboardRec(Camera camera, Texture2D texture, Rectangle source, Vector
void DrawBillboardPro(Camera camera, Texture2D texture, Rectangle source, Vector3 position, Vector3 up, Vector2 size, Vector2 origin, float rotation, Color tint)
{
// NOTE: Billboard size will maintain source rectangle aspect ratio, size will represent billboard width
- Vector2 sizeRatio = { size.x*(float)source.width/source.height, size.y };
+ Vector2 sizeRatio = { size.x*fabsf((float)source.width/source.height), size.y };
Matrix matView = MatrixLookAt(camera.position, camera.target, camera.up);
@@ -3558,21 +3558,40 @@ void DrawBillboardPro(Camera camera, Texture2D texture, Rectangle source, Vector
rlBegin(RL_QUADS);
rlColor4ub(tint.r, tint.g, tint.b, tint.a);
- // Bottom-left corner for texture and quad
- rlTexCoord2f((float)source.x/texture.width, (float)source.y/texture.height);
- rlVertex3f(topLeft.x, topLeft.y, topLeft.z);
+ if (sizeRatio.x * sizeRatio.y >= 0.0f)
+ {
+ // Bottom-left corner for texture and quad
+ rlTexCoord2f((float)source.x/texture.width, (float)source.y/texture.height);
+ rlVertex3f(topLeft.x, topLeft.y, topLeft.z);
+
+ // Top-left corner for texture and quad
+ rlTexCoord2f((float)source.x/texture.width, (float)(source.y + source.height)/texture.height);
+ rlVertex3f(bottomLeft.x, bottomLeft.y, bottomLeft.z);
- // Top-left corner for texture and quad
- rlTexCoord2f((float)source.x/texture.width, (float)(source.y + source.height)/texture.height);
- rlVertex3f(bottomLeft.x, bottomLeft.y, bottomLeft.z);
+ // Top-right corner for texture and quad
+ rlTexCoord2f((float)(source.x + source.width)/texture.width, (float)(source.y + source.height)/texture.height);
+ rlVertex3f(bottomRight.x, bottomRight.y, bottomRight.z);
- // Top-right corner for texture and quad
- rlTexCoord2f((float)(source.x + source.width)/texture.width, (float)(source.y + source.height)/texture.height);
- rlVertex3f(bottomRight.x, bottomRight.y, bottomRight.z);
+ // Bottom-right corner for texture and quad
+ rlTexCoord2f((float)(source.x + source.width)/texture.width, (float)source.y/texture.height);
+ rlVertex3f(topRight.x, topRight.y, topRight.z);
+ }
+ else
+ {
+ // Reverse vertex order if the size has only one negative dimension
+ rlTexCoord2f((float)(source.x + source.width)/texture.width, (float)source.y/texture.height);
+ rlVertex3f(topRight.x, topRight.y, topRight.z);
+
+ rlTexCoord2f((float)(source.x + source.width)/texture.width, (float)(source.y + source.height)/texture.height);
+ rlVertex3f(bottomRight.x, bottomRight.y, bottomRight.z);
+
+ rlTexCoord2f((float)source.x/texture.width, (float)(source.y + source.height)/texture.height);
+ rlVertex3f(bottomLeft.x, bottomLeft.y, bottomLeft.z);
+
+ rlTexCoord2f((float)source.x/texture.width, (float)source.y/texture.height);
+ rlVertex3f(topLeft.x, topLeft.y, topLeft.z);
+ }
- // Bottom-right corner for texture and quad
- rlTexCoord2f((float)(source.x + source.width)/texture.width, (float)source.y/texture.height);
- rlVertex3f(topRight.x, topRight.y, topRight.z);
rlEnd();
rlSetTexture(0);