mirror of
https://github.com/AxioDL/zeus.git
synced 2025-12-17 17:05:30 +00:00
Bulk-run of clang-format
This commit is contained in:
@@ -6,5 +6,4 @@ namespace zeus
|
||||
|
||||
const CAABox CAABox::skInvertedBox = CAABox();
|
||||
const CAABox CAABox::skNullBox = CAABox(CVector3f::skZero, CVector3f::skZero);
|
||||
|
||||
}
|
||||
|
||||
@@ -3,16 +3,16 @@
|
||||
|
||||
namespace zeus
|
||||
{
|
||||
const CColor CColor::skRed (Comp32(0xFF0000FFul));
|
||||
const CColor CColor::skBlack (Comp32(0x000000FFul));
|
||||
const CColor CColor::skBlue (Comp32(0x0000FFFFul));
|
||||
const CColor CColor::skGreen (Comp32(0x00FF00FFul));
|
||||
const CColor CColor::skGrey (Comp32(0x808080FFul));
|
||||
const CColor CColor::skRed(Comp32(0xFF0000FFul));
|
||||
const CColor CColor::skBlack(Comp32(0x000000FFul));
|
||||
const CColor CColor::skBlue(Comp32(0x0000FFFFul));
|
||||
const CColor CColor::skGreen(Comp32(0x00FF00FFul));
|
||||
const CColor CColor::skGrey(Comp32(0x808080FFul));
|
||||
const CColor CColor::skOrange(Comp32(0xFF7000FFul));
|
||||
const CColor CColor::skPurple(Comp32(0xA000FFFFul));
|
||||
const CColor CColor::skYellow(Comp32(0xFFFF00FFul));
|
||||
const CColor CColor::skWhite (Comp32(0xFFFFFFFFul));
|
||||
const CColor CColor::skClear (Comp32(0x00000000ul));
|
||||
const CColor CColor::skWhite(Comp32(0xFFFFFFFFul));
|
||||
const CColor CColor::skClear(Comp32(0x00000000ul));
|
||||
|
||||
float hueToRgb(float p, float q, float t)
|
||||
{
|
||||
@@ -20,17 +20,22 @@ float hueToRgb(float p, float q, float t)
|
||||
t += 1.0f;
|
||||
if (t > 1.0f)
|
||||
t -= 1.0f;
|
||||
if (t < 1.f/6.f)
|
||||
if (t < 1.f / 6.f)
|
||||
return p + (q - p) * 6.f * t;
|
||||
if (t < 1.f/2.f)
|
||||
if (t < 1.f / 2.f)
|
||||
return q;
|
||||
if (t < 2.f/3.f)
|
||||
return p + (q - p) * (2.f/3.f - t) * 6.f;
|
||||
if (t < 2.f / 3.f)
|
||||
return p + (q - p) * (2.f / 3.f - t) * 6.f;
|
||||
return p;
|
||||
}
|
||||
|
||||
CColor::CColor(const CVector4f& other)
|
||||
{ r = other.x; g = other.y; b = other.z; a = other.w; }
|
||||
{
|
||||
r = other.x;
|
||||
g = other.y;
|
||||
b = other.z;
|
||||
a = other.w;
|
||||
}
|
||||
|
||||
CColor& CColor::operator=(const CVector4f& other)
|
||||
{
|
||||
@@ -50,14 +55,26 @@ void CColor::fromHSV(float h, float s, float v, float _a)
|
||||
float t = v * (1 - (1 - f) * s);
|
||||
float _r, _g, _b;
|
||||
|
||||
switch(i % 6)
|
||||
switch (i % 6)
|
||||
{
|
||||
case 0: _r = v, _g = t, _b = p; break;
|
||||
case 1: _r = q, _g = v, _b = p; break;
|
||||
case 2: _r = p, _g = v, _b = t; break;
|
||||
case 3: _r = p, _g = q, _b = v; break;
|
||||
case 4: _r = t, _g = p, _b = v; break;
|
||||
case 5: _r = v, _g = p, _b = q; break;
|
||||
case 0:
|
||||
_r = v, _g = t, _b = p;
|
||||
break;
|
||||
case 1:
|
||||
_r = q, _g = v, _b = p;
|
||||
break;
|
||||
case 2:
|
||||
_r = p, _g = v, _b = t;
|
||||
break;
|
||||
case 3:
|
||||
_r = p, _g = q, _b = v;
|
||||
break;
|
||||
case 4:
|
||||
_r = t, _g = p, _b = v;
|
||||
break;
|
||||
case 5:
|
||||
_r = v, _g = p, _b = q;
|
||||
break;
|
||||
}
|
||||
|
||||
r = _r;
|
||||
@@ -66,7 +83,7 @@ void CColor::fromHSV(float h, float s, float v, float _a)
|
||||
a = _a;
|
||||
}
|
||||
|
||||
void CColor::toHSV(float &h, float &s, float &v) const
|
||||
void CColor::toHSV(float& h, float& s, float& v) const
|
||||
{
|
||||
float min = std::min(r, std::min(g, b));
|
||||
float max = std::max(r, std::max(g, b));
|
||||
@@ -97,14 +114,14 @@ void CColor::fromHSL(float h, float s, float l, float _a)
|
||||
{
|
||||
const float q = l < 0.5f ? l * (1.f + s) : l + s - 1.f * s;
|
||||
const float p = 2 * l - q;
|
||||
r = hueToRgb(p, q, h + 1.f/3);
|
||||
r = hueToRgb(p, q, h + 1.f / 3);
|
||||
g = hueToRgb(p, q, h);
|
||||
b = hueToRgb(p, q, h - 1.f/3);
|
||||
b = hueToRgb(p, q, h - 1.f / 3);
|
||||
}
|
||||
a = _a;
|
||||
}
|
||||
|
||||
void CColor::toHSL(float &h, float &s, float &l)
|
||||
void CColor::toHSL(float& h, float& s, float& l)
|
||||
{
|
||||
const float min = std::min(r, std::min(g, b));
|
||||
const float max = std::max(r, std::max(g, b));
|
||||
@@ -125,5 +142,4 @@ void CColor::toHSL(float &h, float &s, float &l)
|
||||
h /= 6;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,19 +12,19 @@ CMatrix3f::CMatrix3f(const CQuaternion& quat)
|
||||
float x2 = nq.x * nq.x;
|
||||
float y2 = nq.y * nq.y;
|
||||
float z2 = nq.z * nq.z;
|
||||
|
||||
|
||||
m[0][0] = 1.0 - 2.0 * y2 - 2.0 * z2;
|
||||
m[1][0] = 2.0 * nq.x * nq.y - 2.0 * nq.z * nq.w;
|
||||
m[2][0] = 2.0 * nq.x * nq.z + 2.0 * nq.y * nq.w;
|
||||
|
||||
|
||||
m[0][1] = 2.0 * nq.x * nq.y + 2.0 * nq.z * nq.w;
|
||||
m[1][1] = 1.0 - 2.0 * x2 - 2.0 * z2;
|
||||
m[2][1] = 2.0 * nq.y * nq.z - 2.0 * nq.x * nq.w;
|
||||
|
||||
|
||||
m[0][2] = 2.0 * nq.x * nq.z - 2.0 * nq.y * nq.w;
|
||||
m[1][2] = 2.0 * nq.y * nq.z + 2.0 * nq.x * nq.w;
|
||||
m[2][2] = 1.0 - 2.0 * x2 - 2.0 * y2;
|
||||
|
||||
|
||||
m[0][3] = 0.0f;
|
||||
m[1][3] = 0.0f;
|
||||
m[2][3] = 0.0f;
|
||||
@@ -48,15 +48,15 @@ void CMatrix3f::transpose()
|
||||
vec[2].mVec128 = _mm_movelh_ps(T1, T3);
|
||||
#else
|
||||
float tmp;
|
||||
|
||||
|
||||
tmp = m[0][1];
|
||||
m[0][1] = m[1][0];
|
||||
m[1][0] = tmp;
|
||||
|
||||
|
||||
tmp = m[0][2];
|
||||
m[0][2] = m[2][0];
|
||||
m[2][0] = tmp;
|
||||
|
||||
|
||||
tmp = m[1][2];
|
||||
m[1][2] = m[2][1];
|
||||
m[2][1] = tmp;
|
||||
@@ -77,45 +77,36 @@ CMatrix3f CMatrix3f::transposed() const
|
||||
#else
|
||||
CMatrix3f ret(*this);
|
||||
float tmp;
|
||||
|
||||
|
||||
tmp = ret.m[0][1];
|
||||
ret.m[0][1] = ret.m[1][0];
|
||||
ret.m[1][0] = tmp;
|
||||
|
||||
|
||||
tmp = m[0][2];
|
||||
ret.m[0][2] = ret.m[2][0];
|
||||
ret.m[2][0] = tmp;
|
||||
|
||||
|
||||
tmp = m[1][2];
|
||||
ret.m[1][2] = ret.m[2][1];
|
||||
ret.m[2][1] = tmp;
|
||||
|
||||
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
|
||||
CMatrix3f CMatrix3f::inverted() const
|
||||
{
|
||||
float det =
|
||||
m[0][0] * m[1][1] * m[2][2] +
|
||||
m[1][0] * m[2][1] * m[0][2] +
|
||||
m[2][0] * m[0][1] * m[1][2] -
|
||||
m[0][2] * m[1][1] * m[2][0] -
|
||||
m[1][2] * m[2][1] * m[0][0] -
|
||||
m[2][2] * m[0][1] * m[1][0];
|
||||
|
||||
float det = m[0][0] * m[1][1] * m[2][2] + m[1][0] * m[2][1] * m[0][2] + m[2][0] * m[0][1] * m[1][2] -
|
||||
m[0][2] * m[1][1] * m[2][0] - m[1][2] * m[2][1] * m[0][0] - m[2][2] * m[0][1] * m[1][0];
|
||||
|
||||
if (det == 0.0)
|
||||
return CMatrix3f();
|
||||
|
||||
|
||||
det = 1.0f / det;
|
||||
return CMatrix3f((m[1][1]*m[2][2] - m[1][2]*m[2][1]) * det,
|
||||
-(m[1][0]*m[2][2] - m[1][2]*m[2][0]) * det,
|
||||
(m[1][0]*m[2][1] - m[1][1]*m[2][0]) * det,
|
||||
-(m[0][1]*m[2][2] - m[0][2]*m[2][1]) * det,
|
||||
(m[0][0]*m[2][2] - m[0][2]*m[2][0]) * det,
|
||||
-(m[0][0]*m[2][1] - m[0][1]*m[2][0]) * det,
|
||||
(m[0][1]*m[1][2] - m[0][2]*m[1][1]) * det,
|
||||
-(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);
|
||||
return CMatrix3f((m[1][1] * m[2][2] - m[1][2] * m[2][1]) * det, -(m[1][0] * m[2][2] - m[1][2] * m[2][0]) * det,
|
||||
(m[1][0] * m[2][1] - m[1][1] * m[2][0]) * det, -(m[0][1] * m[2][2] - m[0][2] * m[2][1]) * det,
|
||||
(m[0][0] * m[2][2] - m[0][2] * m[2][0]) * det, -(m[0][0] * m[2][1] - m[0][1] * m[2][0]) * det,
|
||||
(m[0][1] * m[1][2] - m[0][2] * m[1][1]) * det, -(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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,5 +42,4 @@ CMatrix4f CMatrix4f::transposed() const
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,3 +1 @@
|
||||
#include "zeus/CPlane.hpp"
|
||||
|
||||
|
||||
|
||||
@@ -10,25 +10,25 @@ void CProjection::_updateCachedMatrix()
|
||||
if (m_projType == EProjType::Orthographic)
|
||||
{
|
||||
float tmp;
|
||||
|
||||
|
||||
tmp = 1.0f / (m_ortho.right - m_ortho.left);
|
||||
m_mtx.m[0][0] = 2.0f * tmp;
|
||||
m_mtx.m[1][0] = 0.0f;
|
||||
m_mtx.m[2][0] = 0.0f;
|
||||
m_mtx.m[3][0] = -(m_ortho.right + m_ortho.left) * tmp;
|
||||
|
||||
|
||||
tmp = 1.0f / (m_ortho.top - m_ortho.bottom);
|
||||
m_mtx.m[0][1] = 0.0f;
|
||||
m_mtx.m[1][1] = 2.0f * tmp;
|
||||
m_mtx.m[2][1] = 0.0f;
|
||||
m_mtx.m[3][1] = -(m_ortho.top + m_ortho.bottom) * tmp;
|
||||
|
||||
|
||||
tmp = 1.0f / (m_ortho.far - m_ortho.near);
|
||||
m_mtx.m[0][2] = 0.0f;
|
||||
m_mtx.m[1][2] = 0.0f;
|
||||
m_mtx.m[2][2] = -(1.0f) * tmp;
|
||||
m_mtx.m[3][2] = -m_ortho.far * tmp;
|
||||
|
||||
|
||||
m_mtx.m[0][3] = 0.0f;
|
||||
m_mtx.m[1][3] = 0.0f;
|
||||
m_mtx.m[2][3] = 0.0f;
|
||||
@@ -36,27 +36,27 @@ void CProjection::_updateCachedMatrix()
|
||||
}
|
||||
else if (m_projType == EProjType::Perspective)
|
||||
{
|
||||
float cot,tmp;
|
||||
float cot, tmp;
|
||||
float t_fovy = std::tan(m_persp.fov / 2.0f);
|
||||
|
||||
|
||||
cot = 1.0f / t_fovy;
|
||||
|
||||
m_mtx.m[0][0] = cot/m_persp.aspect;
|
||||
|
||||
m_mtx.m[0][0] = cot / m_persp.aspect;
|
||||
m_mtx.m[1][0] = 0.0f;
|
||||
m_mtx.m[2][0] = 0.0f;
|
||||
m_mtx.m[3][0] = 0.0f;
|
||||
|
||||
|
||||
m_mtx.m[0][1] = 0.0f;
|
||||
m_mtx.m[1][1] = cot;
|
||||
m_mtx.m[2][1] = 0.0f;
|
||||
m_mtx.m[3][1] = 0.0f;
|
||||
|
||||
|
||||
tmp = 1.0f / (m_persp.far - m_persp.near);
|
||||
m_mtx.m[0][2] = 0.0f;
|
||||
m_mtx.m[1][2] = 0.0f;
|
||||
m_mtx.m[2][2] = -m_persp.far * tmp;
|
||||
m_mtx.m[3][2] = -(m_persp.far * m_persp.near) * tmp;
|
||||
|
||||
|
||||
m_mtx.m[0][3] = 0.0f;
|
||||
m_mtx.m[1][3] = 0.0f;
|
||||
m_mtx.m[2][3] = -1.0f;
|
||||
@@ -64,4 +64,3 @@ void CProjection::_updateCachedMatrix()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,22 +34,14 @@ CQuaternion& CQuaternion::operator=(const CQuaternion& q)
|
||||
return *this;
|
||||
}
|
||||
|
||||
CQuaternion CQuaternion::operator+(const CQuaternion& q) const
|
||||
{
|
||||
return CQuaternion(w + q.w, x + q.x, y + q.y, z + q.z);
|
||||
}
|
||||
CQuaternion CQuaternion::operator+(const CQuaternion& q) const { return CQuaternion(w + q.w, x + q.x, y + q.y, z + q.z); }
|
||||
|
||||
CQuaternion CQuaternion::operator-(const CQuaternion& q) const
|
||||
{
|
||||
return CQuaternion(w - q.w, x - q.x, y - q.y, z - q.z);
|
||||
}
|
||||
CQuaternion CQuaternion::operator-(const CQuaternion& q) const { return CQuaternion(w - q.w, x - q.x, y - q.y, z - q.z); }
|
||||
|
||||
CQuaternion CQuaternion::operator*(const CQuaternion& q) const
|
||||
{
|
||||
return CQuaternion(w*q.w - CVector3f(x, y, z).dot({q.x, q.y, q.z}),
|
||||
y * q.z - z * q.y + w * q.x + x*q.w,
|
||||
z * q.x - x * q.z + w * q.y + y*q.w,
|
||||
x * q.y - y * q.x + w * q.z + z*q.w);
|
||||
return CQuaternion(w * q.w - CVector3f(x, y, z).dot({q.x, q.y, q.z}), y * q.z - z * q.y + w * q.x + x * q.w,
|
||||
z * q.x - x * q.z + w * q.y + y * q.w, x * q.y - y * q.x + w * q.z + z * q.w);
|
||||
}
|
||||
|
||||
CQuaternion CQuaternion::operator/(const CQuaternion& q) const
|
||||
@@ -59,20 +51,11 @@ CQuaternion CQuaternion::operator/(const CQuaternion& q) const
|
||||
return *this * p;
|
||||
}
|
||||
|
||||
CQuaternion CQuaternion::operator*(float scale) const
|
||||
{
|
||||
return CQuaternion(w*scale, x*scale, y*scale, z*scale);
|
||||
}
|
||||
CQuaternion CQuaternion::operator*(float scale) const { return CQuaternion(w * scale, x * scale, y * scale, z * scale); }
|
||||
|
||||
CQuaternion CQuaternion::operator/(float scale) const
|
||||
{
|
||||
return CQuaternion(w/scale, x/scale, y/scale, z/scale);
|
||||
}
|
||||
CQuaternion CQuaternion::operator/(float scale) const { return CQuaternion(w / scale, x / scale, y / scale, z / scale); }
|
||||
|
||||
CQuaternion CQuaternion::operator-() const
|
||||
{
|
||||
return CQuaternion(-w, -x, -y, -z);
|
||||
}
|
||||
CQuaternion CQuaternion::operator-() const { return CQuaternion(-w, -x, -y, -z); }
|
||||
|
||||
const CQuaternion& CQuaternion::operator+=(const CQuaternion& q)
|
||||
{
|
||||
@@ -92,17 +75,17 @@ const CQuaternion& CQuaternion::operator-=(const CQuaternion& q)
|
||||
return *this;
|
||||
}
|
||||
|
||||
const CQuaternion& CQuaternion::operator *=(const CQuaternion& q)
|
||||
const CQuaternion& CQuaternion::operator*=(const CQuaternion& q)
|
||||
{
|
||||
w = w*q.w - CVector3f(x, y, z).dot({q.x, q.y, q.z});
|
||||
x = y * q.z - z * q.y + w * q.x + x*q.w;
|
||||
y = z * q.x - x * q.z + w * q.y + y*q.w;
|
||||
z = x * q.y - y * q.x + w * q.z + z*q.w;
|
||||
w = w * q.w - CVector3f(x, y, z).dot({q.x, q.y, q.z});
|
||||
x = y * q.z - z * q.y + w * q.x + x * q.w;
|
||||
y = z * q.x - x * q.z + w * q.y + y * q.w;
|
||||
z = x * q.y - y * q.x + w * q.z + z * q.w;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
const CQuaternion& CQuaternion::operator *=(float scale)
|
||||
const CQuaternion& CQuaternion::operator*=(float scale)
|
||||
{
|
||||
w *= scale;
|
||||
x *= scale;
|
||||
@@ -120,25 +103,13 @@ const CQuaternion& CQuaternion::operator/=(float scale)
|
||||
return *this;
|
||||
}
|
||||
|
||||
float CQuaternion::magnitude() const
|
||||
{
|
||||
return std::sqrt(magSquared());
|
||||
}
|
||||
float CQuaternion::magnitude() const { return std::sqrt(magSquared()); }
|
||||
|
||||
float CQuaternion::magSquared() const
|
||||
{
|
||||
return w*w + x*x + y*y + z*z;
|
||||
}
|
||||
float CQuaternion::magSquared() const { return w * w + x * x + y * y + z * z; }
|
||||
|
||||
void CQuaternion::normalize()
|
||||
{
|
||||
*this /= magnitude();
|
||||
}
|
||||
void CQuaternion::normalize() { *this /= magnitude(); }
|
||||
|
||||
CQuaternion CQuaternion::normalized() const
|
||||
{
|
||||
return *this/magnitude();
|
||||
}
|
||||
CQuaternion CQuaternion::normalized() const { return *this / magnitude(); }
|
||||
|
||||
void CQuaternion::invert()
|
||||
{
|
||||
@@ -147,25 +118,22 @@ void CQuaternion::invert()
|
||||
z = -z;
|
||||
}
|
||||
|
||||
CQuaternion CQuaternion::inverse() const
|
||||
{
|
||||
return CQuaternion(w, -x, -y, -z);
|
||||
}
|
||||
CQuaternion CQuaternion::inverse() const { return CQuaternion(w, -x, -y, -z); }
|
||||
|
||||
CAxisAngle CQuaternion::toAxisAngle()
|
||||
{
|
||||
// CAxisAngle ret;
|
||||
// ret.angle = std::acos(r);
|
||||
// CAxisAngle ret;
|
||||
// ret.angle = std::acos(r);
|
||||
|
||||
// float thetaInv = 1.0f/std::sin(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.axis.x = v.x * thetaInv;
|
||||
// ret.axis.y = v.y * thetaInv;
|
||||
// ret.axis.z = v.z * thetaInv;
|
||||
|
||||
// ret.angle *= 2.f;
|
||||
// ret.angle *= 2.f;
|
||||
|
||||
// return ret;
|
||||
// return ret;
|
||||
return CAxisAngle();
|
||||
}
|
||||
|
||||
@@ -217,20 +185,11 @@ CQuaternion CQuaternion::exp() const
|
||||
return ret;
|
||||
}
|
||||
|
||||
float CQuaternion::dot(const CQuaternion& b) const
|
||||
{
|
||||
return x * b.x + y * b.y + z * b.z + w * b.w;
|
||||
}
|
||||
float CQuaternion::dot(const CQuaternion& b) const { return x * b.x + y * b.y + z * b.z + w * b.w; }
|
||||
|
||||
CQuaternion CQuaternion::lerp(const CQuaternion& a, const CQuaternion& b, double t)
|
||||
{
|
||||
return (a + t * (b - a));
|
||||
}
|
||||
CQuaternion CQuaternion::lerp(const CQuaternion& a, const CQuaternion& b, double t) { return (a + t * (b - a)); }
|
||||
|
||||
CQuaternion CQuaternion::nlerp(const CQuaternion& a, const CQuaternion& b, double t)
|
||||
{
|
||||
return lerp(a, b, t).normalized();
|
||||
}
|
||||
CQuaternion CQuaternion::nlerp(const CQuaternion& a, const CQuaternion& b, double t) { return lerp(a, b, t).normalized(); }
|
||||
|
||||
CQuaternion CQuaternion::slerp(const CQuaternion& a, const CQuaternion& b, double t)
|
||||
{
|
||||
|
||||
@@ -6,23 +6,23 @@ CTransform CTransformFromEditorEuler(const CVector3f& eulerVec)
|
||||
{
|
||||
CTransform result;
|
||||
double ti, tj, th, ci, cj, ch, si, sj, sh, cc, cs, sc, ss;
|
||||
|
||||
|
||||
ti = eulerVec[0];
|
||||
tj = eulerVec[1];
|
||||
th = eulerVec[2];
|
||||
|
||||
|
||||
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.basis.m[0][0] = float(cj * ch);
|
||||
result.basis.m[1][0] = float(sj * sc - cs);
|
||||
result.basis.m[2][0] = float(sj * cc + ss);
|
||||
@@ -32,7 +32,7 @@ CTransform CTransformFromEditorEuler(const CVector3f& eulerVec)
|
||||
result.basis.m[0][2] = float(-sj);
|
||||
result.basis.m[1][2] = float(cj * si);
|
||||
result.basis.m[2][2] = float(cj * ci);
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -40,23 +40,23 @@ CTransform CTransformFromAxisAngle(const CVector3f& axis, float angle)
|
||||
{
|
||||
CTransform result;
|
||||
CVector3f axisN = axis.normalized();
|
||||
|
||||
|
||||
float c = std::cos(angle);
|
||||
float s = std::sin(angle);
|
||||
float t = 1.f - c;
|
||||
|
||||
|
||||
result.basis.m[0][0] = t * axisN.v[0] * axisN.v[0] + c;
|
||||
result.basis.m[1][0] = t * axisN.v[0] * axisN.v[1] - axisN.v[2] * s;
|
||||
result.basis.m[2][0] = t * axisN.v[0] * axisN.v[2] + axisN.v[1] * s;
|
||||
|
||||
|
||||
result.basis.m[0][1] = t * axisN.v[0] * axisN.v[1] + axisN.v[2] * s;
|
||||
result.basis.m[1][1] = t * axisN.v[1] * axisN.v[1] + c;
|
||||
result.basis.m[2][1] = t * axisN.v[1] * axisN.v[2] - axisN.v[0] * s;
|
||||
|
||||
|
||||
result.basis.m[0][2] = t * axisN.v[0] * axisN.v[2] - axisN.v[1] * s;
|
||||
result.basis.m[1][2] = t * axisN.v[1] * axisN.v[2] + axisN.v[0] * s;
|
||||
result.basis.m[2][2] = t * axisN.v[2] * axisN.v[2] + c;
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ CVector3f CVector3f::slerp(const CVector3f& a, const CVector3f& b, float t)
|
||||
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 s1 = sin(sign * t * theta);
|
||||
const double d = 1.0 / sin(theta);
|
||||
const double s0 = sin((1.0 - t) * theta);
|
||||
|
||||
|
||||
@@ -3,10 +3,7 @@
|
||||
|
||||
namespace zeus
|
||||
{
|
||||
CVector4f::CVector4f(const zeus::CColor& other)
|
||||
: x(other.r), y(other.g), z(other.b), w(other.a)
|
||||
{
|
||||
}
|
||||
CVector4f::CVector4f(const zeus::CColor& other) : x(other.r), y(other.g), z(other.b), w(other.a) {}
|
||||
|
||||
CVector4f& CVector4f::operator=(const CColor& other)
|
||||
{
|
||||
|
||||
59
src/Math.cpp
59
src/Math.cpp
@@ -42,11 +42,11 @@ void detectCPU()
|
||||
{
|
||||
getCpuInfo(i, regs);
|
||||
// Interpret CPU brand string and cache information.
|
||||
if (i == 0x80000002)
|
||||
if (i == 0x80000002)
|
||||
memcpy((char*)g_cpuFeatures.cpuBrand, regs, sizeof(regs));
|
||||
else if( i == 0x80000003 )
|
||||
else if (i == 0x80000003)
|
||||
memcpy((char*)g_cpuFeatures.cpuBrand + 16, regs, sizeof(regs));
|
||||
else if( i == 0x80000004 )
|
||||
else if (i == 0x80000004)
|
||||
memcpy((char*)g_cpuFeatures.cpuBrand + 32, regs, sizeof(regs));
|
||||
}
|
||||
}
|
||||
@@ -54,33 +54,31 @@ void detectCPU()
|
||||
getCpuInfo(1, regs);
|
||||
|
||||
memset((bool*)&g_cpuFeatures.AESNI, ((regs[2] & 0x02000000) != 0), 1);
|
||||
memset((bool*)&g_cpuFeatures.SSE1, ((regs[3] & 0x02000000) != 0), 1);
|
||||
memset((bool*)&g_cpuFeatures.SSE2, ((regs[3] & 0x04000000) != 0), 1);
|
||||
memset((bool*)&g_cpuFeatures.SSE3, ((regs[2] & 0x00000001) != 0), 1);
|
||||
memset((bool*)&g_cpuFeatures.SSE1, ((regs[3] & 0x02000000) != 0), 1);
|
||||
memset((bool*)&g_cpuFeatures.SSE2, ((regs[3] & 0x04000000) != 0), 1);
|
||||
memset((bool*)&g_cpuFeatures.SSE3, ((regs[2] & 0x00000001) != 0), 1);
|
||||
memset((bool*)&g_cpuFeatures.SSSE3, ((regs[2] & 0x00000200) != 0), 1);
|
||||
memset((bool*)&g_cpuFeatures.SSE41, ((regs[2] & 0x00080000) != 0), 1);
|
||||
memset((bool*)&g_cpuFeatures.SSE42, ((regs[2] & 0x00100000) != 0), 1);
|
||||
|
||||
|
||||
isInit = true;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
const CPUInfo& cpuFeatures() { return g_cpuFeatures; }
|
||||
|
||||
CTransform lookAt(const CVector3f& pos, const CVector3f& lookPos, const CVector3f& up)
|
||||
{
|
||||
CVector3f vLook,vRight,vUp;
|
||||
|
||||
CVector3f vLook, vRight, vUp;
|
||||
|
||||
vLook = lookPos - pos;
|
||||
if (vLook.magnitude() < FLT_EPSILON)
|
||||
vLook = {0.f, 1.f, 0.f};
|
||||
vLook.normalize();
|
||||
|
||||
|
||||
vRight = vLook.cross(up);
|
||||
vRight.normalize();
|
||||
|
||||
|
||||
vUp = vRight.cross(vLook);
|
||||
|
||||
CMatrix3f rmBasis(vRight, vLook, vUp);
|
||||
@@ -89,11 +87,9 @@ CTransform lookAt(const CVector3f& pos, const CVector3f& lookPos, const CVector3
|
||||
|
||||
CVector3f getBezierPoint(const CVector3f& a, const CVector3f& b, const CVector3f& c, const CVector3f& d, float t)
|
||||
{
|
||||
const float oneMinusTime= (1.0 - t);
|
||||
return (a * oneMinusTime * oneMinusTime) +
|
||||
(b * 3.f * t * oneMinusTime) +
|
||||
(c * 3.f * t * t * oneMinusTime) +
|
||||
(d * t * t * t);
|
||||
const float oneMinusTime = (1.0 - t);
|
||||
return (a * oneMinusTime * oneMinusTime) + (b * 3.f * t * oneMinusTime) + (c * 3.f * t * t * oneMinusTime) +
|
||||
(d * t * t * t);
|
||||
}
|
||||
|
||||
double sqrtD(double val)
|
||||
@@ -109,17 +105,15 @@ double sqrtD(double val)
|
||||
}
|
||||
double q;
|
||||
#if __SSE__
|
||||
union
|
||||
{
|
||||
union {
|
||||
__m128d v;
|
||||
double d[2];
|
||||
} qv = { val };
|
||||
} qv = {val};
|
||||
qv.v = _mm_sqrt_sd(qv.v, qv.v);
|
||||
q = qv.d[0];
|
||||
#else
|
||||
// le sigh, let's use Carmack's inverse square -.-
|
||||
union
|
||||
{
|
||||
union {
|
||||
double v;
|
||||
int i;
|
||||
} p;
|
||||
@@ -266,13 +260,11 @@ float getCatmullRomSplinePoint(float a, float b, float c, float d, float t)
|
||||
if (t >= 1.0f)
|
||||
return c;
|
||||
|
||||
const float t2 = t * t;
|
||||
const float t2 = t * t;
|
||||
const float t3 = t2 * t;
|
||||
|
||||
return (a * (-0.5f * t3 + t2 - 0.5f * t) +
|
||||
b * ( 1.5f * t3 + -2.5f * t2 + 1.0f) +
|
||||
c * (-1.5f * t3 + 2.0f * t2 + 0.5f * t) +
|
||||
d * ( 0.5f * t3 - 0.5f * t2));
|
||||
return (a * (-0.5f * t3 + t2 - 0.5f * t) + b * (1.5f * t3 + -2.5f * t2 + 1.0f) + c * (-1.5f * t3 + 2.0f * t2 + 0.5f * t) +
|
||||
d * (0.5f * t3 - 0.5f * t2));
|
||||
}
|
||||
|
||||
CVector3f getCatmullRomSplinePoint(const CVector3f& a, const CVector3f& b, const CVector3f& c, const CVector3f& d, float t)
|
||||
@@ -282,13 +274,11 @@ CVector3f getCatmullRomSplinePoint(const CVector3f& a, const CVector3f& b, const
|
||||
if (t >= 1.0f)
|
||||
return c;
|
||||
|
||||
const float t2 = t * t;
|
||||
const float t2 = t * t;
|
||||
const float t3 = t2 * t;
|
||||
|
||||
return (a * (-0.5f * t3 + t2 - 0.5f * t) +
|
||||
b * ( 1.5f * t3 + -2.5f * t2 + 1.0f) +
|
||||
c * (-1.5f * t3 + 2.0f * t2 + 0.5f * t) +
|
||||
d * ( 0.5f * t3 - 0.5f * t2));
|
||||
return (a * (-0.5f * t3 + t2 - 0.5f * t) + b * (1.5f * t3 + -2.5f * t2 + 1.0f) + c * (-1.5f * t3 + 2.0f * t2 + 0.5f * t) +
|
||||
d * (0.5f * t3 - 0.5f * t2));
|
||||
}
|
||||
|
||||
CVector3f getRoundCatmullRomSplinePoint(const CVector3f& a, const CVector3f& b, const CVector3f& c, const CVector3f& d, float t)
|
||||
@@ -319,6 +309,7 @@ CVector3f getRoundCatmullRomSplinePoint(const CVector3f& a, const CVector3f& b,
|
||||
}
|
||||
|
||||
CVector3f baryToWorld(const CVector3f& p0, const CVector3f& p1, const CVector3f& p2, const CVector3f& bary)
|
||||
{ return bary.x * p0 + bary.y * p1 + bary.z * p2; }
|
||||
|
||||
{
|
||||
return bary.x * p0 + bary.y * p1 + bary.z * p2;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,5 +96,4 @@ CMatrix4f CMatrix4f::transposedSSE3() const
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user