[rmodels] Make DrawBillboardPro consistent with DrawTexturePro
This commit is contained in:
parent
7f89b40a85
commit
ad0cf03782
|
|
@ -44,10 +44,12 @@ int main(void)
|
||||||
// NOTE: Billboard locked on axis-Y
|
// NOTE: Billboard locked on axis-Y
|
||||||
Vector3 billUp = { 0.0f, 1.0f, 0.0f };
|
Vector3 billUp = { 0.0f, 1.0f, 0.0f };
|
||||||
|
|
||||||
|
// Set the height of the rotating billboard to 1.0 with the aspect ratio fixed
|
||||||
|
Vector2 size = { source.width / source.height, 1.0f };
|
||||||
|
|
||||||
// Rotate around origin
|
// Rotate around origin
|
||||||
// Here we choose to rotate around the image center
|
// 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 origin = Vector2Scale(size, 0.5f);
|
||||||
Vector2 rotateOrigin = { 0.0f };
|
|
||||||
|
|
||||||
// Distance is needed for the correct billboard draw order
|
// Distance is needed for the correct billboard draw order
|
||||||
// Larger distance (further away from the camera) should be drawn prior to smaller distance.
|
// Larger distance (further away from the camera) should be drawn prior to smaller distance.
|
||||||
|
|
@ -84,11 +86,11 @@ int main(void)
|
||||||
if (distanceStatic > distanceRotating)
|
if (distanceStatic > distanceRotating)
|
||||||
{
|
{
|
||||||
DrawBillboard(camera, bill, billPositionStatic, 2.0f, WHITE);
|
DrawBillboard(camera, bill, billPositionStatic, 2.0f, WHITE);
|
||||||
DrawBillboardPro(camera, bill, source, billPositionRotating, billUp, (Vector2) {1.0f, 1.0f}, rotateOrigin, rotation, WHITE);
|
DrawBillboardPro(camera, bill, source, billPositionRotating, billUp, size, origin, rotation, WHITE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DrawBillboardPro(camera, bill, source, billPositionRotating, billUp, (Vector2) {1.0f, 1.0f}, rotateOrigin, rotation, WHITE);
|
DrawBillboardPro(camera, bill, source, billPositionRotating, billUp, size, origin, rotation, WHITE);
|
||||||
DrawBillboard(camera, bill, billPositionStatic, 2.0f, WHITE);
|
DrawBillboard(camera, bill, billPositionStatic, 2.0f, WHITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -108,4 +110,4 @@ int main(void)
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1546,7 +1546,7 @@ RLAPI void DrawModelEx(Model model, Vector3 position, Vector3 rotationAxis, floa
|
||||||
RLAPI void DrawModelWires(Model model, Vector3 position, float scale, Color tint); // Draw a model wires (with texture if set)
|
RLAPI void DrawModelWires(Model model, Vector3 position, float scale, Color tint); // Draw a model wires (with texture if set)
|
||||||
RLAPI void DrawModelWiresEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint); // Draw a model wires (with texture if set) with extended parameters
|
RLAPI void DrawModelWiresEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint); // Draw a model wires (with texture if set) with extended parameters
|
||||||
RLAPI void DrawBoundingBox(BoundingBox box, Color color); // Draw bounding box (wires)
|
RLAPI void DrawBoundingBox(BoundingBox box, Color color); // Draw bounding box (wires)
|
||||||
RLAPI void DrawBillboard(Camera camera, Texture2D texture, Vector3 position, float size, Color tint); // Draw a billboard texture
|
RLAPI void DrawBillboard(Camera camera, Texture2D texture, Vector3 position, float scale, Color tint); // Draw a billboard texture
|
||||||
RLAPI void DrawBillboardRec(Camera camera, Texture2D texture, Rectangle source, Vector3 position, Vector2 size, Color tint); // Draw a billboard texture defined by source
|
RLAPI void DrawBillboardRec(Camera camera, Texture2D texture, Rectangle source, Vector3 position, Vector2 size, Color tint); // Draw a billboard texture defined by source
|
||||||
RLAPI void DrawBillboardPro(Camera camera, Texture2D texture, Rectangle source, Vector3 position, Vector3 up, Vector2 size, Vector2 origin, float rotation, Color tint); // Draw a billboard texture defined by source and rotation
|
RLAPI void DrawBillboardPro(Camera camera, Texture2D texture, Rectangle source, Vector3 position, Vector3 up, Vector2 size, Vector2 origin, float rotation, Color tint); // Draw a billboard texture defined by source and rotation
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3638,11 +3638,11 @@ void DrawModelWiresEx(Model model, Vector3 position, Vector3 rotationAxis, float
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw a billboard
|
// Draw a billboard
|
||||||
void DrawBillboard(Camera camera, Texture2D texture, Vector3 position, float size, Color tint)
|
void DrawBillboard(Camera camera, Texture2D texture, Vector3 position, float scale, Color tint)
|
||||||
{
|
{
|
||||||
Rectangle source = { 0.0f, 0.0f, (float)texture.width, (float)texture.height };
|
Rectangle source = { 0.0f, 0.0f, (float)texture.width, (float)texture.height };
|
||||||
|
|
||||||
DrawBillboardRec(camera, texture, source, position, (Vector2){ size, size }, tint);
|
DrawBillboardRec(camera, texture, source, position, (Vector2) { scale*fabsf((float)source.width/source.height), scale }, tint);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw a billboard (part of a texture defined by a rectangle)
|
// Draw a billboard (part of a texture defined by a rectangle)
|
||||||
|
|
@ -3651,16 +3651,12 @@ void DrawBillboardRec(Camera camera, Texture2D texture, Rectangle source, Vector
|
||||||
// NOTE: Billboard locked on axis-Y
|
// NOTE: Billboard locked on axis-Y
|
||||||
Vector3 up = { 0.0f, 1.0f, 0.0f };
|
Vector3 up = { 0.0f, 1.0f, 0.0f };
|
||||||
|
|
||||||
DrawBillboardPro(camera, texture, source, position, up, size, Vector2Zero(), 0.0f, tint);
|
DrawBillboardPro(camera, texture, source, position, up, size, Vector2Scale(size, 0.5), 0.0f, tint);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw a billboard with additional parameters
|
// Draw a billboard with additional parameters
|
||||||
// NOTE: Size defines the destination rectangle size, stretching the source texture as required
|
|
||||||
void DrawBillboardPro(Camera camera, Texture2D texture, Rectangle source, Vector3 position, Vector3 up, Vector2 size, Vector2 origin, float rotation, Color tint)
|
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
|
|
||||||
size = (Vector2) { size.x*fabsf((float)source.width/source.height), size.y };
|
|
||||||
|
|
||||||
// Compute the up vector and the right vector
|
// Compute the up vector and the right vector
|
||||||
Matrix matView = MatrixLookAt(camera.position, camera.target, camera.up);
|
Matrix matView = MatrixLookAt(camera.position, camera.target, camera.up);
|
||||||
Vector3 right = { matView.m0, matView.m4, matView.m8 };
|
Vector3 right = { matView.m0, matView.m4, matView.m8 };
|
||||||
|
|
@ -3683,10 +3679,6 @@ void DrawBillboardPro(Camera camera, Texture2D texture, Rectangle source, Vector
|
||||||
origin.y *= -1.0f;
|
origin.y *= -1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assume the given origin is normalized and does not alter the position of the billboard
|
|
||||||
position = Vector3Add(position, Vector3Scale(Vector3Add(Vector3Scale(right, origin.x), Vector3Scale(up, origin.y)), 0.5f));
|
|
||||||
origin = Vector2Multiply(Vector2Scale(Vector2Add(origin, Vector2One()), 0.5f), (Vector2) { fabsf(size.x), fabsf(size.y) });
|
|
||||||
|
|
||||||
// Draw the texture region described by source on the following rectangle in 3D space:
|
// Draw the texture region described by source on the following rectangle in 3D space:
|
||||||
//
|
//
|
||||||
// size.x <--.
|
// size.x <--.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user