This commit is contained in:
Branimir Karadžić 2016-12-05 19:01:11 -08:00
parent 26aa7253f5
commit f9bc9d560f
2 changed files with 18 additions and 18 deletions

View File

@ -94,15 +94,7 @@ void aabbTransformToObb(Obb& _obb, const Aabb& _aabb, const float* _mtx)
memcpy(_obb.m_mtx, result, sizeof(result) );
}
float calcAreaAabb(Aabb& _aabb)
{
float ww = _aabb.m_max[0] - _aabb.m_min[0];
float hh = _aabb.m_max[1] - _aabb.m_min[1];
float dd = _aabb.m_max[2] - _aabb.m_min[2];
return 2.0f * (ww*hh + ww*dd + hh*dd);
}
void calcAabb(Aabb& _aabb, const void* _vertices, uint32_t _numVertices, uint32_t _stride)
void toAabb(Aabb& _aabb, const void* _vertices, uint32_t _numVertices, uint32_t _stride)
{
float min[3], max[3];
uint8_t* vertex = (uint8_t*)_vertices;
@ -136,7 +128,7 @@ void calcAabb(Aabb& _aabb, const void* _vertices, uint32_t _numVertices, uint32_
_aabb.m_max[2] = max[2];
}
void calcAabb(Aabb& _aabb, const float* _mtx, const void* _vertices, uint32_t _numVertices, uint32_t _stride)
void toAabb(Aabb& _aabb, const float* _mtx, const void* _vertices, uint32_t _numVertices, uint32_t _stride)
{
float min[3], max[3];
uint8_t* vertex = (uint8_t*)_vertices;
@ -172,6 +164,14 @@ void calcAabb(Aabb& _aabb, const float* _mtx, const void* _vertices, uint32_t _n
_aabb.m_max[2] = max[2];
}
float calcAreaAabb(const Aabb& _aabb)
{
float ww = _aabb.m_max[0] - _aabb.m_min[0];
float hh = _aabb.m_max[1] - _aabb.m_min[1];
float dd = _aabb.m_max[2] - _aabb.m_min[2];
return 2.0f * (ww*hh + ww*dd + hh*dd);
}
void aabbExpand(Aabb& _aabb, float _factor)
{
_aabb.m_min[0] -= _factor;
@ -204,7 +204,7 @@ uint32_t aabbOverlapTest(const Aabb& _aabb0, const Aabb& _aabb1)
void calcObb(Obb& _obb, const void* _vertices, uint32_t _numVertices, uint32_t _stride, uint32_t _steps)
{
Aabb aabb;
calcAabb(aabb, _vertices, _numVertices, _stride);
toAabb(aabb, _vertices, _numVertices, _stride);
float minArea = calcAreaAabb(aabb);
Obb best;
@ -228,7 +228,7 @@ void calcObb(Obb& _obb, const void* _vertices, uint32_t _numVertices, uint32_t _
float mtxT[16];
bx::mtxTranspose(mtxT, mtx);
calcAabb(aabb, mtxT, _vertices, _numVertices, _stride);
toAabb(aabb, mtxT, _vertices, _numVertices, _stride);
float area = calcAreaAabb(aabb);
if (area < minArea)
@ -252,7 +252,7 @@ void calcObb(Obb& _obb, const void* _vertices, uint32_t _numVertices, uint32_t _
void calcMaxBoundingSphere(Sphere& _sphere, const void* _vertices, uint32_t _numVertices, uint32_t _stride)
{
Aabb aabb;
calcAabb(aabb, _vertices, _numVertices, _stride);
toAabb(aabb, _vertices, _numVertices, _stride);
float center[3];
center[0] = (aabb.m_min[0] + aabb.m_max[0]) * 0.5f;

View File

@ -75,18 +75,18 @@ void toAabb(Aabb& _aabb, const Disk& _disk);
/// Convert cylinder to axis aligned bounding box.
void toAabb(Aabb& _aabb, const Cylinder& _cylinder);
/// Calculate surface area of axis aligned bounding box.
float calcAabbArea(Aabb& _aabb);
/// Calculate axis aligned bounding box.
void calcAabb(Aabb& _aabb, const void* _vertices, uint32_t _numVertices, uint32_t _stride);
void toAabb(Aabb& _aabb, const void* _vertices, uint32_t _numVertices, uint32_t _stride);
/// Transform vertices and calculate axis aligned bounding box.
void calcAabb(Aabb& _aabb, const float* _mtx, const void* _vertices, uint32_t _numVertices, uint32_t _stride);
void toAabb(Aabb& _aabb, const float* _mtx, const void* _vertices, uint32_t _numVertices, uint32_t _stride);
/// Expand AABB.
void aabbExpand(Aabb& _aabb, float _factor);
/// Calculate surface area of axis aligned bounding box.
float calcAreaAabb(const Aabb& _aabb);
/// Returns 0 is two AABB don't overlap, otherwise returns flags of overlap
/// test.
uint32_t aabbOverlapTest(const Aabb& _aabb0, const Aabb& _aabb1);