Corrected bug on bounding box
if mesh is not loaded properly it breaks the game!
This commit is contained in:
parent
ee9bf76ae9
commit
136408d8b8
1 changed files with 11 additions and 5 deletions
10
src/models.c
10
src/models.c
|
@ -1328,14 +1328,20 @@ bool CheckCollisionRayBox(Ray ray, BoundingBox box)
|
||||||
BoundingBox CalculateBoundingBox(Mesh mesh)
|
BoundingBox CalculateBoundingBox(Mesh mesh)
|
||||||
{
|
{
|
||||||
// Get min and max vertex to construct bounds (AABB)
|
// Get min and max vertex to construct bounds (AABB)
|
||||||
Vector3 minVertex = (Vector3){ mesh.vertices[0], mesh.vertices[1], mesh.vertices[2] };
|
Vector3 minVertex = { 0 };
|
||||||
Vector3 maxVertex = (Vector3){ mesh.vertices[0], mesh.vertices[1], mesh.vertices[2] };
|
Vector3 maxVertex = { 0 };
|
||||||
|
|
||||||
|
if (mesh.vertices != NULL)
|
||||||
|
{
|
||||||
|
minVertex = (Vector3){ mesh.vertices[0], mesh.vertices[1], mesh.vertices[2] };
|
||||||
|
maxVertex = (Vector3){ mesh.vertices[0], mesh.vertices[1], mesh.vertices[2] };
|
||||||
|
|
||||||
for (int i = 1; i < mesh.vertexCount; i++)
|
for (int i = 1; i < mesh.vertexCount; i++)
|
||||||
{
|
{
|
||||||
minVertex = VectorMin(minVertex, (Vector3){ mesh.vertices[i*3], mesh.vertices[i*3 + 1], mesh.vertices[i*3 + 2] });
|
minVertex = VectorMin(minVertex, (Vector3){ mesh.vertices[i*3], mesh.vertices[i*3 + 1], mesh.vertices[i*3 + 2] });
|
||||||
maxVertex = VectorMax(maxVertex, (Vector3){ mesh.vertices[i*3], mesh.vertices[i*3 + 1], mesh.vertices[i*3 + 2] });
|
maxVertex = VectorMax(maxVertex, (Vector3){ mesh.vertices[i*3], mesh.vertices[i*3 + 1], mesh.vertices[i*3 + 2] });
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Create the bounding box
|
// Create the bounding box
|
||||||
BoundingBox box;
|
BoundingBox box;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue