summaryrefslogtreecommitdiffhomepage
path: root/src/models.c
diff options
context:
space:
mode:
authorraysan5 <[email protected]>2021-07-28 13:15:10 +0200
committerraysan5 <[email protected]>2021-07-28 13:15:10 +0200
commit0c3902b5433e1271df8a0a5252a6f10b1e8b8633 (patch)
treee0e9ff4d96b2a05a497ee285841115a9fe4cdf94 /src/models.c
parent7c7ee1cdc870d58a58ff196b1e8c119f6a8616cb (diff)
downloadraylib-0c3902b5433e1271df8a0a5252a6f10b1e8b8633.tar.gz
raylib-0c3902b5433e1271df8a0a5252a6f10b1e8b8633.zip
ADDED: GetModelBoundingBox()
Reorganized models functionality, it still needs some review...
Diffstat (limited to 'src/models.c')
-rw-r--r--src/models.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/models.c b/src/models.c
index 18ae48d1..3d200d2a 100644
--- a/src/models.c
+++ b/src/models.c
@@ -819,6 +819,35 @@ void UnloadModelKeepMeshes(Model model)
TRACELOG(LOG_INFO, "MODEL: Unloaded model (but not meshes) from RAM and VRAM");
}
+// Compute model bounding box limits (considers all meshes)
+BoundingBox GetModelBoundingBox(Model model)
+{
+ BoundingBox bounds = { 0 };
+
+ if (model.meshCount > 0)
+ {
+ Vector3 temp = { 0 };
+ bounds = GetMeshBoundingBox(model.meshes[0]);
+
+ for (int i = 1; i < model.meshCount; i++)
+ {
+ BoundingBox tempBounds = GetMeshBoundingBox(model.meshes[i]);
+
+ temp.x = (bounds.min.x < tempBounds.min.x)? bounds.min.x : tempBounds.min.x;
+ temp.y = (bounds.min.y < tempBounds.min.y)? bounds.min.y : tempBounds.min.y;
+ temp.z = (bounds.min.z < tempBounds.min.z)? bounds.min.z : tempBounds.min.z;
+ bounds.min = temp;
+
+ temp.x = (bounds.max.x > tempBounds.max.x)? bounds.max.x : tempBounds.max.x;
+ temp.y = (bounds.max.y > tempBounds.max.y)? bounds.max.y : tempBounds.max.y;
+ temp.z = (bounds.max.z > tempBounds.max.z)? bounds.max.z : tempBounds.max.z;
+ bounds.max = temp;
+ }
+ }
+
+ return bounds;
+}
+
// Upload vertex data into a VAO (if supported) and VBO
void UploadMesh(Mesh *mesh, bool dynamic)
{