Added AABB overlap test.

This commit is contained in:
Branimir Karadžić 2014-05-26 16:55:46 -07:00
parent f028ba8f24
commit 816860d38e
2 changed files with 36 additions and 0 deletions

View File

@ -119,6 +119,35 @@ void calcAabb(Aabb& _aabb, const float* _mtx, const void* _vertices, uint32_t _n
_aabb.m_max[2] = max[2];
}
void aabbExpand(Aabb& _aabb, float _factor)
{
_aabb.m_min[0] -= _factor;
_aabb.m_min[1] -= _factor;
_aabb.m_min[2] -= _factor;
_aabb.m_max[0] += _factor;
_aabb.m_max[1] += _factor;
_aabb.m_max[2] += _factor;
}
uint32_t aabbOverlapTest(Aabb& _aabb0, Aabb& _aabb1)
{
const uint32_t ltMinX = _aabb0.m_max[0] < _aabb1.m_min[0];
const uint32_t gtMaxX = _aabb0.m_min[0] > _aabb1.m_max[0];
const uint32_t ltMinY = _aabb0.m_max[1] < _aabb1.m_min[1];
const uint32_t gtMaxY = _aabb0.m_min[1] > _aabb1.m_max[1];
const uint32_t ltMinZ = _aabb0.m_max[2] < _aabb1.m_min[2];
const uint32_t gtMaxZ = _aabb0.m_min[2] > _aabb1.m_max[2];
return 0
| (ltMinX<<0)
| (gtMaxX<<1)
| (ltMinY<<2)
| (gtMaxY<<3)
| (ltMinZ<<4)
| (gtMaxZ<<5)
;
}
void calcObb(Obb& _obb, const void* _vertices, uint32_t _numVertices, uint32_t _stride, uint32_t _steps)
{
Aabb aabb;

View File

@ -38,6 +38,13 @@ void calcAabb(Aabb& _aabb, const void* _vertices, uint32_t _numVertices, uint32_
/// Transform vertices and calculate axis aligned bounding box.
void calcAabb(Aabb& _aabb, const float* _mtx, const void* _vertices, uint32_t _numVertices, uint32_t _stride);
/// Expand AABB.
void aabbExpand(Aabb& _aabb, float _factor);
/// Returns 0 is two AABB don't overlap, otherwise returns flags of overlap
/// test.
uint32_t aabbOverlapTest(Aabb& _aabb0, Aabb& _aabb1);
/// Calculate oriented bounding box.
void calcObb(Obb& _obb, const void* _vertices, uint32_t _numVertices, uint32_t _stride, uint32_t _steps = 17);