mirror of
https://github.com/AxioDL/zeus.git
synced 2025-12-09 21:47:51 +00:00
Humungous refactor
This commit is contained in:
@@ -1,2 +1,2 @@
|
||||
#include "CAABox.hpp"
|
||||
const Zeus::CAABox Zeus::CAABox::skInvertedBox = CAABox();
|
||||
#include "zeus/CAABox.hpp"
|
||||
const zeus::CAABox zeus::CAABox::skInvertedBox = CAABox();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "CColor.hpp"
|
||||
#include "CVector4f.hpp"
|
||||
#include "zeus/CColor.hpp"
|
||||
#include "zeus/CVector4f.hpp"
|
||||
|
||||
namespace Zeus
|
||||
namespace zeus
|
||||
{
|
||||
const CColor CColor::skRed (Comp32(0xFF0000FFul));
|
||||
const CColor CColor::skBlack (Comp32(0x000000FFul));
|
||||
@@ -68,8 +68,8 @@ void CColor::fromHSV(float h, float s, float v, float _a)
|
||||
|
||||
void CColor::toHSV(float &h, float &s, float &v) const
|
||||
{
|
||||
float min = Math::min(r, Math::min(g, b));
|
||||
float max = Math::max(r, Math::max(g, b));
|
||||
float min = std::min(r, std::min(g, b));
|
||||
float max = std::max(r, std::max(g, b));
|
||||
v = max;
|
||||
|
||||
float delta = max - min;
|
||||
@@ -106,8 +106,8 @@ void CColor::fromHSL(float h, float s, float l, float _a)
|
||||
|
||||
void CColor::toHSL(float &h, float &s, float &l)
|
||||
{
|
||||
const float min = Math::min(r, Math::min(g, b));
|
||||
const float max = Math::max(r, Math::max(g, b));
|
||||
const float min = std::min(r, std::min(g, b));
|
||||
const float max = std::max(r, std::max(g, b));
|
||||
const float d = max - min;
|
||||
|
||||
if (max == min)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include "CMatrix3f.hpp"
|
||||
#include "CQuaternion.hpp"
|
||||
#include "Global.hpp"
|
||||
#include "zeus/CMatrix3f.hpp"
|
||||
#include "zeus/CQuaternion.hpp"
|
||||
#include "zeus/Global.hpp"
|
||||
|
||||
namespace Zeus
|
||||
namespace zeus
|
||||
{
|
||||
const CMatrix3f CMatrix3f::skIdentityMatrix3f = CMatrix3f();
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
#include "CMatrix4f.hpp"
|
||||
#include "zeus/CMatrix4f.hpp"
|
||||
|
||||
const Zeus::CMatrix4f Zeus::CMatrix4f::skIdentityMatrix4f = CMatrix4f();
|
||||
const zeus::CMatrix4f zeus::CMatrix4f::skIdentityMatrix4f = CMatrix4f();
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
#include "CPlane.hpp"
|
||||
#include "zeus/CPlane.hpp"
|
||||
|
||||
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
#include "CProjection.hpp"
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include "zeus/CProjection.hpp"
|
||||
#include "zeus/Math.hpp"
|
||||
#include <cassert>
|
||||
|
||||
namespace Zeus
|
||||
namespace zeus
|
||||
{
|
||||
void CProjection::_updateCachedMatrix()
|
||||
{
|
||||
assert(m_projType == EProjType::Orthographic || m_projType == EProjType::Perspective);
|
||||
if (m_projType == EProjType::Orthographic)
|
||||
{
|
||||
float tmp;
|
||||
@@ -36,7 +37,7 @@ void CProjection::_updateCachedMatrix()
|
||||
else if (m_projType == EProjType::Perspective)
|
||||
{
|
||||
float cot,tmp;
|
||||
float t_fovy = tanf(m_persp.m_fov / 2.0);
|
||||
float t_fovy = std::tan(m_persp.m_fov / 2.0f);
|
||||
|
||||
cot = 1.0f / t_fovy;
|
||||
|
||||
@@ -61,11 +62,6 @@ void CProjection::_updateCachedMatrix()
|
||||
m_mtx.m[2][3] = -1.0f;
|
||||
m_mtx.m[3][3] = 0.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "attempted to cache invalid projection type");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
#include "CQuaternion.hpp"
|
||||
#include <math.h>
|
||||
#include "zeus/CQuaternion.hpp"
|
||||
#include "zeus/Math.hpp"
|
||||
|
||||
namespace Zeus
|
||||
namespace zeus
|
||||
{
|
||||
void CQuaternion::fromVector3f(const CVector3f& vec)
|
||||
{
|
||||
float cosX = cosf(0.5 * vec.x);
|
||||
float cosY = cosf(0.5 * vec.y);
|
||||
float cosZ = cosf(0.5 * vec.z);
|
||||
float cosX = std::cos(0.5f * vec.x);
|
||||
float cosY = std::cos(0.5f * vec.y);
|
||||
float cosZ = std::cos(0.5f * vec.z);
|
||||
|
||||
float sinX = sinf(0.5 * vec.x);
|
||||
float sinY = sinf(0.5 * vec.y);
|
||||
float sinZ = sinf(0.5 * vec.z);
|
||||
float sinX = std::sin(0.5f * vec.x);
|
||||
float sinY = std::sin(0.5f * vec.y);
|
||||
float sinZ = std::sin(0.5f * vec.z);
|
||||
|
||||
r = cosZ * cosY * cosX + sinZ * sinY * sinX;
|
||||
v.x = cosZ * cosY * sinX - sinZ * sinY * cosX;
|
||||
@@ -106,7 +106,7 @@ const CQuaternion& CQuaternion::operator/=(float scale)
|
||||
|
||||
float CQuaternion::magnitude() const
|
||||
{
|
||||
return sqrt(magSquared());
|
||||
return std::sqrt(magSquared());
|
||||
}
|
||||
|
||||
float CQuaternion::magSquared() const
|
||||
@@ -137,15 +137,15 @@ CQuaternion CQuaternion::inverse() const
|
||||
CAxisAngle CQuaternion::toAxisAngle()
|
||||
{
|
||||
// CAxisAngle ret;
|
||||
// ret.angle = acosf(r);
|
||||
// ret.angle = std::acos(r);
|
||||
|
||||
// float thetaInv = 1.0f/sinf(ret.angle);
|
||||
// float thetaInv = 1.0f/std::sin(ret.angle);
|
||||
|
||||
// ret.axis.x = v.x * thetaInv;
|
||||
// ret.axis.y = v.y * thetaInv;
|
||||
// ret.axis.z = v.z * thetaInv;
|
||||
|
||||
// ret.angle *= 2;
|
||||
// ret.angle *= 2.f;
|
||||
|
||||
// return ret;
|
||||
return CAxisAngle();
|
||||
@@ -153,20 +153,20 @@ CAxisAngle CQuaternion::toAxisAngle()
|
||||
|
||||
CQuaternion CQuaternion::log() const
|
||||
{
|
||||
float a = acosf(r);
|
||||
float sina = sinf(a);
|
||||
float a = std::acos(r);
|
||||
float sina = std::sin(a);
|
||||
CQuaternion ret;
|
||||
|
||||
ret.r = 0;
|
||||
ret.r = 0.f;
|
||||
|
||||
if (sina > 0)
|
||||
if (sina > 0.f)
|
||||
{
|
||||
ret.v.x = a * v.x / sina;
|
||||
ret.v.y = a * v.y / sina;
|
||||
ret.v.z = a * v.z / sina;
|
||||
}
|
||||
else
|
||||
ret.v = CVector3f(0);
|
||||
ret.v = CVector3f(0.f);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -174,19 +174,19 @@ CQuaternion CQuaternion::log() const
|
||||
CQuaternion CQuaternion::exp() const
|
||||
{
|
||||
float a = (v.magnitude());
|
||||
float sina = sinf(a);
|
||||
float cosa = cos(a);
|
||||
float sina = std::sin(a);
|
||||
float cosa = std::cos(a);
|
||||
CQuaternion ret;
|
||||
|
||||
ret.r = cosa;
|
||||
if (a > 0)
|
||||
if (a > 0.f)
|
||||
{
|
||||
ret.v.x = sina * v.x / a;
|
||||
ret.v.y = sina * v.y / a;
|
||||
ret.v.z = sina * v.z / a;
|
||||
}
|
||||
else
|
||||
ret.v = CVector3f(0);
|
||||
ret.v = CVector3f(0.f);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -215,18 +215,18 @@ CQuaternion CQuaternion::slerp(CQuaternion& a, CQuaternion& b, double t)
|
||||
|
||||
CQuaternion ret;
|
||||
|
||||
float mag = sqrtf(a.dot(a) * b.dot(b));
|
||||
float mag = std::sqrt(a.dot(a) * b.dot(b));
|
||||
|
||||
float prod = a.dot(b) / mag;
|
||||
|
||||
if (fabsf(prod) < 1.0)
|
||||
if (std::fabs(prod) < 1.0f)
|
||||
{
|
||||
const double sign = (prod < 0.0) ? -1.0 : 1.0;
|
||||
const double sign = (prod < 0.0f) ? -1.0f : 1.0f;
|
||||
|
||||
const double theta = acos(sign * prod);
|
||||
const double s1 = sin (sign * t * theta);
|
||||
const double d = 1.0 / sin(theta);
|
||||
const double s0 = sin((1.0 - t) * theta);
|
||||
const double theta = std::acos(sign * prod);
|
||||
const double s1 = std::sin(sign * t * theta);
|
||||
const double d = 1.0 / std::sin(theta);
|
||||
const double s0 = std::sin((1.0 - t) * theta);
|
||||
|
||||
ret.v.x = (float)(a.v.x * s0 + b.v.x * s1) * d;
|
||||
ret.v.y = (float)(a.v.y * s0 + b.v.y * s1) * d;
|
||||
|
||||
@@ -1 +1 @@
|
||||
#include "CRectangle.hpp"
|
||||
#include "zeus/CRectangle.hpp"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "CTransform.hpp"
|
||||
#include "zeus/CTransform.hpp"
|
||||
|
||||
namespace Zeus
|
||||
namespace zeus
|
||||
{
|
||||
CTransform CTransformFromEditorEuler(const CVector3f& eulerVec)
|
||||
{
|
||||
@@ -11,27 +11,27 @@ CTransform CTransformFromEditorEuler(const CVector3f& eulerVec)
|
||||
tj = eulerVec[1];
|
||||
th = eulerVec[2];
|
||||
|
||||
ci = cos(ti);
|
||||
cj = cos(tj);
|
||||
ch = cos(th);
|
||||
si = sin(ti);
|
||||
sj = sin(tj);
|
||||
sh = sin(th);
|
||||
ci = std::cos(ti);
|
||||
cj = std::cos(tj);
|
||||
ch = std::cos(th);
|
||||
si = std::sin(ti);
|
||||
sj = std::sin(tj);
|
||||
sh = std::sin(th);
|
||||
|
||||
cc = ci * ch;
|
||||
cs = ci * sh;
|
||||
sc = si * ch;
|
||||
ss = si * sh;
|
||||
|
||||
result.m_basis.m[0][0] = (float)(cj * ch);
|
||||
result.m_basis.m[1][0] = (float)(sj * sc - cs);
|
||||
result.m_basis.m[2][0] = (float)(sj * cc + ss);
|
||||
result.m_basis.m[0][1] = (float)(cj * sh);
|
||||
result.m_basis.m[1][1] = (float)(sj * ss + cc);
|
||||
result.m_basis.m[2][1] = (float)(sj * cs - sc);
|
||||
result.m_basis.m[0][2] = (float)(-sj);
|
||||
result.m_basis.m[1][2] = (float)(cj * si);
|
||||
result.m_basis.m[2][2] = (float)(cj * ci);
|
||||
result.m_basis.m[0][0] = float(cj * ch);
|
||||
result.m_basis.m[1][0] = float(sj * sc - cs);
|
||||
result.m_basis.m[2][0] = float(sj * cc + ss);
|
||||
result.m_basis.m[0][1] = float(cj * sh);
|
||||
result.m_basis.m[1][1] = float(sj * ss + cc);
|
||||
result.m_basis.m[2][1] = float(sj * cs - sc);
|
||||
result.m_basis.m[0][2] = float(-sj);
|
||||
result.m_basis.m[1][2] = float(cj * si);
|
||||
result.m_basis.m[2][2] = float(cj * ci);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -41,9 +41,9 @@ CTransform CTransformFromAxisAngle(const CVector3f& axis, float angle)
|
||||
CTransform result;
|
||||
CVector3f axisN = axis.normalized();
|
||||
|
||||
float c = cosf(angle);
|
||||
float s = sinf(angle);
|
||||
float t = 1 - c;
|
||||
float c = std::cos(angle);
|
||||
float s = std::sin(angle);
|
||||
float t = 1.f - c;
|
||||
|
||||
result.m_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;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#include "CVector2f.hpp"
|
||||
#include "zeus/CVector2f.hpp"
|
||||
#include <memory.h>
|
||||
#include <cmath>
|
||||
#include <assert.h>
|
||||
#include "Math.hpp"
|
||||
#include "zeus/Math.hpp"
|
||||
|
||||
namespace Zeus
|
||||
namespace zeus
|
||||
{
|
||||
const CVector2f CVector2f::skOne = CVector2f(1.0);
|
||||
const CVector2f CVector2f::skNegOne = CVector2f(-1.0);
|
||||
@@ -19,7 +19,7 @@ float CVector2f::getAngleDiff(const CVector2f& a, const CVector2f& b)
|
||||
return 0;
|
||||
|
||||
float dot = a.dot(b);
|
||||
float theta = Math::arcCosineR(dot / (mag1 * mag2));
|
||||
float theta = std::acos(dot / (mag1 * mag2));
|
||||
return theta;
|
||||
}
|
||||
|
||||
@@ -32,18 +32,18 @@ CVector2f CVector2f::slerp(const CVector2f& a, const CVector2f& b, float t)
|
||||
|
||||
CVector2f ret;
|
||||
|
||||
float mag = sqrtf(a.dot(a) * b.dot(b));
|
||||
float mag = std::sqrt(a.dot(a) * b.dot(b));
|
||||
|
||||
float prod = a.dot(b) / mag;
|
||||
|
||||
if (fabsf(prod) < 1.0)
|
||||
if (std::fabs(prod) < 1.0f)
|
||||
{
|
||||
const double sign = (prod < 0.0) ? -1.0 : 1.0;
|
||||
const double sign = (prod < 0.0f) ? -1.0f : 1.0f;
|
||||
|
||||
const double theta = acos(sign * prod);
|
||||
const double s1 = sin (sign * t * theta);
|
||||
const double d = 1.0 / sin(theta);
|
||||
const double s0 = sin((1.0 - t) * theta);
|
||||
const double theta = std::acos(sign * prod);
|
||||
const double s1 = std::sin(sign * t * theta);
|
||||
const double d = 1.0 / std::sin(theta);
|
||||
const double s0 = std::sin((1.0f - t) * theta);
|
||||
|
||||
ret = (a * s0 + b * s1) * d;
|
||||
return ret;
|
||||
|
||||
@@ -1,25 +1,29 @@
|
||||
#include "CVector3f.hpp"
|
||||
#include "zeus/CVector3f.hpp"
|
||||
#include <memory.h>
|
||||
#include <cmath>
|
||||
#include <assert.h>
|
||||
#include "Math.hpp"
|
||||
#include "zeus/Math.hpp"
|
||||
|
||||
namespace Zeus
|
||||
namespace zeus
|
||||
{
|
||||
const CVector3f CVector3f::skOne = CVector3f(1.0);
|
||||
const CVector3f CVector3f::skNegOne = CVector3f(-1.0);
|
||||
const CVector3f CVector3f::skZero;
|
||||
|
||||
const CVector3f kUpVec(0.0, 0.0, 1.0);
|
||||
const CVector3f kRadToDegVec(180.0f / M_PI);
|
||||
const CVector3f kDegToRadVec(M_PI / 180.0f);
|
||||
|
||||
float CVector3f::getAngleDiff(const CVector3f& a, const CVector3f& b)
|
||||
{
|
||||
float mag1 = a.magnitude();
|
||||
float mag2 = b.magnitude();
|
||||
|
||||
if (!mag1 || !mag2)
|
||||
return 0;
|
||||
return 0.f;
|
||||
|
||||
float dot = a.dot(b);
|
||||
float theta = Math::arcCosineR(dot / (mag1 * mag2));
|
||||
float theta = std::acos(dot / (mag1 * mag2));
|
||||
return theta;
|
||||
}
|
||||
|
||||
@@ -32,13 +36,13 @@ CVector3f CVector3f::slerp(const CVector3f& a, const CVector3f& b, float t)
|
||||
|
||||
CVector3f ret;
|
||||
|
||||
float mag = sqrtf(a.dot(a) * b.dot(b));
|
||||
float mag = std::sqrt(a.dot(a) * b.dot(b));
|
||||
|
||||
float prod = a.dot(b) / mag;
|
||||
|
||||
if (fabsf(prod) < 1.0)
|
||||
if (std::fabs(prod) < 1.0f)
|
||||
{
|
||||
const double sign = (prod < 0.0) ? -1.0 : 1.0;
|
||||
const double sign = (prod < 0.0f) ? -1.0f : 1.0f;
|
||||
|
||||
const double theta = acos(sign * prod);
|
||||
const double s1 = sin (sign * t * theta);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include "CVector4f.hpp"
|
||||
#include "CColor.hpp"
|
||||
#include "zeus/CVector4f.hpp"
|
||||
#include "zeus/CColor.hpp"
|
||||
|
||||
namespace Zeus
|
||||
namespace zeus
|
||||
{
|
||||
CVector4f::CVector4f(const Zeus::CColor& other)
|
||||
CVector4f::CVector4f(const zeus::CColor& other)
|
||||
: x(other.r), y(other.g), z(other.b), w(other.a)
|
||||
{
|
||||
}
|
||||
|
||||
38
src/Math.cpp
38
src/Math.cpp
@@ -1,13 +1,13 @@
|
||||
#include "Math.hpp"
|
||||
#include "CTransform.hpp"
|
||||
#include "CVector3f.hpp"
|
||||
#include "zeus/Math.hpp"
|
||||
#include "zeus/CTransform.hpp"
|
||||
#include "zeus/CVector3f.hpp"
|
||||
#if _WIN32
|
||||
#include <intrin.h>
|
||||
#else
|
||||
#include <cpuid.h>
|
||||
#endif
|
||||
|
||||
namespace Zeus
|
||||
namespace zeus
|
||||
{
|
||||
|
||||
static CPUInfo g_cpuFeatures;
|
||||
@@ -69,12 +69,6 @@ void detectCPU()
|
||||
|
||||
const CPUInfo& cpuFeatures() { return g_cpuFeatures; }
|
||||
|
||||
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 lookAt(const CVector3f& pos, const CVector3f& lookPos, const CVector3f& up)
|
||||
{
|
||||
CVector3f vLook,vRight,vUp;
|
||||
@@ -158,18 +152,18 @@ double sqrtD(double val)
|
||||
return q;
|
||||
}
|
||||
|
||||
float fastArcCosR(float val)
|
||||
float fastArcCosF(float val)
|
||||
{
|
||||
/* If we're not at a low enough value,
|
||||
* the approximation below won't provide any benefit,
|
||||
* and we simply fall back to the standard implementation
|
||||
*/
|
||||
if (fabs(val) >= 0.925000011920929)
|
||||
return float(acos(val));
|
||||
if (std::fabs(val) >= 0.925000011920929)
|
||||
return std::acos(val);
|
||||
|
||||
/* Fast Arc Cosine approximation using Taylor Polynomials
|
||||
* while this implementation is fast, it's also not as accurate.
|
||||
* This is a straight reimplementation of Retro's CMath::FastArcCosR
|
||||
* This is a straight reimplementation of Retro's CFastArcCosR
|
||||
* and as a result of the polynomials, it returns the inverse value,
|
||||
* I'm not certain if this was intended originally, but we'll leave it
|
||||
* in order to be as accurate as possible.
|
||||
@@ -217,9 +211,9 @@ int ceilingPowerOfTwo(int x)
|
||||
return x;
|
||||
}
|
||||
|
||||
float fastCosR(float val)
|
||||
float fastCosF(float val)
|
||||
{
|
||||
if (fabs(val) > M_PI)
|
||||
if (std::fabs(val) > M_PI)
|
||||
{
|
||||
float rVal = float(uint32_t(val));
|
||||
val = -((rVal * val) - 6.2831855);
|
||||
@@ -240,9 +234,9 @@ float fastCosR(float val)
|
||||
return val;
|
||||
}
|
||||
|
||||
float fastSinR(float val)
|
||||
float fastSinF(float val)
|
||||
{
|
||||
if (fabs(val) > M_PI)
|
||||
if (std::fabs(val) > M_PI)
|
||||
{
|
||||
float rVal = float(uint32_t(val));
|
||||
val = -((rVal * val) - 6.2831855);
|
||||
@@ -319,16 +313,10 @@ CVector3f getRoundCatmullRomSplinePoint(const CVector3f& a, const CVector3f& b,
|
||||
if (cVelocity.canBeNormalized())
|
||||
cVelocity.normalize();
|
||||
const float cbDistance = cb.magnitude();
|
||||
return getCatmullRomSplinePoint(b, c, bVelocity * cbDistance, cVelocity * cbDistance, t);
|
||||
return zeus::getCatmullRomSplinePoint(b, c, bVelocity * cbDistance, cVelocity * cbDistance, t);
|
||||
}
|
||||
|
||||
CVector3f baryToWorld(const CVector3f& p0, const CVector3f& p1, const CVector3f& p2, const CVector3f& bary)
|
||||
{ return bary.x * p0 + bary.y * p1 + bary.z * p2; }
|
||||
|
||||
CVector3f radToDeg(const CVector3f& rad) {return rad * kRadToDegVec;}
|
||||
|
||||
CVector3f degToRad(const CVector3f& deg) {return deg * kDegToRadVec;}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user