More reimplementations

Move API to Zeus namespace
This commit is contained in:
Phillip Stephens 2015-10-07 17:21:38 -07:00
parent 394a225062
commit 8012694fc7
33 changed files with 253 additions and 178 deletions

View File

@ -25,7 +25,6 @@ add_library(Math
src/CMatrix4f.cpp
src/CAABox.cpp
include/CVector3f.hpp
include/Math.hpp
include/CQuaternion.hpp
include/CMatrix3f.hpp
@ -37,11 +36,13 @@ add_library(Math
include/CColor.hpp
include/Global.hpp
include/MathLib.hpp
include/TVectorUnion.hpp
include/CVector2f.hpp
include/CVector3f.hpp
include/CVector3d.hpp
include/CVector4f.hpp
include/CRectangle.hpp
include/CMatrix4f.hpp
include/TVectorUnion.hpp
include/CVector4f.hpp
include/CFrustum.hpp
include/CAABox.hpp
include/COBBox.hpp

View File

@ -7,6 +7,8 @@
#include "Math.hpp"
#include <Athena/IStreamReader.hpp>
namespace Zeus
{
class ZE_ALIGN(16) CAABox
{
public:
@ -107,26 +109,29 @@ public:
return true;
}
CVector3f center() const
{
return (m_min + m_max) * 0.5f;
}
CVector3f volume() const
{
return (m_max - m_min) * 0.5f;
}
CVector3f center() const {return (m_min + m_max) * 0.5f;}
CVector3f volume() const {return (m_max - m_min) * 0.5f;}
inline CAABox getTransformedAABox(const CTransform& xfrm)
{
CAABox box;
for (int i = 0; i < 8; i+=2)
{
CVector3f point = xfrm * getPoint(i);
box.accumulateBounds(point);
point = xfrm * getPoint(i+1);
box.accumulateBounds(point);
}
CVector3f point = xfrm * getPoint(0);
box.accumulateBounds(point);
point = xfrm * getPoint(1);
box.accumulateBounds(point);
point = xfrm * getPoint(2);
box.accumulateBounds(point);
point = xfrm * getPoint(3);
box.accumulateBounds(point);
point = xfrm * getPoint(4);
box.accumulateBounds(point);
point = xfrm * getPoint(5);
box.accumulateBounds(point);
point = xfrm * getPoint(6);
box.accumulateBounds(point);
point = xfrm * getPoint(7);
box.accumulateBounds(point);
return box;
}
@ -138,7 +143,6 @@ public:
m_min.y = point.y;
if (m_min.z > point.z)
m_min.z = point.z;
if (m_max.x < point.x)
m_max.x = point.x;
if (m_max.y < point.y)
@ -184,9 +188,9 @@ public:
inline CVector3f clampToBox(const CVector3f& vec)
{
CVector3f ret = vec;
Math::clamp(ret.x, m_min.x, m_max.x);
Math::clamp(ret.y, m_min.y, m_max.y);
Math::clamp(ret.z, m_min.z, m_max.z);
Math::clamp(m_min.x, ret.x, m_max.x);
Math::clamp(m_min.y, ret.y, m_max.y);
Math::clamp(m_min.z, ret.z, m_max.z);
return ret;
}
@ -223,20 +227,11 @@ public:
negZ.m_min = m_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 (m_max.x < m_min.x || m_max.y < m_min.y || m_max.z < m_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.m_min != right.m_min || left.m_max != right.m_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.m_min != right.m_min || left.m_max != right.m_max);}
}
#endif // CAABOX_HPP

View File

@ -4,6 +4,8 @@
#include "Global.hpp"
#include "CVector3f.hpp"
namespace Zeus
{
struct ZE_ALIGN(16) CAxisAngle
{
ZE_DECLARE_ALIGNED_ALLOCATOR();
@ -20,5 +22,6 @@ struct ZE_ALIGN(16) CAxisAngle
CVector3f axis;
float angle;
};
}
#endif // CAXISANGLE_H

View File

@ -11,7 +11,9 @@
#define COLOR(rgba) rgba
#endif
typedef union _RGBA32
namespace Zeus
{
typedef union
{
struct
{
@ -170,19 +172,19 @@ public:
}
inline void normalize()
{
float mag = length();
float mag = magnitude();
assert(mag != 0.0);
mag = 1.0 / mag;
*this *= mag;
}
inline CColor normalized()
{
float mag = length();
float mag = magnitude();
assert(mag != 0.0);
mag = 1.0 / mag;
return *this * mag;
}
inline float lengthSquared() const
inline float magSquared() const
{
#if __SSE4_1__
TVectorUnion result;
@ -196,9 +198,9 @@ public:
return r * r + g * g + b * b + a * a;
#endif
}
inline float length() const
inline float magnitude() const
{
return sqrtf(lengthSquared());
return sqrtf(magSquared());
}
static inline CColor lerp(const CColor& a, const CColor& b, float t)
{
@ -288,4 +290,6 @@ static inline CColor operator/(float lhs, const CColor& rhs)
#endif
}
}
#endif // CCOLOR_HPP

View File

@ -4,6 +4,8 @@
#include "CPlane.hpp"
#include "CAABox.hpp"
namespace Zeus
{
class CFrustum
{
CPlane m_planes[6];
@ -123,5 +125,5 @@ public:
}
};
}
#endif // CFRUSTUM_HPP

View File

@ -6,7 +6,8 @@
#include <assert.h>
/* Column-major matrix class */
namespace Zeus
{
class CQuaternion;
class ZE_ALIGN(16) CMatrix3f
{
@ -106,4 +107,6 @@ public:
CMatrix3f operator*(const CMatrix3f& lhs, const CMatrix3f& rhs);
}
#endif // CMATRIX3F_HPP

View File

@ -4,6 +4,8 @@
#include "CVector4f.hpp"
#include "CVector3f.hpp"
namespace Zeus
{
class ZE_ALIGN(16) CMatrix4f
{
public:
@ -178,6 +180,7 @@ static inline CMatrix4f operator*(const CMatrix4f& lhs, const CMatrix4f& rhs)
#endif
return ret;
}
}
#endif // CMATRIX4F

View File

@ -5,6 +5,8 @@
#include "CVector3f.hpp"
#include "CAABox.hpp"
namespace Zeus
{
class ZE_ALIGN(16) COBBox
{
public:
@ -36,17 +38,27 @@ public:
{-1.0, 1.0, -1.0},
{-1.0, 1.0, 1.0}
};
CVector3f p = m_extents * basis[0];
for (int i = 0; i < 8; i+=2)
{
CVector3f p = (m_extents * basis[i]);
ret.accumulateBounds(trans * p);
p = m_extents * basis[i + 1];
ret.accumulateBounds(trans * p);
}
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

View File

@ -3,7 +3,10 @@
#include "Global.hpp"
#include "CVector3f.hpp"
#include "Math.hpp"
namespace Zeus
{
class ZE_ALIGN(16) CPlane
{
public:
@ -28,11 +31,18 @@ public:
#endif
d = displacement;
}
float clipLineSegment(const CVector3f& a, const CVector3f& b)
{
float mag = ((b.z - a.z) * (((b.x - a.x) * ((b.y - a.y) * vec.y)) + vec.x)) + vec.z;
float dis = (-(vec.y - d)) / mag;
return Math::clamp(0.0f, dis, 1.0f);
}
inline void normalize()
{
float nd = d;
float mag = vec.length();
float mag = vec.magnitude();
assert(mag != 0.0f);
mag = 1.0 / mag;
vec *= mag;
@ -52,5 +62,6 @@ public:
#endif
};
};
}
#endif // CPLANE_HPP

View File

@ -7,7 +7,8 @@
#define _USE_MATH_DEFINES 1
#include <math.h>
namespace Zeus
{
enum EProjType
{
PROJ_NONE = 0,
@ -110,5 +111,6 @@ protected:
CMatrix4f m_mtx;
};
}
#endif // CMATRIX3F_HPP

View File

@ -8,6 +8,8 @@
#include <math.h>
#include <Athena/IStreamReader.hpp>
namespace Zeus
{
class ZE_ALIGN(16) CQuaternion
{
public:
@ -46,8 +48,8 @@ public:
const CQuaternion& operator*=(const CQuaternion& q);
const CQuaternion& operator*=(float scale);
const CQuaternion& operator/=(float scale);
float length() const;
float lengthSquared() const;
float magnitude() const;
float magSquared() const;
void normalize();
CQuaternion normalized() const;
void invert();
@ -106,4 +108,5 @@ public:
CQuaternion operator+(float lhs, const CQuaternion& rhs);
CQuaternion operator-(float lhs, const CQuaternion& rhs);
CQuaternion operator*(float lhs, const CQuaternion& rhs);
}
#endif // CQUATERNION_HPP

View File

@ -2,6 +2,8 @@
#define CRECTANGLE_HPP
#include "CVector2f.hpp"
namespace Zeus
{
class CRectangle
{
public:
@ -28,5 +30,6 @@ public:
CVector2f position;
CVector2f size;
};
}
#endif // CRECTANGLE_HPP

View File

@ -4,6 +4,8 @@
#include "CVector3f.hpp"
#include "Math.hpp"
namespace Zeus
{
/**
* @brief The CRelAngle class represents relative angles in radians
*/
@ -26,5 +28,6 @@ public:
{
}
};
}
#endif // CRELANGLE_HPP

View File

@ -3,23 +3,15 @@
#include "CVector3f.hpp"
namespace Zeus
{
class ZE_ALIGN(16) CSphere
{
public:
ZE_DECLARE_ALIGNED_ALLOCATOR();
CSphere(const CVector3f& position, float radius)
{
#if __SSE__
mVec128 = position.mVec128;
#endif
r = radius;
}
inline CVector3f getSurfaceNormal(const CVector3f& coord)
{
return (vec - coord).normalized();
}
CSphere(const CVector3f& position, float radius) { vec = position; r = radius; }
inline CVector3f getSurfaceNormal(const CVector3f& coord) { return (vec - coord).normalized(); }
union
{
@ -31,5 +23,6 @@ public:
#endif
};
};
}
#endif

View File

@ -7,6 +7,8 @@
#include "CVector3f.hpp"
#include "CQuaternion.hpp"
namespace Zeus
{
class ZE_ALIGN(16) CTransform
{
public:
@ -31,55 +33,40 @@ public:
m_origin = position;
}
inline void rotate(const CVector3f& euler)
{
*this = *this * CMatrix3f(CQuaternion(euler));
}
inline void translate(float x, float y, float z) { translate({x, y, z}); }
inline void rotate(const CVector3f& euler) { *this = *this * CMatrix3f(CQuaternion(euler)); }
inline void scaleBy(float factor)
{
CTransform xfrm(CMatrix3f(CVector3f(factor, factor, factor)));
*this = *this * xfrm;
}
{ CTransform xfrm(CMatrix3f(CVector3f(factor, factor, factor))); *this = *this * xfrm; }
inline void scale(const CVector3f& scale)
inline void scale(const CVector3f& factor)
{
m_basis = CMatrix3f(true);
m_basis[0][0] = scale.x;
m_basis[1][1] = scale.y;
m_basis[2][2] = scale.z;
m_basis[0][0] = factor.x;
m_basis[1][1] = factor.y;
m_basis[2][2] = factor.z;
m_origin.zeroOut();
}
inline void scale(float x, float y, float z)
{
scale({x, y, z});
}
inline void multiplyIgnoreTranslation(const CTransform& xfrm)
{
m_basis = m_basis*xfrm.m_basis;
}
inline void scale(float x, float y, float z) { scale({x, y, z}); }
inline void scale(float factor) { scale({factor, factor, factor}); }
inline CTransform getRotation()
{
CTransform ret = *this;
ret.m_origin.zeroOut();
return ret;
}
inline void multiplyIgnoreTranslation(const CTransform& xfrm) { m_basis = m_basis*xfrm.m_basis; }
inline CTransform getRotation() { CTransform ret = *this; ret.m_origin.zeroOut(); return ret; }
void setRotation(const CMatrix3f& mat) { m_basis = mat; }
void setRotation(const CTransform& xfrm) { setRotation(xfrm.m_basis); }
/**
* @brief buildMatrix3f Returns the stored matrix
* buildMatrix3f is here for compliance with Retro's Math API
* @return The Matrix (Neo, you are the one)
*/
inline CMatrix3f buildMatrix3f()
{
return m_basis;
}
inline CMatrix3f buildMatrix3f() { return m_basis; }
inline CVector3f operator*(const CVector3f& other) const
{return m_origin + m_basis * other;}
inline CVector3f operator*(const CVector3f& other) const {return m_origin + m_basis * other;}
inline void toMatrix4f(CMatrix4f& mat) const
{
@ -125,5 +112,6 @@ static inline CTransform CTransformFromScaleVector(const CVector3f& scale)
CTransform CTransformFromEditorEuler(const CVector3f& eulerVec);
CTransform CTransformFromEditorEulers(const CVector3f& eulerVec, const CVector3f& origin);
CTransform CTransformFromAxisAngle(const CVector3f& axis, float angle);
}
#endif // CTRANSFORM_HPP

View File

@ -3,6 +3,8 @@
#include "CVector3f.hpp"
namespace Zeus
{
class ZE_ALIGN(16) CUnitVector3f : public CVector3f
{
public:
@ -15,5 +17,5 @@ public:
normalize();
}
};
}
#endif

View File

@ -8,7 +8,8 @@
#include <math.h>
#include <assert.h>
namespace Zeus
{
class ZE_ALIGN(16) CVector2f
{
public:
@ -197,7 +198,7 @@ class ZE_ALIGN(16) CVector2f
}
inline void normalize()
{
float mag = length();
float mag = magnitude();
if (mag > 1e-6f)
{
mag = 1.0 / mag;
@ -209,7 +210,7 @@ class ZE_ALIGN(16) CVector2f
inline CVector2f normalized() const
{
float mag = length();
float mag = magnitude();
if (mag > 1e-6f)
{
mag = 1.0 / mag;
@ -236,7 +237,7 @@ class ZE_ALIGN(16) CVector2f
return (x * rhs.x) + (y * rhs.y);
#endif
}
inline float lengthSquared() const
inline float magSquared() const
{
#if __SSE4_1__
TVectorUnion result;
@ -250,9 +251,9 @@ class ZE_ALIGN(16) CVector2f
return x*x + y*y;
#endif
}
inline float length() const
inline float magnitude() const
{
return sqrtf(lengthSquared());
return sqrtf(magSquared());
}
inline void zeroOut()
@ -288,7 +289,7 @@ class ZE_ALIGN(16) CVector2f
inline bool isNormalized(float thresh = 1e-5f) const
{
return (fabs(1.0f - lengthSquared()) <= thresh);
return (fabs(1.0f - magSquared()) <= thresh);
}
inline bool canBeNormalized()
@ -357,5 +358,6 @@ static inline CVector2f operator/(float lhs, const CVector2f& rhs)
return CVector2f(lhs / rhs.x, lhs / rhs.y);
#endif
}
}
#endif // CVECTOR2F_HPP

View File

@ -8,6 +8,8 @@
#include <math.h>
#include <assert.h>
namespace Zeus
{
class ZE_ALIGN(16) CVector3f
{
public:
@ -162,7 +164,7 @@ public:
}
inline void normalize()
{
float mag = length();
float mag = magnitude();
if (mag > 1e-6f)
{
mag = 1.0 / mag;
@ -173,7 +175,7 @@ public:
}
inline CVector3f normalized() const
{
float mag = length();
float mag = magnitude();
if (mag > 1e-6f)
{
mag = 1.0 / mag;
@ -182,9 +184,8 @@ public:
return {0, 0, 0};
}
inline CVector3f cross(const CVector3f& rhs) const
{
return CVector3f(y * rhs.z - z * rhs.y, z * rhs.x - x * rhs.z, x * rhs.y - y * rhs.x);
}
{ return CVector3f(y * rhs.z - z * rhs.y, z * rhs.x - x * rhs.z, x * rhs.y - y * rhs.x); }
inline float dot(const CVector3f& rhs) const
{
#if __SSE4_1__
@ -199,7 +200,7 @@ public:
return (x * rhs.x) + (y * rhs.y) + (z * rhs.z);
#endif
}
inline float lengthSquared() const
inline float magSquared() const
{
#if __SSE4_1__
TVectorUnion result;
@ -213,10 +214,8 @@ public:
return x*x + y*y + z*z;
#endif
}
inline float length() const
{
return sqrtf(lengthSquared());
}
inline float magnitude() const
{ return sqrtf(magSquared()); }
inline void zeroOut()
{
@ -240,34 +239,24 @@ public:
static float getAngleDiff(const CVector3f& a, const CVector3f& b);
static inline CVector3f lerp(const CVector3f& a, const CVector3f& b, float t)
{
return (a + (b - a) * t);
}
{ return (a + (b - a) * t); }
static inline CVector3f nlerp(const CVector3f& a, const CVector3f& b, float t)
{
return lerp(a, b, t).normalized();
}
{ return lerp(a, b, t).normalized(); }
static CVector3f slerp(const CVector3f& a, const CVector3f& b, float t);
//static CVector3f slerp(const CVector3f& a, const CVector3f& b, const CRelAngle& angle);
inline bool isNormalized(float thresh = 1e-5f) const
{
return (fabs(1.0f - lengthSquared()) <= thresh);
}
{ return (fabs(1.0f - magSquared()) <= thresh); }
inline bool canBeNormalized()
{
return !isNormalized();
}
{ return !isNormalized(); }
inline bool isZero() const
{
return lengthSquared() <= 1e-7;
}
{ return magSquared() <= 1e-7; }
inline void scaleToLength(float newLength)
{
float length = lengthSquared();
float length = magSquared();
if (length < 1e-6f)
{
x = newLength, y = 0.f, z = 0.f;
@ -298,10 +287,7 @@ public:
union
{
struct
{
float x, y, z;
};
struct { float x, y, z; };
float v[4];
#if __SSE__
__m128 mVec128;
@ -353,5 +339,6 @@ static inline CVector3f operator/(float lhs, const CVector3f& rhs)
return CVector3f(lhs / rhs.x, lhs / rhs.y, lhs / rhs.z);
#endif
}
}
#endif // CVECTOR3F_HPP

View File

@ -9,6 +9,8 @@
#include <float.h>
#include <assert.h>
namespace Zeus
{
class ZE_ALIGN(16) CVector4f
{
public:
@ -221,7 +223,7 @@ class ZE_ALIGN(16) CVector4f
}
inline void normalize()
{
float mag = length();
float mag = magnitude();
if (mag > 1e-6f)
{
mag = 1.0 / mag;
@ -232,7 +234,7 @@ class ZE_ALIGN(16) CVector4f
}
inline CVector4f normalized() const
{
float mag = length();
float mag = magnitude();
if (mag > 1e-6f)
{
mag = 1.0 / mag;
@ -255,7 +257,7 @@ class ZE_ALIGN(16) CVector4f
return (x * rhs.x) + (y * rhs.y) + (z * rhs.z) + (w * rhs.w);
#endif
}
inline float lengthSquared() const
inline float magSquared() const
{
#if __SSE4_1__
TVectorUnion result;
@ -269,9 +271,9 @@ class ZE_ALIGN(16) CVector4f
return x*x + y*y + z*z + w*w;
#endif
}
inline float length() const
inline float magnitude() const
{
return sqrtf(lengthSquared());
return sqrtf(magSquared());
}
inline void zeroOut()
@ -304,7 +306,7 @@ class ZE_ALIGN(16) CVector4f
inline bool isNormalized(float thresh = 1e-5f) const
{
return (fabs(1.0f - lengthSquared()) <= thresh);
return (fabs(1.0f - magSquared()) <= thresh);
}
inline bool canBeNormalized()
@ -373,5 +375,6 @@ static inline CVector4f operator/(float lhs, const CVector4f& rhs)
return CVector4f(lhs / rhs.x, lhs / rhs.y, lhs / rhs.z, lhs / rhs.w);
#endif
}
}
#endif // CVECTOR4F_HPP

View File

@ -6,18 +6,12 @@
#include "CVector3f.hpp"
#include "CTransform.hpp"
/* Macros for min/max. */
#ifndef MIN
#define MIN(a,b) (((a)<(b))?(a):(b))
#endif /* MIN */
#ifndef MAX
#define MAX(a,b) (((a)>(b))?(a):(b))
#endif /* MAX */
namespace Zeus
{
namespace Math
{
template<typename T>
inline T clamp(T min, T val, T max) {return MAX(min, MIN(max, val));}
inline T clamp(T min, T val, T max) {return std::max(min, std::min(max, val));}
inline float radToDeg(float rad) {return rad * 180.f / M_PI;}
inline float degToRad(float deg) {return deg * M_PI / 180;}
@ -26,10 +20,17 @@ namespace Math
inline CVector3f radToDeg(CVector3f rad) {return rad * kRadToDegVec;}
inline CVector3f degToRad(CVector3f deg) {return deg * kDegToRadVec;}
// Since round(double) doesn't exist in some <cmath> implementations
// we'll define our own
inline float round(double val) { return (val < 0.0 ? floor(val - 0.5) : floor(val + 0.5)); }
extern const CVector3f kUpVec;
CTransform lookAt(const CVector3f& pos, const CVector3f& lookPos, const CVector3f& up=kUpVec);
inline CVector3f baryToWorld(const CVector3f& p0, const CVector3f& p1, const CVector3f& p2, const CVector3f& bary)
{ return bary.x * p0 + bary.y * p1 + bary.z * p2; }
inline CVector3f getBezierPoint(const CVector3f& a, const CVector3f& b, const CVector3f& c, const CVector3f& d, float t);
}
}
#endif // MATH_HPP

View File

@ -10,6 +10,7 @@
#include "CQuaternion.hpp"
#include "CVector2f.hpp"
#include "CVector3f.hpp"
#include "CVector3d.hpp"
#include "CVector4f.hpp"
#include "CUnitVector.hpp"
#include "CRectangle.hpp"

View File

@ -1,6 +1,8 @@
#ifndef TVECTORUNION
#define TVECTORUNION
namespace Zeus
{
typedef union
{
float v[4];
@ -9,5 +11,14 @@ typedef union
#endif
} TVectorUnion;
typedef union
{
double v[4];
#if __SSE__
__m128d mVec128[2];
#endif
} TDblVectorUnion;
}
#endif // TVECTORUNION

View File

@ -1,2 +1,2 @@
#include "CAABox.hpp"
const CAABox CAABox::skInvertedBox = CAABox();
const Zeus::CAABox Zeus::CAABox::skInvertedBox = CAABox();

View File

@ -1,11 +1,11 @@
#include "CColor.hpp"
const CColor CColor::skRed (COLOR(0xFF0000FF));
const CColor CColor::skBlack (COLOR(0x000000FF));
const CColor CColor::skBlue (COLOR(0x0000FFFF));
const CColor CColor::skGreen (COLOR(0x00FF00FF));
const CColor CColor::skGrey (COLOR(0x808080FF));
const CColor CColor::skOrange(COLOR(0xFF7000FF));
const CColor CColor::skPurple(COLOR(0xA000FFFF));
const CColor CColor::skYellow(COLOR(0xFFFF00FF));
const CColor CColor::skWhite (COLOR(0xFFFFFFFF));
const Zeus::CColor Zeus::CColor::skRed (COLOR(0xFF0000FF));
const Zeus::CColor Zeus::CColor::skBlack (COLOR(0x000000FF));
const Zeus::CColor Zeus::CColor::skBlue (COLOR(0x0000FFFF));
const Zeus::CColor Zeus::CColor::skGreen (COLOR(0x00FF00FF));
const Zeus::CColor Zeus::CColor::skGrey (COLOR(0x808080FF));
const Zeus::CColor Zeus::CColor::skOrange(COLOR(0xFF7000FF));
const Zeus::CColor Zeus::CColor::skPurple(COLOR(0xA000FFFF));
const Zeus::CColor Zeus::CColor::skYellow(COLOR(0xFFFF00FF));
const Zeus::CColor Zeus::CColor::skWhite (COLOR(0xFFFFFFFF));

View File

@ -2,6 +2,8 @@
#include "CQuaternion.hpp"
#include "Global.hpp"
namespace Zeus
{
const CMatrix3f CMatrix3f::skIdentityMatrix3f = CMatrix3f();
CMatrix3f::CMatrix3f(const CQuaternion& quat)
@ -136,4 +138,4 @@ CMatrix3f CMatrix3f::inverted() const
-(m[0][0]*m[1][2] - m[0][2]*m[1][0]) * det,
(m[0][0]*m[1][1] - m[0][1]*m[1][0]) * det);
}
}

View File

@ -1,3 +1,3 @@
#include "CMatrix4f.hpp"
const CMatrix4f CMatrix4f::skIdentityMatrix4f = CMatrix4f();
const Zeus::CMatrix4f Zeus::CMatrix4f::skIdentityMatrix4f = CMatrix4f();

View File

@ -2,6 +2,8 @@
#include <math.h>
#include <stdio.h>
namespace Zeus
{
void CProjection::_updateCachedMatrix()
{
if (m_projType == PROJ_ORTHO)
@ -65,4 +67,5 @@ void CProjection::_updateCachedMatrix()
abort();
}
}
}

View File

@ -1,6 +1,8 @@
#include "CQuaternion.hpp"
#include <math.h>
namespace Zeus
{
void CQuaternion::fromVector3f(const CVector3f& vec)
{
float cosX = cosf(0.5 * vec.x);
@ -102,24 +104,24 @@ const CQuaternion& CQuaternion::operator/=(float scale)
return *this;
}
float CQuaternion::length() const
float CQuaternion::magnitude() const
{
return sqrt(lengthSquared());
return sqrt(magSquared());
}
float CQuaternion::lengthSquared() const
float CQuaternion::magSquared() const
{
return (r*r + (v.dot(v)));
}
void CQuaternion::normalize()
{
*this /= length();
*this /= magnitude();
}
CQuaternion CQuaternion::normalized() const
{
return *this/length();
return *this/magnitude();
}
void CQuaternion::invert()
@ -170,7 +172,7 @@ CQuaternion CQuaternion::log() const
CQuaternion CQuaternion::exp() const
{
float a = (v.length());
float a = (v.magnitude());
float sina = sinf(a);
float cosa = cos(a);
CQuaternion ret;
@ -249,3 +251,4 @@ CQuaternion operator*(float lhs, const CQuaternion& rhs)
{
return CQuaternion(lhs * rhs.r, lhs * rhs.v);
}
}

View File

@ -1,5 +1,7 @@
#include "CTransform.hpp"
namespace Zeus
{
CTransform CTransformFromEditorEuler(const CVector3f& eulerVec)
{
CTransform result;
@ -64,3 +66,4 @@ CTransform CTransformFromEditorEulers(const CVector3f& eulerVec, const CVector3f
ret.m_origin = origin;
return ret;
}
}

View File

@ -4,14 +4,16 @@
#include <assert.h>
#include "Math.hpp"
namespace Zeus
{
const CVector2f CVector2f::skOne = CVector2f(1.0);
const CVector2f CVector2f::skNegOne = CVector2f(-1.0);
const CVector2f CVector2f::skZero;
float CVector2f::getAngleDiff(const CVector2f& a, const CVector2f& b)
{
float mag1 = a.length();
float mag2 = b.length();
float mag1 = a.magnitude();
float mag2 = b.magnitude();
if (!mag1 || !mag2)
return 0;
@ -47,4 +49,4 @@ CVector2f CVector2f::slerp(const CVector2f& a, const CVector2f& b, float t)
}
return a;
}
}

View File

@ -4,14 +4,16 @@
#include <assert.h>
#include "Math.hpp"
namespace Zeus
{
const CVector3f CVector3f::skOne = CVector3f(1.0);
const CVector3f CVector3f::skNegOne = CVector3f(-1.0);
const CVector3f CVector3f::skZero;
float CVector3f::getAngleDiff(const CVector3f& a, const CVector3f& b)
{
float mag1 = a.length();
float mag2 = b.length();
float mag1 = a.magnitude();
float mag2 = b.magnitude();
if (!mag1 || !mag2)
return 0;
@ -50,3 +52,4 @@ CVector3f CVector3f::slerp(const CVector3f& a, const CVector3f& b, float t)
}
return a;
}
}

View File

@ -1,10 +1,14 @@
#include "Math.hpp"
const CVector3f Math::kUpVec(0.0, 0.0, 1.0);
const CVector3f Math::kRadToDegVec(180.0f / M_PI);
const CVector3f Math::kDegToRadVec(M_PI / 180.0f);
namespace Zeus
{
namespace Math
{
const CVector3f kUpVec(0.0, 0.0, 1.0);
const CVector3f kRadToDegVec(180.0f / M_PI);
const CVector3f kDegToRadVec(M_PI / 180.0f);
CTransform Math::lookAt(const CVector3f& pos, const CVector3f& lookPos, const CVector3f& up)
CTransform lookAt(const CVector3f& pos, const CVector3f& lookPos, const CVector3f& up)
{
CVector3f vLook,vRight,vUp;
@ -19,3 +23,20 @@ CTransform Math::lookAt(const CVector3f& pos, const CVector3f& lookPos, const CV
CMatrix3f rmBasis(vRight, vUp, vLook);
return CTransform(rmBasis.transposed(), CVector3f(-pos.dot(vRight), -pos.dot(vUp), -pos.dot(vLook)));
}
CVector3f getBezierPoint(const CVector3f& r4, const CVector3f& r5, const CVector3f& r6, const CVector3f& r7, float f1)
{
//TODO: This isn't quite right, figure out what's really going on and reimplement
#if 0
float inv = 1.0 - f1;
CVector3f r3;
r3.x = ((((((r4.x * (r5.x * f1)) + inv) * (((r5.x * (r6.x * f1)) + inv) * f1)) + inv) * (((((r5.x * (r6.x * f1)) + inv) * (((r6.x * (r7.x * f1)) + inv) * f1)) + inv) * f1)) + inv);
r3.y = ((((((r4.y * (r5.y * f1)) + inv) * (((r5.y * (r6.y * f1)) + inv) * f1)) + inv) * (((((r5.y * (r6.y * f1)) + inv) * (((r6.y * (r7.y * f1)) + inv) * f1)) + inv) * f1)) + inv);
r3.z = ((((((r4.z * (r5.z * f1)) + inv) * (((r5.z * (r6.z * f1)) + inv) * f1)) + inv) * (((((r5.z * (r6.z * f1)) + inv) * (((r6.z * (r7.z * f1)) + inv) * f1)) + inv) * f1)) + inv);
return r3;
#endif
return CVector3f::skZero;
}
}
}

View File

@ -1,6 +1,9 @@
#include <iostream>
#include <MathLib.hpp>
// This is only for testing, do NOT do this normally
using namespace Zeus;
int main()
{
assert(!CAABox({100, 100, 100}, {100, 100, 100}).invalid());
@ -26,5 +29,7 @@ int main()
assert(test3.inside(test));
assert(!test4.inside(test));
std::cout << Math::round(1.5) << std::endl;
return 0;
}