AABB stuff

This commit is contained in:
Irlan 2019-06-12 17:41:41 -03:00
parent cb492f7d51
commit 078081fa3c
3 changed files with 13 additions and 6 deletions

View File

@ -37,8 +37,8 @@ struct b3AABB3
return support; return support;
} }
// Compute this AABB from a list of points. // Set this AABB from a list of points.
void Compute(const b3Vec3* points, u32 count) void Set(const b3Vec3* points, u32 count)
{ {
m_lower = m_upper = points[0]; m_lower = m_upper = points[0];
for (u32 i = 1; i < count; ++i) for (u32 i = 1; i < count; ++i)
@ -48,8 +48,8 @@ struct b3AABB3
} }
} }
// Compute this AABB from a list of points and a transform. // Set this AABB from a list of points and a transform.
void Compute(const b3Vec3* points, u32 count, const b3Transform& xf) void Set(const b3Vec3* points, u32 count, const b3Transform& xf)
{ {
m_lower = m_upper = b3Mul(xf, points[0]); m_lower = m_upper = b3Mul(xf, points[0]);
for (u32 i = 1; i < count; ++i) for (u32 i = 1; i < count; ++i)
@ -60,6 +60,13 @@ struct b3AABB3
} }
} }
// Set this AABB from a triangle.
void Set(const b3Vec3& v1, const b3Vec3& v2, const b3Vec3& v3)
{
m_lower = b3Min(v1, b3Min(v2, v3));
m_upper = b3Max(v1, b3Max(v2, v3));
}
// Set this AABB from a center point and a radius vector. // Set this AABB from a center point and a radius vector.
void Set(const b3Vec3& center, const b3Vec3& r) void Set(const b3Vec3& center, const b3Vec3& r)
{ {

View File

@ -161,7 +161,7 @@ void b3HullShape::ComputeMass(b3MassData* massData, float32 density) const
void b3HullShape::ComputeAABB(b3AABB3* aabb, const b3Transform& xf) const void b3HullShape::ComputeAABB(b3AABB3* aabb, const b3Transform& xf) const
{ {
aabb->Compute(m_hull->vertices, m_hull->vertexCount, xf); aabb->Set(m_hull->vertices, m_hull->vertexCount, xf);
aabb->Extend(m_radius); aabb->Extend(m_radius);
} }

View File

@ -56,7 +56,7 @@ void b3MeshShape::ComputeMass(b3MassData* massData, float32 density) const
void b3MeshShape::ComputeAABB(b3AABB3* output, const b3Transform& xf) const void b3MeshShape::ComputeAABB(b3AABB3* output, const b3Transform& xf) const
{ {
output->Compute(m_mesh->vertices, m_mesh->vertexCount, xf); output->Set(m_mesh->vertices, m_mesh->vertexCount, xf);
output->Extend(m_radius); output->Extend(m_radius);
} }