zeus/include/COBBox.hpp

65 lines
1.5 KiB
C++
Raw Normal View History

#ifndef COBBOX_HPP
#define COBBOX_HPP
#include "CTransform.hpp"
#include "CVector3f.hpp"
#include "CAABox.hpp"
namespace Zeus
{
2015-08-25 06:56:05 +00:00
class ZE_ALIGN(16) COBBox
{
public:
2015-08-25 06:56:05 +00:00
ZE_DECLARE_ALIGNED_ALLOCATOR();
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();
}
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}
};
CVector3f p = m_extents * basis[0];
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);
return ret;
}
};
}
#endif