Remove m_ from all non-private members

This commit is contained in:
Phillip Stephens 2016-04-29 01:44:58 -07:00
parent 48b0aa4601
commit c36927076c
7 changed files with 233 additions and 233 deletions

View File

@ -41,31 +41,31 @@ public:
static const CAABox skInvertedBox; static const CAABox skInvertedBox;
static const CAABox skNullBox; static const CAABox skNullBox;
CVector3f m_min; CVector3f min;
CVector3f m_max; CVector3f max;
// set default AABox to insane inverse min/max to allow for accumulation // set default AABox to insane inverse min/max to allow for accumulation
inline CAABox() inline CAABox()
: m_min(1e16f), m_max(-1e16f) : min(1e16f), max(-1e16f)
{} {}
CAABox(const CVector3f& min, const CVector3f& max) CAABox(const CVector3f& min, const CVector3f& max)
: m_min(min), : min(min),
m_max(max) max(max)
{ {
} }
CAABox(float minX, float minY, float minZ, CAABox(float minX, float minY, float minZ,
float maxX, float maxY, float maxZ) float maxX, float maxY, float maxZ)
: m_min(minX, minY, minZ), : min(minX, minY, minZ),
m_max(maxX, maxY, maxZ) max(maxX, maxY, maxZ)
{ {
} }
#if ZE_ATHENA_TYPES #if ZE_ATHENA_TYPES
inline void readBoundingBoxBig(athena::io::IStreamReader& in) inline void readBoundingBoxBig(athena::io::IStreamReader& in)
{ {
m_min.readBig(in); min.readBig(in);
m_max.readBig(in); max.readBig(in);
} }
#endif #endif
@ -74,14 +74,14 @@ public:
float dist = 0; float dist = 0;
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
{ {
if (other[i] < m_min[i]) if (other[i] < min[i])
{ {
const float tmp = (m_min[i] - other[i]); const float tmp = (min[i] - other[i]);
dist += tmp * tmp; dist += tmp * tmp;
} }
else if (other[i] > m_max[i]) else if (other[i] > max[i])
{ {
const float tmp = (other[i] - m_max[i]); const float tmp = (other[i] - max[i]);
dist += tmp * tmp; dist += tmp * tmp;
} }
} }
@ -96,12 +96,12 @@ public:
inline bool intersects(const CAABox& other) const inline bool intersects(const CAABox& other) const
{ {
bool x1 = (m_max[0] < other.m_min[0]); bool x1 = (max[0] < other.min[0]);
bool x2 = (m_min[0] > other.m_max[0]); bool x2 = (min[0] > other.max[0]);
bool y1 = (m_max[1] < other.m_min[1]); bool y1 = (max[1] < other.min[1]);
bool y2 = (m_min[1] > other.m_max[1]); bool y2 = (min[1] > other.max[1]);
bool z1 = (m_max[2] < other.m_min[2]); bool z1 = (max[2] < other.min[2]);
bool z2 = (m_min[2] > other.m_max[2]); bool z2 = (min[2] > other.max[2]);
return x1 && x2 && y1 && y2 && z1 && z2; return x1 && x2 && y1 && y2 && z1 && z2;
} }
bool intersects(const CSphere& other) const bool intersects(const CSphere& other) const
@ -111,9 +111,9 @@ public:
inline bool inside(const CAABox& other) const inline bool inside(const CAABox& other) const
{ {
bool x = m_min[0] >= other.m_min[0] && m_max[0] <= other.m_max[0]; bool x = min[0] >= other.min[0] && max[0] <= other.max[0];
bool y = m_min[1] >= other.m_min[1] && m_max[1] <= other.m_max[1]; bool y = min[1] >= other.min[1] && max[1] <= other.max[1];
bool z = m_min[2] >= other.m_min[2] && m_max[2] <= other.m_max[2]; bool z = min[2] >= other.min[2] && max[2] <= other.max[2];
return x && y && z; return x && y && z;
} }
@ -122,27 +122,27 @@ public:
CVector3f vmin, vmax; CVector3f vmin, vmax;
/* X axis */ /* X axis */
if (plane.a >= 0) { if (plane.a >= 0) {
vmin[0] = m_min[0]; vmin[0] = min[0];
vmax[0] = m_max[0]; vmax[0] = max[0];
} else { } else {
vmin[0] = m_max[0]; vmin[0] = max[0];
vmax[0] = m_min[0]; vmax[0] = min[0];
} }
/* Y axis */ /* Y axis */
if (plane.b >= 0) { if (plane.b >= 0) {
vmin[1] = m_min[1]; vmin[1] = min[1];
vmax[1] = m_max[1]; vmax[1] = max[1];
} else { } else {
vmin[1] = m_max[1]; vmin[1] = max[1];
vmax[1] = m_min[1]; vmax[1] = min[1];
} }
/* Z axis */ /* Z axis */
if (plane.c >= 0) { if (plane.c >= 0) {
vmin[2] = m_min[2]; vmin[2] = min[2];
vmax[2] = m_max[2]; vmax[2] = max[2];
} else { } else {
vmin[2] = m_max[2]; vmin[2] = max[2];
vmax[2] = m_min[2]; vmax[2] = min[2];
} }
float dadot = plane.vec.dot(vmax); float dadot = plane.vec.dot(vmax);
if (dadot + plane.d < 0) if (dadot + plane.d < 0)
@ -150,53 +150,53 @@ public:
return true; return true;
} }
CVector3f center() const {return (m_min + m_max) * 0.5f;} CVector3f center() const {return (min + max) * 0.5f;}
CVector3f volume() const {return (m_max - m_min) * 0.5f;} CVector3f volume() const {return (max - min) * 0.5f;}
inline CLineSeg getEdge(EBoxEdgeId id) inline CLineSeg getEdge(EBoxEdgeId id)
{ {
switch (id) switch (id)
{ {
case EBoxEdgeId::UnknownEdge0: case EBoxEdgeId::UnknownEdge0:
return CLineSeg({m_min.x, m_min.y, m_min.z}, return CLineSeg({min.x, min.y, min.z},
{m_min.x, m_min.y, m_max.z}); {min.x, min.y, max.z});
case EBoxEdgeId::UnknownEdge1: case EBoxEdgeId::UnknownEdge1:
return CLineSeg({m_max.x, m_min.y, m_min.z}, return CLineSeg({max.x, min.y, min.z},
{m_min.x, m_min.y, m_min.z}); {min.x, min.y, min.z});
case EBoxEdgeId::UnknownEdge2: case EBoxEdgeId::UnknownEdge2:
return CLineSeg({m_max.x, m_min.y, m_max.z}, return CLineSeg({max.x, min.y, max.z},
{m_max.x, m_min.y, m_max.z}); {max.x, min.y, max.z});
case EBoxEdgeId::UnknownEdge3: case EBoxEdgeId::UnknownEdge3:
return CLineSeg({m_min.x, m_min.y, m_max.z}, return CLineSeg({min.x, min.y, max.z},
{m_max.x, m_min.y, m_max.z}); {max.x, min.y, max.z});
case EBoxEdgeId::UnknownEdge4: case EBoxEdgeId::UnknownEdge4:
return CLineSeg({m_max.x, m_max.y, m_min.z}, return CLineSeg({max.x, max.y, min.z},
{m_max.x, m_max.y, m_max.z}); {max.x, max.y, max.z});
case EBoxEdgeId::UnknownEdge5: case EBoxEdgeId::UnknownEdge5:
return CLineSeg({m_min.x, m_max.y, m_min.z}, return CLineSeg({min.x, max.y, min.z},
{m_max.x, m_max.y, m_min.z}); {max.x, max.y, min.z});
case EBoxEdgeId::UnknownEdge6: case EBoxEdgeId::UnknownEdge6:
return CLineSeg({m_min.x, m_max.y, m_max.z}, return CLineSeg({min.x, max.y, max.z},
{m_min.x, m_max.y, m_min.z}); {min.x, max.y, min.z});
case EBoxEdgeId::UnknownEdge7: case EBoxEdgeId::UnknownEdge7:
return CLineSeg({m_max.x, m_max.y, m_max.z}, return CLineSeg({max.x, max.y, max.z},
{m_min.x, m_max.y, m_max.z}); {min.x, max.y, max.z});
case EBoxEdgeId::UnknownEdge8: case EBoxEdgeId::UnknownEdge8:
return CLineSeg({m_min.x, m_max.y, m_max.z}, return CLineSeg({min.x, max.y, max.z},
{m_min.x, m_min.y, m_max.z}); {min.x, min.y, max.z});
case EBoxEdgeId::UnknownEdge9: case EBoxEdgeId::UnknownEdge9:
return CLineSeg({m_min.x, m_max.y, m_min.z}, return CLineSeg({min.x, max.y, min.z},
{m_min.x, m_min.y, m_min.z}); {min.x, min.y, min.z});
case EBoxEdgeId::UnknownEdge10: case EBoxEdgeId::UnknownEdge10:
return CLineSeg({m_max.x, m_max.y, m_min.z}, return CLineSeg({max.x, max.y, min.z},
{m_max.x, m_min.y, m_min.z}); {max.x, min.y, min.z});
case EBoxEdgeId::UnknownEdge11: case EBoxEdgeId::UnknownEdge11:
return CLineSeg({m_max.x, m_max.y, m_max.z}, return CLineSeg({max.x, max.y, max.z},
{m_max.x, m_min.y, m_max.z}); {max.x, min.y, max.z});
default: default:
return CLineSeg({m_min.x, m_min.y, m_min.z}, return CLineSeg({min.x, min.y, min.z},
{m_min.x, m_min.y, m_max.z}); {min.x, min.y, max.z});
} }
} }
@ -224,47 +224,47 @@ public:
inline void accumulateBounds(const CVector3f& point) inline void accumulateBounds(const CVector3f& point)
{ {
if (m_min.x > point.x) if (min.x > point.x)
m_min.x = point.x; min.x = point.x;
if (m_min.y > point.y) if (min.y > point.y)
m_min.y = point.y; min.y = point.y;
if (m_min.z > point.z) if (min.z > point.z)
m_min.z = point.z; min.z = point.z;
if (m_max.x < point.x) if (max.x < point.x)
m_max.x = point.x; max.x = point.x;
if (m_max.y < point.y) if (max.y < point.y)
m_max.y = point.y; max.y = point.y;
if (m_max.z < point.z) if (max.z < point.z)
m_max.z = point.z; max.z = point.z;
} }
inline void accumulateBounds(const CAABox& other) inline void accumulateBounds(const CAABox& other)
{ {
accumulateBounds(other.m_min); accumulateBounds(other.min);
accumulateBounds(other.m_max); accumulateBounds(other.max);
} }
inline bool pointInside(const CVector3f& other) const inline bool pointInside(const CVector3f& other) const
{ {
return (m_min.x <= other.x && other.x <= m_max.z && return (min.x <= other.x && other.x <= max.z &&
m_min.y <= other.y && other.y <= m_max.z && min.y <= other.y && other.y <= max.z &&
m_min.z <= other.z && other.z <= m_max.z); min.z <= other.z && other.z <= max.z);
} }
inline CVector3f closestPointAlongVector(const CVector3f& other) const inline CVector3f closestPointAlongVector(const CVector3f& other) const
{ {
CVector3f center = this->center(); CVector3f center = this->center();
return {(other.x < center.x ? m_min.x : m_max.x), return {(other.x < center.x ? min.x : max.x),
(other.y < center.y ? m_min.y : m_max.y), (other.y < center.y ? min.y : max.y),
(other.z < center.z ? m_min.z : m_max.z)}; (other.z < center.z ? min.z : max.z)};
} }
inline CVector3f furthestPointAlongVector(const CVector3f& other) const inline CVector3f furthestPointAlongVector(const CVector3f& other) const
{ {
CVector3f center = this->center(); CVector3f center = this->center();
return {(other.x < center.x ? m_max.x : m_min.x), return {(other.x < center.x ? max.x : min.x),
(other.y < center.y ? m_max.y : m_min.y), (other.y < center.y ? max.y : min.y),
(other.z < center.z ? m_max.z : m_min.z)}; (other.z < center.z ? max.z : min.z)};
} }
inline CVector3f getPoint(const int point) const inline CVector3f getPoint(const int point) const
@ -272,60 +272,60 @@ public:
int zOff = point & 4; int zOff = point & 4;
int yOff = (point * 2) & 4; int yOff = (point * 2) & 4;
int xOff = (point * 4) & 4; int xOff = (point * 4) & 4;
float z = ((float*)(&m_min.x) + zOff)[2]; float z = ((float*)(&min.x) + zOff)[2];
float y = ((float*)(&m_min.x) + yOff)[1]; float y = ((float*)(&min.x) + yOff)[1];
float x = ((float*)(&m_min.x) + xOff)[0]; float x = ((float*)(&min.x) + xOff)[0];
return CVector3f(x, y, z); return CVector3f(x, y, z);
} }
inline CVector3f clampToBox(const CVector3f& vec) inline CVector3f clampToBox(const CVector3f& vec)
{ {
CVector3f ret = vec; CVector3f ret = vec;
clamp(m_min.x, ret.x, m_max.x); clamp(min.x, ret.x, max.x);
clamp(m_min.y, ret.y, m_max.y); clamp(min.y, ret.y, max.y);
clamp(m_min.z, ret.z, m_max.z); clamp(min.z, ret.z, max.z);
return ret; return ret;
} }
inline void splitX(CAABox& posX, CAABox& negX) const inline void splitX(CAABox& posX, CAABox& negX) const
{ {
float midX = (m_max.x - m_min.x) * .5 + m_min.x; float midX = (max.x - min.x) * .5 + min.x;
posX.m_max = m_max; posX.max = max;
posX.m_min = m_min; posX.min = min;
posX.m_min.x = midX; posX.min.x = midX;
negX.m_max = m_max; negX.max = max;
negX.m_max.x = midX; negX.max.x = midX;
negX.m_min = m_min; negX.min = min;
} }
inline void splitY(CAABox& posY, CAABox& negY) const inline void splitY(CAABox& posY, CAABox& negY) const
{ {
float midY = (m_max.y - m_min.y) * .5 + m_min.y; float midY = (max.y - min.y) * .5 + min.y;
posY.m_max = m_max; posY.max = max;
posY.m_min = m_min; posY.min = min;
posY.m_min.y = midY; posY.min.y = midY;
negY.m_max = m_max; negY.max = max;
negY.m_max.y = midY; negY.max.y = midY;
negY.m_min = m_min; negY.min = min;
} }
inline void splitZ(CAABox& posZ, CAABox& negZ) const inline void splitZ(CAABox& posZ, CAABox& negZ) const
{ {
float midZ = (m_max.z - m_min.z) * .5 + m_min.z; float midZ = (max.z - min.z) * .5 + min.z;
posZ.m_max = m_max; posZ.max = max;
posZ.m_min = m_min; posZ.min = min;
posZ.m_min.z = midZ; posZ.min.z = midZ;
negZ.m_max = m_max; negZ.max = max;
negZ.m_max.z = midZ; negZ.max.z = midZ;
negZ.m_min = m_min; negZ.min = min;
} }
inline bool invalid() {return (m_max.x < m_min.x || m_max.y < m_min.y || m_max.z < m_min.z);} inline bool invalid() {return (max.x < min.x || max.y < min.y || max.z < min.z);}
}; };
inline bool operator ==(const CAABox& left, const CAABox& right) {return (left.m_min == right.m_min && left.m_max == right.m_max);} inline bool operator ==(const CAABox& left, const CAABox& right) {return (left.min == right.min && left.max == right.max);}
inline bool operator !=(const CAABox& left, const CAABox& right) {return (left.m_min != right.m_min || left.m_max != right.m_max);} inline bool operator !=(const CAABox& left, const CAABox& right) {return (left.min != right.min || left.max != right.max);}
} }
#endif // CAABOX_HPP #endif // CAABOX_HPP

View File

@ -8,7 +8,7 @@ namespace zeus
{ {
class CFrustum class CFrustum
{ {
CPlane m_planes[6]; CPlane planes[6];
public: public:
inline void updatePlanes(const CTransform& modelview, const CProjection& projection) inline void updatePlanes(const CTransform& modelview, const CProjection& projection)
@ -20,22 +20,22 @@ public:
#if __SSE__ #if __SSE__
/* Left */ /* Left */
m_planes[0].mVec128 = _mm_add_ps(mvp_rm.vec[0].mVec128, mvp_rm.vec[3].mVec128); planes[0].mVec128 = _mm_add_ps(mvp_rm.vec[0].mVec128, mvp_rm.vec[3].mVec128);
/* Right */ /* Right */
m_planes[1].mVec128 = _mm_add_ps(_mm_sub_ps(CVector3f::skZero.mVec128, mvp_rm.vec[0].mVec128), mvp_rm.vec[3].mVec128); planes[1].mVec128 = _mm_add_ps(_mm_sub_ps(CVector3f::skZero.mVec128, mvp_rm.vec[0].mVec128), mvp_rm.vec[3].mVec128);
/* Bottom */ /* Bottom */
m_planes[2].mVec128 = _mm_add_ps(mvp_rm.vec[1].mVec128, mvp_rm.vec[3].mVec128); planes[2].mVec128 = _mm_add_ps(mvp_rm.vec[1].mVec128, mvp_rm.vec[3].mVec128);
/* Top */ /* Top */
m_planes[3].mVec128 = _mm_add_ps(_mm_sub_ps(CVector3f::skZero.mVec128, mvp_rm.vec[1].mVec128), mvp_rm.vec[3].mVec128); planes[3].mVec128 = _mm_add_ps(_mm_sub_ps(CVector3f::skZero.mVec128, mvp_rm.vec[1].mVec128), mvp_rm.vec[3].mVec128);
/* Near */ /* Near */
m_planes[4].mVec128 = _mm_add_ps(mvp_rm.vec[2].mVec128, mvp_rm.vec[3].mVec128); planes[4].mVec128 = _mm_add_ps(mvp_rm.vec[2].mVec128, mvp_rm.vec[3].mVec128);
/* Far */ /* Far */
m_planes[5].mVec128 = _mm_add_ps(_mm_sub_ps(CVector3f::skZero.mVec128, mvp_rm.vec[2].mVec128), mvp_rm.vec[3].mVec128); planes[5].mVec128 = _mm_add_ps(_mm_sub_ps(CVector3f::skZero.mVec128, mvp_rm.vec[2].mVec128), mvp_rm.vec[3].mVec128);
#else #else
/* Left */ /* Left */
@ -76,12 +76,12 @@ public:
#endif #endif
m_planes[0].normalize(); planes[0].normalize();
m_planes[1].normalize(); planes[1].normalize();
m_planes[2].normalize(); planes[2].normalize();
m_planes[3].normalize(); planes[3].normalize();
m_planes[4].normalize(); planes[4].normalize();
m_planes[5].normalize(); planes[5].normalize();
} }
@ -90,31 +90,31 @@ public:
CVector3f vmin, vmax; CVector3f vmin, vmax;
int i; int i;
for (i=0 ; i<6 ; ++i) { for (i=0 ; i<6 ; ++i) {
const CPlane& plane = m_planes[i]; const CPlane& plane = planes[i];
/* X axis */ /* X axis */
if (plane.a >= 0) { if (plane.a >= 0) {
vmin[0] = aabb.m_min[0]; vmin[0] = aabb.min[0];
vmax[0] = aabb.m_max[0]; vmax[0] = aabb.max[0];
} else { } else {
vmin[0] = aabb.m_max[0]; vmin[0] = aabb.max[0];
vmax[0] = aabb.m_min[0]; vmax[0] = aabb.min[0];
} }
/* Y axis */ /* Y axis */
if (plane.b >= 0) { if (plane.b >= 0) {
vmin[1] = aabb.m_min[1]; vmin[1] = aabb.min[1];
vmax[1] = aabb.m_max[1]; vmax[1] = aabb.max[1];
} else { } else {
vmin[1] = aabb.m_max[1]; vmin[1] = aabb.max[1];
vmax[1] = aabb.m_min[1]; vmax[1] = aabb.min[1];
} }
/* Z axis */ /* Z axis */
if (plane.c >= 0) { if (plane.c >= 0) {
vmin[2] = aabb.m_min[2]; vmin[2] = aabb.min[2];
vmax[2] = aabb.m_max[2]; vmax[2] = aabb.max[2];
} else { } else {
vmin[2] = aabb.m_max[2]; vmin[2] = aabb.max[2];
vmax[2] = aabb.m_min[2]; vmax[2] = aabb.min[2];
} }
float dadot = plane.vec.dot(vmax); float dadot = plane.vec.dot(vmax);
if (dadot + plane.d < 0) if (dadot + plane.d < 0)

View File

@ -35,7 +35,7 @@ public:
COBBox(const CAABox& aabb) COBBox(const CAABox& aabb)
: extents(aabb.volume()) : extents(aabb.volume())
{ {
transform.m_origin = aabb.center(); transform.origin = aabb.center();
} }
COBBox(const CTransform& xf, const CVector3f& point) COBBox(const CTransform& xf, const CVector3f& point)

View File

@ -17,16 +17,16 @@ enum class EProjType
}; };
struct SProjOrtho struct SProjOrtho
{ {
float m_top, m_bottom, m_left, m_right, m_near, m_far; float top, bottom, left, right, near, far;
SProjOrtho(float p_top=1.0f, float p_bottom=-1.0f, float p_left=-1.0f, float p_right=1.0f, SProjOrtho(float p_top=1.0f, float p_bottom=-1.0f, float p_left=-1.0f, float p_right=1.0f,
float p_near=1.0f, float p_far=-1.0f) : float p_near=1.0f, float p_far=-1.0f) :
m_top(p_top), m_bottom(p_bottom), m_left(p_left), m_right(p_right), m_near(p_near), m_far(p_far) {} top(p_top), bottom(p_bottom), left(p_left), right(p_right), near(p_near), far(p_far) {}
}; };
struct SProjPersp struct SProjPersp
{ {
float m_fov, m_aspect, m_near, m_far; float fov, aspect, near, far;
SProjPersp(float p_fov=degToRad(55.0f), float p_aspect=1.0f, float p_near=0.1f, float p_far=4096.f) : SProjPersp(float p_fov=degToRad(55.0f), float p_aspect=1.0f, float p_near=0.1f, float p_far=4096.f) :
m_fov(p_fov), m_aspect(p_aspect), m_near(p_near), m_far(p_far) {} fov(p_fov), aspect(p_aspect), near(p_near), far(p_far) {}
}; };
extern const SProjOrtho kOrthoIdentity; extern const SProjOrtho kOrthoIdentity;

View File

@ -14,21 +14,21 @@ class alignas(16) CTransform
public: public:
ZE_DECLARE_ALIGNED_ALLOCATOR(); ZE_DECLARE_ALIGNED_ALLOCATOR();
CTransform() : m_basis(false) {} CTransform() : basis(false) {}
CTransform(const CMatrix3f& basis, const CVector3f& offset=CVector3f::skZero) : CTransform(const CMatrix3f& basis, const CVector3f& offset=CVector3f::skZero) :
m_basis(basis), m_origin(offset) {} basis(basis), origin(offset) {}
#if ZE_ATHENA_TYPES #if ZE_ATHENA_TYPES
CTransform(const atVec4f* mtx) CTransform(const atVec4f* mtx)
: m_basis(mtx[0], mtx[1], mtx[2]), m_origin(mtx[0].vec[3], mtx[1].vec[3], mtx[2].vec[3]) {} : basis(mtx[0], mtx[1], mtx[2]), origin(mtx[0].vec[3], mtx[1].vec[3], mtx[2].vec[3]) {}
void read34RowMajor(athena::io::IStreamReader& r) void read34RowMajor(athena::io::IStreamReader& r)
{ {
atVec4f r0 = r.readVec4fBig(); atVec4f r0 = r.readVec4fBig();
atVec4f r1 = r.readVec4fBig(); atVec4f r1 = r.readVec4fBig();
atVec4f r2 = r.readVec4fBig(); atVec4f r2 = r.readVec4fBig();
m_basis = CMatrix3f(r0, r1, r2); basis = CMatrix3f(r0, r1, r2);
m_basis.transpose(); basis.transpose();
m_origin = CVector3f(r0.vec[3], r1.vec[3], r2.vec[3]); origin = CVector3f(r0.vec[3], r1.vec[3], r2.vec[3]);
} }
#endif #endif
@ -38,12 +38,12 @@ public:
} }
inline CTransform operator*(const CTransform& rhs) const inline CTransform operator*(const CTransform& rhs) const
{return CTransform(m_basis * rhs.m_basis, m_origin + (m_basis * rhs.m_origin));} {return CTransform(basis * rhs.basis, origin + (basis * rhs.origin));}
inline CTransform inverse() const inline CTransform inverse() const
{ {
CMatrix3f inv = m_basis.inverted(); CMatrix3f inv = basis.inverted();
return CTransform(inv, inv * -m_origin); return CTransform(inv, inv * -origin);
} }
static inline CTransform Translate(const CVector3f& position) static inline CTransform Translate(const CVector3f& position)
@ -55,23 +55,23 @@ public:
inline CTransform operator+(const CVector3f& other) inline CTransform operator+(const CVector3f& other)
{ {
return CTransform(m_basis, m_origin + other); return CTransform(basis, origin + other);
} }
inline CTransform& operator+=(const CVector3f& other) inline CTransform& operator+=(const CVector3f& other)
{ {
m_origin += other; origin += other;
return *this; return *this;
} }
inline CTransform operator-(const CVector3f& other) inline CTransform operator-(const CVector3f& other)
{ {
return CTransform(m_basis, m_origin - other); return CTransform(basis, origin - other);
} }
inline CTransform& operator-=(const CVector3f& other) inline CTransform& operator-=(const CVector3f& other)
{ {
m_origin -= other; origin -= other;
return *this; return *this;
} }
@ -109,15 +109,15 @@ public:
float sinT = std::sin(theta); float sinT = std::sin(theta);
float cosT = std::cos(theta); float cosT = std::cos(theta);
zeus::CVector3f b2 = m_basis[2] * sinT; zeus::CVector3f b2 = basis[2] * sinT;
zeus::CVector3f b1 = m_basis[1] * sinT; zeus::CVector3f b1 = basis[1] * sinT;
zeus::CVector3f cosV(cosT); zeus::CVector3f cosV(cosT);
m_basis[1] *= cosV; basis[1] *= cosV;
m_basis[2] *= cosV; basis[2] *= cosV;
m_basis[1] += b2; basis[1] += b2;
m_basis[2] -= b1; basis[2] -= b1;
} }
inline void rotateLocalY(float theta) inline void rotateLocalY(float theta)
@ -125,15 +125,15 @@ public:
float sinT = std::sin(theta); float sinT = std::sin(theta);
float cosT = std::cos(theta); float cosT = std::cos(theta);
zeus::CVector3f b0 = m_basis[0] * sinT; zeus::CVector3f b0 = basis[0] * sinT;
zeus::CVector3f b2 = m_basis[2] * sinT; zeus::CVector3f b2 = basis[2] * sinT;
zeus::CVector3f cosV(cosT); zeus::CVector3f cosV(cosT);
m_basis[0] *= cosV; basis[0] *= cosV;
m_basis[2] *= cosV; basis[2] *= cosV;
m_basis[2] += b0; basis[2] += b0;
m_basis[0] -= b2; basis[0] -= b2;
} }
inline void rotateLocalZ(float theta) inline void rotateLocalZ(float theta)
@ -141,20 +141,20 @@ public:
float sinT = std::sin(theta); float sinT = std::sin(theta);
float cosT = std::cos(theta); float cosT = std::cos(theta);
zeus::CVector3f b0 = m_basis[0] * sinT; zeus::CVector3f b0 = basis[0] * sinT;
zeus::CVector3f b1 = m_basis[1] * sinT; zeus::CVector3f b1 = basis[1] * sinT;
zeus::CVector3f cosV(cosT); zeus::CVector3f cosV(cosT);
m_basis[0] *= cosV; basis[0] *= cosV;
m_basis[1] *= cosV; basis[1] *= cosV;
m_basis[0] += b1; basis[0] += b1;
m_basis[1] -= b0; basis[1] -= b0;
} }
inline CVector3f transposeRotate(const CVector3f& in) const inline CVector3f transposeRotate(const CVector3f& in) const
{ {
return CVector3f(m_basis[0].dot(in), m_basis[1].dot(in), m_basis[2].dot(in)); return CVector3f(basis[0].dot(in), basis[1].dot(in), basis[2].dot(in));
} }
inline void scaleBy(float factor) inline void scaleBy(float factor)
@ -184,26 +184,26 @@ public:
inline CTransform multiplyIgnoreTranslation(const CTransform& xfrm) inline CTransform multiplyIgnoreTranslation(const CTransform& xfrm)
{ {
CTransform ret; CTransform ret;
ret.m_basis = m_basis * xfrm.m_basis; ret.basis = basis * xfrm.basis;
return ret; return ret;
} }
inline CTransform getRotation() const { CTransform ret = *this; ret.m_origin.zeroOut(); return ret; } inline CTransform getRotation() const { CTransform ret = *this; ret.origin.zeroOut(); return ret; }
void setRotation(const CMatrix3f& mat) { m_basis = mat; } void setRotation(const CMatrix3f& mat) { basis = mat; }
void setRotation(const CTransform& xfrm) { setRotation(xfrm.m_basis); } void setRotation(const CTransform& xfrm) { setRotation(xfrm.basis); }
/** /**
* @brief buildMatrix3f Returns the stored matrix * @brief buildMatrix3f Returns the stored matrix
* buildMatrix3f is here for compliance with Retro's Math API * buildMatrix3f is here for compliance with Retro's Math API
* @return The Matrix (Neo, you are the one) * @return The Matrix (Neo, you are the one)
*/ */
inline CMatrix3f buildMatrix3f() { return m_basis; } inline CMatrix3f buildMatrix3f() { return basis; }
inline CVector3f operator*(const CVector3f& other) const {return m_origin + m_basis * other;} inline CVector3f operator*(const CVector3f& other) const {return origin + basis * other;}
inline CMatrix4f toMatrix4f() const inline CMatrix4f toMatrix4f() const
{ {
CMatrix4f ret(m_basis[0], m_basis[1], m_basis[2], m_origin); CMatrix4f ret(basis[0], basis[1], basis[2], origin);
ret[0][3] = 0.0f; ret[0][3] = 0.0f;
ret[1][3] = 0.0f; ret[1][3] = 0.0f;
ret[2][3] = 0.0f; ret[2][3] = 0.0f;
@ -214,31 +214,31 @@ public:
static inline CTransform fromColumns(const CVector3f& m0, const CVector3f& m1, const CVector3f& m2, const CVector3f& m3) static inline CTransform fromColumns(const CVector3f& m0, const CVector3f& m1, const CVector3f& m2, const CVector3f& m3)
{ {
CTransform ret; CTransform ret;
ret.m_basis[0][0] = m0[0]; ret.basis[0][0] = m0[0];
ret.m_basis[0][1] = m1[0]; ret.basis[0][1] = m1[0];
ret.m_basis[0][2] = m2[0]; ret.basis[0][2] = m2[0];
ret.m_origin[0] = m3[0]; ret.origin[0] = m3[0];
ret.m_basis[1][0] = m0[1]; ret.basis[1][0] = m0[1];
ret.m_basis[1][1] = m1[1]; ret.basis[1][1] = m1[1];
ret.m_basis[1][2] = m2[1]; ret.basis[1][2] = m2[1];
ret.m_origin[1] = m3[1]; ret.origin[1] = m3[1];
ret.m_basis[2][0] = m0[2]; ret.basis[2][0] = m0[2];
ret.m_basis[2][1] = m1[2]; ret.basis[2][1] = m1[2];
ret.m_basis[2][2] = m2[2]; ret.basis[2][2] = m2[2];
ret.m_origin[2] = m3[2]; ret.origin[2] = m3[2];
return ret; return ret;
} }
inline void orthonormalize() inline void orthonormalize()
{ {
m_basis[0].normalize(); basis[0].normalize();
m_basis[2] = m_basis[0].cross(m_basis[1]); basis[2] = basis[0].cross(basis[1]);
m_basis[2].normalize(); basis[2].normalize();
m_basis[1] = m_basis[2].cross(m_basis[0]); basis[1] = basis[2].cross(basis[0]);
} }
CMatrix3f m_basis; CMatrix3f basis;
CVector3f m_origin; CVector3f origin;
}; };
static inline CTransform CTransformFromScaleVector(const CVector3f& scale) static inline CTransform CTransformFromScaleVector(const CVector3f& scale)

View File

@ -11,23 +11,23 @@ void CProjection::_updateCachedMatrix()
{ {
float tmp; float tmp;
tmp = 1.0f / (m_ortho.m_right - m_ortho.m_left); tmp = 1.0f / (m_ortho.right - m_ortho.left);
m_mtx.m[0][0] = 2.0f * tmp; m_mtx.m[0][0] = 2.0f * tmp;
m_mtx.m[1][0] = 0.0f; m_mtx.m[1][0] = 0.0f;
m_mtx.m[2][0] = 0.0f; m_mtx.m[2][0] = 0.0f;
m_mtx.m[3][0] = -(m_ortho.m_right + m_ortho.m_left) * tmp; m_mtx.m[3][0] = -(m_ortho.right + m_ortho.left) * tmp;
tmp = 1.0f / (m_ortho.m_top - m_ortho.m_bottom); tmp = 1.0f / (m_ortho.top - m_ortho.bottom);
m_mtx.m[0][1] = 0.0f; m_mtx.m[0][1] = 0.0f;
m_mtx.m[1][1] = 2.0f * tmp; m_mtx.m[1][1] = 2.0f * tmp;
m_mtx.m[2][1] = 0.0f; m_mtx.m[2][1] = 0.0f;
m_mtx.m[3][1] = -(m_ortho.m_top + m_ortho.m_bottom) * tmp; m_mtx.m[3][1] = -(m_ortho.top + m_ortho.bottom) * tmp;
tmp = 1.0f / (m_ortho.m_far - m_ortho.m_near); tmp = 1.0f / (m_ortho.far - m_ortho.near);
m_mtx.m[0][2] = 0.0f; m_mtx.m[0][2] = 0.0f;
m_mtx.m[1][2] = 0.0f; m_mtx.m[1][2] = 0.0f;
m_mtx.m[2][2] = -(1.0f) * tmp; m_mtx.m[2][2] = -(1.0f) * tmp;
m_mtx.m[3][2] = -m_ortho.m_far * tmp; m_mtx.m[3][2] = -m_ortho.far * tmp;
m_mtx.m[0][3] = 0.0f; m_mtx.m[0][3] = 0.0f;
m_mtx.m[1][3] = 0.0f; m_mtx.m[1][3] = 0.0f;
@ -37,11 +37,11 @@ void CProjection::_updateCachedMatrix()
else if (m_projType == EProjType::Perspective) else if (m_projType == EProjType::Perspective)
{ {
float cot,tmp; float cot,tmp;
float t_fovy = std::tan(m_persp.m_fov / 2.0f); float t_fovy = std::tan(m_persp.fov / 2.0f);
cot = 1.0f / t_fovy; cot = 1.0f / t_fovy;
m_mtx.m[0][0] = cot/m_persp.m_aspect; m_mtx.m[0][0] = cot/m_persp.aspect;
m_mtx.m[1][0] = 0.0f; m_mtx.m[1][0] = 0.0f;
m_mtx.m[2][0] = 0.0f; m_mtx.m[2][0] = 0.0f;
m_mtx.m[3][0] = 0.0f; m_mtx.m[3][0] = 0.0f;
@ -51,11 +51,11 @@ void CProjection::_updateCachedMatrix()
m_mtx.m[2][1] = 0.0f; m_mtx.m[2][1] = 0.0f;
m_mtx.m[3][1] = 0.0f; m_mtx.m[3][1] = 0.0f;
tmp = 1.0f / (m_persp.m_far - m_persp.m_near); tmp = 1.0f / (m_persp.far - m_persp.near);
m_mtx.m[0][2] = 0.0f; m_mtx.m[0][2] = 0.0f;
m_mtx.m[1][2] = 0.0f; m_mtx.m[1][2] = 0.0f;
m_mtx.m[2][2] = -m_persp.m_far * tmp; m_mtx.m[2][2] = -m_persp.far * tmp;
m_mtx.m[3][2] = -(m_persp.m_far * m_persp.m_near) * tmp; m_mtx.m[3][2] = -(m_persp.far * m_persp.near) * tmp;
m_mtx.m[0][3] = 0.0f; m_mtx.m[0][3] = 0.0f;
m_mtx.m[1][3] = 0.0f; m_mtx.m[1][3] = 0.0f;

View File

@ -23,15 +23,15 @@ CTransform CTransformFromEditorEuler(const CVector3f& eulerVec)
sc = si * ch; sc = si * ch;
ss = si * sh; ss = si * sh;
result.m_basis.m[0][0] = float(cj * ch); result.basis.m[0][0] = float(cj * ch);
result.m_basis.m[1][0] = float(sj * sc - cs); result.basis.m[1][0] = float(sj * sc - cs);
result.m_basis.m[2][0] = float(sj * cc + ss); result.basis.m[2][0] = float(sj * cc + ss);
result.m_basis.m[0][1] = float(cj * sh); result.basis.m[0][1] = float(cj * sh);
result.m_basis.m[1][1] = float(sj * ss + cc); result.basis.m[1][1] = float(sj * ss + cc);
result.m_basis.m[2][1] = float(sj * cs - sc); result.basis.m[2][1] = float(sj * cs - sc);
result.m_basis.m[0][2] = float(-sj); result.basis.m[0][2] = float(-sj);
result.m_basis.m[1][2] = float(cj * si); result.basis.m[1][2] = float(cj * si);
result.m_basis.m[2][2] = float(cj * ci); result.basis.m[2][2] = float(cj * ci);
return result; return result;
} }
@ -45,17 +45,17 @@ CTransform CTransformFromAxisAngle(const CVector3f& axis, float angle)
float s = std::sin(angle); float s = std::sin(angle);
float t = 1.f - c; float t = 1.f - c;
result.m_basis.m[0][0] = t * axisN.v[0] * axisN.v[0] + c; result.basis.m[0][0] = t * axisN.v[0] * axisN.v[0] + c;
result.m_basis.m[1][0] = t * axisN.v[0] * axisN.v[1] - axisN.v[2] * s; result.basis.m[1][0] = t * axisN.v[0] * axisN.v[1] - axisN.v[2] * s;
result.m_basis.m[2][0] = t * axisN.v[0] * axisN.v[2] + axisN.v[1] * s; result.basis.m[2][0] = t * axisN.v[0] * axisN.v[2] + axisN.v[1] * s;
result.m_basis.m[0][1] = t * axisN.v[0] * axisN.v[1] + axisN.v[2] * s; result.basis.m[0][1] = t * axisN.v[0] * axisN.v[1] + axisN.v[2] * s;
result.m_basis.m[1][1] = t * axisN.v[1] * axisN.v[1] + c; result.basis.m[1][1] = t * axisN.v[1] * axisN.v[1] + c;
result.m_basis.m[2][1] = t * axisN.v[1] * axisN.v[2] - axisN.v[0] * s; result.basis.m[2][1] = t * axisN.v[1] * axisN.v[2] - axisN.v[0] * s;
result.m_basis.m[0][2] = t * axisN.v[0] * axisN.v[2] - axisN.v[1] * s; result.basis.m[0][2] = t * axisN.v[0] * axisN.v[2] - axisN.v[1] * s;
result.m_basis.m[1][2] = t * axisN.v[1] * axisN.v[2] + axisN.v[0] * s; result.basis.m[1][2] = t * axisN.v[1] * axisN.v[2] + axisN.v[0] * s;
result.m_basis.m[2][2] = t * axisN.v[2] * axisN.v[2] + c; result.basis.m[2][2] = t * axisN.v[2] * axisN.v[2] + c;
return result; return result;
} }
@ -63,7 +63,7 @@ CTransform CTransformFromAxisAngle(const CVector3f& axis, float angle)
CTransform CTransformFromEditorEulers(const CVector3f& eulerVec, const CVector3f& origin) CTransform CTransformFromEditorEulers(const CVector3f& eulerVec, const CVector3f& origin)
{ {
CTransform ret = CTransformFromEditorEuler(eulerVec); CTransform ret = CTransformFromEditorEuler(eulerVec);
ret.m_origin = origin; ret.origin = origin;
return ret; return ret;
} }
} }