New code style refactor

This commit is contained in:
Jack Andersen 2018-12-07 19:23:50 -10:00
parent e8dfecbb6e
commit e172225845
49 changed files with 712 additions and 1265 deletions

View File

@ -1,6 +1,6 @@
---
IndentWidth: 2
ColumnLimit: 128
BasedOnStyle: LLVM
ColumnLimit: 120
UseTab: Never
---
Language: Cpp
@ -8,7 +8,6 @@ DerivePointerAlignment: false
PointerAlignment: Left
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
BreakBeforeBraces: Allman
IndentCaseLabels: false
AllowShortBlocksOnASingleLine: true
AlignOperands: true
@ -16,7 +15,6 @@ AlignTrailingComments: true
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true
BreakConstructorInitializersBeforeComma: true
BreakStringLiterals: true
AlwaysBreakAfterReturnType: None
AlwaysBreakAfterDefinitionReturnType: None
AllowShortFunctionsOnASingleLine: All
@ -25,6 +23,6 @@ NamespaceIndentation: None
BinPackArguments: true
BinPackParameters: true
SortIncludes: false
AccessModifierOffset: -4
AccessModifierOffset: -2
ConstructorInitializerIndentWidth: 0
ConstructorInitializerAllOnOneLineOrOnePerLine: true

View File

@ -16,23 +16,9 @@
namespace zeus {
class CAABox {
public:
enum class EBoxEdgeId {
Z0,
X0,
Z1,
X1,
Z2,
X2,
Z3,
X3,
Y0,
Y1,
Y2,
Y3
};
enum class EBoxEdgeId { Z0, X0, Z1, X1, Z2, X2, Z3, X3, Y0, Y1, Y2, Y3 };
enum class EBoxFaceID {
};
enum class EBoxFaceID {};
static const CAABox skInvertedBox;
static const CAABox skNullBox;
@ -48,8 +34,7 @@ public:
CAABox(float min, float max) : min(CVector3f(min)), max(CVector3f(max)) {}
CAABox(float minX, float minY, float minZ, float maxX, float maxY, float maxZ)
: min(minX, minY, minZ), max(maxX, maxY, maxZ) {
}
: min(minX, minY, minZ), max(maxX, maxY, maxZ) {}
#if ZE_ATHENA_TYPES
@ -233,20 +218,17 @@ public:
}
bool pointInside(const CVector3f& other) const {
return (min.x() <= other.x() && other.x() <= max.x() &&
min.y() <= other.y() && other.y() <= max.y() &&
return (min.x() <= other.x() && other.x() <= max.x() && min.y() <= other.y() && other.y() <= max.y() &&
min.z() <= other.z() && other.z() <= max.z());
}
CVector3f closestPointAlongVector(const CVector3f& other) const {
return {(other.x() >= 0.f ? min.x() : max.x()),
(other.y() >= 0.f ? min.y() : max.y()),
return {(other.x() >= 0.f ? min.x() : max.x()), (other.y() >= 0.f ? min.y() : max.y()),
(other.z() >= 0.f ? min.z() : max.z())};
}
CVector3f furthestPointAlongVector(const CVector3f& other) const {
return {(other.x() >= 0.f ? max.x() : min.x()),
(other.y() >= 0.f ? max.y() : min.y()),
return {(other.x() >= 0.f ? max.x() : min.x()), (other.y() >= 0.f ? max.y() : min.y()),
(other.z() >= 0.f ? max.z() : min.z())};
}
@ -368,5 +350,4 @@ inline bool operator==(const CAABox& left, const CAABox& right) {
inline bool operator!=(const CAABox& left, const CAABox& right) {
return (left.min != right.min || left.max != right.max);
}
}
} // namespace zeus

View File

@ -14,5 +14,4 @@ struct CAxisAngle : CVector3f {
const CVector3f& getVector() const { return *this; }
static const CAxisAngle sIdentity;
};
}
} // namespace zeus

View File

@ -18,8 +18,9 @@
#undef max
#if BYTE_ORDER == __ORDER_LITTLE_ENDIAN__
#define COLOR(rgba) \
(unsigned)(((rgba)&0x000000FF) << 24 | ((rgba)&0x0000FF00) << 8 | ((rgba)&0x00FF0000) >> 8 | ((rgba)&0xFF000000) >> 24)
#define COLOR(rgba) \
(unsigned)(((rgba)&0x000000FF) << 24 | ((rgba)&0x0000FF00) << 8 | ((rgba)&0x00FF0000) >> 8 | \
((rgba)&0xFF000000) >> 24)
#else
#define COLOR(rgba) rgba
#endif
@ -136,37 +137,21 @@ public:
bool operator!=(const CColor& rhs) const { return !(*this == rhs); }
CColor operator+(const CColor& rhs) const {
return mSimd + rhs.mSimd;
}
CColor operator+(const CColor& rhs) const { return mSimd + rhs.mSimd; }
CColor operator-(const CColor& rhs) const {
return mSimd - rhs.mSimd;
}
CColor operator-(const CColor& rhs) const { return mSimd - rhs.mSimd; }
CColor operator*(const CColor& rhs) const {
return mSimd * rhs.mSimd;
}
CColor operator*(const CColor& rhs) const { return mSimd * rhs.mSimd; }
CColor operator/(const CColor& rhs) const {
return mSimd / rhs.mSimd;
}
CColor operator/(const CColor& rhs) const { return mSimd / rhs.mSimd; }
CColor operator+(float val) const {
return mSimd + simd<float>(val);
}
CColor operator+(float val) const { return mSimd + simd<float>(val); }
CColor operator-(float val) const {
return mSimd - simd<float>(val);
}
CColor operator-(float val) const { return mSimd - simd<float>(val); }
CColor operator*(float val) const {
return mSimd * simd<float>(val);
}
CColor operator*(float val) const { return mSimd * simd<float>(val); }
CColor operator/(float val) const {
return mSimd / simd<float>(val);
}
CColor operator/(float val) const { return mSimd / simd<float>(val); }
const CColor& operator+=(const CColor& rhs) {
mSimd += rhs.mSimd;
@ -220,9 +205,7 @@ public:
return *this * mag;
}
float magSquared() const {
return mSimd.dot4(mSimd);
}
float magSquared() const { return mSimd.dot4(mSimd); }
float magnitude() const { return std::sqrt(magSquared()); }
@ -247,9 +230,7 @@ public:
mSimd[3] = a;
}
float rgbDot(const CColor& rhs) const {
return mSimd.dot3(rhs.mSimd);
}
float rgbDot(const CColor& rhs) const { return mSimd.dot3(rhs.mSimd); }
void fromRGBA8(const Comp8 ri, const Comp8 gi, const Comp8 bi, const Comp8 ai) {
mSimd = simd<float>(ri * OneOver255, gi * OneOver255, bi * OneOver255, ai * OneOver255);
@ -320,19 +301,11 @@ public:
simd<float>::reference a() { return mSimd[3]; }
};
static inline CColor operator+(float lhs, const CColor& rhs) {
return simd<float>(lhs) + rhs.mSimd;
}
static inline CColor operator+(float lhs, const CColor& rhs) { return simd<float>(lhs) + rhs.mSimd; }
static inline CColor operator-(float lhs, const CColor& rhs) {
return simd<float>(lhs) - rhs.mSimd;
}
static inline CColor operator-(float lhs, const CColor& rhs) { return simd<float>(lhs) - rhs.mSimd; }
static inline CColor operator*(float lhs, const CColor& rhs) {
return simd<float>(lhs) * rhs.mSimd;
}
static inline CColor operator*(float lhs, const CColor& rhs) { return simd<float>(lhs) * rhs.mSimd; }
static inline CColor operator/(float lhs, const CColor& rhs) {
return simd<float>(lhs) / rhs.mSimd;
}
}
static inline CColor operator/(float lhs, const CColor& rhs) { return simd<float>(lhs) / rhs.mSimd; }
} // namespace zeus

View File

@ -12,5 +12,4 @@ public:
CEulerAngles(const CTransform& xf);
};
}
} // namespace zeus

View File

@ -16,4 +16,4 @@ public:
bool sphereFrustumTest(const CSphere& sphere) const;
bool pointFrustumTest(const CVector3f& point) const;
};
}
} // namespace zeus

View File

@ -11,5 +11,4 @@ public:
CVector3f origin;
CVector3f dir;
};
}
} // namespace zeus

View File

@ -18,5 +18,4 @@ public:
CVector3f xc_dir;
CVector3f x18_end;
};
}
} // namespace zeus

View File

@ -7,13 +7,13 @@
namespace zeus {
struct CMRay {
CMRay(const CVector3f& start, const CVector3f& dirin, float len)
: start(start), length(len), invLength(1.f / len), dir(dirin) {
: start(start), length(len), invLength(1.f / len), dir(dirin) {
end = start + (len * dirin);
delta = end - start;
}
CMRay(const CVector3f& start, const CVector3f& end, float len, float invLen)
: start(start), end(end), length(len), invLength(invLen) {
: start(start), end(end), length(len), invLength(invLen) {
delta = end - start;
dir = invLen * delta;
}
@ -24,11 +24,10 @@ struct CMRay {
}
CVector3f start; // x0
CVector3f end; // xc
CVector3f end; // xc
CVector3f delta; // x18
float length; // x24
float length; // x24
float invLength; // x28
CVector3f dir; // x2c
CVector3f dir; // x2c
};
}
} // namespace zeus

View File

@ -11,7 +11,6 @@ class CQuaternion;
class CMatrix3f {
public:
explicit CMatrix3f(bool zero = false) {
m[0] = simd<float>(0.f);
m[1] = simd<float>(0.f);
@ -23,12 +22,8 @@ public:
}
}
CMatrix3f(float m00, float m01, float m02,
float m10, float m11, float m12,
float m20, float m21, float m22)
: m{{m00, m10, m20},
{m01, m11, m21},
{m02, m12, m22}} {}
CMatrix3f(float m00, float m01, float m02, float m10, float m11, float m12, float m20, float m21, float m22)
: m{{m00, m10, m20}, {m01, m11, m21}, {m02, m12, m22}} {}
CMatrix3f(const CVector3f& scaleVec) {
m[0] = simd<float>(0.f);
@ -99,8 +94,7 @@ public:
}
CVector3f operator*(const CVector3f& other) const {
return m[0].mSimd * other.mSimd.shuffle<0, 0, 0, 0>() +
m[1].mSimd * other.mSimd.shuffle<1, 1, 1, 1>() +
return m[0].mSimd * other.mSimd.shuffle<0, 0, 0, 0>() + m[1].mSimd * other.mSimd.shuffle<1, 1, 1, 1>() +
m[2].mSimd * other.mSimd.shuffle<2, 2, 2, 2>();
}
@ -147,32 +141,27 @@ public:
static CMatrix3f RotateX(float theta) {
float sinT = std::sin(theta);
float cosT = std::cos(theta);
return CMatrix3f(simd<float>{1.f, 0.f, 0.f, 0.f},
simd<float>{0.f, cosT, sinT, 0.f},
return CMatrix3f(simd<float>{1.f, 0.f, 0.f, 0.f}, simd<float>{0.f, cosT, sinT, 0.f},
simd<float>{0.f, -sinT, cosT, 0.f});
}
static CMatrix3f RotateY(float theta) {
float sinT = std::sin(theta);
float cosT = std::cos(theta);
return CMatrix3f(simd<float>{cosT, 0.f, -sinT, 0.f},
simd<float>{0.f, 1.f, 0.f, 0.f},
return CMatrix3f(simd<float>{cosT, 0.f, -sinT, 0.f}, simd<float>{0.f, 1.f, 0.f, 0.f},
simd<float>{sinT, 0.f, cosT, 0.f});
}
static CMatrix3f RotateZ(float theta) {
float sinT = std::sin(theta);
float cosT = std::cos(theta);
return CMatrix3f(simd<float>{cosT, sinT, 0.f, 0.f},
simd<float>{-sinT, cosT, 0.f, 0.f},
return CMatrix3f(simd<float>{cosT, sinT, 0.f, 0.f}, simd<float>{-sinT, cosT, 0.f, 0.f},
simd<float>{0.f, 0.f, 1.f, 0.f});
}
float determinant() const {
return
m[1][0] * (m[2][1] * m[0][2] - m[0][1] * m[2][2]) +
m[0][0] * (m[1][1] * m[2][2] - m[2][1] * m[1][2]) +
m[2][0] * (m[0][1] * m[1][2] - m[1][1] * m[0][2]);
return m[1][0] * (m[2][1] * m[0][2] - m[0][1] * m[2][2]) + m[0][0] * (m[1][1] * m[2][2] - m[2][1] * m[1][2]) +
m[2][0] * (m[0][1] * m[1][2] - m[1][1] * m[0][2]);
}
CVector3f m[3];
@ -181,10 +170,8 @@ public:
static inline CMatrix3f operator*(const CMatrix3f& lhs, const CMatrix3f& rhs) {
simd<float> v[3];
for (int i = 0; i < 3; ++i)
v[i] = lhs.m[0].mSimd * rhs[i].mSimd.shuffle<0, 0, 0, 0>() +
lhs.m[1].mSimd * rhs[i].mSimd.shuffle<1, 1, 1, 1>() +
v[i] = lhs.m[0].mSimd * rhs[i].mSimd.shuffle<0, 0, 0, 0>() + lhs.m[1].mSimd * rhs[i].mSimd.shuffle<1, 1, 1, 1>() +
lhs.m[2].mSimd * rhs[i].mSimd.shuffle<2, 2, 2, 2>();
return CMatrix3f(v[0], v[1], v[2]);
}
}
} // namespace zeus

View File

@ -18,14 +18,9 @@ public:
}
}
CMatrix4f(float m00, float m01, float m02, float m03,
float m10, float m11, float m12, float m13,
float m20, float m21, float m22, float m23,
float m30, float m31, float m32, float m33)
: m{{m00, m10, m20, m30},
{m01, m11, m21, m31},
{m02, m12, m22, m32},
{m03, m13, m23, m33}} {}
CMatrix4f(float m00, float m01, float m02, float m03, float m10, float m11, float m12, float m13, float m20,
float m21, float m22, float m23, float m30, float m31, float m32, float m33)
: m{{m00, m10, m20, m30}, {m01, m11, m21, m31}, {m02, m12, m22, m32}, {m03, m13, m23, m33}} {}
CMatrix4f(const CVector3f& scaleVec) {
m[0][0] = scaleVec[0];
@ -47,7 +42,7 @@ public:
m[2] = other.m[2];
m[3] = other.m[3];
}
CMatrix4f(const simd<float>& r0, const simd<float>& r1, const simd<float>& r2, const simd<float>& r3) {
m[0].mSimd = r0;
m[1].mSimd = r1;
@ -71,10 +66,8 @@ public:
}
CVector4f operator*(const CVector4f& other) const {
return m[0].mSimd * other.mSimd.shuffle<0, 0, 0, 0>() +
m[1].mSimd * other.mSimd.shuffle<1, 1, 1, 1>() +
m[2].mSimd * other.mSimd.shuffle<2, 2, 2, 2>() +
m[3].mSimd * other.mSimd.shuffle<3, 3, 3, 3>();
return m[0].mSimd * other.mSimd.shuffle<0, 0, 0, 0>() + m[1].mSimd * other.mSimd.shuffle<1, 1, 1, 1>() +
m[2].mSimd * other.mSimd.shuffle<2, 2, 2, 2>() + m[3].mSimd * other.mSimd.shuffle<3, 3, 3, 3>();
}
CVector4f& operator[](size_t i) {
@ -106,11 +99,8 @@ public:
static inline CMatrix4f operator*(const CMatrix4f& lhs, const CMatrix4f& rhs) {
simd<float> v[4];
for (int i = 0; i < 4; ++i)
v[i] = lhs.m[0].mSimd * rhs[i].mSimd.shuffle<0, 0, 0, 0>() +
lhs.m[1].mSimd * rhs[i].mSimd.shuffle<1, 1, 1, 1>() +
lhs.m[2].mSimd * rhs[i].mSimd.shuffle<2, 2, 2, 2>() +
lhs.m[3].mSimd * rhs[i].mSimd.shuffle<3, 3, 3, 3>();
v[i] = lhs.m[0].mSimd * rhs[i].mSimd.shuffle<0, 0, 0, 0>() + lhs.m[1].mSimd * rhs[i].mSimd.shuffle<1, 1, 1, 1>() +
lhs.m[2].mSimd * rhs[i].mSimd.shuffle<2, 2, 2, 2>() + lhs.m[3].mSimd * rhs[i].mSimd.shuffle<3, 3, 3, 3>();
return CMatrix4f(v[0], v[1], v[2], v[3]);
}
}
} // namespace zeus

View File

@ -42,9 +42,6 @@ public:
bool OBBIntersectsBox(const COBBox& other) const;
bool AABoxIntersectsBox(const CAABox& other) {
return OBBIntersectsBox(FromAABox(other, CTransform::Identity()));
}
bool AABoxIntersectsBox(const CAABox& other) { return OBBIntersectsBox(FromAABox(other, CTransform::Identity())); }
};
}
} // namespace zeus

View File

@ -36,9 +36,7 @@ public:
mSimd[3] = nd * mag;
}
float pointToPlaneDist(const CVector3f& pos) const {
return pos.dot(normal()) - d();
}
float pointToPlaneDist(const CVector3f& pos) const { return pos.dot(normal()) - d(); }
bool rayPlaneIntersection(const CVector3f& from, const CVector3f& to, CVector3f& point) const;
@ -66,5 +64,4 @@ public:
zeus::simd<float> mSimd;
};
}
} // namespace zeus

View File

@ -7,11 +7,7 @@
#include <cmath>
namespace zeus {
enum class EProjType {
None = 0,
Orthographic = 1,
Perspective = 2
};
enum class EProjType { None = 0, Orthographic = 1, Perspective = 2 };
class SProjOrtho {
public:
@ -19,16 +15,14 @@ public:
explicit 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)
: top(p_top), bottom(p_bottom), left(p_left), right(p_right), znear(p_near), zfar(p_far) {
}
: top(p_top), bottom(p_bottom), left(p_left), right(p_right), znear(p_near), zfar(p_far) {}
};
struct SProjPersp {
float fov, aspect, znear, zfar;
SProjPersp(float p_fov = degToRad(55.0f), float p_aspect = 1.0f, float p_near = 0.1f, float p_far = 4096.f)
: fov(p_fov), aspect(p_aspect), znear(p_near), zfar(p_far) {
}
: fov(p_fov), aspect(p_aspect), znear(p_near), zfar(p_far) {}
};
extern const SProjOrtho kOrthoIdentity;
@ -101,13 +95,11 @@ protected:
/* Projection intermediate */
union {
#ifdef _MSC_VER
struct
{
SProjOrtho m_ortho;
struct {
SProjOrtho m_ortho;
};
struct
{
SProjPersp m_persp;
struct {
SProjPersp m_persp;
};
#else
SProjOrtho m_ortho;
@ -118,5 +110,4 @@ protected:
/* Cached projection matrix */
CMatrix4f m_mtx;
};
}
} // namespace zeus

View File

@ -37,9 +37,7 @@ public:
CQuaternion(float xi, float yi, float zi) { fromVector3f(CVector3f(xi, yi, zi)); }
CQuaternion(float wi, const CVector3f& vec) : mSimd(vec.mSimd.shuffle<0, 0, 1, 2>()) {
mSimd[0] = wi;
}
CQuaternion(float wi, const CVector3f& vec) : mSimd(vec.mSimd.shuffle<0, 0, 1, 2>()) { mSimd[0] = wi; }
template <typename T>
CQuaternion(const simd<T>& s) : mSimd(s) {}
@ -57,13 +55,9 @@ public:
CQuaternion(const atVec4f& vec) : mSimd(vec.simd) {}
operator atVec4f&() {
return *reinterpret_cast<atVec4f*>(this);
}
operator atVec4f&() { return *reinterpret_cast<atVec4f*>(this); }
operator const atVec4f&() const {
return *reinterpret_cast<const atVec4f*>(this);
}
operator const atVec4f&() const { return *reinterpret_cast<const atVec4f*>(this); }
#endif
@ -158,9 +152,7 @@ public:
CTransform toTransform(const zeus::CVector3f& origin) const { return CTransform(CMatrix3f(*this), origin); }
float dot(const CQuaternion& rhs) const {
return mSimd.dot4(rhs.mSimd);
}
float dot(const CQuaternion& rhs) const { return mSimd.dot4(rhs.mSimd); }
static CQuaternion lerp(const CQuaternion& a, const CQuaternion& b, double t);
@ -177,7 +169,7 @@ public:
float roll() const {
simd_floats f(mSimd);
return std::atan2(2.f * (f[1] * f[2] + f[0] * f[3]), f[0] * f[0] + f[1] * f[1] - f[2] * f[2] - f[3] * f[3]);
return std::asin(-2.f * (f[1] * f[3] - f[0] * f[2]));
}
float pitch() const {
@ -187,7 +179,7 @@ public:
float yaw() const {
simd_floats f(mSimd);
return std::asin(-2.f * (f[1] * f[3] - f[0] * f[2]));
return std::atan2(2.f * (f[1] * f[2] + f[0] * f[3]), f[0] * f[0] + f[1] * f[1] - f[2] * f[2] - f[3] * f[3]);
}
CQuaternion buildEquivalent() const;
@ -238,9 +230,7 @@ public:
CNUQuaternion(float wi, float xi, float yi, float zi) : mSimd(wi, xi, yi, zi) {}
CNUQuaternion(float win, const zeus::CVector3f& vec) : mSimd(vec.mSimd.shuffle<0, 0, 1, 2>()) {
w() = win;
}
CNUQuaternion(float win, const zeus::CVector3f& vec) : mSimd(vec.mSimd.shuffle<0, 0, 1, 2>()) { w() = win; }
CNUQuaternion(const CQuaternion& other) : mSimd(other.mSimd) {}
@ -307,4 +297,4 @@ CQuaternion operator-(float lhs, const CQuaternion& rhs);
CQuaternion operator*(float lhs, const CQuaternion& rhs);
CNUQuaternion operator*(float lhs, const CNUQuaternion& rhs);
}
} // namespace zeus

View File

@ -26,5 +26,4 @@ public:
CVector2f position;
CVector2f size;
};
}
} // namespace zeus

View File

@ -91,5 +91,4 @@ struct CRelAngle {
return *this;
}
};
}
} // namespace zeus

View File

@ -17,5 +17,4 @@ public:
CVector3f position;
float radius;
};
}
} // namespace zeus

View File

@ -13,14 +13,12 @@ class CTransform {
public:
CTransform() : basis(false) {}
CTransform(const CMatrix3f& basis, const CVector3f& offset = CVector3f::skZero)
: basis(basis), origin(offset) {}
CTransform(const CMatrix3f& basis, const CVector3f& offset = CVector3f::skZero) : basis(basis), origin(offset) {}
#if ZE_ATHENA_TYPES
CTransform(const atVec4f* mtx)
: basis(mtx[0], mtx[1], mtx[2])
, origin(mtx[0].simd[3], mtx[1].simd[3], mtx[2].simd[3]) {}
: basis(mtx[0], mtx[1], mtx[2]), origin(mtx[0].simd[3], mtx[1].simd[3], mtx[2].simd[3]) {}
void read34RowMajor(athena::io::IStreamReader& r) {
atVec4f r0 = r.readVec4fBig();
@ -37,13 +35,9 @@ public:
CTransform(const CVector3f& c0, const CVector3f& c1, const CVector3f& c2, const CVector3f& c3)
: basis(c0, c1, c2), origin(c3) {}
static CTransform Identity() {
return CTransform(CMatrix3f::skIdentityMatrix3f);
}
static CTransform Identity() { return CTransform(CMatrix3f::skIdentityMatrix3f); }
bool operator==(const CTransform& other) const {
return origin == other.origin && basis == other.basis;
}
bool operator==(const CTransform& other) const { return origin == other.origin && basis == other.basis; }
CTransform operator*(const CTransform& rhs) const {
return CTransform(basis * rhs.basis, origin + (basis * rhs.origin));
@ -54,57 +48,44 @@ public:
return CTransform(inv, inv * -origin);
}
static CTransform Translate(const CVector3f& position) {
return {CMatrix3f::skIdentityMatrix3f, position};
}
static CTransform Translate(const CVector3f& position) { return {CMatrix3f::skIdentityMatrix3f, position}; }
static CTransform Translate(float x, float y, float z) {
return Translate({x, y, z});
}
static CTransform Translate(float x, float y, float z) { return Translate({x, y, z}); }
CTransform operator+(const CVector3f& other) {
return CTransform(basis, origin + other);
}
CTransform operator+(const CVector3f& other) { return CTransform(basis, origin + other); }
CTransform& operator+=(const CVector3f& other) {
origin += other;
return *this;
}
CTransform operator-(const CVector3f& other) {
return CTransform(basis, origin - other);
}
CTransform operator-(const CVector3f& other) { return CTransform(basis, origin - other); }
CTransform& operator-=(const CVector3f& other) {
origin -= other;
return *this;
}
zeus::CVector3f rotate(const CVector3f& vec) const {
return basis * vec;
}
zeus::CVector3f rotate(const CVector3f& vec) const { return basis * vec; }
static CTransform RotateX(float theta) {
float sinT = std::sin(theta);
float cosT = std::cos(theta);
return CTransform(CMatrix3f(simd<float>{1.f, 0.f, 0.f, 0.f},
simd<float>{0.f, cosT, sinT, 0.f},
return CTransform(CMatrix3f(simd<float>{1.f, 0.f, 0.f, 0.f}, simd<float>{0.f, cosT, sinT, 0.f},
simd<float>{0.f, -sinT, cosT, 0.f}));
}
static CTransform RotateY(float theta) {
float sinT = std::sin(theta);
float cosT = std::cos(theta);
return CTransform(CMatrix3f(simd<float>{cosT, 0.f, -sinT, 0.f},
simd<float>{0.f, 1.f, 0.f, 0.f},
return CTransform(CMatrix3f(simd<float>{cosT, 0.f, -sinT, 0.f}, simd<float>{0.f, 1.f, 0.f, 0.f},
simd<float>{sinT, 0.f, cosT, 0.f}));
}
static CTransform RotateZ(float theta) {
float sinT = std::sin(theta);
float cosT = std::cos(theta);
return CTransform(CMatrix3f(simd<float>{cosT, sinT, 0.f, 0.f},
simd<float>{-sinT, cosT, 0.f, 0.f},
return CTransform(CMatrix3f(simd<float>{cosT, sinT, 0.f, 0.f}, simd<float>{-sinT, cosT, 0.f, 0.f},
simd<float>{0.f, 0.f, 1.f, 0.f}));
}
@ -163,20 +144,17 @@ public:
}
static CTransform Scale(const CVector3f& factor) {
return CTransform(CMatrix3f(simd<float>{factor.x(), 0.f, 0.f, 0.f},
simd<float>{0.f, factor.y(), 0.f, 0.f},
return CTransform(CMatrix3f(simd<float>{factor.x(), 0.f, 0.f, 0.f}, simd<float>{0.f, factor.y(), 0.f, 0.f},
simd<float>{0.f, 0.f, factor.z(), 0.f}));
}
static CTransform Scale(float x, float y, float z) {
return CTransform(CMatrix3f(simd<float>{x, 0.f, 0.f, 0.f},
simd<float>{0.f, y, 0.f, 0.f},
simd<float>{0.f, 0.f, z, 0.f}));
return CTransform(
CMatrix3f(simd<float>{x, 0.f, 0.f, 0.f}, simd<float>{0.f, y, 0.f, 0.f}, simd<float>{0.f, 0.f, z, 0.f}));
}
static CTransform Scale(float factor) {
return CTransform(CMatrix3f(simd<float>{factor, 0.f, 0.f, 0.f},
simd<float>{0.f, factor, 0.f, 0.f},
return CTransform(CMatrix3f(simd<float>{factor, 0.f, 0.f, 0.f}, simd<float>{0.f, factor, 0.f, 0.f},
simd<float>{0.f, 0.f, factor, 0.f}));
}
@ -192,26 +170,18 @@ public:
return ret;
}
void setRotation(const CMatrix3f& mat) {
basis = mat;
}
void setRotation(const CMatrix3f& mat) { basis = mat; }
void setRotation(const CTransform& xfrm) {
setRotation(xfrm.basis);
}
void setRotation(const CTransform& xfrm) { setRotation(xfrm.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)
*/
const CMatrix3f& buildMatrix3f() const {
return basis;
}
const CMatrix3f& buildMatrix3f() const { return basis; }
CVector3f operator*(const CVector3f& other) const {
return origin + basis * other;
}
CVector3f operator*(const CVector3f& other) const { return origin + basis * other; }
CMatrix4f toMatrix4f() const {
CMatrix4f ret(basis[0], basis[1], basis[2], origin);
@ -222,17 +192,11 @@ public:
return ret;
}
CVector3f upVector() const {
return basis.m[2];
}
CVector3f upVector() const { return basis.m[2]; }
CVector3f frontVector() const {
return basis.m[1];
}
CVector3f frontVector() const { return basis.m[1]; }
CVector3f rightVector() const {
return basis.m[0];
}
CVector3f rightVector() const { return basis.m[0]; }
void orthonormalize() {
basis[0].normalize();
@ -242,14 +206,13 @@ public:
}
void printMatrix() const {
printf("%f %f %f %f\n"
"%f %f %f %f\n"
"%f %f %f %f\n"
"%f %f %f %f\n",
basis[0][0], basis[1][0], basis[2][0], origin[0],
basis[0][1], basis[1][1], basis[2][1], origin[1],
basis[0][2], basis[1][2], basis[2][2], origin[2],
0.f, 0.f, 0.f, 1.f);
printf(
"%f %f %f %f\n"
"%f %f %f %f\n"
"%f %f %f %f\n"
"%f %f %f %f\n",
basis[0][0], basis[1][0], basis[2][0], origin[0], basis[0][1], basis[1][1], basis[2][1], origin[1], basis[0][2],
basis[1][2], basis[2][2], origin[2], 0.f, 0.f, 0.f, 1.f);
}
static zeus::CTransform MakeRotationsBasedOnY(const CUnitVector3f& uVec) {
@ -269,9 +232,7 @@ public:
CVector3f origin;
};
static inline CTransform CTransformFromScaleVector(const CVector3f& scale) {
return CTransform(CMatrix3f(scale));
}
static inline CTransform CTransformFromScaleVector(const CVector3f& scale) { return CTransform(CMatrix3f(scale)); }
CTransform CTransformFromEditorEuler(const CVector3f& eulerVec);
@ -280,5 +241,4 @@ CTransform CTransformFromEditorEulers(const CVector3f& eulerVec, const CVector3f
CTransform CTransformFromAxisAngle(const CVector3f& axis, float angle);
CTransform lookAt(const CVector3f& pos, const CVector3f& lookPos, const CVector3f& up = CVector3f::skUp);
}
} // namespace zeus

View File

@ -17,4 +17,4 @@ public:
normalize();
}
};
}
} // namespace zeus

View File

@ -13,18 +13,14 @@ public:
template <typename T>
CVector2f(const simd<T>& s) : mSimd(s) {}
#if ZE_ATHENA_TYPES
CVector2f(const atVec2f& vec) : mSimd(vec.simd) {}
operator atVec2f&() {
return *reinterpret_cast<atVec2f*>(this);
}
operator atVec2f&() { return *reinterpret_cast<atVec2f*>(this); }
operator const atVec2f&() const {
return *reinterpret_cast<const atVec2f*>(this);
}
operator const atVec2f&() const { return *reinterpret_cast<const atVec2f*>(this); }
void readBig(athena::io::IStreamReader& input) {
mSimd[0] = input.readFloatBig();
@ -52,61 +48,33 @@ public:
CVector2f(float x, float y) { assign(x, y); }
bool operator==(const CVector2f& rhs) const {
return mSimd[0] == rhs.mSimd[0] && mSimd[1] == rhs.mSimd[1];
}
bool operator==(const CVector2f& rhs) const { return mSimd[0] == rhs.mSimd[0] && mSimd[1] == rhs.mSimd[1]; }
bool operator!=(const CVector2f& rhs) const {
return mSimd[0] != rhs.mSimd[0] || mSimd[1] != rhs.mSimd[1];
}
bool operator!=(const CVector2f& rhs) const { return mSimd[0] != rhs.mSimd[0] || mSimd[1] != rhs.mSimd[1]; }
bool operator<(const CVector2f& rhs) const {
return mSimd[0] < rhs.mSimd[0] && mSimd[1] < rhs.mSimd[1];
}
bool operator<(const CVector2f& rhs) const { return mSimd[0] < rhs.mSimd[0] && mSimd[1] < rhs.mSimd[1]; }
bool operator<=(const CVector2f& rhs) const {
return mSimd[0] <= rhs.mSimd[0] && mSimd[1] <= rhs.mSimd[1];
}
bool operator<=(const CVector2f& rhs) const { return mSimd[0] <= rhs.mSimd[0] && mSimd[1] <= rhs.mSimd[1]; }
bool operator>(const CVector2f& rhs) const {
return mSimd[0] > rhs.mSimd[0] && mSimd[1] > rhs.mSimd[1];
}
bool operator>(const CVector2f& rhs) const { return mSimd[0] > rhs.mSimd[0] && mSimd[1] > rhs.mSimd[1]; }
bool operator>=(const CVector2f& rhs) const {
return mSimd[0] >= rhs.mSimd[0] && mSimd[1] >= rhs.mSimd[1];
}
bool operator>=(const CVector2f& rhs) const { return mSimd[0] >= rhs.mSimd[0] && mSimd[1] >= rhs.mSimd[1]; }
CVector2f operator+(const CVector2f& rhs) const {
return mSimd + rhs.mSimd;
}
CVector2f operator+(const CVector2f& rhs) const { return mSimd + rhs.mSimd; }
CVector2f operator-(const CVector2f& rhs) const {
return mSimd - rhs.mSimd;
}
CVector2f operator-(const CVector2f& rhs) const { return mSimd - rhs.mSimd; }
CVector2f operator-() const {
return -mSimd;
}
CVector2f operator-() const { return -mSimd; }
CVector2f operator*(const CVector2f& rhs) const {
return mSimd * rhs.mSimd;
}
CVector2f operator*(const CVector2f& rhs) const { return mSimd * rhs.mSimd; }
CVector2f operator/(const CVector2f& rhs) const {
return mSimd / rhs.mSimd;
}
CVector2f operator/(const CVector2f& rhs) const { return mSimd / rhs.mSimd; }
CVector2f operator+(float val) const {
return mSimd + simd<float>(val);
}
CVector2f operator+(float val) const { return mSimd + simd<float>(val); }
CVector2f operator-(float val) const {
return mSimd - simd<float>(val);
}
CVector2f operator-(float val) const { return mSimd - simd<float>(val); }
CVector2f operator*(float val) const {
return mSimd * simd<float>(val);
}
CVector2f operator*(float val) const { return mSimd * simd<float>(val); }
CVector2f operator/(float val) const {
float ooval = 1.f / val;
@ -170,25 +138,15 @@ public:
float cross(const CVector2f& rhs) const { return (x() * rhs.y()) - (y() * rhs.x()); }
float dot(const CVector2f& rhs) const {
return mSimd.dot2(rhs.mSimd);
}
float dot(const CVector2f& rhs) const { return mSimd.dot2(rhs.mSimd); }
float magSquared() const {
return mSimd.dot2(mSimd);
}
float magSquared() const { return mSimd.dot2(mSimd); }
float magnitude() const {
return std::sqrt(magSquared());
}
float magnitude() const { return std::sqrt(magSquared()); }
void zeroOut() {
*this = CVector2f::skZero;
}
void zeroOut() { *this = CVector2f::skZero; }
void splat(float xy) {
mSimd = zeus::simd<float>(xy);
}
void splat(float xy) { mSimd = zeus::simd<float>(xy); }
static float getAngleDiff(const CVector2f& a, const CVector2f& b);
@ -196,15 +154,11 @@ public:
return zeus::simd<float>(1.f - t) * a.mSimd + b.mSimd * zeus::simd<float>(t);
}
static CVector2f nlerp(const CVector2f& a, const CVector2f& b, float t) {
return lerp(a, b, t).normalized();
}
static CVector2f nlerp(const CVector2f& a, const CVector2f& b, float t) { return lerp(a, b, t).normalized(); }
static CVector2f slerp(const CVector2f& a, const CVector2f& b, float t);
bool isNormalized() const {
return std::fabs(1.f - magSquared()) < 0.01f;
}
bool isNormalized() const { return std::fabs(1.f - magSquared()) < 0.01f; }
bool canBeNormalized() const {
if (std::isinf(x()) || std::isinf(y()))
@ -212,9 +166,7 @@ public:
return std::fabs(x()) >= FLT_EPSILON || std::fabs(y()) >= FLT_EPSILON;
}
bool isZero() const {
return magSquared() <= FLT_EPSILON;
}
bool isZero() const { return magSquared() <= FLT_EPSILON; }
bool isEqu(const CVector2f& other, float epsilon = FLT_EPSILON) {
const CVector2f diffVec = other - *this;
@ -242,20 +194,11 @@ public:
static const CVector2f skZero;
};
static inline CVector2f operator+(float lhs, const CVector2f& rhs) {
return zeus::simd<float>(lhs) + rhs.mSimd;
}
static inline CVector2f operator+(float lhs, const CVector2f& rhs) { return zeus::simd<float>(lhs) + rhs.mSimd; }
static inline CVector2f operator-(float lhs, const CVector2f& rhs) {
return zeus::simd<float>(lhs) - rhs.mSimd;
}
static inline CVector2f operator-(float lhs, const CVector2f& rhs) { return zeus::simd<float>(lhs) - rhs.mSimd; }
static inline CVector2f operator*(float lhs, const CVector2f& rhs) {
return zeus::simd<float>(lhs) * rhs.mSimd;
}
static inline CVector2f operator/(float lhs, const CVector2f& rhs) {
return zeus::simd<float>(lhs) / rhs.mSimd;
}
}
static inline CVector2f operator*(float lhs, const CVector2f& rhs) { return zeus::simd<float>(lhs) * rhs.mSimd; }
static inline CVector2f operator/(float lhs, const CVector2f& rhs) { return zeus::simd<float>(lhs) / rhs.mSimd; }
} // namespace zeus

View File

@ -29,33 +29,18 @@ public:
CVector2f toVec2f() const { return CVector2f(x, y); }
CVector2i operator+(const CVector2i& val) const {
return CVector2i(x + val.x, y + val.y);
}
CVector2i operator+(const CVector2i& val) const { return CVector2i(x + val.x, y + val.y); }
CVector2i operator-(const CVector2i& val) const {
return CVector2i(x - val.x, y - val.y);
}
CVector2i operator-(const CVector2i& val) const { return CVector2i(x - val.x, y - val.y); }
CVector2i operator*(const CVector2i& val) const {
return CVector2i(x * val.x, y * val.y);
}
CVector2i operator*(const CVector2i& val) const { return CVector2i(x * val.x, y * val.y); }
CVector2i operator/(const CVector2i& val) const {
return CVector2i(x / val.x, y / val.y);
}
CVector2i operator/(const CVector2i& val) const { return CVector2i(x / val.x, y / val.y); }
bool operator==(const CVector2i& other) const {
return x == other.x && y == other.y;
}
bool operator==(const CVector2i& other) const { return x == other.x && y == other.y; }
bool operator!=(const CVector2i& other) const {
return x != other.x || y != other.y;
}
bool operator!=(const CVector2i& other) const { return x != other.x || y != other.y; }
CVector2i operator*(int val) const {
return CVector2i(x * val, y * val);
}
CVector2i operator*(int val) const { return CVector2i(x * val, y * val); }
};
}
} // namespace zeus

View File

@ -14,7 +14,7 @@ public:
template <typename T>
CVector3d(const simd<T>& s) : mSimd(s) {}
#if ZE_ATHENA_TYPES
CVector3d(const atVec3d& vec) : mSimd(vec.simd) {}
#endif
@ -25,27 +25,17 @@ public:
CVector3d(double x, double y, double z) : mSimd(x, y, z) {}
CVector3f asCVector3f() {
return mSimd;
}
CVector3f asCVector3f() { return mSimd; }
double magSquared() const {
return mSimd.dot3(mSimd);
}
double magSquared() const { return mSimd.dot3(mSimd); }
double magnitude() const {
return sqrt(magSquared());
}
double magnitude() const { return sqrt(magSquared()); }
CVector3d cross(const CVector3d& rhs) const {
return {y() * rhs.z() - z() * rhs.y(),
z() * rhs.x() - x() * rhs.z(),
x() * rhs.y() - y() * rhs.x()};
return {y() * rhs.z() - z() * rhs.y(), z() * rhs.x() - x() * rhs.z(), x() * rhs.y() - y() * rhs.x()};
}
double dot(const CVector3d& rhs) const {
return mSimd.dot3(rhs.mSimd);
}
double dot(const CVector3d& rhs) const { return mSimd.dot3(rhs.mSimd); }
CVector3d asNormalized() {
double mag = magnitude();
@ -53,29 +43,17 @@ public:
return mSimd * zeus::simd<double>(mag);
}
void splat(double xyz) {
mSimd = zeus::simd<double>(xyz);
}
void splat(double xyz) { mSimd = zeus::simd<double>(xyz); }
void zeroOut() {
*this = skZero;
}
void zeroOut() { *this = skZero; }
CVector3d operator+(const CVector3d& rhs) const {
return mSimd + rhs.mSimd;
}
CVector3d operator+(const CVector3d& rhs) const { return mSimd + rhs.mSimd; }
CVector3d operator-(const CVector3d& rhs) const {
return mSimd - rhs.mSimd;
}
CVector3d operator-(const CVector3d& rhs) const { return mSimd - rhs.mSimd; }
CVector3d operator*(const CVector3d& rhs) const {
return mSimd * rhs.mSimd;
}
CVector3d operator*(const CVector3d& rhs) const { return mSimd * rhs.mSimd; }
CVector3d operator/(const CVector3d& rhs) const {
return mSimd / rhs.mSimd;
}
CVector3d operator/(const CVector3d& rhs) const { return mSimd / rhs.mSimd; }
zeus::simd<double>::reference operator[](size_t idx) {
assert(idx < 3);
@ -98,21 +76,12 @@ public:
static const CVector3d skZero;
};
static inline CVector3d operator+(double lhs, const CVector3d& rhs) {
return zeus::simd<double>(lhs) + rhs.mSimd;
}
static inline CVector3d operator+(double lhs, const CVector3d& rhs) { return zeus::simd<double>(lhs) + rhs.mSimd; }
static inline CVector3d operator-(double lhs, const CVector3d& rhs) {
return zeus::simd<double>(lhs) - rhs.mSimd;
}
static inlin