2015-08-12 01:41:28 +00:00
|
|
|
#ifndef COBBOX_HPP
|
|
|
|
#define COBBOX_HPP
|
|
|
|
|
|
|
|
#include "CTransform.hpp"
|
|
|
|
#include "CVector3f.hpp"
|
|
|
|
#include "CAABox.hpp"
|
|
|
|
|
2015-08-25 06:56:05 +00:00
|
|
|
class ZE_ALIGN(16) COBBox
|
2015-08-12 01:41:28 +00:00
|
|
|
{
|
|
|
|
public:
|
2015-08-25 06:56:05 +00:00
|
|
|
ZE_DECLARE_ALIGNED_ALLOCATOR();
|
2015-08-12 01:41:28 +00:00
|
|
|
CTransform m_transform;
|
|
|
|
CVector3f m_extents;
|
|
|
|
|
|
|
|
COBBox()
|
|
|
|
{}
|
|
|
|
|
|
|
|
COBBox(const CAABox& aabb)
|
2015-08-29 04:49:19 +00:00
|
|
|
: m_extents(aabb.volume())
|
2015-08-25 06:56:05 +00:00
|
|
|
{
|
|
|
|
m_transform.m_origin = aabb.center();
|
|
|
|
}
|
2015-08-12 01:41:28 +00:00
|
|
|
|
|
|
|
CAABox calculateAABox(const CTransform& transform = CTransform())
|
|
|
|
{
|
|
|
|
CAABox ret = CAABox::skInvertedBox;
|
|
|
|
|
|
|
|
CTransform trans = transform * m_transform;
|
|
|
|
static const CVector3f basis[8] ={
|
|
|
|
{ 1.0, 1.0, 1.0},
|
|
|
|
{ 1.0, 1.0, -1.0},
|
|
|
|
{ 1.0, -1.0, 1.0},
|
|
|
|
{ 1.0, -1.0, -1.0},
|
|
|
|
{-1.0, -1.0, -1.0},
|
|
|
|
{-1.0, -1.0, 1.0},
|
|
|
|
{-1.0, 1.0, -1.0},
|
|
|
|
{-1.0, 1.0, 1.0}
|
|
|
|
};
|
|
|
|
|
2015-08-25 06:56:05 +00:00
|
|
|
for (int i = 0; i < 8; i+=2)
|
2015-08-12 01:41:28 +00:00
|
|
|
{
|
|
|
|
CVector3f p = (m_extents * basis[i]);
|
|
|
|
ret.accumulateBounds(trans * p);
|
2015-08-25 06:56:05 +00:00
|
|
|
p = m_extents * basis[i + 1];
|
|
|
|
ret.accumulateBounds(trans * p);
|
2015-08-12 01:41:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|