mirror of https://github.com/AxioDL/zeus.git
commit
1f3d3cf22a
|
@ -0,0 +1,31 @@
|
|||
---
|
||||
IndentWidth: 4
|
||||
ColumnLimit: 128
|
||||
UseTab: Never
|
||||
---
|
||||
Language: Cpp
|
||||
DerivePointerAlignment: false
|
||||
PointerAlignment: Left
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignConsecutiveAssignments: false
|
||||
BreakBeforeBraces: Allman
|
||||
IndentCaseLabels: false
|
||||
AllowShortBlocksOnASingleLine: true
|
||||
AlignOperands: true
|
||||
AlignTrailingComments: true
|
||||
AlwaysBreakBeforeMultilineStrings: true
|
||||
AlwaysBreakTemplateDeclarations: true
|
||||
BreakConstructorInitializersBeforeComma: true
|
||||
BreakStringLiterals: true
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
AllowShortFunctionsOnASingleLine: All
|
||||
Cpp11BracedListStyle: true
|
||||
NamespaceIndentation: None
|
||||
ReflowComments: true
|
||||
BinPackArguments: true
|
||||
BinPackParameters: true
|
||||
SortIncludes: false
|
||||
AccessModifierOffset: -4
|
||||
ConstructorInitializerIndentWidth: 0
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
|
@ -45,20 +45,12 @@ public:
|
|||
CVector3f max;
|
||||
|
||||
// set default AABox to insane inverse min/max to allow for accumulation
|
||||
inline CAABox()
|
||||
: min(1e16f), max(-1e16f)
|
||||
{}
|
||||
|
||||
CAABox(const CVector3f& min, const CVector3f& max)
|
||||
: min(min),
|
||||
max(max)
|
||||
{
|
||||
}
|
||||
inline CAABox() : min(1e16f), max(-1e16f) {}
|
||||
|
||||
CAABox(float minX, float minY, float minZ,
|
||||
float maxX, float maxY, float maxZ)
|
||||
: min(minX, minY, minZ),
|
||||
max(maxX, maxY, maxZ)
|
||||
CAABox(const CVector3f& min, const CVector3f& max) : min(min), max(max) {}
|
||||
|
||||
CAABox(float minX, float minY, float minZ, float maxX, float maxY, float maxZ)
|
||||
: min(minX, minY, minZ), max(maxX, maxY, maxZ)
|
||||
{
|
||||
}
|
||||
#if ZE_ATHENA_TYPES
|
||||
|
@ -89,11 +81,8 @@ public:
|
|||
return dist;
|
||||
}
|
||||
|
||||
float distanceFromPoint(const CVector3f &other) const
|
||||
{
|
||||
return sqrtF(distanceFromPointSquared(other));
|
||||
}
|
||||
|
||||
float distanceFromPoint(const CVector3f& other) const { return sqrtF(distanceFromPointSquared(other)); }
|
||||
|
||||
inline bool intersects(const CAABox& other) const
|
||||
{
|
||||
bool x1 = (max[0] < other.min[0]);
|
||||
|
@ -121,26 +110,35 @@ public:
|
|||
{
|
||||
CVector3f vmin, vmax;
|
||||
/* X axis */
|
||||
if (plane.a >= 0) {
|
||||
if (plane.a >= 0)
|
||||
{
|
||||
vmin[0] = min[0];
|
||||
vmax[0] = max[0];
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
vmin[0] = max[0];
|
||||
vmax[0] = min[0];
|
||||
}
|
||||
/* Y axis */
|
||||
if (plane.b >= 0) {
|
||||
if (plane.b >= 0)
|
||||
{
|
||||
vmin[1] = min[1];
|
||||
vmax[1] = max[1];
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
vmin[1] = max[1];
|
||||
vmax[1] = min[1];
|
||||
}
|
||||
/* Z axis */
|
||||
if (plane.c >= 0) {
|
||||
if (plane.c >= 0)
|
||||
{
|
||||
vmin[2] = min[2];
|
||||
vmax[2] = max[2];
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
vmin[2] = max[2];
|
||||
vmax[2] = min[2];
|
||||
}
|
||||
|
@ -150,53 +148,40 @@ public:
|
|||
return true;
|
||||
}
|
||||
|
||||
CVector3f center() const {return (min + max) * 0.5f;}
|
||||
CVector3f center() const { return (min + max) * 0.5f; }
|
||||
|
||||
CVector3f volume() const {return (max - min) * 0.5f;}
|
||||
CVector3f volume() const { return (max - min) * 0.5f; }
|
||||
|
||||
inline CLineSeg getEdge(EBoxEdgeId id)
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case EBoxEdgeId::UnknownEdge0:
|
||||
return CLineSeg({min.x, min.y, min.z},
|
||||
{min.x, min.y, max.z});
|
||||
case EBoxEdgeId::UnknownEdge1:
|
||||
return CLineSeg({max.x, min.y, min.z},
|
||||
{min.x, min.y, min.z});
|
||||
case EBoxEdgeId::UnknownEdge2:
|
||||
return CLineSeg({max.x, min.y, max.z},
|
||||
{max.x, min.y, max.z});
|
||||
case EBoxEdgeId::UnknownEdge3:
|
||||
return CLineSeg({min.x, min.y, max.z},
|
||||
{max.x, min.y, max.z});
|
||||
case EBoxEdgeId::UnknownEdge4:
|
||||
return CLineSeg({max.x, max.y, min.z},
|
||||
{max.x, max.y, max.z});
|
||||
case EBoxEdgeId::UnknownEdge5:
|
||||
return CLineSeg({min.x, max.y, min.z},
|
||||
{max.x, max.y, min.z});
|
||||
case EBoxEdgeId::UnknownEdge6:
|
||||
return CLineSeg({min.x, max.y, max.z},
|
||||
{min.x, max.y, min.z});
|
||||
case EBoxEdgeId::UnknownEdge7:
|
||||
return CLineSeg({max.x, max.y, max.z},
|
||||
{min.x, max.y, max.z});
|
||||
case EBoxEdgeId::UnknownEdge8:
|
||||
return CLineSeg({min.x, max.y, max.z},
|
||||
{min.x, min.y, max.z});
|
||||
case EBoxEdgeId::UnknownEdge9:
|
||||
return CLineSeg({min.x, max.y, min.z},
|
||||
{min.x, min.y, min.z});
|
||||
case EBoxEdgeId::UnknownEdge10:
|
||||
return CLineSeg({max.x, max.y, min.z},
|
||||
{max.x, min.y, min.z});
|
||||
case EBoxEdgeId::UnknownEdge11:
|
||||
return CLineSeg({max.x, max.y, max.z},
|
||||
{max.x, min.y, max.z});
|
||||
default:
|
||||
return CLineSeg({min.x, min.y, min.z},
|
||||
{min.x, min.y, max.z});
|
||||
case EBoxEdgeId::UnknownEdge0:
|
||||
return CLineSeg({min.x, min.y, min.z}, {min.x, min.y, max.z});
|
||||
case EBoxEdgeId::UnknownEdge1:
|
||||
return CLineSeg({max.x, min.y, min.z}, {min.x, min.y, min.z});
|
||||
case EBoxEdgeId::UnknownEdge2:
|
||||
return CLineSeg({max.x, min.y, max.z}, {max.x, min.y, max.z});
|
||||
case EBoxEdgeId::UnknownEdge3:
|
||||
return CLineSeg({min.x, min.y, max.z}, {max.x, min.y, max.z});
|
||||
case EBoxEdgeId::UnknownEdge4:
|
||||
return CLineSeg({max.x, max.y, min.z}, {max.x, max.y, max.z});
|
||||
case EBoxEdgeId::UnknownEdge5:
|
||||
return CLineSeg({min.x, max.y, min.z}, {max.x, max.y, min.z});
|
||||
case EBoxEdgeId::UnknownEdge6:
|
||||
return CLineSeg({min.x, max.y, max.z}, {min.x, max.y, min.z});
|
||||
case EBoxEdgeId::UnknownEdge7:
|
||||
return CLineSeg({max.x, max.y, max.z}, {min.x, max.y, max.z});
|
||||
case EBoxEdgeId::UnknownEdge8:
|
||||
return CLineSeg({min.x, max.y, max.z}, {min.x, min.y, max.z});
|
||||
case EBoxEdgeId::UnknownEdge9:
|
||||
return CLineSeg({min.x, max.y, min.z}, {min.x, min.y, min.z});
|
||||
case EBoxEdgeId::UnknownEdge10:
|
||||
return CLineSeg({max.x, max.y, min.z}, {max.x, min.y, min.z});
|
||||
case EBoxEdgeId::UnknownEdge11:
|
||||
return CLineSeg({max.x, max.y, max.z}, {max.x, min.y, max.z});
|
||||
default:
|
||||
return CLineSeg({min.x, min.y, min.z}, {min.x, min.y, max.z});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -246,24 +231,21 @@ public:
|
|||
|
||||
inline bool pointInside(const CVector3f& other) const
|
||||
{
|
||||
return (min.x <= other.x && other.x <= max.z &&
|
||||
min.y <= other.y && other.y <= max.z &&
|
||||
min.z <= other.z && other.z <= max.z);
|
||||
return (min.x <= other.x && other.x <= max.z && min.y <= other.y && other.y <= max.z && min.z <= other.z &&
|
||||
other.z <= max.z);
|
||||
}
|
||||
|
||||
inline CVector3f closestPointAlongVector(const CVector3f& other) const
|
||||
{
|
||||
CVector3f center = this->center();
|
||||
return {(other.x < center.x ? min.x : max.x),
|
||||
(other.y < center.y ? min.y : max.y),
|
||||
return {(other.x < center.x ? min.x : max.x), (other.y < center.y ? min.y : max.y),
|
||||
(other.z < center.z ? min.z : max.z)};
|
||||
}
|
||||
|
||||
inline CVector3f furthestPointAlongVector(const CVector3f& other) const
|
||||
{
|
||||
CVector3f center = this->center();
|
||||
return {(other.x < center.x ? max.x : min.x),
|
||||
(other.y < center.y ? max.y : min.y),
|
||||
return {(other.x < center.x ? max.x : min.x), (other.y < center.y ? max.y : min.y),
|
||||
(other.z < center.z ? max.z : min.z)};
|
||||
}
|
||||
|
||||
|
@ -297,7 +279,7 @@ public:
|
|||
negX.max.x = midX;
|
||||
negX.min = min;
|
||||
}
|
||||
|
||||
|
||||
inline void splitY(CAABox& posY, CAABox& negY) const
|
||||
{
|
||||
float midY = (max.y - min.y) * .5 + min.y;
|
||||
|
@ -308,7 +290,7 @@ public:
|
|||
negY.max.y = midY;
|
||||
negY.min = min;
|
||||
}
|
||||
|
||||
|
||||
inline void splitZ(CAABox& posZ, CAABox& negZ) const
|
||||
{
|
||||
float midZ = (max.z - min.z) * .5 + min.z;
|
||||
|
@ -320,12 +302,11 @@ public:
|
|||
negZ.min = min;
|
||||
}
|
||||
|
||||
|
||||
inline bool invalid() {return (max.x < min.x || max.y < min.y || max.z < min.z);}
|
||||
inline bool invalid() { return (max.x < min.x || max.y < min.y || max.z < min.z); }
|
||||
};
|
||||
|
||||
inline bool operator ==(const CAABox& left, const CAABox& right) {return (left.min == right.min && left.max == right.max);}
|
||||
inline bool operator !=(const CAABox& left, const CAABox& right) {return (left.min != right.min || left.max != right.max);}
|
||||
inline bool operator==(const CAABox& left, const CAABox& right) { return (left.min == right.min && left.max == right.max); }
|
||||
inline bool operator!=(const CAABox& left, const CAABox& right) { return (left.min != right.min || left.max != right.max); }
|
||||
}
|
||||
|
||||
#endif // CAABOX_HPP
|
||||
|
|
|
@ -10,15 +10,11 @@ namespace zeus
|
|||
struct alignas(16) CAxisAngle : CVector3f
|
||||
{
|
||||
ZE_DECLARE_ALIGNED_ALLOCATOR();
|
||||
|
||||
CAxisAngle() = default;
|
||||
CAxisAngle(const CUnitVector3f& axis, float distance)
|
||||
: CVector3f(distance * axis)
|
||||
{}
|
||||
|
||||
CAxisAngle(const CVector3f& axisAngle)
|
||||
: CVector3f(axisAngle)
|
||||
{}
|
||||
CAxisAngle() = default;
|
||||
CAxisAngle(const CUnitVector3f& axis, float distance) : CVector3f(distance * axis) {}
|
||||
|
||||
CAxisAngle(const CVector3f& axisAngle) : CVector3f(axisAngle) {}
|
||||
|
||||
float angle() { return magnitude(); }
|
||||
const CVector3f& getVector() { return *this; }
|
||||
|
|
|
@ -10,8 +10,8 @@
|
|||
#include <iostream>
|
||||
|
||||
#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
|
||||
|
@ -20,10 +20,9 @@ namespace zeus
|
|||
{
|
||||
typedef uint8_t Comp8;
|
||||
typedef uint32_t Comp32;
|
||||
constexpr float OneOver255 = 1.f/255.f;
|
||||
constexpr float OneOver255 = 1.f / 255.f;
|
||||
|
||||
typedef union
|
||||
{
|
||||
typedef union {
|
||||
struct
|
||||
{
|
||||
Comp8 r, g, b, a;
|
||||
|
@ -55,11 +54,19 @@ public:
|
|||
|
||||
CColor() : r(1.0f), g(1.0f), b(1.0f), a(1.0f) {}
|
||||
CColor(float rgb, float a = 1.0) { splat(rgb, a); }
|
||||
CColor(float r, float g, float b, float a = 1.0f) {v[0] = r; v[1] = g; v[2] = b; v[3] = a; }
|
||||
CColor(float r, float g, float b, float a = 1.0f)
|
||||
{
|
||||
v[0] = r;
|
||||
v[1] = g;
|
||||
v[2] = b;
|
||||
v[3] = a;
|
||||
}
|
||||
#if ZE_ATHENA_TYPES
|
||||
CColor(const atVec4f& vec)
|
||||
#if __SSE__ || __GEKKO_PS__
|
||||
: mVec128(vec.mVec128){}
|
||||
: mVec128(vec.mVec128)
|
||||
{
|
||||
}
|
||||
#else
|
||||
{
|
||||
r = vec.vec[0], g = vec.vec[1], b = vec.vec[2], a = vec.vec[3];
|
||||
|
@ -90,10 +97,8 @@ public:
|
|||
}
|
||||
#endif
|
||||
|
||||
inline bool operator==(const CColor& rhs) const
|
||||
{ return (r == rhs.r && g == rhs.g && b == rhs.b && a == rhs.a); }
|
||||
inline bool operator!=(const CColor& rhs) const
|
||||
{ return !(*this == rhs); }
|
||||
inline bool operator==(const CColor& rhs) const { return (r == rhs.r && g == rhs.g && b == rhs.b && a == rhs.a); }
|
||||
inline bool operator!=(const CColor& rhs) const { return !(*this == rhs); }
|
||||
inline CColor operator+(const CColor& rhs) const
|
||||
{
|
||||
#if __SSE__
|
||||
|
@ -167,7 +172,10 @@ public:
|
|||
#if __SSE__
|
||||
mVec128 = _mm_add_ps(mVec128, rhs.mVec128);
|
||||
#else
|
||||
r += rhs.r; g += rhs.g; b += rhs.b; a += rhs.a;
|
||||
r += rhs.r;
|
||||
g += rhs.g;
|
||||
b += rhs.b;
|
||||
a += rhs.a;
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
|
@ -176,25 +184,34 @@ public:
|
|||
#if __SSE__
|
||||
mVec128 = _mm_sub_ps(mVec128, rhs.mVec128);
|
||||
#else
|
||||
r -= rhs.r; g -= rhs.g; b -= rhs.b; a -= rhs.a;
|
||||
r -= rhs.r;
|
||||
g -= rhs.g;
|
||||
b -= rhs.b;
|
||||
a -= rhs.a;
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
inline const CColor& operator *=(const CColor& rhs)
|
||||
inline const CColor& operator*=(const CColor& rhs)
|
||||
{
|
||||
#if __SSE__
|
||||
mVec128 = _mm_mul_ps(mVec128, rhs.mVec128);
|
||||
#else
|
||||
r *= rhs.r; g *= rhs.g; b *= rhs.b; a *= rhs.a;
|
||||
r *= rhs.r;
|
||||
g *= rhs.g;
|
||||
b *= rhs.b;
|
||||
a *= rhs.a;
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
inline const CColor& operator /=(const CColor& rhs)
|
||||
inline const CColor& operator/=(const CColor& rhs)
|
||||
{
|
||||
#if __SSE__
|
||||
mVec128 = _mm_div_ps(mVec128, rhs.mVec128);
|
||||
#else
|
||||
r /= rhs.r; g /= rhs.g; b /= rhs.b; a /= rhs.a;
|
||||
r /= rhs.r;
|
||||
g /= rhs.g;
|
||||
b /= rhs.b;
|
||||
a /= rhs.a;
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
|
@ -229,19 +246,10 @@ public:
|
|||
return r * r + g * g + b * b + a * a;
|
||||
#endif
|
||||
}
|
||||
inline float magnitude() const
|
||||
{
|
||||
return std::sqrt(magSquared());
|
||||
}
|
||||
static inline CColor lerp(const CColor& a, const CColor& b, float t)
|
||||
{
|
||||
return (a + (b - a) * t);
|
||||
}
|
||||
static inline CColor nlerp(const CColor& a, const CColor& b, float t)
|
||||
{
|
||||
return lerp(a, b, t).normalized();
|
||||
}
|
||||
inline float& operator[](const size_t& idx) {return (&r)[idx];}
|
||||
inline float magnitude() const { return std::sqrt(magSquared()); }
|
||||
static inline CColor lerp(const CColor& a, const CColor& b, float t) { return (a + (b - a) * t); }
|
||||
static inline CColor nlerp(const CColor& a, const CColor& b, float t) { return lerp(a, b, t).normalized(); }
|
||||
inline float& operator[](const size_t& idx) { return (&r)[idx]; }
|
||||
inline const float& operator[](const size_t& idx) const { return (&r)[idx]; }
|
||||
inline void splat(float rgb, float a)
|
||||
{
|
||||
|
@ -249,12 +257,14 @@ public:
|
|||
TVectorUnion splat = {{rgb, rgb, rgb, a}};
|
||||
mVec128 = splat.mVec128;
|
||||
#else
|
||||
v[0] = rgb; v[1] = rgb; v[2] = rgb; v[3] = a;
|
||||
v[0] = rgb;
|
||||
v[1] = rgb;
|
||||
v[2] = rgb;
|
||||
v[3] = a;
|
||||
#endif
|
||||
}
|
||||
|
||||
union
|
||||
{
|
||||
union {
|
||||
struct
|
||||
{
|
||||
float r, g, b, a;
|
||||
|
@ -313,13 +323,11 @@ public:
|
|||
*/
|
||||
void toHSV(float& h, float& s, float& v) const;
|
||||
|
||||
|
||||
void fromHSL(float h, float s, float l, float _a = 1.0);
|
||||
|
||||
void toHSL(float& h, float& s, float& l);
|
||||
|
||||
CColor toGrayscale()
|
||||
{ return {sqrtF((r * r + g * g + b * b) / 3), a}; }
|
||||
CColor toGrayscale() { return {sqrtF((r * r + g * g + b * b) / 3), a}; }
|
||||
|
||||
/**
|
||||
* @brief Clamps to GPU-safe RGBA values [0,1]
|
||||
|
@ -372,6 +380,5 @@ static inline CColor operator/(float lhs, const CColor& rhs)
|
|||
return CColor(lhs / rhs.r, lhs / rhs.g, lhs / rhs.b, lhs / rhs.a);
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
#endif // CCOLOR_HPP
|
||||
|
|
|
@ -9,110 +9,119 @@ namespace zeus
|
|||
class CFrustum
|
||||
{
|
||||
CPlane planes[6];
|
||||
|
||||
public:
|
||||
|
||||
inline void updatePlanes(const CTransform& modelview, const CProjection& projection)
|
||||
{
|
||||
CMatrix4f mv = modelview.toMatrix4f();
|
||||
CMatrix4f mvp = projection.getCachedMatrix() * mv;
|
||||
CMatrix4f mvp_rm = mvp.transposed();
|
||||
|
||||
|
||||
#if __SSE__
|
||||
|
||||
|
||||
/* Left */
|
||||
planes[0].mVec128 = _mm_add_ps(mvp_rm.vec[0].mVec128, mvp_rm.vec[3].mVec128);
|
||||
|
||||
|
||||
/* Right */
|
||||
planes[1].mVec128 = _mm_add_ps(_mm_sub_ps(CVector3f::skZero.mVec128, mvp_rm.vec[0].mVec128), mvp_rm.vec[3].mVec128);
|
||||
|
||||
|
||||
/* Bottom */
|
||||
planes[2].mVec128 = _mm_add_ps(mvp_rm.vec[1].mVec128, mvp_rm.vec[3].mVec128);
|
||||
|
||||
|
||||
/* Top */
|
||||
planes[3].mVec128 = _mm_add_ps(_mm_sub_ps(CVector3f::skZero.mVec128, mvp_rm.vec[1].mVec128), mvp_rm.vec[3].mVec128);
|
||||
|
||||
|
||||
/* Near */
|
||||
planes[4].mVec128 = _mm_add_ps(mvp_rm.vec[2].mVec128, mvp_rm.vec[3].mVec128);
|
||||
|
||||
|
||||
/* Far */
|
||||
planes[5].mVec128 = _mm_add_ps(_mm_sub_ps(CVector3f::skZero.mVec128, mvp_rm.vec[2].mVec128), mvp_rm.vec[3].mVec128);
|
||||
|
||||
|
||||
#else
|
||||
/* Left */
|
||||
m_planes[0].a = mvp_rm.m[0][0] + mvp_rm.m[3][0];
|
||||
m_planes[0].b = mvp_rm.m[0][1] + mvp_rm.m[3][1];
|
||||
m_planes[0].c = mvp_rm.m[0][2] + mvp_rm.m[3][2];
|
||||
m_planes[0].d = mvp_rm.m[0][3] + mvp_rm.m[3][3];
|
||||
|
||||
|
||||
/* Right */
|
||||
m_planes[1].a = -mvp_rm.m[0][0] + mvp_rm.m[3][0];
|
||||
m_planes[1].b = -mvp_rm.m[0][1] + mvp_rm.m[3][1];
|
||||
m_planes[1].c = -mvp_rm.m[0][2] + mvp_rm.m[3][2];
|
||||
m_planes[1].d = -mvp_rm.m[0][3] + mvp_rm.m[3][3];
|
||||
|
||||
|
||||
/* Bottom */
|
||||
m_planes[2].a = mvp_rm.m[1][0] + mvp_rm.m[3][0];
|
||||
m_planes[2].b = mvp_rm.m[1][1] + mvp_rm.m[3][1];
|
||||
m_planes[2].c = mvp_rm.m[1][2] + mvp_rm.m[3][2];
|
||||
m_planes[2].d = mvp_rm.m[1][3] + mvp_rm.m[3][3];
|
||||
|
||||
|
||||
/* Top */
|
||||
m_planes[3].a = -mvp_rm.m[1][0] + mvp_rm.m[3][0];
|
||||
m_planes[3].b = -mvp_rm.m[1][1] + mvp_rm.m[3][1];
|
||||
m_planes[3].c = -mvp_rm.m[1][2] + mvp_rm.m[3][2];
|
||||
m_planes[3].d = -mvp_rm.m[1][3] + mvp_rm.m[3][3];
|
||||
|
||||
|
||||
/* Near */
|
||||
m_planes[4].a = mvp_rm.m[2][0] + mvp_rm.m[3][0];
|
||||
m_planes[4].b = mvp_rm.m[2][1] + mvp_rm.m[3][1];
|
||||
m_planes[4].c = mvp_rm.m[2][2] + mvp_rm.m[3][2];
|
||||
m_planes[4].d = mvp_rm.m[2][3] + mvp_rm.m[3][3];
|
||||
|
||||
|
||||
/* Far */
|
||||
m_planes[5].a = -mvp_rm.m[2][0] + mvp_rm.m[3][0];
|
||||
m_planes[5].b = -mvp_rm.m[2][1] + mvp_rm.m[3][1];
|
||||
m_planes[5].c = -mvp_rm.m[2][2] + mvp_rm.m[3][2];
|
||||
m_planes[5].d = -mvp_rm.m[2][3] + mvp_rm.m[3][3];
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
planes[0].normalize();
|
||||
planes[1].normalize();
|
||||
planes[2].normalize();
|
||||
planes[3].normalize();
|
||||
planes[4].normalize();
|
||||
planes[5].normalize();
|
||||
|
||||
}
|
||||
|
||||
|
||||
inline bool aabbFrustumTest(const CAABox& aabb) const
|
||||
{
|
||||
CVector3f vmin, vmax;
|
||||
int i;
|
||||
for (i=0 ; i<6 ; ++i) {
|
||||
for (i = 0; i < 6; ++i)
|
||||
{
|
||||
const CPlane& plane = planes[i];
|
||||
|
||||
|
||||
/* X axis */
|
||||
if (plane.a >= 0) {
|
||||
if (plane.a >= 0)
|
||||
{
|
||||
vmin[0] = aabb.min[0];
|
||||
vmax[0] = aabb.max[0];
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
vmin[0] = aabb.max[0];
|
||||
vmax[0] = aabb.min[0];
|
||||
}
|
||||
/* Y axis */
|
||||
if (plane.b >= 0) {
|
||||
if (plane.b >= 0)
|
||||
{
|
||||
vmin[1] = aabb.min[1];
|
||||
vmax[1] = aabb.max[1];
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
vmin[1] = aabb.max[1];
|
||||
vmax[1] = aabb.min[1];
|
||||
}
|
||||
/* Z axis */
|
||||
if (plane.c >= 0) {
|
||||
if (plane.c >= 0)
|
||||
{
|
||||
vmin[2] = aabb.min[2];
|
||||
vmax[2] = aabb.max[2];
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
vmin[2] = aabb.max[2];
|
||||
vmax[2] = aabb.min[2];
|
||||
}
|
||||
|
@ -122,7 +131,6 @@ public:
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
#endif // CFRUSTUM_HPP
|
||||
|
|
|
@ -9,16 +9,13 @@ namespace zeus
|
|||
class CLineSeg
|
||||
{
|
||||
public:
|
||||
CLineSeg(const CVector3f& start, const CVector3f& end)
|
||||
: start(start),
|
||||
end(end)
|
||||
CLineSeg(const CVector3f& start, const CVector3f& end) : start(start), end(end)
|
||||
{
|
||||
CVector3f tmp = (end - start).normalized();
|
||||
if (tmp.x != 0 || tmp.y != 0 || tmp.z != 0)
|
||||
normal = tmp.normalized();
|
||||
else
|
||||
normal = CVector3f::skZero;
|
||||
|
||||
}
|
||||
|
||||
CVector3f normal;
|
||||
|
|
|
@ -8,21 +8,13 @@ namespace zeus
|
|||
{
|
||||
struct CMRay
|
||||
{
|
||||
CMRay(const CVector3f& start, const CVector3f& end, float d)
|
||||
: start(start),
|
||||
end(end),
|
||||
d(d),
|
||||
invD(1.f/d)
|
||||
CMRay(const CVector3f& start, const CVector3f& end, float d) : start(start), end(end), d(d), invD(1.f / d)
|
||||
{
|
||||
normal = start + (d * end);
|
||||
delta = normal - start;
|
||||
}
|
||||
|
||||
CMRay(const CVector3f& start, const CVector3f& norm, float d, float invD)
|
||||
: start(start),
|
||||
normal(norm),
|
||||
d(d),
|
||||
invD(invD)
|
||||
CMRay(const CVector3f& start, const CVector3f& norm, float d, float invD) : start(start), normal(norm), d(d), invD(invD)
|
||||
{
|
||||
delta = normal - start;
|
||||
end = invD * delta;
|
||||
|
|
|
@ -14,7 +14,7 @@ class alignas(16) CMatrix3f
|
|||
{
|
||||
public:
|
||||
ZE_DECLARE_ALIGNED_ALLOCATOR();
|
||||
|
||||
|
||||
explicit CMatrix3f(bool zero = false)
|
||||
{
|
||||
memset(m, 0, sizeof(m));
|
||||
|
@ -25,9 +25,7 @@ public:
|
|||
m[2][2] = 1.0;
|
||||
}
|
||||
}
|
||||
CMatrix3f(float m00, float m01, float m02,
|
||||
float m10, float m11, float m12,
|
||||
float m20, float m21, float m22)
|
||||
CMatrix3f(float m00, float m01, float m02, float m10, float m11, float m12, float m20, float m21, float m22)
|
||||
{
|
||||
m[0][0] = m00, m[1][0] = m01, m[2][0] = m02;
|
||||
m[0][1] = m10, m[1][1] = m11, m[2][1] = m12;
|
||||
|
@ -40,25 +38,44 @@ public:
|
|||
m[1][1] = scaleVec[1];
|
||||
m[2][2] = scaleVec[2];
|
||||
}
|
||||
CMatrix3f(float scale)
|
||||
: CMatrix3f(CVector3f(scale)) {}
|
||||
CMatrix3f(float scale) : CMatrix3f(CVector3f(scale)) {}
|
||||
CMatrix3f(const CVector3f& r0, const CVector3f& r1, const CVector3f& r2)
|
||||
{vec[0] = r0; vec[1] = r1; vec[2] = r2;}
|
||||
{
|
||||
vec[0] = r0;
|
||||
vec[1] = r1;
|
||||
vec[2] = r2;
|
||||
}
|
||||
CMatrix3f(const CMatrix3f& other)
|
||||
{vec[0] = other.vec[0]; vec[1] = other.vec[1]; vec[2] = other.vec[2];}
|
||||
{
|
||||
vec[0] = other.vec[0];
|
||||
vec[1] = other.vec[1];
|
||||
vec[2] = other.vec[2];
|
||||
}
|
||||
#if __SSE__
|
||||
CMatrix3f(const __m128& r0, const __m128& r1, const __m128& r2)
|
||||
{vec[0].mVec128 = r0; vec[1].mVec128 = r1; vec[2].mVec128 = r2;}
|
||||
{
|
||||
vec[0].mVec128 = r0;
|
||||
vec[1].mVec128 = r1;
|
||||
vec[2].mVec128 = r2;
|
||||
}
|
||||
#endif
|
||||
#if ZE_ATHENA_TYPES
|
||||
CMatrix3f(const atVec4f& r0, const atVec4f& r1, const atVec4f& r2)
|
||||
{
|
||||
#if __SSE__
|
||||
vec[0].mVec128 = r0.mVec128; vec[1].mVec128 = r1.mVec128; vec[2].mVec128 = r2.mVec128;
|
||||
vec[0].mVec128 = r0.mVec128;
|
||||
vec[1].mVec128 = r1.mVec128;
|
||||
vec[2].mVec128 = r2.mVec128;
|
||||
#else
|
||||
vec[0].x = r0.vec[0]; vec[0].y = r0.vec[1]; vec[0].z = r0.vec[2];
|
||||
vec[1].x = r1.vec[0]; vec[1].y = r1.vec[1]; vec[1].z = r1.vec[2];
|
||||
vec[2].x = r2.vec[0]; vec[2].y = r2.vec[1]; vec[2].z = r2.vec[2];
|
||||
vec[0].x = r0.vec[0];
|
||||
vec[0].y = r0.vec[1];
|
||||
vec[0].z = r0.vec[2];
|
||||
vec[1].x = r1.vec[0];
|
||||
vec[1].y = r1.vec[1];
|
||||
vec[1].z = r1.vec[2];
|
||||
vec[2].x = r2.vec[0];
|
||||
vec[2].y = r2.vec[1];
|
||||
vec[2].z = r2.vec[2];
|
||||
#endif
|
||||
}
|
||||
void readBig(athena::io::IStreamReader& input)
|
||||
|
@ -79,11 +96,19 @@ public:
|
|||
CMatrix3f(const TVectorUnion& r0, const TVectorUnion& r1, const TVectorUnion& r2)
|
||||
{
|
||||
#if __SSE__
|
||||
vec[0].mVec128 = r0.mVec128; vec[1].mVec128 = r1.mVec128; vec[2].mVec128 = r2.mVec128;
|
||||
vec[0].mVec128 = r0.mVec128;
|
||||
vec[1].mVec128 = r1.mVec128;
|
||||
vec[2].mVec128 = r2.mVec128;
|
||||
#else
|
||||
vec[0].x = r0.vec[0]; vec[0].y = r0.vec[1]; vec[0].z = r0.vec[2];
|
||||
vec[1].x = r1.vec[0]; vec[1].y = r1.vec[1]; vec[1].z = r1.vec[2];
|
||||
vec[2].x = r2.vec[0]; vec[2].y = r2.vec[1]; vec[2].z = r2.vec[2];
|
||||
vec[0].x = r0.vec[0];
|
||||
vec[0].y = r0.vec[1];
|
||||
vec[0].z = r0.vec[2];
|
||||
vec[1].x = r1.vec[0];
|
||||
vec[1].y = r1.vec[1];
|
||||
vec[1].z = r1.vec[2];
|
||||
vec[2].x = r2.vec[0];
|
||||
vec[2].y = r2.vec[1];
|
||||
vec[2].z = r2.vec[2];
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -94,16 +119,14 @@ public:
|
|||
vec[2] = other.vec[2];
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
inline CVector3f operator*(const CVector3f& other) const
|
||||
{
|
||||
#if __SSE__
|
||||
TVectorUnion res;
|
||||
res.mVec128 =
|
||||
_mm_add_ps(_mm_add_ps(
|
||||
_mm_mul_ps(vec[0].mVec128, ze_splat_ps(other.mVec128, 0)),
|
||||
_mm_mul_ps(vec[1].mVec128, ze_splat_ps(other.mVec128, 1))),
|
||||
_mm_mul_ps(vec[2].mVec128, ze_splat_ps(other.mVec128, 2)));
|
||||
res.mVec128 = _mm_add_ps(_mm_add_ps(_mm_mul_ps(vec[0].mVec128, ze_splat_ps(other.mVec128, 0)),
|
||||
_mm_mul_ps(vec[1].mVec128, ze_splat_ps(other.mVec128, 1))),
|
||||
_mm_mul_ps(vec[2].mVec128, ze_splat_ps(other.mVec128, 2)));
|
||||
return CVector3f(res.mVec128);
|
||||
#else
|
||||
return CVector3f(m[0][0] * other.v[0] + m[1][0] * other.v[1] + m[2][0] * other.v[2],
|
||||
|
@ -111,13 +134,13 @@ public:
|
|||
m[0][2] * other.v[0] + m[1][2] * other.v[1] + m[2][2] * other.v[2]);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
inline CVector3f& operator[](int i)
|
||||
{
|
||||
assert(0 <= i && i < 3);
|
||||
return vec[i];
|
||||
}
|
||||
|
||||
|
||||
inline const CVector3f& operator[](int i) const
|
||||
{
|
||||
assert(0 <= i && i < 3);
|
||||
|
@ -135,13 +158,13 @@ public:
|
|||
}
|
||||
|
||||
static const CMatrix3f skIdentityMatrix3f;
|
||||
|
||||
|
||||
void transpose();
|
||||
void transposeSSE3();
|
||||
CMatrix3f transposed() const;
|
||||
CMatrix3f transposedSSE3() const;
|
||||
|
||||
inline void invert() {*this = inverted();}
|
||||
inline void invert() { *this = inverted(); }
|
||||
CMatrix3f inverted() const;
|
||||
|
||||
void addScaledMatrix(const CMatrix3f& other, float scale)
|
||||
|
@ -151,9 +174,8 @@ public:
|
|||
vec[1] += other.vec[1] * scaleVec;
|
||||
vec[2] += other.vec[2] * scaleVec;
|
||||
}
|
||||
|
||||
union
|
||||
{
|
||||
|
||||
union {
|
||||
float m[3][4]; /* 4th row for union-alignment */
|
||||
struct
|
||||
{
|
||||
|
@ -167,12 +189,11 @@ static CMatrix3f operator*(const CMatrix3f& lhs, const CMatrix3f& rhs)
|
|||
#if __SSE__
|
||||
unsigned i;
|
||||
TVectorUnion resVec[3];
|
||||
for (i=0 ; i<3 ; ++i) {
|
||||
resVec[i].mVec128 =
|
||||
_mm_add_ps(_mm_add_ps(
|
||||
_mm_mul_ps(lhs[0].mVec128, ze_splat_ps(rhs[i].mVec128, 0)),
|
||||
_mm_mul_ps(lhs[1].mVec128, ze_splat_ps(rhs[i].mVec128, 1))),
|
||||
_mm_mul_ps(lhs[2].mVec128, ze_splat_ps(rhs[i].mVec128, 2)));
|
||||
for (i = 0; i < 3; ++i)
|
||||
{
|
||||
resVec[i].mVec128 = _mm_add_ps(_mm_add_ps(_mm_mul_ps(lhs[0].mVec128, ze_splat_ps(rhs[i].mVec128, 0)),
|
||||
_mm_mul_ps(lhs[1].mVec128, ze_splat_ps(rhs[i].mVec128, 1))),
|
||||
_mm_mul_ps(lhs[2].mVec128, ze_splat_ps(rhs[i].mVec128, 2)));
|
||||
resVec[i].v[3] = 0.0;
|
||||
}
|
||||
return CMatrix3f(resVec[0].mVec128, resVec[1].mVec128, resVec[2].mVec128);
|
||||
|
@ -188,7 +209,6 @@ static CMatrix3f operator*(const CMatrix3f& lhs, const CMatrix3f& rhs)
|
|||
lhs[0][2] * rhs[2][0] + lhs[1][2] * rhs[2][1] + lhs[2][2] * rhs[2][2]);
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // CMATRIX3F_HPP
|
||||
|
|
|
@ -23,10 +23,8 @@ public:
|
|||
m[3][3] = 1.0;
|
||||
}
|
||||
}
|
||||
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)
|
||||
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[0][0] = m00, m[1][0] = m01, m[2][0] = m02, m[3][0] = m03;
|
||||
m[0][1] = m10, m[1][1] = m11, m[2][1] = m12, m[3][1] = m13;
|
||||
|
@ -42,12 +40,27 @@ public:
|
|||
m[3][3] = 1.0f;
|
||||
}
|
||||
CMatrix4f(const CVector4f& r0, const CVector4f& r1, const CVector4f& r2, const CVector4f& r3)
|
||||
{vec[0] = r0; vec[1] = r1; vec[2] = r2; vec[3] = r3;}
|
||||
{
|
||||
vec[0] = r0;
|
||||
vec[1] = r1;
|
||||
vec[2] = r2;
|
||||
vec[3] = r3;
|
||||
}
|
||||
CMatrix4f(const CMatrix4f& other)
|
||||
{vec[0] = other.vec[0]; vec[1] = other.vec[1]; vec[2] = other.vec[2]; vec[3] = other.vec[3];}
|
||||
{
|
||||
vec[0] = other.vec[0];
|
||||
vec[1] = other.vec[1];
|
||||
vec[2] = other.vec[2];
|
||||
vec[3] = other.vec[3];
|
||||
}
|
||||
#if __SSE__
|
||||
CMatrix4f(const __m128& r0, const __m128& r1, const __m128& r2, const __m128& r3)
|
||||
{vec[0].mVec128 = r0; vec[1].mVec128 = r1; vec[2].mVec128 = r2; vec[3].mVec128 = r3;}
|
||||
{
|
||||
vec[0].mVec128 = r0;
|
||||
vec[1].mVec128 = r1;
|
||||
vec[2].mVec128 = r2;
|
||||
vec[3].mVec128 = r3;
|
||||
}
|
||||
#endif
|
||||
CMatrix4f(const CMatrix3f& other)
|
||||
{
|
||||
|
@ -76,11 +89,10 @@ public:
|
|||
|
||||
return CVector4f(res.mVec128);
|
||||
#else
|
||||
return CVector4f(
|
||||
m[0][0] * other.v[0] + m[1][0] * other.v[1] + m[2][0] * other.v[2] + m[3][0] * other.v[3],
|
||||
m[0][1] * other.v[0] + m[1][1] * other.v[1] + m[2][1] * other.v[2] + m[3][1] * other.v[3],
|
||||
m[0][2] * other.v[0] + m[1][2] * other.v[1] + m[2][2] * other.v[2] + m[3][2] * other.v[3],
|
||||
m[0][3] * other.v[0] + m[1][3] * other.v[1] + m[2][3] * other.v[2] + m[3][3] * other.v[3]);
|
||||
return CVector4f(m[0][0] * other.v[0] + m[1][0] * other.v[1] + m[2][0] * other.v[2] + m[3][0] * other.v[3],
|
||||
m[0][1] * other.v[0] + m[1][1] * other.v[1] + m[2][1] * other.v[2] + m[3][1] * other.v[3],
|
||||
m[0][2] * other.v[0] + m[1][2] * other.v[1] + m[2][2] * other.v[2] + m[3][2] * other.v[3],
|
||||
m[0][3] * other.v[0] + m[1][3] * other.v[1] + m[2][3] * other.v[2] + m[3][3] * other.v[3]);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -105,8 +117,7 @@ public:
|
|||
return xfVec.toVec3f() / xfVec.w;
|
||||
}
|
||||
|
||||
union
|
||||
{
|
||||
union {
|
||||
float m[4][4];
|
||||
struct
|
||||
{
|
||||
|
@ -120,14 +131,16 @@ static inline CMatrix4f operator*(const CMatrix4f& lhs, const CMatrix4f& rhs)
|
|||
#if __SSE__
|
||||
unsigned i;
|
||||
|
||||
for (i = 0 ; i < 4 ; ++i)
|
||||
for (i = 0; i < 4; ++i)
|
||||
{
|
||||
ret.vec[i].mVec128 =
|
||||
_mm_add_ps(_mm_add_ps(_mm_add_ps(
|
||||
_mm_mul_ps(lhs.vec[0].mVec128, _mm_shuffle_ps(rhs.vec[i].mVec128, rhs.vec[i].mVec128, _MM_SHUFFLE(0, 0, 0, 0))),
|
||||
_mm_mul_ps(lhs.vec[1].mVec128, _mm_shuffle_ps(rhs.vec[i].mVec128, rhs.vec[i].mVec128, _MM_SHUFFLE(1, 1, 1, 1)))),
|
||||
_mm_mul_ps(lhs.vec[2].mVec128, _mm_shuffle_ps(rhs.vec[i].mVec128, rhs.vec[i].mVec128, _MM_SHUFFLE(2, 2, 2, 2)))),
|
||||
_mm_mul_ps(lhs.vec[3].mVec128, _mm_shuffle_ps(rhs.vec[i].mVec128, rhs.vec[i].mVec128, _MM_SHUFFLE(3, 3, 3, 3))));
|
||||
ret.vec[i].mVec128 = _mm_add_ps(
|
||||
_mm_add_ps(_mm_add_ps(_mm_mul_ps(lhs.vec[0].mVec128,
|
||||
_mm_shuffle_ps(rhs.vec[i].mVec128, rhs.vec[i].mVec128, _MM_SHUFFLE(0, 0, 0, 0))),
|
||||
_mm_mul_ps(lhs.vec[1].mVec128,
|
||||
_mm_shuffle_ps(rhs.vec[i].mVec128, rhs.vec[i].mVec128, _MM_SHUFFLE(1, 1, 1, 1)))),
|
||||
_mm_mul_ps(lhs.vec[2].mVec128,
|
||||
_mm_shuffle_ps(rhs.vec[i].mVec128, rhs.vec[i].mVec128, _MM_SHUFFLE(2, 2, 2, 2)))),
|
||||
_mm_mul_ps(lhs.vec[3].mVec128, _mm_shuffle_ps(rhs.vec[i].mVec128, rhs.vec[i].mVec128, _MM_SHUFFLE(3, 3, 3, 3))));
|
||||
}
|
||||
|
||||
#else
|
||||
|
@ -156,4 +169,3 @@ static inline CMatrix4f operator*(const CMatrix4f& lhs, const CMatrix4f& rhs)
|
|||
}
|
||||
|
||||
#endif // CMATRIX4F
|
||||
|
||||
|
|
|
@ -28,38 +28,21 @@ public:
|
|||
#endif
|
||||
|
||||
CTransform transform;
|
||||
CVector3f extents;
|
||||
CVector3f extents;
|
||||
|
||||
COBBox()
|
||||
{}
|
||||
COBBox() {}
|
||||
|
||||
COBBox(const CAABox& aabb)
|
||||
: extents(aabb.volume())
|
||||
{
|
||||
transform.origin = aabb.center();
|
||||
}
|
||||
COBBox(const CAABox& aabb) : extents(aabb.volume()) { transform.origin = aabb.center(); }
|
||||
|
||||
COBBox(const CTransform& xf, const CVector3f& extents)
|
||||
: transform(xf),
|
||||
extents(extents)
|
||||
{
|
||||
}
|
||||
COBBox(const CTransform& xf, const CVector3f& extents) : transform(xf), extents(extents) {}
|
||||
|
||||
CAABox calculateAABox(const CTransform& transform = CTransform()) const
|
||||
{
|
||||
CAABox ret = CAABox::skInvertedBox;
|
||||
|
||||
CTransform trans = transform * transform;
|
||||
static const CVector3f basis[8] ={
|
||||
{ 1.0, 1.0, 1.0},
|
||||
{ 1.0, 1.0, -1.0},
|
||||
{ 1.0, -1.0, 1.0},
|
||||
{ 1.0, -1.0, -1.0},
|
||||
{-1.0, -1.0, -1.0},
|
||||
{-1.0, -1.0, 1.0},
|
||||
{-1.0, 1.0, -1.0},
|
||||
{-1.0, 1.0, 1.0}
|
||||
};
|
||||
static const CVector3f basis[8] = {{1.0, 1.0, 1.0}, {1.0, 1.0, -1.0}, {1.0, -1.0, 1.0}, {1.0, -1.0, -1.0},
|
||||
{-1.0, -1.0, -1.0}, {-1.0, -1.0, 1.0}, {-1.0, 1.0, -1.0}, {-1.0, 1.0, 1.0}};
|
||||
CVector3f p = extents * basis[0];
|
||||
|
||||
ret.accumulateBounds(trans * p);
|
||||
|
|
|
@ -27,7 +27,9 @@ public:
|
|||
#if __SSE__
|
||||
mVec128 = point.mVec128;
|
||||
#else
|
||||
a = point[0]; b = point[1]; c = point[2];
|
||||
a = point[0];
|
||||
b = point[1];
|
||||
c = point[2];
|
||||
#endif
|
||||
d = displacement;
|
||||
}
|
||||
|
@ -38,7 +40,7 @@ public:
|
|||
float dis = (-(vec.y - d)) / mag;
|
||||
return clamp(0.0f, dis, 1.0f);
|
||||
}
|
||||
|
||||
|
||||
inline void normalize()
|
||||
{
|
||||
float nd = d;
|
||||
|
@ -47,9 +49,8 @@ public:
|
|||
vec *= mag;
|
||||
d = nd * mag;
|
||||
}
|
||||
|
||||
union
|
||||
{
|
||||
|
||||
union {
|
||||
struct
|
||||
{
|
||||
float a, b, c, d;
|
||||
|
|
|
@ -22,21 +22,26 @@ class SProjOrtho
|
|||
{
|
||||
public:
|
||||
float top, bottom, left, right, near, far;
|
||||
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), near(p_near), far(p_far) {}
|
||||
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), near(p_near), far(p_far)
|
||||
{
|
||||
}
|
||||
};
|
||||
struct SProjPersp
|
||||
{
|
||||
float fov, aspect, near, far;
|
||||
SProjPersp(float p_fov=degToRad(55.0f), float p_aspect=1.0f, float p_near=0.1f, float p_far=4096.f) :
|
||||
fov(p_fov), aspect(p_aspect), near(p_near), far(p_far) {}
|
||||
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), near(p_near), far(p_far)
|
||||
{
|
||||
}
|
||||
};
|
||||
extern const SProjOrtho kOrthoIdentity;
|
||||
|
||||
class alignas(16) CProjection
|
||||
{
|
||||
void _updateCachedMatrix();
|
||||
|
||||
public:
|
||||
ZE_DECLARE_ALIGNED_ALLOCATOR();
|
||||
|
||||
|
@ -46,10 +51,10 @@ public:
|
|||
m_ortho = SProjOrtho();
|
||||
m_mtx = CMatrix4f::skIdentityMatrix4f;
|
||||
}
|
||||
CProjection(const CProjection& other) {*this = other;}
|
||||
CProjection(const SProjOrtho& ortho) {setOrtho(ortho);}
|
||||
CProjection(const SProjPersp& persp) {setPersp(persp);}
|
||||
|
||||
CProjection(const CProjection& other) { *this = other; }
|
||||
CProjection(const SProjOrtho& ortho) { setOrtho(ortho); }
|
||||
CProjection(const SProjPersp& persp) { setPersp(persp); }
|
||||
|
||||
inline CProjection& operator=(const CProjection& other)
|
||||
{
|
||||
if (this != &other)
|
||||
|
@ -60,13 +65,21 @@ public:
|
|||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
inline void setOrtho(const SProjOrtho& ortho)
|
||||
{m_projType = EProjType::Orthographic; m_ortho = ortho; _updateCachedMatrix();}
|
||||
{
|
||||
m_projType = EProjType::Orthographic;
|
||||
m_ortho = ortho;
|
||||
_updateCachedMatrix();
|
||||
}
|
||||
inline void setPersp(const SProjPersp& persp)
|
||||
{m_projType = EProjType::Perspective; m_persp = persp; _updateCachedMatrix();}
|
||||
|
||||
inline EProjType getType() const {return m_projType;}
|
||||
{
|
||||
m_projType = EProjType::Perspective;
|
||||
m_persp = persp;
|
||||
_updateCachedMatrix();
|
||||
}
|
||||
|
||||
inline EProjType getType() const { return m_projType; }
|
||||
inline const SProjOrtho& getOrtho() const
|
||||
{
|
||||
if (m_projType != EProjType::Orthographic)
|
||||
|
@ -85,17 +98,15 @@ public:
|
|||
}
|
||||
return m_persp;
|
||||
}
|
||||
|
||||
inline const CMatrix4f& getCachedMatrix() const {return m_mtx;}
|
||||
|
||||
protected:
|
||||
|
||||
inline const CMatrix4f& getCachedMatrix() const { return m_mtx; }
|
||||
|
||||
protected:
|
||||
/* Projection type */
|
||||
EProjType m_projType;
|
||||
|
||||
|
||||
/* Projection intermediate */
|
||||
union
|
||||
{
|
||||
union {
|
||||
#ifdef _MSC_VER
|
||||
struct
|
||||
{
|
||||
|
@ -113,7 +124,6 @@ protected:
|
|||
|
||||
/* Cached projection matrix */
|
||||
CMatrix4f m_mtx;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,10 @@ public:
|
|||
#if __SSE__
|
||||
mVec128 = vec.mVec128;
|
||||
#else
|
||||
x = vec.vec[1]; y = vec.vec[2]; z = vec.vec[3]; w = vec.vec[0];
|
||||
x = vec.vec[1];
|
||||
y = vec.vec[2];
|
||||
z = vec.vec[3];
|
||||
w = vec.vec[0];
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -116,7 +119,10 @@ public:
|
|||
#if __SSE__
|
||||
mVec128 = vec.mVec128;
|
||||
#else
|
||||
x = vec[1]; y = vec[2]; z = vec[3]; w = vec[0];
|
||||
x = vec[1];
|
||||
y = vec[2];
|
||||
z = vec[3];
|
||||
w = vec[0];
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -165,7 +171,6 @@ public:
|
|||
void rotateY(float angle) { *this *= fromAxisAngle({0.0f, 1.0f, 0.0f}, angle); }
|
||||
void rotateZ(float angle) { *this *= fromAxisAngle({0.0f, 0.0f, 1.0f}, angle); }
|
||||
|
||||
|
||||
CAxisAngle toAxisAngle();
|
||||
|
||||
static inline CVector3f rotate(const CQuaternion& rotation, const CVector3f& v)
|
||||
|
@ -186,28 +191,21 @@ public:
|
|||
static CQuaternion slerp(const CQuaternion& a, const CQuaternion& b, double t);
|
||||
static CQuaternion nlerp(const CQuaternion& a, const CQuaternion& b, double t);
|
||||
|
||||
inline float roll() const
|
||||
{
|
||||
return std::atan2(2.f * (x * y + w * z), w * w + x * x - y * y - z * z);
|
||||
}
|
||||
inline float roll() const { return std::atan2(2.f * (x * y + w * z), w * w + x * x - y * y - z * z); }
|
||||
|
||||
inline float pitch() const
|
||||
{
|
||||
return std::atan2(2.f * (y * z + w * x), w * w - x * x - y * y + z * z);
|
||||
}
|
||||
inline float pitch() const { return std::atan2(2.f * (y * z + w * x), w * w - x * x - y * y + z * z); }
|
||||
|
||||
inline float yaw() const
|
||||
{
|
||||
return std::asin(-2.f * (x * z - w * y));
|
||||
}
|
||||
inline float yaw() const { return std::asin(-2.f * (x * z - w * y)); }
|
||||
|
||||
inline float& operator[](size_t idx) {return (&w)[idx];}
|
||||
inline const float& operator[](size_t idx) const {return (&w)[idx];}
|
||||
inline float& operator[](size_t idx) { return (&w)[idx]; }
|
||||
inline const float& operator[](size_t idx) const { return (&w)[idx]; }
|
||||
|
||||
union
|
||||
{
|
||||
union {
|
||||
__m128 mVec128;
|
||||
struct { float w, x, y, z; };
|
||||
struct
|
||||
{
|
||||
float w, x, y, z;
|
||||
};
|
||||
};
|
||||
|
||||
static const CQuaternion skNoRotation;
|
||||
|
|
|
@ -21,10 +21,8 @@ public:
|
|||
|
||||
inline bool intersects(const CRectangle& rect) const
|
||||
{
|
||||
return !( position.x > rect.position.x + rect.size.x ||
|
||||
rect.position.x > position.x + size.x ||
|
||||
position.y > rect.position.y + rect.size.y ||
|
||||
rect.position.y > position.y + size.y);
|
||||
return !(position.x > rect.position.x + rect.size.x || rect.position.x > position.x + size.x ||
|
||||
position.y > rect.position.y + rect.size.y || rect.position.y > position.y + size.y);
|
||||
}
|
||||
|
||||
CVector2f position;
|
||||
|
|
|
@ -23,10 +23,7 @@ public:
|
|||
z = degToRad(angles.z);
|
||||
}
|
||||
|
||||
CRelAngle(float x, float y, float z)
|
||||
: CRelAngle(CVector3f{x, y, z})
|
||||
{
|
||||
}
|
||||
CRelAngle(float x, float y, float z) : CRelAngle(CVector3f{x, y, z}) {}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -10,11 +10,9 @@ class alignas(16) CSphere
|
|||
public:
|
||||
ZE_DECLARE_ALIGNED_ALLOCATOR();
|
||||
|
||||
CSphere(const CVector3f& position, float radius)
|
||||
: position(position), radius(radius) { }
|
||||
CSphere(const CVector3f& position, float radius) : position(position), radius(radius) {}
|
||||
|
||||
inline CVector3f getSurfaceNormal(const CVector3f& coord)
|
||||
{ return (position - coord).normalized(); }
|
||||
inline CVector3f getSurfaceNormal(const CVector3f& coord) { return (position - coord).normalized(); }
|
||||
|
||||
inline bool intersects(const CSphere& other)
|
||||
{
|
||||
|
|
|
@ -15,11 +15,9 @@ public:
|
|||
ZE_DECLARE_ALIGNED_ALLOCATOR();
|
||||
|
||||
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].vec[3], mtx[1].vec[3], mtx[2].vec[3]) {}
|
||||
CTransform(const atVec4f* mtx) : basis(mtx[0], mtx[1], mtx[2]), origin(mtx[0].vec[3], mtx[1].vec[3], mtx[2].vec[3]) {}
|
||||
|
||||
void read34RowMajor(athena::io::IStreamReader& r)
|
||||
{
|
||||
|
@ -32,13 +30,12 @@ public:
|
|||
}
|
||||
#endif
|
||||
|
||||
static inline CTransform Identity()
|
||||
{
|
||||
return CTransform(CMatrix3f::skIdentityMatrix3f);
|
||||
}
|
||||
static inline CTransform Identity() { return CTransform(CMatrix3f::skIdentityMatrix3f); }
|
||||
|
||||
inline CTransform operator*(const CTransform& rhs) const
|
||||
{return CTransform(basis * rhs.basis, origin + (basis * rhs.origin));}
|
||||
{
|
||||
return CTransform(basis * rhs.basis, origin + (basis * rhs.origin));
|
||||
}
|
||||
|
||||
inline CTransform inverse() const
|
||||
{
|
||||
|
@ -46,17 +43,11 @@ public:
|
|||
return CTransform(inv, inv * -origin);
|
||||
}
|
||||
|
||||
static inline CTransform Translate(const CVector3f& position)
|
||||
{
|
||||
return {CMatrix3f::skIdentityMatrix3f, position};
|
||||
}
|
||||
static inline CTransform Translate(const CVector3f& position) { return {CMatrix3f::skIdentityMatrix3f, position}; }
|
||||
|
||||
static inline CTransform Translate(float x, float y, float z) { return Translate({x, y, z}); }
|
||||
|
||||
inline CTransform operator+(const CVector3f& other)
|
||||
{
|
||||
return CTransform(basis, origin + other);
|
||||
}
|
||||
inline CTransform operator+(const CVector3f& other) { return CTransform(basis, origin + other); }
|
||||
|
||||
inline CTransform& operator+=(const CVector3f& other)
|
||||
{
|
||||
|
@ -64,10 +55,7 @@ public:
|
|||
return *this;
|
||||
}
|
||||
|
||||
inline CTransform operator-(const CVector3f& other)
|
||||
{
|
||||
return CTransform(basis, origin - other);
|
||||
}
|
||||
inline CTransform operator-(const CVector3f& other) { return CTransform(basis, origin - other); }
|
||||
|
||||
inline CTransform& operator-=(const CVector3f& other)
|
||||
{
|
||||
|
@ -81,8 +69,7 @@ public:
|
|||
{
|
||||
float sinT = std::sin(theta);
|
||||
float cosT = std::cos(theta);
|
||||
return CTransform(CMatrix3f(TVectorUnion{1.f, 0.f, 0.f, 0.f},
|
||||
TVectorUnion{0.f, cosT, sinT, 0.f},
|
||||
return CTransform(CMatrix3f(TVectorUnion{1.f, 0.f, 0.f, 0.f}, TVectorUnion{0.f, cosT, sinT, 0.f},
|
||||
TVectorUnion{0.f, -sinT, cosT, 0.f}));
|
||||
}
|
||||
|
||||
|
@ -90,8 +77,7 @@ public:
|
|||
{
|
||||
float sinT = std::sin(theta);
|
||||
float cosT = std::cos(theta);
|
||||
return CTransform(CMatrix3f(TVectorUnion{cosT, 0.f, -sinT, 0.f},
|
||||
TVectorUnion{0.f, 1.f, 0.f, 0.f},
|
||||
return CTransform(CMatrix3f(TVectorUnion{cosT, 0.f, -sinT, 0.f}, TVectorUnion{0.f, 1.f, 0.f, 0.f},
|
||||
TVectorUnion{sinT, 0.f, cosT, 0.f}));
|
||||
}
|
||||
|
||||
|
@ -99,8 +85,7 @@ public:
|
|||
{
|
||||
float sinT = std::sin(theta);
|
||||
float cosT = std::cos(theta);
|
||||
return CTransform(CMatrix3f(TVectorUnion{cosT, sinT, 0.f, 0.f},
|
||||
TVectorUnion{-sinT, cosT, 0.f, 0.f},
|
||||
return CTransform(CMatrix3f(TVectorUnion{cosT, sinT, 0.f, 0.f}, TVectorUnion{-sinT, cosT, 0.f, 0.f},
|
||||
TVectorUnion{0.f, 0.f, 1.f, 0.f}));
|
||||
}
|
||||
|
||||
|
@ -158,26 +143,26 @@ public:
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
static inline CTransform Scale(const CVector3f& factor)
|
||||
{
|
||||
return CTransform(CMatrix3f(TVectorUnion{factor.x, 0.f, 0.f, 0.f},
|
||||
TVectorUnion{0.f, factor.y, 0.f, 0.f},
|
||||
return CTransform(CMatrix3f(TVectorUnion{factor.x, 0.f, 0.f, 0.f}, TVectorUnion{0.f, factor.y, 0.f, 0.f},
|
||||
TVectorUnion{0.f, 0.f, factor.z, 0.f}));
|
||||
}
|
||||
|
||||
static inline CTransform Scale(float x, float y, float z)
|
||||
{
|
||||
return CTransform(CMatrix3f(TVectorUnion{x, 0.f, 0.f, 0.f},
|
||||
TVectorUnion{0.f, y, 0.f, 0.f},
|
||||
TVectorUnion{0.f, 0.f, z, 0.f}));
|
||||
return CTransform(
|
||||
CMatrix3f(TVectorUnion{x, 0.f, 0.f, 0.f}, TVectorUnion{0.f, y, 0.f, 0.f}, TVectorUnion{0.f, 0.f, z, 0.f}));
|
||||
}
|
||||
|
||||
static inline CTransform Scale(float factor)
|
||||
{
|
||||
return CTransform(CMatrix3f(TVectorUnion{factor, 0.f, 0.f, 0.f},
|
||||
TVectorUnion{0.f, factor, 0.f, 0.f},
|
||||
return CTransform(CMatrix3f(TVectorUnion{factor, 0.f, 0.f, 0.f}, TVectorUnion{0.f, factor, 0.f, 0.f},
|
||||
TVectorUnion{0.f, 0.f, factor, 0.f}));
|
||||
}
|
||||
|
||||
|
@ -188,8 +173,13 @@ public:
|
|||
return ret;
|
||||
}
|
||||
|
||||
inline CTransform getRotation() const { CTransform ret = *this; ret.origin.zeroOut(); return ret; }
|
||||
void setRotation(const CMatrix3f& mat) { basis = mat; }
|
||||
inline CTransform getRotation() const
|
||||
{
|
||||
CTransform ret = *this;
|
||||
ret.origin.zeroOut();
|
||||
return ret;
|
||||
}
|
||||
void setRotation(const CMatrix3f& mat) { basis = mat; }
|
||||
void setRotation(const CTransform& xfrm) { setRotation(xfrm.basis); }
|
||||
|
||||
/**
|
||||
|
@ -199,7 +189,7 @@ public:
|
|||
*/
|
||||
inline CMatrix3f buildMatrix3f() { return basis; }
|
||||
|
||||
inline CVector3f operator*(const CVector3f& other) const {return origin + basis * other;}
|
||||
inline CVector3f operator*(const CVector3f& other) const { return origin + basis * other; }
|
||||
|
||||
inline CMatrix4f toMatrix4f() const
|
||||
{
|
||||
|
@ -217,15 +207,15 @@ public:
|
|||
ret.basis[0][0] = m0[0];
|
||||
ret.basis[0][1] = m1[0];
|
||||
ret.basis[0][2] = m2[0];
|
||||
ret.origin[0] = m3[0];
|
||||
ret.origin[0] = m3[0];
|
||||
ret.basis[1][0] = m0[1];
|
||||
ret.basis[1][1] = m1[1];
|
||||
ret.basis[1][2] = m2[1];
|
||||
ret.origin[1] = m3[1];
|
||||
ret.origin[1] = m3[1];
|
||||
ret.basis[2][0] = m0[2];
|
||||
ret.basis[2][1] = m1[2];
|
||||
ret.basis[2][2] = m2[2];
|
||||
ret.origin[2] = m3[2];
|
||||
ret.origin[2] = m3[2];
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -241,14 +231,11 @@ 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);
|
||||
CTransform CTransformFromEditorEulers(const CVector3f& eulerVec, const CVector3f& origin);
|
||||
CTransform CTransformFromAxisAngle(const CVector3f& axis, float angle);
|
||||
CTransform lookAt(const CVector3f& pos, const CVector3f& lookPos, const CVector3f& up=kUpVec);
|
||||
CTransform lookAt(const CVector3f& pos, const CVector3f& lookPos, const CVector3f& up = kUpVec);
|
||||
}
|
||||
|
||||
#endif // CTRANSFORM_HPP
|
||||
|
|
|
@ -10,13 +10,9 @@ class alignas(16) CUnitVector3f : public CVector3f
|
|||
public:
|
||||
ZE_DECLARE_ALIGNED_ALLOCATOR();
|
||||
|
||||
CUnitVector3f()
|
||||
: CVector3f(0, 1, 0)
|
||||
{
|
||||
}
|
||||
CUnitVector3f() : CVector3f(0, 1, 0) {}
|
||||
|
||||
CUnitVector3f(const CVector3f& vec, bool doNormalize = false)
|
||||
: CVector3f(vec)
|
||||
CUnitVector3f(const CVector3f& vec, bool doNormalize = false) : CVector3f(vec)
|
||||
{
|
||||
if (doNormalize && canBeNormalized())
|
||||
normalize();
|
||||
|
|
|
@ -20,9 +20,8 @@ class alignas(16) CVector2f
|
|||
float clangVec __attribute__((__vector_size__(8)));
|
||||
#endif
|
||||
public:
|
||||
//ZE_DECLARE_ALIGNED_ALLOCATOR();
|
||||
union
|
||||
{
|
||||
// ZE_DECLARE_ALIGNED_ALLOCATOR();
|
||||
union {
|
||||
struct
|
||||
{
|
||||
float x, y;
|
||||
|
@ -33,14 +32,20 @@ public:
|
|||
#endif
|
||||
};
|
||||
|
||||
inline CVector2f() {zeroOut();}
|
||||
inline CVector2f() { zeroOut(); }
|
||||
#if __SSE__
|
||||
CVector2f(const __m128& mVec128) : mVec128(mVec128) {v[2] = 0.0f; v[3] = 0.0f;}
|
||||
CVector2f(const __m128& mVec128) : mVec128(mVec128)
|
||||
{
|
||||
v[2] = 0.0f;
|
||||
v[3] = 0.0f;
|
||||
}
|
||||
#endif
|
||||
#if ZE_ATHENA_TYPES
|
||||
CVector2f(const atVec2f& vec)
|
||||
#if __SSE__
|
||||
: mVec128(vec.mVec128){}
|
||||
: mVec128(vec.mVec128)
|
||||
{
|
||||
}
|
||||
#else
|
||||
{
|
||||
x = vec.vec[0], y = vec.vec[1], v[2] = 0.0f, v[3] = 0.0f;
|
||||
|
@ -77,15 +82,19 @@ public:
|
|||
}
|
||||
#endif
|
||||
|
||||
CVector2f(float xy) {splat(xy);}
|
||||
void assign(float x, float y) {v[0] = x; v[1] = y; v[2] = 0; v[3] = 0.0f;}
|
||||
CVector2f(float x, float y) {assign(x, y);}
|
||||
CVector2f(float xy) { splat(xy); }
|
||||
void assign(float x, float y)
|
||||
{
|
||||
v[0] = x;
|
||||
v[1] = y;
|
||||
v[2] = 0;
|
||||
v[3] = 0.0f;
|
||||
}
|
||||
CVector2f(float x, float y) { assign(x, y); }
|
||||
|
||||
inline bool operator ==(const CVector2f& rhs) const
|
||||
{return (x == rhs.x && y == rhs.y);}
|
||||
inline bool operator !=(const CVector2f& rhs) const
|
||||
{return !(*this == rhs);}
|
||||
inline bool operator <(const CVector2f& rhs) const
|
||||
inline bool operator==(const CVector2f& rhs) const { return (x == rhs.x && y == rhs.y); }
|
||||
inline bool operator!=(const CVector2f& rhs) const { return !(*this == rhs); }
|
||||
inline bool operator<(const CVector2f& rhs) const
|
||||
{
|
||||
#if __SSE__
|
||||
TVectorUnion vec;
|
||||
|
@ -95,7 +104,7 @@ public:
|
|||
return (x < rhs.x || y < rhs.y);
|
||||
#endif
|
||||
}
|
||||
inline bool operator <=(const CVector2f& rhs) const
|
||||
inline bool operator<=(const CVector2f& rhs) const
|
||||
{
|
||||
#if __SSE__
|
||||
TVectorUnion vec;
|
||||
|
@ -105,7 +114,7 @@ public:
|
|||
return (x <= rhs.x || y <= rhs.y);
|
||||
#endif
|
||||
}
|
||||
inline bool operator >(const CVector2f& rhs) const
|
||||
inline bool operator>(const CVector2f& rhs) const
|
||||
{
|
||||
#if __SSE__
|
||||
TVectorUnion vec;
|
||||
|
@ -115,7 +124,7 @@ public:
|
|||
return (x > rhs.x || y > rhs.y);
|
||||
#endif
|
||||
}
|
||||
inline bool operator >=(const CVector2f& rhs) const
|
||||
inline bool operator>=(const CVector2f& rhs) const
|
||||
{
|
||||
#if __SSE__
|
||||
TVectorUnion vec;
|
||||
|
@ -202,39 +211,43 @@ public:
|
|||
return CVector2f(x / val, y / val);
|
||||
#endif
|
||||
}
|
||||
inline const CVector2f& operator +=(const CVector2f& rhs)
|
||||
inline const CVector2f& operator+=(const CVector2f& rhs)
|
||||
{
|
||||
#if __SSE__
|
||||
mVec128 = _mm_add_ps(mVec128, rhs.mVec128);
|
||||
#else
|
||||
x += rhs.x; y += rhs.y;
|
||||
x += rhs.x;
|
||||
y += rhs.y;
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
inline const CVector2f& operator -=(const CVector2f& rhs)
|
||||
inline const CVector2f& operator-=(const CVector2f& rhs)
|
||||
{
|
||||
#if __SSE__
|
||||
mVec128 = _mm_sub_ps(mVec128, rhs.mVec128);
|
||||
#else
|
||||
x -= rhs.x; y -= rhs.y;
|
||||
x -= rhs.x;
|
||||
y -= rhs.y;
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
inline const CVector2f& operator *=(const CVector2f& rhs)
|
||||
inline const CVector2f& operator*=(const CVector2f& rhs)
|
||||
{
|
||||
#if __SSE__
|
||||
mVec128 = _mm_mul_ps(mVec128, rhs.mVec128);
|
||||
#else
|
||||
x *= rhs.x; y *= rhs.y;
|
||||
x *= rhs.x;
|
||||
y *= rhs.y;
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
inline const CVector2f& operator /=(const CVector2f& rhs)
|
||||
inline const CVector2f& operator/=(const CVector2f& rhs)
|
||||
{
|
||||
#if __SSE__
|
||||
mVec128 = _mm_div_ps(mVec128, rhs.mVec128);
|
||||
#else
|
||||
x /= rhs.x; y /= rhs.y;
|
||||
x /= rhs.x;
|
||||
y /= rhs.y;
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
|
@ -252,15 +265,9 @@ public:
|
|||
return *this * mag;
|
||||
}
|
||||
|
||||
inline CVector2f perpendicularVector() const
|
||||
{
|
||||
return {-y, x};
|
||||
}
|
||||
inline CVector2f perpendicularVector() const { return {-y, x}; }
|
||||
|
||||
inline float cross(const CVector2f& rhs) const
|
||||
{
|
||||
return (x * rhs.y) - (y * rhs.x);
|
||||
}
|
||||
inline float cross(const CVector2f& rhs) const { return (x * rhs.y) - (y * rhs.x); }
|
||||
inline float dot(const CVector2f& rhs) const
|
||||
{
|
||||
#if __SSE__
|
||||
|
@ -292,18 +299,20 @@ public:
|
|||
result.mVec128 = _mm_mul_ps(mVec128, mVec128);
|
||||
return result.v[0] + result.v[1];
|
||||
#else
|
||||
return x*x + y*y;
|
||||
return x * x + y * y;
|
||||
#endif
|
||||
}
|
||||
inline float magnitude() const
|
||||
{ return sqrtF(magSquared()); }
|
||||
inline float magnitude() const { return sqrtF(magSquared()); }
|
||||
|
||||
inline void zeroOut()
|
||||
{
|
||||
#if __SSE__
|
||||
mVec128 = _mm_xor_ps(mVec128, mVec128);
|
||||
#else
|
||||
v[0] = 0.0; v[1] = 0.0; v[2] = 0.0; v[3] = 0.0;
|
||||
v[0] = 0.0;
|
||||
v[1] = 0.0;
|
||||
v[2] = 0.0;
|
||||
v[3] = 0.0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -313,47 +322,39 @@ public:
|
|||
TVectorUnion splat = {{xy, xy, 0.0f, 0.0f}};
|
||||
mVec128 = splat.mVec128;
|
||||
#else
|
||||
v[0] = xy; v[1] = xy; v[2] = 0.0f; v[3] = 0.0f;
|
||||
v[0] = xy;
|
||||
v[1] = xy;
|
||||
v[2] = 0.0f;
|
||||
v[3] = 0.0f;
|
||||
#endif
|
||||
}
|
||||
|
||||
static float getAngleDiff(const CVector2f& a, const CVector2f& b);
|
||||
|
||||
static inline CVector2f lerp(const CVector2f& a, const CVector2f& b, float t)
|
||||
{
|
||||
return (a + (b - a) * t);
|
||||
}
|
||||
static inline CVector2f nlerp(const CVector2f& a, const CVector2f& b, float t)
|
||||
{
|
||||
return lerp(a, b, t).normalized();
|
||||
}
|
||||
static inline CVector2f lerp(const CVector2f& a, const CVector2f& b, float t) { return (a + (b - a) * t); }
|
||||
static inline 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);
|
||||
|
||||
inline bool isNormalized() const
|
||||
{ return std::fabs(1.f - magSquared()) < 0.01f; }
|
||||
inline bool isNormalized() const { return std::fabs(1.f - magSquared()) < 0.01f; }
|
||||
|
||||
inline bool canBeNormalized() const
|
||||
{ return !isNormalized(); }
|
||||
inline bool canBeNormalized() const { return !isNormalized(); }
|
||||
|
||||
inline bool isZero() const
|
||||
{ return magSquared() <= 1.1920929e-7f; }
|
||||
inline bool isZero() const { return magSquared() <= 1.1920929e-7f; }
|
||||
|
||||
inline bool isEqu(const CVector2f& other, float epsilon=1.1920929e-7f)
|
||||
inline bool isEqu(const CVector2f& other, float epsilon = 1.1920929e-7f)
|
||||
{
|
||||
const CVector2f diffVec = other - *this;
|
||||
return (diffVec.x <= epsilon && diffVec.y <= epsilon);
|
||||
}
|
||||
|
||||
inline float& operator[](size_t idx) {return (&x)[idx];}
|
||||
inline const float& operator[](size_t idx) const {return (&x)[idx];}
|
||||
|
||||
inline float& operator[](size_t idx) { return (&x)[idx]; }
|
||||
inline const float& operator[](size_t idx) const { return (&x)[idx]; }
|
||||
|
||||
static const CVector2f skOne;
|
||||
static const CVector2f skNegOne;
|
||||
static const CVector2f skZero;
|
||||
};
|
||||
|
||||
|
||||
static inline CVector2f operator+(float lhs, const CVector2f& rhs)
|
||||
{
|
||||
#if __SSE__
|
||||
|
|
|
@ -14,8 +14,7 @@ namespace zeus
|
|||
class CVector2i
|
||||
{
|
||||
public:
|
||||
union
|
||||
{
|
||||
union {
|
||||
struct
|
||||
{
|
||||
int x, y;
|
||||
|
@ -25,7 +24,6 @@ public:
|
|||
CVector2i() = default;
|
||||
CVector2i(int xin, int yin) : x(xin), y(yin) {}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // CVECTOR2i_HPP
|
||||
|
|
|
@ -36,16 +36,23 @@ public:
|
|||
CVector3d(double xyz) { splat(xyz); }
|
||||
|
||||
CVector3d(const CVector3f& vec)
|
||||
{ v[0] = vec[0]; v[1] = vec[1]; v[2] = vec[2]; }
|
||||
{
|
||||
v[0] = vec[0];
|
||||
v[1] = vec[1];
|
||||
v[2] = vec[2];
|
||||
}
|
||||
|
||||
CVector3d(double x, double y, double z)
|
||||
{
|
||||
#if __SSE__
|
||||
TDblVectorUnion splat {x, y, z, 0.0};
|
||||
TDblVectorUnion splat{x, y, z, 0.0};
|
||||
mVec128[0] = splat.mVec128[0];
|
||||
mVec128[1] = splat.mVec128[1];
|
||||
#else
|
||||
v[0] = x; v[1] = y; v[2] = z; v[3] = 0.0;
|
||||
v[0] = x;
|
||||
v[1] = y;
|
||||
v[2] = z;
|
||||
v[3] = 0.0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -74,13 +81,15 @@ public:
|
|||
result.mVec128[1] = _mm_mul_pd(mVec128[1], mVec128[1]);
|
||||
return result.v[0] + result.v[1] + result.v[2];
|
||||
#else
|
||||
return x*x + y*y + z*z;
|
||||
return x * x + y * y + z * z;
|
||||
#endif
|
||||
}
|
||||
|
||||
double magnitude() const { return sqrt(magSquared()); }
|
||||
inline 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
|
||||
{
|
||||
|
@ -111,7 +120,6 @@ public:
|
|||
return {x * mag, y * mag, z * mag};
|
||||
}
|
||||
|
||||
|
||||
void splat(double xyz)
|
||||
{
|
||||
#if __SSE__
|
||||
|
@ -119,7 +127,10 @@ public:
|
|||
mVec128[0] = splat.mVec128[0];
|
||||
mVec128[1] = splat.mVec128[1];
|
||||
#else
|
||||
v[0] = xyz; v[1] = xyz; v[2] = xyz; v[3] = 0.0;
|
||||
v[0] = xyz;
|
||||
v[1] = xyz;
|
||||
v[2] = xyz;
|
||||
v[3] = 0.0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -129,13 +140,18 @@ public:
|
|||
_mm_xor_pd(mVec128[0], mVec128[0]);
|
||||
_mm_xor_pd(mVec128[1], mVec128[1]);
|
||||
#else
|
||||
v[0] = 0.0; v[1] = 0.0; v[2] = 0.0; v[3] = 0.0;
|
||||
v[0] = 0.0;
|
||||
v[1] = 0.0;
|
||||
v[2] = 0.0;
|
||||
v[3] = 0.0;
|
||||
#endif
|
||||
}
|
||||
|
||||
union
|
||||
{
|
||||
struct {double x, y, z; };
|
||||
union {
|
||||
struct
|
||||
{
|
||||
double x, y, z;
|
||||
};
|
||||
double v[4];
|
||||
#if __SSE__
|
||||
__m128d mVec128[2];
|
||||
|
@ -143,11 +159,10 @@ public:
|
|||
};
|
||||
};
|
||||
|
||||
|
||||
static inline CVector3d operator+(double lhs, const CVector3d& rhs)
|
||||
{
|
||||
#if __SSE__
|
||||
TDblVectorUnion splat { lhs, lhs, lhs, 0 };
|
||||
TDblVectorUnion splat{lhs, lhs, lhs, 0};
|
||||
splat.mVec128[0] = _mm_add_pd(splat.mVec128[0], rhs.mVec128[0]);
|
||||
splat.mVec128[1] = _mm_add_pd(splat.mVec128[1], rhs.mVec128[1]);
|
||||
return {splat.mVec128};
|
||||
|
@ -171,7 +186,7 @@ static inline CVector3d operator+(const CVector3d& lhs, const CVector3d& rhs)
|
|||
static inline CVector3d operator*(double lhs, const CVector3d& rhs)
|
||||
{
|
||||
#if __SSE__
|
||||
TDblVectorUnion splat { lhs, lhs, lhs, 0 };
|
||||
TDblVectorUnion splat{lhs, lhs, lhs, 0};
|
||||
splat.mVec128[0] = _mm_mul_pd(splat.mVec128[0], rhs.mVec128[0]);
|
||||
splat.mVec128[1] = _mm_mul_pd(splat.mVec128[1], rhs.mVec128[1]);
|
||||
return {splat.mVec128};
|
||||
|
@ -207,7 +222,7 @@ static inline CVector3d operator/(const CVector3d& lhs, const CVector3d& rhs)
|
|||
static inline CVector3d operator/(double lhs, const CVector3d& rhs)
|
||||
{
|
||||
#if __SSE__
|
||||
TDblVectorUnion splat { lhs, lhs, lhs, 0 };
|
||||
TDblVectorUnion splat{lhs, lhs, lhs, 0};
|
||||
splat.mVec128[0] = _mm_div_pd(splat.mVec128[0], rhs.mVec128[0]);
|
||||
splat.mVec128[1] = _mm_div_pd(splat.mVec128[1], rhs.mVec128[1]);
|
||||
return {splat.mVec128};
|
||||
|
|
|
@ -19,9 +19,11 @@ class alignas(16) CVector3f
|
|||
public:
|
||||
ZE_DECLARE_ALIGNED_ALLOCATOR();
|
||||
|
||||
union
|
||||
{
|
||||
struct { float x, y, z; };
|
||||
union {
|
||||
struct
|
||||
{
|
||||
float x, y, z;
|
||||
};
|
||||
float v[4];
|
||||
#if __SSE__
|
||||
__m128 mVec128;
|
||||
|
@ -30,15 +32,17 @@ public:
|
|||
#endif
|
||||
};
|
||||
|
||||
inline CVector3f() {zeroOut();}
|
||||
inline CVector3f() { zeroOut(); }
|
||||
#if __SSE__ || __GEKKO_PS__
|
||||
CVector3f(const __m128& mVec128) : mVec128(mVec128) {v[3] = 0.0f;}
|
||||
CVector3f(const __m128& mVec128) : mVec128(mVec128) { v[3] = 0.0f; }
|
||||
#endif
|
||||
|
||||
#if ZE_ATHENA_TYPES
|
||||
CVector3f(const atVec3f& vec)
|
||||
#if __SSE__ || __GEKKO_PS__
|
||||
: mVec128(vec.mVec128){}
|
||||
: mVec128(vec.mVec128)
|
||||
{
|
||||
}
|
||||
#else
|
||||
{
|
||||
x = vec.vec[0], y = vec.vec[1], z = vec.vec[2], v[3] = 0.0f;
|
||||
|
@ -82,9 +86,15 @@ public:
|
|||
}
|
||||
#endif
|
||||
|
||||
CVector3f(float xyz) {splat(xyz);}
|
||||
void assign(float x, float y, float z) {v[0] = x; v[1] = y; v[2] = z; v[3] = 0.0f;}
|
||||
CVector3f(float x, float y, float z) {assign(x, y, z);}
|
||||
CVector3f(float xyz) { splat(xyz); }
|
||||
void assign(float x, float y, float z)
|
||||
{
|
||||
v[0] = x;
|
||||
v[1] = y;
|
||||
v[2] = z;
|
||||
v[3] = 0.0f;
|
||||
}
|
||||
CVector3f(float x, float y, float z) { assign(x, y, z); }
|
||||
|
||||
CVector3f(const CVector2f& other)
|
||||
{
|
||||
|
@ -103,10 +113,8 @@ public:
|
|||
#endif
|
||||
}
|
||||
|
||||
inline bool operator ==(const CVector3f& rhs) const
|
||||
{return (x == rhs.x && y == rhs.y && z == rhs.z);}
|
||||
inline bool operator !=(const CVector3f& rhs) const
|
||||
{return !(*this == rhs);}
|
||||
inline bool operator==(const CVector3f& rhs) const { return (x == rhs.x && y == rhs.y && z == rhs.z); }
|
||||
inline bool operator!=(const CVector3f& rhs) const { return !(*this == rhs); }
|
||||
inline CVector3f operator+(const CVector3f& rhs) const
|
||||
{
|
||||
#if __SSE__
|
||||
|
@ -199,41 +207,49 @@ public:
|
|||
return CVector3f(x / val, y / val, z / val);
|
||||
#endif
|
||||
}
|
||||
inline const CVector3f& operator +=(const CVector3f& rhs)
|
||||
inline const CVector3f& operator+=(const CVector3f& rhs)
|
||||
{
|
||||
#if __SSE__
|
||||
mVec128 = _mm_add_ps(mVec128, rhs.mVec128);
|
||||
#elif __GEKKO_PS__
|
||||
mVec128 = _mm_gekko_add_ps(mVec128, rhs.mVec128);
|
||||
#else
|
||||
x += rhs.x; y += rhs.y; z += rhs.z;
|
||||
x += rhs.x;
|
||||
y += rhs.y;
|
||||
z += rhs.z;
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
inline const CVector3f& operator -=(const CVector3f& rhs)
|
||||
inline const CVector3f& operator-=(const CVector3f& rhs)
|
||||
{
|
||||
#if __SSE__
|
||||
mVec128 = _mm_sub_ps(mVec128, rhs.mVec128);
|
||||
#else
|
||||
x -= rhs.x; y -= rhs.y; z -= rhs.z;
|
||||
x -= rhs.x;
|
||||
y -= rhs.y;
|
||||
z -= rhs.z;
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
inline const CVector3f& operator *=(const CVector3f& rhs)
|
||||
inline const CVector3f& operator*=(const CVector3f& rhs)
|
||||
{
|
||||
#if __SSE__
|
||||
mVec128 = _mm_mul_ps(mVec128, rhs.mVec128);
|
||||
#else
|
||||
x *= rhs.x; y *= rhs.y; z *= rhs.z;
|
||||
x *= rhs.x;
|
||||
y *= rhs.y;
|
||||
z *= rhs.z;
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
inline const CVector3f& operator /=(const CVector3f& rhs)
|
||||
inline const CVector3f& operator/=(const CVector3f& rhs)
|
||||
{
|
||||
#if __SSE__
|
||||
mVec128 = _mm_div_ps(mVec128, rhs.mVec128);
|
||||
#else
|
||||
x /= rhs.x; y /= rhs.y; z /= rhs.z;
|
||||
x /= rhs.x;
|
||||
y /= rhs.y;
|
||||
z /= rhs.z;
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
|
@ -250,7 +266,9 @@ public:
|
|||
return *this * mag;
|
||||
}
|
||||
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
|
||||
{
|
||||
|
@ -285,48 +303,48 @@ public:
|
|||
result.mVec128 = _mm_mul_ps(mVec128, mVec128);
|
||||
return result.v[0] + result.v[1] + result.v[2];
|
||||
#else
|
||||
return x*x + y*y + z*z;
|
||||
return x * x + y * y + z * z;
|
||||
#endif
|
||||
}
|
||||
|
||||
inline float magnitude() const
|
||||
{ return sqrtF(magSquared()); }
|
||||
|
||||
inline float magnitude() const { return sqrtF(magSquared()); }
|
||||
|
||||
inline void zeroOut()
|
||||
{
|
||||
#if __SSE__
|
||||
mVec128 = _mm_xor_ps(mVec128, mVec128);
|
||||
#else
|
||||
v[0] = 0.0; v[1] = 0.0; v[2] = 0.0; v[3] = 0.0;
|
||||
v[0] = 0.0;
|
||||
v[1] = 0.0;
|
||||
v[2] = 0.0;
|
||||
v[3] = 0.0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
inline void splat(float xyz)
|
||||
{
|
||||
#if __SSE__
|
||||
TVectorUnion splat = {{xyz, xyz, xyz, 0.0f}};
|
||||
mVec128 = splat.mVec128;
|
||||
#else
|
||||
v[0] = xyz; v[1] = xyz; v[2] = xyz; v[3] = 0.0f;
|
||||
v[0] = xyz;
|
||||
v[1] = xyz;
|
||||
v[2] = xyz;
|
||||
v[3] = 0.0f;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
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); }
|
||||
static inline CVector3f nlerp(const CVector3f& a, const CVector3f& b, float t)
|
||||
{ return lerp(a, b, t).normalized(); }
|
||||
static inline CVector3f lerp(const CVector3f& a, const CVector3f& b, float t) { return (a + (b - a) * t); }
|
||||
static inline CVector3f nlerp(const CVector3f& a, const CVector3f& b, float t) { return lerp(a, b, t).normalized(); }
|
||||
static CVector3f slerp(const CVector3f& a, const CVector3f& b, float t);
|
||||
|
||||
inline bool isNormalized() const
|
||||
{ return std::fabs(1.f - magSquared()) < 0.01f; }
|
||||
inline bool isNormalized() const { return std::fabs(1.f - magSquared()) < 0.01f; }
|
||||
|
||||
inline bool canBeNormalized() const
|
||||
{ return !isNormalized(); }
|
||||
inline bool canBeNormalized() const { return !isNormalized(); }
|
||||
|
||||
inline bool isZero() const
|
||||
{ return magSquared() <= 1.1920929e-7f; }
|
||||
inline bool isZero() const { return magSquared() <= 1.1920929e-7f; }
|
||||
|
||||
inline void scaleToLength(float newLength)
|
||||
{
|
||||
|
@ -349,21 +367,20 @@ public:
|
|||
return v;
|
||||
}
|
||||
|
||||
inline bool isEqu(const CVector3f& other, float epsilon=1.1920929e-7f)
|
||||
inline bool isEqu(const CVector3f& other, float epsilon = 1.1920929e-7f)
|
||||
{
|
||||
const CVector3f diffVec = other - *this;
|
||||
return (diffVec.x <= epsilon && diffVec.y <= epsilon && diffVec.z <= epsilon);
|
||||
}
|
||||
|
||||
inline float& operator[](size_t idx) {return (&x)[idx];}
|
||||
inline const float& operator[](size_t idx) const {return (&x)[idx];}
|
||||
inline float& operator[](size_t idx) { return (&x)[idx]; }
|
||||
inline const float& operator[](size_t idx) const { return (&x)[idx]; }
|
||||
|
||||
static const CVector3f skOne;
|
||||
static const CVector3f skNegOne;
|
||||
static const CVector3f skZero;
|
||||
};
|
||||
|
||||
|
||||
static inline CVector3f operator+(float lhs, const CVector3f& rhs)
|
||||
{
|
||||
#if __SSE__
|
||||
|
@ -412,9 +429,8 @@ extern const CVector3f kForwardVec;
|
|||
extern const CVector3f kBackVec;
|
||||
extern const CVector3f kRadToDegVec;
|
||||
extern const CVector3f kDegToRadVec;
|
||||
inline CVector3f radToDeg(const CVector3f& rad) {return rad * kRadToDegVec;}
|
||||
inline CVector3f degToRad(const CVector3f& deg) {return deg * kDegToRadVec;}
|
||||
|
||||
inline CVector3f radToDeg(const CVector3f& rad) { return rad * kRadToDegVec; }
|
||||
inline CVector3f degToRad(const CVector3f& deg) { return deg * kDegToRadVec; }
|
||||
}
|
||||
|
||||
#endif // CVECTOR3F_HPP
|
||||
|
|
|
@ -21,8 +21,7 @@ class alignas(16) CVector4f
|
|||
#endif
|
||||
public:
|
||||
ZE_DECLARE_ALIGNED_ALLOCATOR();
|
||||
union
|
||||
{
|
||||
union {
|
||||
struct
|
||||
{
|
||||
float x, y, z, w;
|
||||
|
@ -33,14 +32,16 @@ public:
|
|||
#endif
|
||||
};
|
||||
|
||||
inline CVector4f() {zeroOut();}
|
||||
inline CVector4f() { zeroOut(); }
|
||||
#if __SSE__
|
||||
CVector4f(const __m128& mVec128) : mVec128(mVec128) {}
|
||||
#endif
|
||||
#if ZE_ATHENA_TYPES
|
||||
CVector4f(const atVec4f& vec)
|
||||
#if __SSE__
|
||||
: mVec128(vec.mVec128){}
|
||||
: mVec128(vec.mVec128)
|
||||
{
|
||||
}
|
||||
#else
|
||||
{
|
||||
x = vec.vec[0], y = vec.vec[1], z = vec.vec[2], w = vec.vec[3];
|
||||
|
@ -77,9 +78,15 @@ public:
|
|||
}
|
||||
#endif
|
||||
|
||||
CVector4f(float xyzw) {splat(xyzw);}
|
||||
void assign(float x, float y, float z, float w) {v[0] = x; v[1] = y; v[2] = z; v[3] = w;}
|
||||
CVector4f(float x, float y, float z, float w) {assign(x, y, z, w);}
|
||||
CVector4f(float xyzw) { splat(xyzw); }
|
||||
void assign(float x, float y, float z, float w)
|
||||
{
|
||||
v[0] = x;
|
||||
v[1] = y;
|
||||
v[2] = z;
|
||||
v[3] = w;
|
||||
}
|
||||
CVector4f(float x, float y, float z, float w) { assign(x, y, z, w); }
|
||||
CVector4f(const CColor& other);
|
||||
|
||||
CVector4f(const CVector3f& other)
|
||||
|
@ -104,7 +111,7 @@ public:
|
|||
}
|
||||
|
||||
CVector4f& operator=(const CColor& other);
|
||||
inline bool operator ==(const CVector4f& rhs) const
|
||||
inline bool operator==(const CVector4f& rhs) const
|
||||
{
|
||||
#if __SSE__
|
||||
TVectorUnion vec;
|
||||
|
@ -114,7 +121,7 @@ public:
|
|||
return (x == rhs.x && y == rhs.y && z == rhs.z && w == rhs.w);
|
||||
#endif
|
||||
}
|
||||
inline bool operator !=(const CVector4f& rhs) const
|
||||
inline bool operator!=(const CVector4f& rhs) const
|
||||
{
|
||||
#if __SSE__
|
||||
TVectorUnion vec;
|
||||
|
@ -124,7 +131,7 @@ public:
|
|||
return !(*this == rhs);
|
||||
#endif
|
||||
}
|
||||
inline bool operator <(const CVector4f& rhs) const
|
||||
inline bool operator<(const CVector4f& rhs) const
|
||||
{
|
||||
#if __SSE__
|
||||
TVectorUnion vec;
|
||||
|
@ -134,7 +141,7 @@ public:
|
|||
return (x < rhs.x || y < rhs.y || z < rhs.z || w < rhs.w);
|
||||
#endif
|
||||
}
|
||||
inline bool operator <=(const CVector4f& rhs) const
|
||||
inline bool operator<=(const CVector4f& rhs) const
|
||||
{
|
||||
#if __SSE__
|
||||
TVectorUnion vec;
|
||||
|
@ -144,7 +151,7 @@ public:
|
|||
return (x <= rhs.x || y <= rhs.y || z <= rhs.z || w <= rhs.w);
|
||||
#endif
|
||||
}
|
||||
inline bool operator >(const CVector4f& rhs) const
|
||||
inline bool operator>(const CVector4f& rhs) const
|
||||
{
|
||||
#if __SSE__
|
||||
TVectorUnion vec;
|
||||
|
@ -154,7 +161,7 @@ public:
|
|||
return (x > rhs.x || y > rhs.y || z > rhs.z || w > rhs.w);
|
||||
#endif
|
||||
}
|
||||
inline bool operator >=(const CVector4f& rhs) const
|
||||
inline bool operator>=(const CVector4f& rhs) const
|
||||
{
|
||||
#if __SSE__
|
||||
TVectorUnion vec;
|
||||
|
@ -240,39 +247,51 @@ public:
|
|||
return CVector4f(x / val, y / val, z / val, w / val);
|
||||
#endif
|
||||
}
|
||||
inline const CVector4f& operator +=(const CVector4f& rhs)
|
||||
inline const CVector4f& operator+=(const CVector4f& rhs)
|
||||
{
|
||||
#if __SSE__
|
||||
mVec128 = _mm_add_ps(mVec128, rhs.mVec128);
|
||||
#else
|
||||
x += rhs.x; y += rhs.y; z += rhs.z; w += rhs.w;
|
||||
x += rhs.x;
|
||||
y += rhs.y;
|
||||
z += rhs.z;
|
||||
w += rhs.w;
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
inline const CVector4f& operator -=(const CVector4f& rhs)
|
||||
inline const CVector4f& operator-=(const CVector4f& rhs)
|
||||
{
|
||||
#if __SSE__
|
||||
mVec128 = _mm_sub_ps(mVec128, rhs.mVec128);
|
||||
#else
|
||||
x -= rhs.x; y -= rhs.y; z -= rhs.z; w -= rhs.w;
|
||||
x -= rhs.x;
|
||||
y -= rhs.y;
|
||||
z -= rhs.z;
|
||||
w -= rhs.w;
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
inline const CVector4f& operator *=(const CVector4f& rhs)
|
||||
inline const CVector4f& operator*=(const CVector4f& rhs)
|
||||
{
|
||||
#if __SSE__
|
||||
mVec128 = _mm_mul_ps(mVec128, rhs.mVec128);
|
||||
#else
|
||||
x *= rhs.x; y *= rhs.y; z *= rhs.z; w *= rhs.w;
|
||||
x *= rhs.x;
|
||||
y *= rhs.y;
|
||||
z *= rhs.z;
|
||||
w *= rhs.w;
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
inline const CVector4f& operator /=(const CVector4f& rhs)
|
||||
inline const CVector4f& operator/=(const CVector4f& rhs)
|
||||
{
|
||||
#if __SSE__
|
||||
mVec128 = _mm_div_ps(mVec128, rhs.mVec128);
|
||||
#else
|
||||
x /= rhs.x; y /= rhs.y; z /= rhs.z; w /= rhs.w;
|
||||
x /= rhs.x;
|
||||
y /= rhs.y;
|
||||
z /= rhs.z;
|
||||
w /= rhs.w;
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
|
@ -321,20 +340,20 @@ public:
|
|||
result.mVec128 = _mm_mul_ps(mVec128, mVec128);
|
||||
return result.v[0] + result.v[1] + result.v[2];
|
||||
#else
|
||||
return x*x + y*y + z*z + w*w;
|
||||
return x * x + y * y + z * z + w * w;
|
||||
#endif
|
||||
}
|
||||
inline float magnitude() const
|
||||
{
|
||||
return std::sqrt(magSquared());
|
||||
}
|
||||
inline float magnitude() const { return std::sqrt(magSquared()); }
|
||||
|
||||
inline void zeroOut()
|
||||
{
|
||||
#if __SSE__
|
||||
mVec128 = _mm_xor_ps(mVec128, mVec128);
|
||||
#else
|
||||
v[0] = 0.0; v[1] = 0.0; v[2] = 0.0; v[3] = 0.0;
|
||||
v[0] = 0.0;
|
||||
v[1] = 0.0;
|
||||
v[2] = 0.0;
|
||||
v[3] = 0.0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -344,41 +363,34 @@ public:
|
|||
TVectorUnion splat = {{xyzw, xyzw, xyzw, xyzw}};
|
||||
mVec128 = splat.mVec128;
|
||||
#else
|
||||
v[0] = xyz; v[1] = xyz; v[2] = xyz; v[3] = xyzw;
|
||||
v[0] = xyz;
|
||||
v[1] = xyz;
|
||||
v[2] = xyz;
|
||||
v[3] = xyzw;
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline CVector4f lerp(const CVector4f& a, const CVector4f& b, float t)
|
||||
{
|
||||
return (a + (b - a) * t);
|
||||
}
|
||||
static inline CVector4f nlerp(const CVector4f& a, const CVector4f& b, float t)
|
||||
{
|
||||
return lerp(a, b, t).normalized();
|
||||
}
|
||||
static inline CVector4f lerp(const CVector4f& a, const CVector4f& b, float t) { return (a + (b - a) * t); }
|
||||
static inline CVector4f nlerp(const CVector4f& a, const CVector4f& b, float t) { return lerp(a, b, t).normalized(); }
|
||||
|
||||
inline bool isNormalized() const
|
||||
{ return std::fabs(1.f - magSquared()) < 0.01f; }
|
||||
inline bool isNormalized() const { return std::fabs(1.f - magSquared()) < 0.01f; }
|
||||
|
||||
inline bool canBeNormalized() const
|
||||
{ return !isNormalized(); }
|
||||
inline bool canBeNormalized() const { return !isNormalized(); }
|
||||
|
||||
inline bool isEqu(const CVector4f& other, float epsilon=1.1920929e-7f)
|
||||
inline bool isEqu(const CVector4f& other, float epsilon = 1.1920929e-7f)
|
||||
{
|
||||
const CVector4f diffVec = other - *this;
|
||||
return (diffVec.x <= epsilon && diffVec.y <= epsilon && diffVec.z <= epsilon && diffVec.w <= epsilon);
|
||||
}
|
||||
|
||||
inline float& operator[](size_t idx) {return (&x)[idx];}
|
||||
inline const float& operator[](size_t idx) const {return (&x)[idx];}
|
||||
|
||||
inline float& operator[](size_t idx) { return (&x)[idx]; }
|
||||
inline const float& operator[](size_t idx) const { return (&x)[idx]; }
|
||||
|
||||
static const CVector4f skOne;
|
||||
static const CVector4f skNegOne;
|
||||
static const CVector4f skZero;
|
||||
};
|
||||
|
||||
|
||||
static inline CVector4f operator+(float lhs, const CVector4f& rhs)
|
||||
{
|
||||
#if __SSE__
|
||||
|
|
|
@ -2,47 +2,47 @@
|
|||
#define ZEUS_GLOBAL_HPP
|
||||
|
||||
#if _M_IX86_FP >= 1 || _M_X64
|
||||
# define __SSE__ 1
|
||||
#define __SSE__ 1
|
||||
#endif
|
||||
|
||||
#if __SSE__
|
||||
# include <immintrin.h>
|
||||
# ifndef _MSC_VER
|
||||
# include <mm_malloc.h>
|
||||
# endif
|
||||
# define zeAlloc(sz, align) _mm_malloc(sz, align)
|
||||
# define zeFree(ptr) _mm_free(ptr)
|
||||
#include <immintrin.h>
|
||||
#ifndef _MSC_VER
|
||||
#include <mm_malloc.h>
|
||||
#endif
|
||||
#define zeAlloc(sz, align) _mm_malloc(sz, align)
|
||||
#define zeFree(ptr) _mm_free(ptr)
|
||||
#elif GEKKO
|
||||
# include <ps_intrins.h>
|
||||
# define zeAlloc(sz, align) _ps_malloc(sz, align)
|
||||
# define zeFree(ptr) _ps_free(ptr)
|
||||
#include <ps_intrins.h>
|
||||
#define zeAlloc(sz, align) _ps_malloc(sz, align)
|
||||
#define zeFree(ptr) _ps_free(ptr)
|
||||
#endif
|
||||
|
||||
#if __SSE__ || __GEKKO_PS__
|
||||
# define ZE_DECLARE_ALIGNED_ALLOCATOR() \
|
||||
inline void* operator new(size_t sizeInBytes) { return zeAlloc(sizeInBytes,16); } \
|
||||
inline void operator delete(void* ptr) { zeFree(ptr); } \
|
||||
inline void* operator new(size_t, void* ptr) { return ptr; } \
|
||||
inline void operator delete(void*, void*) { } \
|
||||
inline void* operator new[](size_t sizeInBytes) { return zeAlloc(sizeInBytes,16); } \
|
||||
inline void operator delete[](void* ptr) { zeFree(ptr); } \
|
||||
inline void* operator new[](size_t, void* ptr) { return ptr; } \
|
||||
inline void operator delete[](void*, void*) { } \
|
||||
void __unused__()
|
||||
#define ZE_DECLARE_ALIGNED_ALLOCATOR() \
|
||||
inline void* operator new(size_t sizeInBytes) { return zeAlloc(sizeInBytes, 16); } \
|
||||
inline void operator delete(void* ptr) { zeFree(ptr); } \
|
||||
inline void* operator new(size_t, void* ptr) { return ptr; } \
|
||||
inline void operator delete(void*, void*) {} \
|
||||
inline void* operator new[](size_t sizeInBytes) { return zeAlloc(sizeInBytes, 16); } \
|
||||
inline void operator delete[](void* ptr) { zeFree(ptr); } \
|
||||
inline void* operator new[](size_t, void* ptr) { return ptr; } \
|
||||
inline void operator delete[](void*, void*) {} \
|
||||
void __unused__()
|
||||
#else
|
||||
# define ZE_DECLARE_ALIGNED_ALLOCATOR() void __unused__()
|
||||
#define ZE_DECLARE_ALIGNED_ALLOCATOR() void __unused__()
|
||||
#endif
|
||||
|
||||
#if __SSE__
|
||||
# define ZE_SHUFFLE(x,y,z,w) ((w)<<6 | (z)<<4 | (y)<<2 | (x))
|
||||
# define ze_pshufd_ps( _a, _mask ) _mm_shuffle_ps((_a), (_a), (_mask) )
|
||||
# define ze_splat3_ps( _a, _i ) ze_pshufd_ps((_a), ZE_SHUFFLE(_i,_i,_i, 3) )
|
||||
# define ze_splat_ps( _a, _i ) ze_pshufd_ps((_a), ZE_SHUFFLE(_i,_i,_i,_i) )
|
||||
# if _WIN32
|
||||
# define zeCastiTo128f(a) (_mm_castsi128_ps(a))
|
||||
# else
|
||||
# define zeCastiTo128f(a) ((__m128) (a))
|
||||
# endif
|
||||
#define ZE_SHUFFLE(x, y, z, w) ((w) << 6 | (z) << 4 | (y) << 2 | (x))
|
||||
#define ze_pshufd_ps(_a, _mask) _mm_shuffle_ps((_a), (_a), (_mask))
|
||||
#define ze_splat3_ps(_a, _i) ze_pshufd_ps((_a), ZE_SHUFFLE(_i, _i, _i, 3))
|
||||
#define ze_splat_ps(_a, _i) ze_pshufd_ps((_a), ZE_SHUFFLE(_i, _i, _i, _i))
|
||||
#if _WIN32
|
||||
#define zeCastiTo128f(a) (_mm_castsi128_ps(a))
|
||||
#else
|
||||
#define zeCastiTo128f(a) ((__m128)(a))
|
||||
#endif
|
||||
#elif __GEKKO_PS__
|
||||
|
||||
#endif
|
||||
|
@ -50,6 +50,4 @@
|
|||
inline int rotr(int x, int n) { return ((x >> n) | (x << (32 - n))); }
|
||||
inline int rotl(int x, int n) { return ((x << n) | (x >> (32 - n))); }
|
||||
|
||||
|
||||
#endif //ZEUS_GLOBAL_HPP
|
||||
|
||||
#endif // ZEUS_GLOBAL_HPP
|
||||
|
|
|
@ -5,22 +5,22 @@
|
|||
#undef max
|
||||
|
||||
#undef M_PI
|
||||
#define M_PI 3.14159265358979323846 /* pi */
|
||||
#define M_PIF 3.14159265358979323846f /* pi */
|
||||
#define M_PI 3.14159265358979323846 /* pi */
|
||||
#define M_PIF 3.14159265358979323846f /* pi */
|
||||
#undef M_PI_2
|
||||
#define M_PI_2 1.57079632679489661923 /* pi/2 */
|
||||
#define M_PI_2 1.57079632679489661923 /* pi/2 */
|
||||
#undef M_PI_4
|
||||
#define M_PI_4 0.78539816339744830962 /* pi/4 */
|
||||
#define M_PI_4 0.78539816339744830962 /* pi/4 */
|
||||
#undef M_1_PI
|
||||
#define M_1_PI 0.31830988618379067154 /* 1/pi */
|
||||
#define M_1_PI 0.31830988618379067154 /* 1/pi */
|
||||
#undef M_2_PI
|
||||
#define M_2_PI 0.63661977236758134308 /* 2/pi */
|
||||
#define M_2_PI 0.63661977236758134308 /* 2/pi */
|
||||
#undef M_2_SQRTPI
|
||||
#define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
|
||||
#define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
|
||||
#undef M_SQRT2
|
||||
#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
|
||||
#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
|
||||
#undef M_SQRT1_2
|
||||
#define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
|
||||
#define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
|
||||
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
|
@ -29,17 +29,17 @@ namespace zeus
|
|||
{
|
||||
struct CPUInfo
|
||||
{
|
||||
const char cpuBrand [48] = {0};
|
||||
const char cpuVendor[32] = {0};
|
||||
const bool isIntel = false;
|
||||
const bool SSE1 = false;
|
||||
const bool SSE2 = false;
|
||||
const bool SSE3 = false;
|
||||
const bool SSSE3 = false;
|
||||
const bool SSE41 = false;
|
||||
const bool SSE42 = false;
|
||||
const bool SSE4a = false;
|
||||
const bool AESNI = false;
|
||||
const char cpuBrand[48] = {0};
|
||||
const char cpuVendor[32] = {0};
|
||||
const bool isIntel = false;
|
||||
const bool SSE1 = false;
|
||||
const bool SSE2 = false;
|
||||
const bool SSE3 = false;
|
||||
const bool SSSE3 = false;
|
||||
const bool SSE41 = false;
|
||||
const bool SSE42 = false;
|
||||
const bool SSE4a = false;
|
||||
const bool AESNI = false;
|
||||
};
|
||||
/**
|
||||
* Detects CPU capabilities and returns true if SSE4.1 or SSE4.2 is available
|
||||
|
@ -49,31 +49,37 @@ const CPUInfo& cpuFeatures();
|
|||
class CVector3f;
|
||||
class CTransform;
|
||||
|
||||
template<typename T>
|
||||
inline T min(T a, T b) { return a < b ? a : b; }
|
||||
template<typename T>
|
||||
inline T max(T a, T b) { return a > b ? a : b; }
|
||||
template <typename T>
|
||||
inline T min(T a, T b)
|
||||
{
|
||||
return a < b ? a : b;
|
||||
}
|
||||
template <typename T>
|
||||
inline T max(T a, T b)
|
||||
{
|
||||
return a > b ? a : b;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T clamp(T a, T val, T b) {return max<T>(a, min<T>(b, val));}
|
||||
inline float radToDeg(float rad) {return rad * (180.f / M_PIF);}
|
||||
inline float degToRad(float deg) {return deg * (M_PIF / 180.f);}
|
||||
inline double radToDeg(double rad) {return rad * (180.0 / M_PI);}
|
||||
inline double degToRad(double deg) {return deg * (M_PI / 180.0);}
|
||||
template <typename T>
|
||||
inline T clamp(T a, T val, T b)
|
||||
{
|
||||
return max<T>(a, min<T>(b, val));
|
||||
}
|
||||
inline float radToDeg(float rad) { return rad * (180.f / M_PIF); }
|
||||
inline float degToRad(float deg) { return deg * (M_PIF / 180.f); }
|
||||
inline double radToDeg(double rad) { return rad * (180.0 / M_PI); }
|
||||
inline double degToRad(double deg) { return deg * (M_PI / 180.0); }
|
||||
|
||||
CVector3f baryToWorld(const CVector3f& p0, const CVector3f& p1, const CVector3f& p2, const CVector3f& bary);
|
||||
|
||||
CVector3f getBezierPoint(const CVector3f& a, const CVector3f& b,
|
||||
const CVector3f& c, const CVector3f& d, float t);
|
||||
float getCatmullRomSplinePoint(float a, float b,
|
||||
float c, float d, float t);
|
||||
CVector3f getCatmullRomSplinePoint(const CVector3f& a, const CVector3f& b,
|
||||
const CVector3f& c, const CVector3f& d, float t);
|
||||
CVector3f getRoundCatmullRomSplinePoint(const CVector3f& a, const CVector3f& b,
|
||||
const CVector3f& c, const CVector3f& d, float t);
|
||||
CVector3f getBezierPoint(const CVector3f& a, const CVector3f& b, const CVector3f& c, const CVector3f& d, float t);
|
||||
float getCatmullRomSplinePoint(float a, float b, float c, float d, float t);
|
||||
CVector3f getCatmullRomSplinePoint(const CVector3f& a, const CVector3f& b, const CVector3f& c, const CVector3f& d, float t);
|
||||
CVector3f getRoundCatmullRomSplinePoint(const CVector3f& a, const CVector3f& b, const CVector3f& c, const CVector3f& d,
|
||||
float t);
|
||||
|
||||
inline float powF(float a, float b) { return std::pow(a, b); }
|
||||
inline float floorF(float val) { return std::floor(val); }
|
||||
inline float powF(float a, float b) { return std::pow(a, b); }
|
||||
inline float floorF(float val) { return std::floor(val); }
|
||||
inline float ceilingF(float val)
|
||||
{
|
||||
float tmp = std::floor(val);
|
||||
|
@ -86,9 +92,9 @@ inline double round(double val) { return (val < 0.0 ? ceilingF(val - 0.5) : floo
|
|||
inline double powD(float a, float b) { return std::exp(b * std::log(a)); }
|
||||
|
||||
double sqrtD(double val);
|
||||
inline double invSqrtD(double val) { return 1.0 / sqrtD(val); }
|
||||
inline float invSqrtF(float val) { return float(1.0 / sqrtD(val)); }
|
||||
inline float sqrtF(float val) { return float(sqrtD(val)); }
|
||||
inline double invSqrtD(double val) { return 1.0 / sqrtD(val); }
|
||||
inline float invSqrtF(float val) { return float(1.0 / sqrtD(val)); }
|
||||
inline float sqrtF(float val) { return float(sqrtD(val)); }
|
||||
float fastArcCosF(float val);
|
||||
float fastCosF(float val);
|
||||
float fastSinF(float val);
|
||||
|
@ -96,27 +102,24 @@ int floorPowerOfTwo(int x);
|
|||
int ceilingPowerOfTwo(int x);
|
||||
|
||||
template <typename U>
|
||||
typename std::enable_if<!std::is_enum<U>::value && std::is_integral<U>::value, int>::type
|
||||
PopCount(U x)
|
||||
typename std::enable_if<!std::is_enum<U>::value && std::is_integral<U>::value, int>::type PopCount(U x)
|
||||
{
|
||||
const U m1 = U(0x5555555555555555); //binary: 0101...
|
||||
const U m2 = U(0x3333333333333333); //binary: 00110011..
|
||||
const U m4 = U(0x0f0f0f0f0f0f0f0f); //binary: 4 zeros, 4 ones ...
|
||||
const U h01 = U(0x0101010101010101); //the sum of 256 to the power of 0,1,2,3...
|
||||
const U m1 = U(0x5555555555555555); // binary: 0101...
|
||||
const U m2 = U(0x3333333333333333); // binary: 00110011..
|
||||
const U m4 = U(0x0f0f0f0f0f0f0f0f); // binary: 4 zeros, 4 ones ...
|
||||
const U h01 = U(0x0101010101010101); // the sum of 256 to the power of 0,1,2,3...
|
||||
|
||||
x -= (x >> 1) & m1; //put count of each 2 bits into those 2 bits
|
||||
x = (x & m2) + ((x >> 2) & m2); //put count of each 4 bits into those 4 bits
|
||||
x = (x + (x >> 4)) & m4; //put count of each 8 bits into those 8 bits
|
||||
return (x * h01) >> ((sizeof(U)-1)*8); //returns left 8 bits of x + (x<<8) + (x<<16) + (x<<24) + ...
|
||||
x -= (x >> 1) & m1; // put count of each 2 bits into those 2 bits
|
||||
x = (x & m2) + ((x >> 2) & m2); // put count of each 4 bits into those 4 bits
|
||||
x = (x + (x >> 4)) & m4; // put count of each 8 bits into those 8 bits
|
||||
return (x * h01) >> ((sizeof(U) - 1) * 8); // returns left 8 bits of x + (x<<8) + (x<<16) + (x<<24) + ...
|
||||
}
|
||||
|
||||
template <typename E>
|
||||
typename std::enable_if<std::is_enum<E>::value, int>::type
|
||||
PopCount(E e)
|
||||
typename std::enable_if<std::is_enum<E>::value, int>::type PopCount(E e)
|
||||
{
|
||||
return PopCount(static_cast<typename std::underlying_type<E>::type>(e));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // MATH_HPP
|
||||
|
|
|
@ -3,16 +3,14 @@
|
|||
|
||||
namespace zeus
|
||||
{
|
||||
typedef union
|
||||
{
|
||||
typedef union {
|
||||
float v[4];
|
||||
#if __SSE__
|
||||
__m128 mVec128;
|
||||
#endif
|
||||
} TVectorUnion;
|
||||
|
||||
typedef union
|
||||
{
|
||||
typedef union {
|
||||
double v[4];
|
||||
#if __SSE__
|
||||
__m128d mVec128[2];
|
||||
|
@ -21,4 +19,3 @@ typedef union
|
|||
}
|
||||
|
||||
#endif // TVECTORUNION
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,9 +5,11 @@
|
|||
// This is only for testing, do NOT do this normally
|
||||
using namespace zeus;
|
||||
|
||||
union Color
|
||||
{
|
||||
struct { zeus::Comp8 r, g, b, a; };
|
||||
union Color {
|
||||
struct
|
||||
{
|
||||
zeus::Comp8 r, g, b, a;
|
||||
};
|
||||
zeus::Comp32 rgba;
|
||||
};
|
||||
|
||||
|
@ -26,7 +28,7 @@ int main()
|
|||
blarg = clamp(0.f, blarg, 1.f);
|
||||
CAABox test{{-100, -100, -100}, {100, 100, 100}};
|
||||
CAABox test2{{-100, -100, -100}, {100, 100, 100}};
|
||||
CAABox test3{{-50, -50, -50}, {50, 50, 50}};
|
||||
CAABox test3{{-50, -50, -50}, {50, 50, 50}};
|
||||
CAABox test4{{-50, -50, -105}, {50, 50, 105}};
|
||||
CVector3f point(-90, 67, -105);
|
||||
CVector3f closestPoint = test.closestPointAlongVector(point);
|
||||
|
@ -47,18 +49,18 @@ int main()
|
|||
std::cout << min(2, 1) << std::endl;
|
||||
std::cout << max(1, 3) << std::endl;
|
||||
std::cout << max(2, 1) << std::endl;
|
||||
std::cout << clamp(-50, 100, 50) << std::endl;
|
||||
std::cout << clamp(-50, 100, 50) << std::endl;
|
||||
std::cout << clamp(-50, -100, 50) << std::endl;
|
||||
std::cout << powF(6.66663489, 2) << std::endl;
|
||||
std::cout << invSqrtF(1) << std::endl;
|
||||
std::cout << floorPowerOfTwo(256) << std::endl;
|
||||
std::cout << " Test 1 " << ( aabb.intersects(s1) ? "succeeded" : "failed" ) << std::endl;
|
||||
std::cout << " Test 2 " << ( aabb.intersects(s2) ? "succeeded" : "failed" ) << std::endl;
|
||||
std::cout << " Test 3 " << ( aabb.intersects(s3) ? "succeeded" : "failed" ) << std::endl;
|
||||
std::cout << " Test 1 " << (aabb.intersects(s1) ? "succeeded" : "failed") << std::endl;
|
||||
std::cout << " Test 2 " << (aabb.intersects(s2) ? "succeeded" : "failed") << std::endl;
|
||||
std::cout << " Test 3 " << (aabb.intersects(s3) ? "succeeded" : "failed") << std::endl;
|
||||
CLineSeg line({-89.120926f, 59.328712f, 3.265882f}, {-90.120926f, 59.328712f, 3.265882f});
|
||||
|
||||
CColor ctest1;
|
||||
ctest1.fromHSV(0, 255/255.f, .5);
|
||||
ctest1.fromHSV(0, 255 / 255.f, .5);
|
||||
float h, s, v;
|
||||
ctest1.toHSV(h, s, v);
|
||||
std::cout << (int)ctest1.r << " " << (int)ctest1.g << " " << (int)ctest1.b << " " << (int)ctest1.a << std::endl;
|
||||
|
|
Loading…
Reference in New Issue