2015-08-12 01:41:28 +00:00
|
|
|
#ifndef COBBOX_HPP
|
|
|
|
#define COBBOX_HPP
|
|
|
|
|
|
|
|
#include "CTransform.hpp"
|
|
|
|
#include "CVector3f.hpp"
|
|
|
|
#include "CAABox.hpp"
|
|
|
|
|
2015-10-08 00:21:38 +00:00
|
|
|
namespace Zeus
|
|
|
|
{
|
2015-10-25 19:31:41 +00:00
|
|
|
class alignas(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-10-08 00:21:38 +00:00
|
|
|
CVector3f p = m_extents * basis[0];
|
2015-08-12 01:41:28 +00:00
|
|
|
|
2015-10-08 00:21:38 +00:00
|
|
|
ret.accumulateBounds(trans * p);
|
|
|
|
p = m_extents * basis[1];
|
|
|
|
ret.accumulateBounds(trans * p);
|
|
|
|
p = m_extents * basis[2];
|
|
|
|
ret.accumulateBounds(trans * p);
|
|
|
|
p = m_extents * basis[3];
|
|
|
|
ret.accumulateBounds(trans * p);
|
|
|
|
p = m_extents * basis[4];
|
|
|
|
ret.accumulateBounds(trans * p);
|
|
|
|
p = m_extents * basis[5];
|
|
|
|
ret.accumulateBounds(trans * p);
|
|
|
|
p = m_extents * basis[6];
|
|
|
|
ret.accumulateBounds(trans * p);
|
|
|
|
p = m_extents * basis[7];
|
|
|
|
ret.accumulateBounds(trans * p);
|
2015-08-12 01:41:28 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
};
|
2015-10-08 00:21:38 +00:00
|
|
|
}
|
2015-08-12 01:41:28 +00:00
|
|
|
|
|
|
|
#endif
|