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;
|
CVector3f max;
|
||||||
|
|
||||||
// set default AABox to insane inverse min/max to allow for accumulation
|
// set default AABox to insane inverse min/max to allow for accumulation
|
||||||
inline CAABox()
|
inline CAABox() : min(1e16f), max(-1e16f) {}
|
||||||
: min(1e16f), max(-1e16f)
|
|
||||||
{}
|
|
||||||
|
|
||||||
CAABox(const CVector3f& min, const CVector3f& max)
|
CAABox(const CVector3f& min, const CVector3f& max) : min(min), max(max) {}
|
||||||
: min(min),
|
|
||||||
max(max)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
CAABox(float minX, float minY, float minZ,
|
CAABox(float minX, float minY, float minZ, float maxX, float maxY, float maxZ)
|
||||||
float maxX, float maxY, float maxZ)
|
: min(minX, minY, minZ), max(maxX, maxY, maxZ)
|
||||||
: min(minX, minY, minZ),
|
|
||||||
max(maxX, maxY, maxZ)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
#if ZE_ATHENA_TYPES
|
#if ZE_ATHENA_TYPES
|
||||||
|
@ -89,10 +81,7 @@ public:
|
||||||
return dist;
|
return dist;
|
||||||
}
|
}
|
||||||
|
|
||||||
float distanceFromPoint(const CVector3f &other) const
|
float distanceFromPoint(const CVector3f& other) const { return sqrtF(distanceFromPointSquared(other)); }
|
||||||
{
|
|
||||||
return sqrtF(distanceFromPointSquared(other));
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool intersects(const CAABox& other) const
|
inline bool intersects(const CAABox& other) const
|
||||||
{
|
{
|
||||||
|
@ -121,26 +110,35 @@ public:
|
||||||
{
|
{
|
||||||
CVector3f vmin, vmax;
|
CVector3f vmin, vmax;
|
||||||
/* X axis */
|
/* X axis */
|
||||||
if (plane.a >= 0) {
|
if (plane.a >= 0)
|
||||||
|
{
|
||||||
vmin[0] = min[0];
|
vmin[0] = min[0];
|
||||||
vmax[0] = max[0];
|
vmax[0] = max[0];
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
vmin[0] = max[0];
|
vmin[0] = max[0];
|
||||||
vmax[0] = min[0];
|
vmax[0] = min[0];
|
||||||
}
|
}
|
||||||
/* Y axis */
|
/* Y axis */
|
||||||
if (plane.b >= 0) {
|
if (plane.b >= 0)
|
||||||
|
{
|
||||||
vmin[1] = min[1];
|
vmin[1] = min[1];
|
||||||
vmax[1] = max[1];
|
vmax[1] = max[1];
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
vmin[1] = max[1];
|
vmin[1] = max[1];
|
||||||
vmax[1] = min[1];
|
vmax[1] = min[1];
|
||||||
}
|
}
|
||||||
/* Z axis */
|
/* Z axis */
|
||||||
if (plane.c >= 0) {
|
if (plane.c >= 0)
|
||||||
|
{
|
||||||
vmin[2] = min[2];
|
vmin[2] = min[2];
|
||||||
vmax[2] = max[2];
|
vmax[2] = max[2];
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
vmin[2] = max[2];
|
vmin[2] = max[2];
|
||||||
vmax[2] = min[2];
|
vmax[2] = min[2];
|
||||||
}
|
}
|
||||||
|
@ -150,53 +148,40 @@ public:
|
||||||
return true;
|
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)
|
inline CLineSeg getEdge(EBoxEdgeId id)
|
||||||
{
|
{
|
||||||
switch (id)
|
switch (id)
|
||||||
{
|
{
|
||||||
case EBoxEdgeId::UnknownEdge0:
|
case EBoxEdgeId::UnknownEdge0:
|
||||||
return CLineSeg({min.x, min.y, min.z},
|
return CLineSeg({min.x, min.y, min.z}, {min.x, min.y, max.z});
|
||||||
{min.x, min.y, max.z});
|
|
||||||
case EBoxEdgeId::UnknownEdge1:
|
case EBoxEdgeId::UnknownEdge1:
|
||||||
return CLineSeg({max.x, min.y, min.z},
|
return CLineSeg({max.x, min.y, min.z}, {min.x, min.y, min.z});
|
||||||
{min.x, min.y, min.z});
|
|
||||||
case EBoxEdgeId::UnknownEdge2:
|
case EBoxEdgeId::UnknownEdge2:
|
||||||
return CLineSeg({max.x, min.y, max.z},
|
return CLineSeg({max.x, min.y, max.z}, {max.x, min.y, max.z});
|
||||||
{max.x, min.y, max.z});
|
|
||||||
case EBoxEdgeId::UnknownEdge3:
|
case EBoxEdgeId::UnknownEdge3:
|
||||||
return CLineSeg({min.x, min.y, max.z},
|
return CLineSeg({min.x, min.y, max.z}, {max.x, min.y, max.z});
|
||||||
{max.x, min.y, max.z});
|
|
||||||
case EBoxEdgeId::UnknownEdge4:
|
case EBoxEdgeId::UnknownEdge4:
|
||||||
return CLineSeg({max.x, max.y, min.z},
|
return CLineSeg({max.x, max.y, min.z}, {max.x, max.y, max.z});
|
||||||
{max.x, max.y, max.z});
|
|
||||||
case EBoxEdgeId::UnknownEdge5:
|
case EBoxEdgeId::UnknownEdge5:
|
||||||
return CLineSeg({min.x, max.y, min.z},
|
return CLineSeg({min.x, max.y, min.z}, {max.x, max.y, min.z});
|
||||||
{max.x, max.y, min.z});
|
|
||||||
case EBoxEdgeId::UnknownEdge6:
|
case EBoxEdgeId::UnknownEdge6:
|
||||||
return CLineSeg({min.x, max.y, max.z},
|
return CLineSeg({min.x, max.y, max.z}, {min.x, max.y, min.z});
|
||||||
{min.x, max.y, min.z});
|
|
||||||
case EBoxEdgeId::UnknownEdge7:
|
case EBoxEdgeId::UnknownEdge7:
|
||||||
return CLineSeg({max.x, max.y, max.z},
|
return CLineSeg({max.x, max.y, max.z}, {min.x, max.y, max.z});
|
||||||
{min.x, max.y, max.z});
|
|
||||||
case EBoxEdgeId::UnknownEdge8:
|
case EBoxEdgeId::UnknownEdge8:
|
||||||
return CLineSeg({min.x, max.y, max.z},
|
return CLineSeg({min.x, max.y, max.z}, {min.x, min.y, max.z});
|
||||||
{min.x, min.y, max.z});
|
|
||||||
case EBoxEdgeId::UnknownEdge9:
|
case EBoxEdgeId::UnknownEdge9:
|
||||||
return CLineSeg({min.x, max.y, min.z},
|
return CLineSeg({min.x, max.y, min.z}, {min.x, min.y, min.z});
|
||||||
{min.x, min.y, min.z});
|
|
||||||
case EBoxEdgeId::UnknownEdge10:
|
case EBoxEdgeId::UnknownEdge10:
|
||||||
return CLineSeg({max.x, max.y, min.z},
|
return CLineSeg({max.x, max.y, min.z}, {max.x, min.y, min.z});
|
||||||
{max.x, min.y, min.z});
|
|
||||||
case EBoxEdgeId::UnknownEdge11:
|
case EBoxEdgeId::UnknownEdge11:
|
||||||
return CLineSeg({max.x, max.y, max.z},
|
return CLineSeg({max.x, max.y, max.z}, {max.x, min.y, max.z});
|
||||||
{max.x, min.y, max.z});
|
|
||||||
default:
|
default:
|
||||||
return CLineSeg({min.x, min.y, min.z},
|
return CLineSeg({min.x, min.y, min.z}, {min.x, min.y, max.z});
|
||||||
{min.x, min.y, max.z});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,24 +231,21 @@ public:
|
||||||
|
|
||||||
inline bool pointInside(const CVector3f& other) const
|
inline bool pointInside(const CVector3f& other) const
|
||||||
{
|
{
|
||||||
return (min.x <= other.x && other.x <= max.z &&
|
return (min.x <= other.x && other.x <= max.z && min.y <= other.y && other.y <= max.z && min.z <= other.z &&
|
||||||
min.y <= other.y && other.y <= max.z &&
|
other.z <= max.z);
|
||||||
min.z <= other.z && other.z <= max.z);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline CVector3f closestPointAlongVector(const CVector3f& other) const
|
inline CVector3f closestPointAlongVector(const CVector3f& other) const
|
||||||
{
|
{
|
||||||
CVector3f center = this->center();
|
CVector3f center = this->center();
|
||||||
return {(other.x < center.x ? min.x : max.x),
|
return {(other.x < center.x ? min.x : max.x), (other.y < center.y ? min.y : max.y),
|
||||||
(other.y < center.y ? min.y : max.y),
|
|
||||||
(other.z < center.z ? min.z : max.z)};
|
(other.z < center.z ? min.z : max.z)};
|
||||||
}
|
}
|
||||||
|
|
||||||
inline CVector3f furthestPointAlongVector(const CVector3f& other) const
|
inline CVector3f furthestPointAlongVector(const CVector3f& other) const
|
||||||
{
|
{
|
||||||
CVector3f center = this->center();
|
CVector3f center = this->center();
|
||||||
return {(other.x < center.x ? max.x : min.x),
|
return {(other.x < center.x ? max.x : min.x), (other.y < center.y ? max.y : min.y),
|
||||||
(other.y < center.y ? max.y : min.y),
|
|
||||||
(other.z < center.z ? max.z : min.z)};
|
(other.z < center.z ? max.z : min.z)};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -320,12 +302,11 @@ public:
|
||||||
negZ.min = min;
|
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
|
#endif // CAABOX_HPP
|
||||||
|
|
|
@ -12,13 +12,9 @@ struct alignas(16) CAxisAngle : CVector3f
|
||||||
ZE_DECLARE_ALIGNED_ALLOCATOR();
|
ZE_DECLARE_ALIGNED_ALLOCATOR();
|
||||||
|
|
||||||
CAxisAngle() = default;
|
CAxisAngle() = default;
|
||||||
CAxisAngle(const CUnitVector3f& axis, float distance)
|
CAxisAngle(const CUnitVector3f& axis, float distance) : CVector3f(distance * axis) {}
|
||||||
: CVector3f(distance * axis)
|
|
||||||
{}
|
|
||||||
|
|
||||||
CAxisAngle(const CVector3f& axisAngle)
|
CAxisAngle(const CVector3f& axisAngle) : CVector3f(axisAngle) {}
|
||||||
: CVector3f(axisAngle)
|
|
||||||
{}
|
|
||||||
|
|
||||||
float angle() { return magnitude(); }
|
float angle() { return magnitude(); }
|
||||||
const CVector3f& getVector() { return *this; }
|
const CVector3f& getVector() { return *this; }
|
||||||
|
|
|
@ -10,8 +10,8 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#if BYTE_ORDER == __ORDER_LITTLE_ENDIAN__
|
#if BYTE_ORDER == __ORDER_LITTLE_ENDIAN__
|
||||||
#define COLOR(rgba) (unsigned)( ( (rgba) & 0x000000FF ) << 24 | ( (rgba) & 0x0000FF00 ) << 8 \
|
#define COLOR(rgba) \
|
||||||
| ( (rgba) & 0x00FF0000 ) >> 8 | ( (rgba) & 0xFF000000 ) >> 24 )
|
(unsigned)(((rgba)&0x000000FF) << 24 | ((rgba)&0x0000FF00) << 8 | ((rgba)&0x00FF0000) >> 8 | ((rgba)&0xFF000000) >> 24)
|
||||||
#else
|
#else
|
||||||
#define COLOR(rgba) rgba
|
#define COLOR(rgba) rgba
|
||||||
#endif
|
#endif
|
||||||
|
@ -20,10 +20,9 @@ namespace zeus
|
||||||
{
|
{
|
||||||
typedef uint8_t Comp8;
|
typedef uint8_t Comp8;
|
||||||
typedef uint32_t Comp32;
|
typedef uint32_t Comp32;
|
||||||
constexpr float OneOver255 = 1.f/255.f;
|
constexpr float OneOver255 = 1.f / 255.f;
|
||||||
|
|
||||||
typedef union
|
typedef union {
|
||||||
{
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
Comp8 r, g, b, a;
|
Comp8 r, g, b, a;
|
||||||
|
@ -55,11 +54,19 @@ public:
|
||||||
|
|
||||||
CColor() : r(1.0f), g(1.0f), b(1.0f), a(1.0f) {}
|
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 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
|
#if ZE_ATHENA_TYPES
|
||||||
CColor(const atVec4f& vec)
|
CColor(const atVec4f& vec)
|
||||||
#if __SSE__ || __GEKKO_PS__
|
#if __SSE__ || __GEKKO_PS__
|
||||||
: mVec128(vec.mVec128){}
|
: mVec128(vec.mVec128)
|
||||||
|
{
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
{
|
{
|
||||||
r = vec.vec[0], g = vec.vec[1], b = vec.vec[2], a = vec.vec[3];
|
r = vec.vec[0], g = vec.vec[1], b = vec.vec[2], a = vec.vec[3];
|
||||||
|
@ -90,10 +97,8 @@ public:
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
inline bool operator==(const CColor& rhs) const
|
inline bool operator==(const CColor& rhs) const { return (r == rhs.r && g == rhs.g && b == rhs.b && a == rhs.a); }
|
||||||
{ 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 !(*this == rhs); }
|
|
||||||
inline CColor operator+(const CColor& rhs) const
|
inline CColor operator+(const CColor& rhs) const
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
|
@ -167,7 +172,10 @@ public:
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
mVec128 = _mm_add_ps(mVec128, rhs.mVec128);
|
mVec128 = _mm_add_ps(mVec128, rhs.mVec128);
|
||||||
#else
|
#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
|
#endif
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -176,25 +184,34 @@ public:
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
mVec128 = _mm_sub_ps(mVec128, rhs.mVec128);
|
mVec128 = _mm_sub_ps(mVec128, rhs.mVec128);
|
||||||
#else
|
#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
|
#endif
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
inline const CColor& operator *=(const CColor& rhs)
|
inline const CColor& operator*=(const CColor& rhs)
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
mVec128 = _mm_mul_ps(mVec128, rhs.mVec128);
|
mVec128 = _mm_mul_ps(mVec128, rhs.mVec128);
|
||||||
#else
|
#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
|
#endif
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
inline const CColor& operator /=(const CColor& rhs)
|
inline const CColor& operator/=(const CColor& rhs)
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
mVec128 = _mm_div_ps(mVec128, rhs.mVec128);
|
mVec128 = _mm_div_ps(mVec128, rhs.mVec128);
|
||||||
#else
|
#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
|
#endif
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -229,19 +246,10 @@ public:
|
||||||
return r * r + g * g + b * b + a * a;
|
return r * r + g * g + b * b + a * a;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
inline float magnitude() const
|
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); }
|
||||||
return std::sqrt(magSquared());
|
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]; }
|
||||||
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 const float& operator[](const size_t& idx) const { return (&r)[idx]; }
|
||||||
inline void splat(float rgb, float a)
|
inline void splat(float rgb, float a)
|
||||||
{
|
{
|
||||||
|
@ -249,12 +257,14 @@ public:
|
||||||
TVectorUnion splat = {{rgb, rgb, rgb, a}};
|
TVectorUnion splat = {{rgb, rgb, rgb, a}};
|
||||||
mVec128 = splat.mVec128;
|
mVec128 = splat.mVec128;
|
||||||
#else
|
#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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
union
|
union {
|
||||||
{
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
float r, g, b, a;
|
float r, g, b, a;
|
||||||
|
@ -313,13 +323,11 @@ public:
|
||||||
*/
|
*/
|
||||||
void toHSV(float& h, float& s, float& v) const;
|
void toHSV(float& h, float& s, float& v) const;
|
||||||
|
|
||||||
|
|
||||||
void fromHSL(float h, float s, float l, float _a = 1.0);
|
void fromHSL(float h, float s, float l, float _a = 1.0);
|
||||||
|
|
||||||
void toHSL(float& h, float& s, float& l);
|
void toHSL(float& h, float& s, float& l);
|
||||||
|
|
||||||
CColor toGrayscale()
|
CColor toGrayscale() { return {sqrtF((r * r + g * g + b * b) / 3), a}; }
|
||||||
{ return {sqrtF((r * r + g * g + b * b) / 3), a}; }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Clamps to GPU-safe RGBA values [0,1]
|
* @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);
|
return CColor(lhs / rhs.r, lhs / rhs.g, lhs / rhs.b, lhs / rhs.a);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif // CCOLOR_HPP
|
#endif // CCOLOR_HPP
|
||||||
|
|
|
@ -9,8 +9,8 @@ namespace zeus
|
||||||
class CFrustum
|
class CFrustum
|
||||||
{
|
{
|
||||||
CPlane planes[6];
|
CPlane planes[6];
|
||||||
public:
|
|
||||||
|
|
||||||
|
public:
|
||||||
inline void updatePlanes(const CTransform& modelview, const CProjection& projection)
|
inline void updatePlanes(const CTransform& modelview, const CProjection& projection)
|
||||||
{
|
{
|
||||||
CMatrix4f mv = modelview.toMatrix4f();
|
CMatrix4f mv = modelview.toMatrix4f();
|
||||||
|
@ -82,37 +82,46 @@ public:
|
||||||
planes[3].normalize();
|
planes[3].normalize();
|
||||||
planes[4].normalize();
|
planes[4].normalize();
|
||||||
planes[5].normalize();
|
planes[5].normalize();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool aabbFrustumTest(const CAABox& aabb) const
|
inline bool aabbFrustumTest(const CAABox& aabb) const
|
||||||
{
|
{
|
||||||
CVector3f vmin, vmax;
|
CVector3f vmin, vmax;
|
||||||
int i;
|
int i;
|
||||||
for (i=0 ; i<6 ; ++i) {
|
for (i = 0; i < 6; ++i)
|
||||||
|
{
|
||||||
const CPlane& plane = planes[i];
|
const CPlane& plane = planes[i];
|
||||||
|
|
||||||
/* X axis */
|
/* X axis */
|
||||||
if (plane.a >= 0) {
|
if (plane.a >= 0)
|
||||||
|
{
|
||||||
vmin[0] = aabb.min[0];
|
vmin[0] = aabb.min[0];
|
||||||
vmax[0] = aabb.max[0];
|
vmax[0] = aabb.max[0];
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
vmin[0] = aabb.max[0];
|
vmin[0] = aabb.max[0];
|
||||||
vmax[0] = aabb.min[0];
|
vmax[0] = aabb.min[0];
|
||||||
}
|
}
|
||||||
/* Y axis */
|
/* Y axis */
|
||||||
if (plane.b >= 0) {
|
if (plane.b >= 0)
|
||||||
|
{
|
||||||
vmin[1] = aabb.min[1];
|
vmin[1] = aabb.min[1];
|
||||||
vmax[1] = aabb.max[1];
|
vmax[1] = aabb.max[1];
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
vmin[1] = aabb.max[1];
|
vmin[1] = aabb.max[1];
|
||||||
vmax[1] = aabb.min[1];
|
vmax[1] = aabb.min[1];
|
||||||
}
|
}
|
||||||
/* Z axis */
|
/* Z axis */
|
||||||
if (plane.c >= 0) {
|
if (plane.c >= 0)
|
||||||
|
{
|
||||||
vmin[2] = aabb.min[2];
|
vmin[2] = aabb.min[2];
|
||||||
vmax[2] = aabb.max[2];
|
vmax[2] = aabb.max[2];
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
vmin[2] = aabb.max[2];
|
vmin[2] = aabb.max[2];
|
||||||
vmax[2] = aabb.min[2];
|
vmax[2] = aabb.min[2];
|
||||||
}
|
}
|
||||||
|
@ -122,7 +131,6 @@ public:
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif // CFRUSTUM_HPP
|
#endif // CFRUSTUM_HPP
|
||||||
|
|
|
@ -9,16 +9,13 @@ namespace zeus
|
||||||
class CLineSeg
|
class CLineSeg
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CLineSeg(const CVector3f& start, const CVector3f& end)
|
CLineSeg(const CVector3f& start, const CVector3f& end) : start(start), end(end)
|
||||||
: start(start),
|
|
||||||
end(end)
|
|
||||||
{
|
{
|
||||||
CVector3f tmp = (end - start).normalized();
|
CVector3f tmp = (end - start).normalized();
|
||||||
if (tmp.x != 0 || tmp.y != 0 || tmp.z != 0)
|
if (tmp.x != 0 || tmp.y != 0 || tmp.z != 0)
|
||||||
normal = tmp.normalized();
|
normal = tmp.normalized();
|
||||||
else
|
else
|
||||||
normal = CVector3f::skZero;
|
normal = CVector3f::skZero;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CVector3f normal;
|
CVector3f normal;
|
||||||
|
|
|
@ -8,21 +8,13 @@ namespace zeus
|
||||||
{
|
{
|
||||||
struct CMRay
|
struct CMRay
|
||||||
{
|
{
|
||||||
CMRay(const CVector3f& start, const CVector3f& end, float d)
|
CMRay(const CVector3f& start, const CVector3f& end, float d) : start(start), end(end), d(d), invD(1.f / d)
|
||||||
: start(start),
|
|
||||||
end(end),
|
|
||||||
d(d),
|
|
||||||
invD(1.f/d)
|
|
||||||
{
|
{
|
||||||
normal = start + (d * end);
|
normal = start + (d * end);
|
||||||
delta = normal - start;
|
delta = normal - start;
|
||||||
}
|
}
|
||||||
|
|
||||||
CMRay(const CVector3f& start, const CVector3f& norm, float d, float invD)
|
CMRay(const CVector3f& start, const CVector3f& norm, float d, float invD) : start(start), normal(norm), d(d), invD(invD)
|
||||||
: start(start),
|
|
||||||
normal(norm),
|
|
||||||
d(d),
|
|
||||||
invD(invD)
|
|
||||||
{
|
{
|
||||||
delta = normal - start;
|
delta = normal - start;
|
||||||
end = invD * delta;
|
end = invD * delta;
|
||||||
|
|
|
@ -25,9 +25,7 @@ public:
|
||||||
m[2][2] = 1.0;
|
m[2][2] = 1.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CMatrix3f(float m00, float m01, float m02,
|
CMatrix3f(float m00, float m01, float m02, float m10, float m11, float m12, float m20, float m21, float m22)
|
||||||
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][0] = m00, m[1][0] = m01, m[2][0] = m02;
|
||||||
m[0][1] = m10, m[1][1] = m11, m[2][1] = m12;
|
m[0][1] = m10, m[1][1] = m11, m[2][1] = m12;
|
||||||
|
@ -40,25 +38,44 @@ public:
|
||||||
m[1][1] = scaleVec[1];
|
m[1][1] = scaleVec[1];
|
||||||
m[2][2] = scaleVec[2];
|
m[2][2] = scaleVec[2];
|
||||||
}
|
}
|
||||||
CMatrix3f(float scale)
|
CMatrix3f(float scale) : CMatrix3f(CVector3f(scale)) {}
|
||||||
: CMatrix3f(CVector3f(scale)) {}
|
|
||||||
CMatrix3f(const CVector3f& r0, const CVector3f& r1, const CVector3f& r2)
|
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)
|
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__
|
#if __SSE__
|
||||||
CMatrix3f(const __m128& r0, const __m128& r1, const __m128& r2)
|
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
|
#endif
|
||||||
#if ZE_ATHENA_TYPES
|
#if ZE_ATHENA_TYPES
|
||||||
CMatrix3f(const atVec4f& r0, const atVec4f& r1, const atVec4f& r2)
|
CMatrix3f(const atVec4f& r0, const atVec4f& r1, const atVec4f& r2)
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#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
|
#else
|
||||||
vec[0].x = r0.vec[0]; vec[0].y = r0.vec[1]; vec[0].z = r0.vec[2];
|
vec[0].x = r0.vec[0];
|
||||||
vec[1].x = r1.vec[0]; vec[1].y = r1.vec[1]; vec[1].z = r1.vec[2];
|
vec[0].y = r0.vec[1];
|
||||||
vec[2].x = r2.vec[0]; vec[2].y = r2.vec[1]; vec[2].z = r2.vec[2];
|
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
|
#endif
|
||||||
}
|
}
|
||||||
void readBig(athena::io::IStreamReader& input)
|
void readBig(athena::io::IStreamReader& input)
|
||||||
|
@ -79,11 +96,19 @@ public:
|
||||||
CMatrix3f(const TVectorUnion& r0, const TVectorUnion& r1, const TVectorUnion& r2)
|
CMatrix3f(const TVectorUnion& r0, const TVectorUnion& r1, const TVectorUnion& r2)
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#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
|
#else
|
||||||
vec[0].x = r0.vec[0]; vec[0].y = r0.vec[1]; vec[0].z = r0.vec[2];
|
vec[0].x = r0.vec[0];
|
||||||
vec[1].x = r1.vec[0]; vec[1].y = r1.vec[1]; vec[1].z = r1.vec[2];
|
vec[0].y = r0.vec[1];
|
||||||
vec[2].x = r2.vec[0]; vec[2].y = r2.vec[1]; vec[2].z = r2.vec[2];
|
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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,9 +124,7 @@ public:
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
TVectorUnion res;
|
TVectorUnion res;
|
||||||
res.mVec128 =
|
res.mVec128 = _mm_add_ps(_mm_add_ps(_mm_mul_ps(vec[0].mVec128, ze_splat_ps(other.mVec128, 0)),
|
||||||
_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[1].mVec128, ze_splat_ps(other.mVec128, 1))),
|
||||||
_mm_mul_ps(vec[2].mVec128, ze_splat_ps(other.mVec128, 2)));
|
_mm_mul_ps(vec[2].mVec128, ze_splat_ps(other.mVec128, 2)));
|
||||||
return CVector3f(res.mVec128);
|
return CVector3f(res.mVec128);
|
||||||
|
@ -141,7 +164,7 @@ public:
|
||||||
CMatrix3f transposed() const;
|
CMatrix3f transposed() const;
|
||||||
CMatrix3f transposedSSE3() const;
|
CMatrix3f transposedSSE3() const;
|
||||||
|
|
||||||
inline void invert() {*this = inverted();}
|
inline void invert() { *this = inverted(); }
|
||||||
CMatrix3f inverted() const;
|
CMatrix3f inverted() const;
|
||||||
|
|
||||||
void addScaledMatrix(const CMatrix3f& other, float scale)
|
void addScaledMatrix(const CMatrix3f& other, float scale)
|
||||||
|
@ -152,8 +175,7 @@ public:
|
||||||
vec[2] += other.vec[2] * scaleVec;
|
vec[2] += other.vec[2] * scaleVec;
|
||||||
}
|
}
|
||||||
|
|
||||||
union
|
union {
|
||||||
{
|
|
||||||
float m[3][4]; /* 4th row for union-alignment */
|
float m[3][4]; /* 4th row for union-alignment */
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
|
@ -167,10 +189,9 @@ static CMatrix3f operator*(const CMatrix3f& lhs, const CMatrix3f& rhs)
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
unsigned i;
|
unsigned i;
|
||||||
TVectorUnion resVec[3];
|
TVectorUnion resVec[3];
|
||||||
for (i=0 ; i<3 ; ++i) {
|
for (i = 0; i < 3; ++i)
|
||||||
resVec[i].mVec128 =
|
{
|
||||||
_mm_add_ps(_mm_add_ps(
|
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[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[1].mVec128, ze_splat_ps(rhs[i].mVec128, 1))),
|
||||||
_mm_mul_ps(lhs[2].mVec128, ze_splat_ps(rhs[i].mVec128, 2)));
|
_mm_mul_ps(lhs[2].mVec128, ze_splat_ps(rhs[i].mVec128, 2)));
|
||||||
resVec[i].v[3] = 0.0;
|
resVec[i].v[3] = 0.0;
|
||||||
|
@ -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]);
|
lhs[0][2] * rhs[2][0] + lhs[1][2] * rhs[2][1] + lhs[2][2] * rhs[2][2]);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // CMATRIX3F_HPP
|
#endif // CMATRIX3F_HPP
|
||||||
|
|
|
@ -23,10 +23,8 @@ public:
|
||||||
m[3][3] = 1.0;
|
m[3][3] = 1.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CMatrix4f(float m00, float m01, float m02, float m03,
|
CMatrix4f(float m00, float m01, float m02, float m03, float m10, float m11, float m12, float m13, float m20, float m21,
|
||||||
float m10, float m11, float m12, float m13,
|
float m22, float m23, float m30, float m31, float m32, float m33)
|
||||||
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][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;
|
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;
|
m[3][3] = 1.0f;
|
||||||
}
|
}
|
||||||
CMatrix4f(const CVector4f& r0, const CVector4f& r1, const CVector4f& r2, const CVector4f& r3)
|
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)
|
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__
|
#if __SSE__
|
||||||
CMatrix4f(const __m128& r0, const __m128& r1, const __m128& r2, const __m128& r3)
|
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
|
#endif
|
||||||
CMatrix4f(const CMatrix3f& other)
|
CMatrix4f(const CMatrix3f& other)
|
||||||
{
|
{
|
||||||
|
@ -76,8 +89,7 @@ public:
|
||||||
|
|
||||||
return CVector4f(res.mVec128);
|
return CVector4f(res.mVec128);
|
||||||
#else
|
#else
|
||||||
return CVector4f(
|
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][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][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][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]);
|
m[0][3] * other.v[0] + m[1][3] * other.v[1] + m[2][3] * other.v[2] + m[3][3] * other.v[3]);
|
||||||
|
@ -105,8 +117,7 @@ public:
|
||||||
return xfVec.toVec3f() / xfVec.w;
|
return xfVec.toVec3f() / xfVec.w;
|
||||||
}
|
}
|
||||||
|
|
||||||
union
|
union {
|
||||||
{
|
|
||||||
float m[4][4];
|
float m[4][4];
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
|
@ -120,13 +131,15 @@ static inline CMatrix4f operator*(const CMatrix4f& lhs, const CMatrix4f& rhs)
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
unsigned i;
|
unsigned i;
|
||||||
|
|
||||||
for (i = 0 ; i < 4 ; ++i)
|
for (i = 0; i < 4; ++i)
|
||||||
{
|
{
|
||||||
ret.vec[i].mVec128 =
|
ret.vec[i].mVec128 = _mm_add_ps(
|
||||||
_mm_add_ps(_mm_add_ps(_mm_add_ps(
|
_mm_add_ps(_mm_add_ps(_mm_mul_ps(lhs.vec[0].mVec128,
|
||||||
_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_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[1].mVec128,
|
||||||
_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_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))));
|
_mm_mul_ps(lhs.vec[3].mVec128, _mm_shuffle_ps(rhs.vec[i].mVec128, rhs.vec[i].mVec128, _MM_SHUFFLE(3, 3, 3, 3))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,4 +169,3 @@ static inline CMatrix4f operator*(const CMatrix4f& lhs, const CMatrix4f& rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // CMATRIX4F
|
#endif // CMATRIX4F
|
||||||
|
|
||||||
|
|
|
@ -30,36 +30,19 @@ public:
|
||||||
CTransform transform;
|
CTransform transform;
|
||||||
CVector3f extents;
|
CVector3f extents;
|
||||||
|
|
||||||
COBBox()
|
COBBox() {}
|
||||||
{}
|
|
||||||
|
|
||||||
COBBox(const CAABox& aabb)
|
COBBox(const CAABox& aabb) : extents(aabb.volume()) { transform.origin = aabb.center(); }
|
||||||
: extents(aabb.volume())
|
|
||||||
{
|
|
||||||
transform.origin = aabb.center();
|
|
||||||
}
|
|
||||||
|
|
||||||
COBBox(const CTransform& xf, const CVector3f& extents)
|
COBBox(const CTransform& xf, const CVector3f& extents) : transform(xf), extents(extents) {}
|
||||||
: transform(xf),
|
|
||||||
extents(extents)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
CAABox calculateAABox(const CTransform& transform = CTransform()) const
|
CAABox calculateAABox(const CTransform& transform = CTransform()) const
|
||||||
{
|
{
|
||||||
CAABox ret = CAABox::skInvertedBox;
|
CAABox ret = CAABox::skInvertedBox;
|
||||||
|
|
||||||
CTransform trans = transform * transform;
|
CTransform trans = transform * transform;
|
||||||
static const CVector3f basis[8] ={
|
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}, {-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];
|
CVector3f p = extents * basis[0];
|
||||||
|
|
||||||
ret.accumulateBounds(trans * p);
|
ret.accumulateBounds(trans * p);
|
||||||
|
|
|
@ -27,7 +27,9 @@ public:
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
mVec128 = point.mVec128;
|
mVec128 = point.mVec128;
|
||||||
#else
|
#else
|
||||||
a = point[0]; b = point[1]; c = point[2];
|
a = point[0];
|
||||||
|
b = point[1];
|
||||||
|
c = point[2];
|
||||||
#endif
|
#endif
|
||||||
d = displacement;
|
d = displacement;
|
||||||
}
|
}
|
||||||
|
@ -48,8 +50,7 @@ public:
|
||||||
d = nd * mag;
|
d = nd * mag;
|
||||||
}
|
}
|
||||||
|
|
||||||
union
|
union {
|
||||||
{
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
float a, b, c, d;
|
float a, b, c, d;
|
||||||
|
|
|
@ -22,21 +22,26 @@ class SProjOrtho
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
float top, bottom, left, right, near, far;
|
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,
|
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) :
|
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) {}
|
: top(p_top), bottom(p_bottom), left(p_left), right(p_right), near(p_near), far(p_far)
|
||||||
|
{
|
||||||
|
}
|
||||||
};
|
};
|
||||||
struct SProjPersp
|
struct SProjPersp
|
||||||
{
|
{
|
||||||
float fov, aspect, near, far;
|
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) :
|
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) {}
|
: fov(p_fov), aspect(p_aspect), near(p_near), far(p_far)
|
||||||
|
{
|
||||||
|
}
|
||||||
};
|
};
|
||||||
extern const SProjOrtho kOrthoIdentity;
|
extern const SProjOrtho kOrthoIdentity;
|
||||||
|
|
||||||
class alignas(16) CProjection
|
class alignas(16) CProjection
|
||||||
{
|
{
|
||||||
void _updateCachedMatrix();
|
void _updateCachedMatrix();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ZE_DECLARE_ALIGNED_ALLOCATOR();
|
ZE_DECLARE_ALIGNED_ALLOCATOR();
|
||||||
|
|
||||||
|
@ -46,9 +51,9 @@ public:
|
||||||
m_ortho = SProjOrtho();
|
m_ortho = SProjOrtho();
|
||||||
m_mtx = CMatrix4f::skIdentityMatrix4f;
|
m_mtx = CMatrix4f::skIdentityMatrix4f;
|
||||||
}
|
}
|
||||||
CProjection(const CProjection& other) {*this = other;}
|
CProjection(const CProjection& other) { *this = other; }
|
||||||
CProjection(const SProjOrtho& ortho) {setOrtho(ortho);}
|
CProjection(const SProjOrtho& ortho) { setOrtho(ortho); }
|
||||||
CProjection(const SProjPersp& persp) {setPersp(persp);}
|
CProjection(const SProjPersp& persp) { setPersp(persp); }
|
||||||
|
|
||||||
inline CProjection& operator=(const CProjection& other)
|
inline CProjection& operator=(const CProjection& other)
|
||||||
{
|
{
|
||||||
|
@ -62,11 +67,19 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void setOrtho(const SProjOrtho& ortho)
|
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)
|
inline void setPersp(const SProjPersp& persp)
|
||||||
{m_projType = EProjType::Perspective; m_persp = persp; _updateCachedMatrix();}
|
{
|
||||||
|
m_projType = EProjType::Perspective;
|
||||||
|
m_persp = persp;
|
||||||
|
_updateCachedMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
inline EProjType getType() const {return m_projType;}
|
inline EProjType getType() const { return m_projType; }
|
||||||
inline const SProjOrtho& getOrtho() const
|
inline const SProjOrtho& getOrtho() const
|
||||||
{
|
{
|
||||||
if (m_projType != EProjType::Orthographic)
|
if (m_projType != EProjType::Orthographic)
|
||||||
|
@ -86,16 +99,14 @@ public:
|
||||||
return m_persp;
|
return m_persp;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const CMatrix4f& getCachedMatrix() const {return m_mtx;}
|
inline const CMatrix4f& getCachedMatrix() const { return m_mtx; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
/* Projection type */
|
/* Projection type */
|
||||||
EProjType m_projType;
|
EProjType m_projType;
|
||||||
|
|
||||||
/* Projection intermediate */
|
/* Projection intermediate */
|
||||||
union
|
union {
|
||||||
{
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
|
@ -113,7 +124,6 @@ protected:
|
||||||
|
|
||||||
/* Cached projection matrix */
|
/* Cached projection matrix */
|
||||||
CMatrix4f m_mtx;
|
CMatrix4f m_mtx;
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,10 @@ public:
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
mVec128 = vec.mVec128;
|
mVec128 = vec.mVec128;
|
||||||
#else
|
#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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,7 +119,10 @@ public:
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
mVec128 = vec.mVec128;
|
mVec128 = vec.mVec128;
|
||||||
#else
|
#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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,7 +171,6 @@ public:
|
||||||
void rotateY(float angle) { *this *= fromAxisAngle({0.0f, 1.0f, 0.0f}, angle); }
|
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); }
|
void rotateZ(float angle) { *this *= fromAxisAngle({0.0f, 0.0f, 1.0f}, angle); }
|
||||||
|
|
||||||
|
|
||||||
CAxisAngle toAxisAngle();
|
CAxisAngle toAxisAngle();
|
||||||
|
|
||||||
static inline CVector3f rotate(const CQuaternion& rotation, const CVector3f& v)
|
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 slerp(const CQuaternion& a, const CQuaternion& b, double t);
|
||||||
static CQuaternion nlerp(const CQuaternion& a, const CQuaternion& b, double t);
|
static CQuaternion nlerp(const CQuaternion& a, const CQuaternion& b, double t);
|
||||||
|
|
||||||
inline float roll() const
|
inline float roll() const { return std::atan2(2.f * (x * y + w * z), w * w + x * x - y * y - z * z); }
|
||||||
{
|
|
||||||
return std::atan2(2.f * (x * y + w * z), w * w + x * x - y * y - z * z);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline float pitch() const
|
inline float pitch() const { return std::atan2(2.f * (y * z + w * x), w * w - x * x - y * y + z * z); }
|
||||||
{
|
|
||||||
return std::atan2(2.f * (y * z + w * x), w * w - x * x - y * y + z * z);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline float yaw() const
|
inline float yaw() const { return std::asin(-2.f * (x * z - w * y)); }
|
||||||
{
|
|
||||||
return std::asin(-2.f * (x * z - w * y));
|
|
||||||
}
|
|
||||||
|
|
||||||
inline float& operator[](size_t idx) {return (&w)[idx];}
|
inline float& operator[](size_t idx) { return (&w)[idx]; }
|
||||||
inline const float& operator[](size_t idx) const {return (&w)[idx];}
|
inline const float& operator[](size_t idx) const { return (&w)[idx]; }
|
||||||
|
|
||||||
union
|
union {
|
||||||
{
|
|
||||||
__m128 mVec128;
|
__m128 mVec128;
|
||||||
struct { float w, x, y, z; };
|
struct
|
||||||
|
{
|
||||||
|
float w, x, y, z;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
static const CQuaternion skNoRotation;
|
static const CQuaternion skNoRotation;
|
||||||
|
|
|
@ -21,10 +21,8 @@ public:
|
||||||
|
|
||||||
inline bool intersects(const CRectangle& rect) const
|
inline bool intersects(const CRectangle& rect) const
|
||||||
{
|
{
|
||||||
return !( position.x > rect.position.x + rect.size.x ||
|
return !(position.x > rect.position.x + rect.size.x || rect.position.x > position.x + size.x ||
|
||||||
rect.position.x > position.x + size.x ||
|
position.y > rect.position.y + rect.size.y || rect.position.y > position.y + size.y);
|
||||||
position.y > rect.position.y + rect.size.y ||
|
|
||||||
rect.position.y > position.y + size.y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CVector2f position;
|
CVector2f position;
|
||||||
|
|
|
@ -23,10 +23,7 @@ public:
|
||||||
z = degToRad(angles.z);
|
z = degToRad(angles.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
CRelAngle(float x, float y, float z)
|
CRelAngle(float x, float y, float z) : CRelAngle(CVector3f{x, y, z}) {}
|
||||||
: CRelAngle(CVector3f{x, y, z})
|
|
||||||
{
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,11 +10,9 @@ class alignas(16) CSphere
|
||||||
public:
|
public:
|
||||||
ZE_DECLARE_ALIGNED_ALLOCATOR();
|
ZE_DECLARE_ALIGNED_ALLOCATOR();
|
||||||
|
|
||||||
CSphere(const CVector3f& position, float radius)
|
CSphere(const CVector3f& position, float radius) : position(position), radius(radius) {}
|
||||||
: position(position), radius(radius) { }
|
|
||||||
|
|
||||||
inline CVector3f getSurfaceNormal(const CVector3f& coord)
|
inline CVector3f getSurfaceNormal(const CVector3f& coord) { return (position - coord).normalized(); }
|
||||||
{ return (position - coord).normalized(); }
|
|
||||||
|
|
||||||
inline bool intersects(const CSphere& other)
|
inline bool intersects(const CSphere& other)
|
||||||
{
|
{
|
||||||
|
|
|
@ -15,11 +15,9 @@ public:
|
||||||
ZE_DECLARE_ALIGNED_ALLOCATOR();
|
ZE_DECLARE_ALIGNED_ALLOCATOR();
|
||||||
|
|
||||||
CTransform() : basis(false) {}
|
CTransform() : basis(false) {}
|
||||||
CTransform(const CMatrix3f& basis, const CVector3f& offset=CVector3f::skZero) :
|
CTransform(const CMatrix3f& basis, const CVector3f& offset = CVector3f::skZero) : basis(basis), origin(offset) {}
|
||||||
basis(basis), origin(offset) {}
|
|
||||||
#if ZE_ATHENA_TYPES
|
#if ZE_ATHENA_TYPES
|
||||||
CTransform(const atVec4f* mtx)
|
CTransform(const atVec4f* mtx) : basis(mtx[0], mtx[1], mtx[2]), origin(mtx[0].vec[3], mtx[1].vec[3], mtx[2].vec[3]) {}
|
||||||
: 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)
|
void read34RowMajor(athena::io::IStreamReader& r)
|
||||||
{
|
{
|
||||||
|
@ -32,13 +30,12 @@ public:
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static inline CTransform Identity()
|
static inline CTransform Identity() { return CTransform(CMatrix3f::skIdentityMatrix3f); }
|
||||||
{
|
|
||||||
return CTransform(CMatrix3f::skIdentityMatrix3f);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline CTransform operator*(const CTransform& rhs) const
|
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
|
inline CTransform inverse() const
|
||||||
{
|
{
|
||||||
|
@ -46,17 +43,11 @@ public:
|
||||||
return CTransform(inv, inv * -origin);
|
return CTransform(inv, inv * -origin);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline CTransform Translate(const CVector3f& position)
|
static inline CTransform Translate(const CVector3f& position) { return {CMatrix3f::skIdentityMatrix3f, position}; }
|
||||||
{
|
|
||||||
return {CMatrix3f::skIdentityMatrix3f, position};
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline CTransform Translate(float x, float y, float z) { return Translate({x, y, z}); }
|
static inline CTransform Translate(float x, float y, float z) { return Translate({x, y, z}); }
|
||||||
|
|
||||||
inline CTransform operator+(const CVector3f& other)
|
inline CTransform operator+(const CVector3f& other) { return CTransform(basis, origin + other); }
|
||||||
{
|
|
||||||
return CTransform(basis, origin + other);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline CTransform& operator+=(const CVector3f& other)
|
inline CTransform& operator+=(const CVector3f& other)
|
||||||
{
|
{
|
||||||
|
@ -64,10 +55,7 @@ public:
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline CTransform operator-(const CVector3f& other)
|
inline CTransform operator-(const CVector3f& other) { return CTransform(basis, origin - other); }
|
||||||
{
|
|
||||||
return CTransform(basis, origin - other);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline CTransform& operator-=(const CVector3f& other)
|
inline CTransform& operator-=(const CVector3f& other)
|
||||||
{
|
{
|
||||||
|
@ -81,8 +69,7 @@ public:
|
||||||
{
|
{
|
||||||
float sinT = std::sin(theta);
|
float sinT = std::sin(theta);
|
||||||
float cosT = std::cos(theta);
|
float cosT = std::cos(theta);
|
||||||
return CTransform(CMatrix3f(TVectorUnion{1.f, 0.f, 0.f, 0.f},
|
return CTransform(CMatrix3f(TVectorUnion{1.f, 0.f, 0.f, 0.f}, TVectorUnion{0.f, cosT, sinT, 0.f},
|
||||||
TVectorUnion{0.f, cosT, sinT, 0.f},
|
|
||||||
TVectorUnion{0.f, -sinT, cosT, 0.f}));
|
TVectorUnion{0.f, -sinT, cosT, 0.f}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,8 +77,7 @@ public:
|
||||||
{
|
{
|
||||||
float sinT = std::sin(theta);
|
float sinT = std::sin(theta);
|
||||||
float cosT = std::cos(theta);
|
float cosT = std::cos(theta);
|
||||||
return CTransform(CMatrix3f(TVectorUnion{cosT, 0.f, -sinT, 0.f},
|
return CTransform(CMatrix3f(TVectorUnion{cosT, 0.f, -sinT, 0.f}, TVectorUnion{0.f, 1.f, 0.f, 0.f},
|
||||||
TVectorUnion{0.f, 1.f, 0.f, 0.f},
|
|
||||||
TVectorUnion{sinT, 0.f, cosT, 0.f}));
|
TVectorUnion{sinT, 0.f, cosT, 0.f}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,8 +85,7 @@ public:
|
||||||
{
|
{
|
||||||
float sinT = std::sin(theta);
|
float sinT = std::sin(theta);
|
||||||
float cosT = std::cos(theta);
|
float cosT = std::cos(theta);
|
||||||
return CTransform(CMatrix3f(TVectorUnion{cosT, sinT, 0.f, 0.f},
|
return CTransform(CMatrix3f(TVectorUnion{cosT, sinT, 0.f, 0.f}, TVectorUnion{-sinT, cosT, 0.f, 0.f},
|
||||||
TVectorUnion{-sinT, cosT, 0.f, 0.f},
|
|
||||||
TVectorUnion{0.f, 0.f, 1.f, 0.f}));
|
TVectorUnion{0.f, 0.f, 1.f, 0.f}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,26 +143,26 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void scaleBy(float factor)
|
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)
|
static inline CTransform Scale(const CVector3f& factor)
|
||||||
{
|
{
|
||||||
return CTransform(CMatrix3f(TVectorUnion{factor.x, 0.f, 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, factor.y, 0.f, 0.f},
|
|
||||||
TVectorUnion{0.f, 0.f, factor.z, 0.f}));
|
TVectorUnion{0.f, 0.f, factor.z, 0.f}));
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline CTransform Scale(float x, float y, float z)
|
static inline CTransform Scale(float x, float y, float z)
|
||||||
{
|
{
|
||||||
return CTransform(CMatrix3f(TVectorUnion{x, 0.f, 0.f, 0.f},
|
return CTransform(
|
||||||
TVectorUnion{0.f, y, 0.f, 0.f},
|
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}));
|
||||||
TVectorUnion{0.f, 0.f, z, 0.f}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline CTransform Scale(float factor)
|
static inline CTransform Scale(float factor)
|
||||||
{
|
{
|
||||||
return CTransform(CMatrix3f(TVectorUnion{factor, 0.f, 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, factor, 0.f, 0.f},
|
|
||||||
TVectorUnion{0.f, 0.f, factor, 0.f}));
|
TVectorUnion{0.f, 0.f, factor, 0.f}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,7 +173,12 @@ public:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline CTransform getRotation() const { CTransform ret = *this; ret.origin.zeroOut(); return ret; }
|
inline CTransform getRotation() const
|
||||||
|
{
|
||||||
|
CTransform ret = *this;
|
||||||
|
ret.origin.zeroOut();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
void setRotation(const CMatrix3f& mat) { basis = mat; }
|
void setRotation(const CMatrix3f& mat) { basis = mat; }
|
||||||
void setRotation(const CTransform& xfrm) { setRotation(xfrm.basis); }
|
void setRotation(const CTransform& xfrm) { setRotation(xfrm.basis); }
|
||||||
|
|
||||||
|
@ -199,7 +189,7 @@ public:
|
||||||
*/
|
*/
|
||||||
inline CMatrix3f buildMatrix3f() { return basis; }
|
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
|
inline CMatrix4f toMatrix4f() const
|
||||||
{
|
{
|
||||||
|
@ -241,14 +231,11 @@ public:
|
||||||
CVector3f origin;
|
CVector3f origin;
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline CTransform CTransformFromScaleVector(const CVector3f& scale)
|
static inline CTransform CTransformFromScaleVector(const CVector3f& scale) { return CTransform(CMatrix3f(scale)); }
|
||||||
{
|
|
||||||
return CTransform(CMatrix3f(scale));
|
|
||||||
}
|
|
||||||
CTransform CTransformFromEditorEuler(const CVector3f& eulerVec);
|
CTransform CTransformFromEditorEuler(const CVector3f& eulerVec);
|
||||||
CTransform CTransformFromEditorEulers(const CVector3f& eulerVec, const CVector3f& origin);
|
CTransform CTransformFromEditorEulers(const CVector3f& eulerVec, const CVector3f& origin);
|
||||||
CTransform CTransformFromAxisAngle(const CVector3f& axis, float angle);
|
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
|
#endif // CTRANSFORM_HPP
|
||||||
|
|
|
@ -10,13 +10,9 @@ class alignas(16) CUnitVector3f : public CVector3f
|
||||||
public:
|
public:
|
||||||
ZE_DECLARE_ALIGNED_ALLOCATOR();
|
ZE_DECLARE_ALIGNED_ALLOCATOR();
|
||||||
|
|
||||||
CUnitVector3f()
|
CUnitVector3f() : CVector3f(0, 1, 0) {}
|
||||||
: CVector3f(0, 1, 0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
CUnitVector3f(const CVector3f& vec, bool doNormalize = false)
|
CUnitVector3f(const CVector3f& vec, bool doNormalize = false) : CVector3f(vec)
|
||||||
: CVector3f(vec)
|
|
||||||
{
|
{
|
||||||
if (doNormalize && canBeNormalized())
|
if (doNormalize && canBeNormalized())
|
||||||
normalize();
|
normalize();
|
||||||
|
|
|
@ -20,9 +20,8 @@ class alignas(16) CVector2f
|
||||||
float clangVec __attribute__((__vector_size__(8)));
|
float clangVec __attribute__((__vector_size__(8)));
|
||||||
#endif
|
#endif
|
||||||
public:
|
public:
|
||||||
//ZE_DECLARE_ALIGNED_ALLOCATOR();
|
// ZE_DECLARE_ALIGNED_ALLOCATOR();
|
||||||
union
|
union {
|
||||||
{
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
float x, y;
|
float x, y;
|
||||||
|
@ -33,14 +32,20 @@ public:
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
inline CVector2f() {zeroOut();}
|
inline CVector2f() { zeroOut(); }
|
||||||
#if __SSE__
|
#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
|
#endif
|
||||||
#if ZE_ATHENA_TYPES
|
#if ZE_ATHENA_TYPES
|
||||||
CVector2f(const atVec2f& vec)
|
CVector2f(const atVec2f& vec)
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
: mVec128(vec.mVec128){}
|
: mVec128(vec.mVec128)
|
||||||
|
{
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
{
|
{
|
||||||
x = vec.vec[0], y = vec.vec[1], v[2] = 0.0f, v[3] = 0.0f;
|
x = vec.vec[0], y = vec.vec[1], v[2] = 0.0f, v[3] = 0.0f;
|
||||||
|
@ -77,15 +82,19 @@ public:
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
CVector2f(float xy) {splat(xy);}
|
CVector2f(float xy) { splat(xy); }
|
||||||
void assign(float x, float y) {v[0] = x; v[1] = y; v[2] = 0; v[3] = 0.0f;}
|
void assign(float x, float y)
|
||||||
CVector2f(float x, float y) {assign(x, 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
|
inline bool operator==(const CVector2f& rhs) const { return (x == rhs.x && y == rhs.y); }
|
||||||
{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 !(*this == rhs);}
|
|
||||||
inline bool operator <(const CVector2f& rhs) const
|
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
TVectorUnion vec;
|
TVectorUnion vec;
|
||||||
|
@ -95,7 +104,7 @@ public:
|
||||||
return (x < rhs.x || y < rhs.y);
|
return (x < rhs.x || y < rhs.y);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
inline bool operator <=(const CVector2f& rhs) const
|
inline bool operator<=(const CVector2f& rhs) const
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
TVectorUnion vec;
|
TVectorUnion vec;
|
||||||
|
@ -105,7 +114,7 @@ public:
|
||||||
return (x <= rhs.x || y <= rhs.y);
|
return (x <= rhs.x || y <= rhs.y);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
inline bool operator >(const CVector2f& rhs) const
|
inline bool operator>(const CVector2f& rhs) const
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
TVectorUnion vec;
|
TVectorUnion vec;
|
||||||
|
@ -115,7 +124,7 @@ public:
|
||||||
return (x > rhs.x || y > rhs.y);
|
return (x > rhs.x || y > rhs.y);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
inline bool operator >=(const CVector2f& rhs) const
|
inline bool operator>=(const CVector2f& rhs) const
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
TVectorUnion vec;
|
TVectorUnion vec;
|
||||||
|
@ -202,39 +211,43 @@ public:
|
||||||
return CVector2f(x / val, y / val);
|
return CVector2f(x / val, y / val);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
inline const CVector2f& operator +=(const CVector2f& rhs)
|
inline const CVector2f& operator+=(const CVector2f& rhs)
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
mVec128 = _mm_add_ps(mVec128, rhs.mVec128);
|
mVec128 = _mm_add_ps(mVec128, rhs.mVec128);
|
||||||
#else
|
#else
|
||||||
x += rhs.x; y += rhs.y;
|
x += rhs.x;
|
||||||
|
y += rhs.y;
|
||||||
#endif
|
#endif
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
inline const CVector2f& operator -=(const CVector2f& rhs)
|
inline const CVector2f& operator-=(const CVector2f& rhs)
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
mVec128 = _mm_sub_ps(mVec128, rhs.mVec128);
|
mVec128 = _mm_sub_ps(mVec128, rhs.mVec128);
|
||||||
#else
|
#else
|
||||||
x -= rhs.x; y -= rhs.y;
|
x -= rhs.x;
|
||||||
|
y -= rhs.y;
|
||||||
#endif
|
#endif
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
inline const CVector2f& operator *=(const CVector2f& rhs)
|
inline const CVector2f& operator*=(const CVector2f& rhs)
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
mVec128 = _mm_mul_ps(mVec128, rhs.mVec128);
|
mVec128 = _mm_mul_ps(mVec128, rhs.mVec128);
|
||||||
#else
|
#else
|
||||||
x *= rhs.x; y *= rhs.y;
|
x *= rhs.x;
|
||||||
|
y *= rhs.y;
|
||||||
#endif
|
#endif
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
inline const CVector2f& operator /=(const CVector2f& rhs)
|
inline const CVector2f& operator/=(const CVector2f& rhs)
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
mVec128 = _mm_div_ps(mVec128, rhs.mVec128);
|
mVec128 = _mm_div_ps(mVec128, rhs.mVec128);
|
||||||
#else
|
#else
|
||||||
x /= rhs.x; y /= rhs.y;
|
x /= rhs.x;
|
||||||
|
y /= rhs.y;
|
||||||
#endif
|
#endif
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -252,15 +265,9 @@ public:
|
||||||
return *this * mag;
|
return *this * mag;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline CVector2f perpendicularVector() const
|
inline CVector2f perpendicularVector() const { return {-y, x}; }
|
||||||
{
|
|
||||||
return {-y, x};
|
|
||||||
}
|
|
||||||
|
|
||||||
inline float cross(const CVector2f& rhs) const
|
inline float cross(const CVector2f& rhs) const { return (x * rhs.y) - (y * rhs.x); }
|
||||||
{
|
|
||||||
return (x * rhs.y) - (y * rhs.x);
|
|
||||||
}
|
|
||||||
inline float dot(const CVector2f& rhs) const
|
inline float dot(const CVector2f& rhs) const
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
|
@ -292,18 +299,20 @@ public:
|
||||||
result.mVec128 = _mm_mul_ps(mVec128, mVec128);
|
result.mVec128 = _mm_mul_ps(mVec128, mVec128);
|
||||||
return result.v[0] + result.v[1];
|
return result.v[0] + result.v[1];
|
||||||
#else
|
#else
|
||||||
return x*x + y*y;
|
return x * x + y * y;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
inline float magnitude() const
|
inline float magnitude() const { return sqrtF(magSquared()); }
|
||||||
{ return sqrtF(magSquared()); }
|
|
||||||
|
|
||||||
inline void zeroOut()
|
inline void zeroOut()
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
mVec128 = _mm_xor_ps(mVec128, mVec128);
|
mVec128 = _mm_xor_ps(mVec128, mVec128);
|
||||||
#else
|
#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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -313,47 +322,39 @@ public:
|
||||||
TVectorUnion splat = {{xy, xy, 0.0f, 0.0f}};
|
TVectorUnion splat = {{xy, xy, 0.0f, 0.0f}};
|
||||||
mVec128 = splat.mVec128;
|
mVec128 = splat.mVec128;
|
||||||
#else
|
#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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static float getAngleDiff(const CVector2f& a, const CVector2f& b);
|
static float getAngleDiff(const CVector2f& a, const CVector2f& b);
|
||||||
|
|
||||||
static inline CVector2f lerp(const CVector2f& a, const CVector2f& b, float t)
|
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(); }
|
||||||
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);
|
static CVector2f slerp(const CVector2f& a, const CVector2f& b, float t);
|
||||||
|
|
||||||
inline bool isNormalized() const
|
inline bool isNormalized() const { return std::fabs(1.f - magSquared()) < 0.01f; }
|
||||||
{ return std::fabs(1.f - magSquared()) < 0.01f; }
|
|
||||||
|
|
||||||
inline bool canBeNormalized() const
|
inline bool canBeNormalized() const { return !isNormalized(); }
|
||||||
{ return !isNormalized(); }
|
|
||||||
|
|
||||||
inline bool isZero() const
|
inline bool isZero() const { return magSquared() <= 1.1920929e-7f; }
|
||||||
{ 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;
|
const CVector2f diffVec = other - *this;
|
||||||
return (diffVec.x <= epsilon && diffVec.y <= epsilon);
|
return (diffVec.x <= epsilon && diffVec.y <= epsilon);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline float& operator[](size_t idx) {return (&x)[idx];}
|
inline float& operator[](size_t idx) { return (&x)[idx]; }
|
||||||
inline const float& operator[](size_t idx) const {return (&x)[idx];}
|
inline const float& operator[](size_t idx) const { return (&x)[idx]; }
|
||||||
|
|
||||||
|
|
||||||
static const CVector2f skOne;
|
static const CVector2f skOne;
|
||||||
static const CVector2f skNegOne;
|
static const CVector2f skNegOne;
|
||||||
static const CVector2f skZero;
|
static const CVector2f skZero;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static inline CVector2f operator+(float lhs, const CVector2f& rhs)
|
static inline CVector2f operator+(float lhs, const CVector2f& rhs)
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
|
|
|
@ -14,8 +14,7 @@ namespace zeus
|
||||||
class CVector2i
|
class CVector2i
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
union
|
union {
|
||||||
{
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
int x, y;
|
int x, y;
|
||||||
|
@ -25,7 +24,6 @@ public:
|
||||||
CVector2i() = default;
|
CVector2i() = default;
|
||||||
CVector2i(int xin, int yin) : x(xin), y(yin) {}
|
CVector2i(int xin, int yin) : x(xin), y(yin) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // CVECTOR2i_HPP
|
#endif // CVECTOR2i_HPP
|
||||||
|
|
|
@ -36,16 +36,23 @@ public:
|
||||||
CVector3d(double xyz) { splat(xyz); }
|
CVector3d(double xyz) { splat(xyz); }
|
||||||
|
|
||||||
CVector3d(const CVector3f& vec)
|
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)
|
CVector3d(double x, double y, double z)
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
TDblVectorUnion splat {x, y, z, 0.0};
|
TDblVectorUnion splat{x, y, z, 0.0};
|
||||||
mVec128[0] = splat.mVec128[0];
|
mVec128[0] = splat.mVec128[0];
|
||||||
mVec128[1] = splat.mVec128[1];
|
mVec128[1] = splat.mVec128[1];
|
||||||
#else
|
#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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,13 +81,15 @@ public:
|
||||||
result.mVec128[1] = _mm_mul_pd(mVec128[1], mVec128[1]);
|
result.mVec128[1] = _mm_mul_pd(mVec128[1], mVec128[1]);
|
||||||
return result.v[0] + result.v[1] + result.v[2];
|
return result.v[0] + result.v[1] + result.v[2];
|
||||||
#else
|
#else
|
||||||
return x*x + y*y + z*z;
|
return x * x + y * y + z * z;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
double magnitude() const { return sqrt(magSquared()); }
|
double magnitude() const { return sqrt(magSquared()); }
|
||||||
inline CVector3d cross(const CVector3d& rhs) const
|
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
|
double dot(const CVector3d& rhs) const
|
||||||
{
|
{
|
||||||
|
@ -111,7 +120,6 @@ public:
|
||||||
return {x * mag, y * mag, z * mag};
|
return {x * mag, y * mag, z * mag};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void splat(double xyz)
|
void splat(double xyz)
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
|
@ -119,7 +127,10 @@ public:
|
||||||
mVec128[0] = splat.mVec128[0];
|
mVec128[0] = splat.mVec128[0];
|
||||||
mVec128[1] = splat.mVec128[1];
|
mVec128[1] = splat.mVec128[1];
|
||||||
#else
|
#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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,13 +140,18 @@ public:
|
||||||
_mm_xor_pd(mVec128[0], mVec128[0]);
|
_mm_xor_pd(mVec128[0], mVec128[0]);
|
||||||
_mm_xor_pd(mVec128[1], mVec128[1]);
|
_mm_xor_pd(mVec128[1], mVec128[1]);
|
||||||
#else
|
#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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
union
|
union {
|
||||||
|
struct
|
||||||
{
|
{
|
||||||
struct {double x, y, z; };
|
double x, y, z;
|
||||||
|
};
|
||||||
double v[4];
|
double v[4];
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
__m128d mVec128[2];
|
__m128d mVec128[2];
|
||||||
|
@ -143,11 +159,10 @@ public:
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static inline CVector3d operator+(double lhs, const CVector3d& rhs)
|
static inline CVector3d operator+(double lhs, const CVector3d& rhs)
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#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[0] = _mm_add_pd(splat.mVec128[0], rhs.mVec128[0]);
|
||||||
splat.mVec128[1] = _mm_add_pd(splat.mVec128[1], rhs.mVec128[1]);
|
splat.mVec128[1] = _mm_add_pd(splat.mVec128[1], rhs.mVec128[1]);
|
||||||
return {splat.mVec128};
|
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)
|
static inline CVector3d operator*(double lhs, const CVector3d& rhs)
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#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[0] = _mm_mul_pd(splat.mVec128[0], rhs.mVec128[0]);
|
||||||
splat.mVec128[1] = _mm_mul_pd(splat.mVec128[1], rhs.mVec128[1]);
|
splat.mVec128[1] = _mm_mul_pd(splat.mVec128[1], rhs.mVec128[1]);
|
||||||
return {splat.mVec128};
|
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)
|
static inline CVector3d operator/(double lhs, const CVector3d& rhs)
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#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[0] = _mm_div_pd(splat.mVec128[0], rhs.mVec128[0]);
|
||||||
splat.mVec128[1] = _mm_div_pd(splat.mVec128[1], rhs.mVec128[1]);
|
splat.mVec128[1] = _mm_div_pd(splat.mVec128[1], rhs.mVec128[1]);
|
||||||
return {splat.mVec128};
|
return {splat.mVec128};
|
||||||
|
|
|
@ -19,9 +19,11 @@ class alignas(16) CVector3f
|
||||||
public:
|
public:
|
||||||
ZE_DECLARE_ALIGNED_ALLOCATOR();
|
ZE_DECLARE_ALIGNED_ALLOCATOR();
|
||||||
|
|
||||||
union
|
union {
|
||||||
|
struct
|
||||||
{
|
{
|
||||||
struct { float x, y, z; };
|
float x, y, z;
|
||||||
|
};
|
||||||
float v[4];
|
float v[4];
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
__m128 mVec128;
|
__m128 mVec128;
|
||||||
|
@ -30,15 +32,17 @@ public:
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
inline CVector3f() {zeroOut();}
|
inline CVector3f() { zeroOut(); }
|
||||||
#if __SSE__ || __GEKKO_PS__
|
#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
|
#endif
|
||||||
|
|
||||||
#if ZE_ATHENA_TYPES
|
#if ZE_ATHENA_TYPES
|
||||||
CVector3f(const atVec3f& vec)
|
CVector3f(const atVec3f& vec)
|
||||||
#if __SSE__ || __GEKKO_PS__
|
#if __SSE__ || __GEKKO_PS__
|
||||||
: mVec128(vec.mVec128){}
|
: mVec128(vec.mVec128)
|
||||||
|
{
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
{
|
{
|
||||||
x = vec.vec[0], y = vec.vec[1], z = vec.vec[2], v[3] = 0.0f;
|
x = vec.vec[0], y = vec.vec[1], z = vec.vec[2], v[3] = 0.0f;
|
||||||
|
@ -82,9 +86,15 @@ public:
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
CVector3f(float xyz) {splat(xyz);}
|
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;}
|
void assign(float x, float y, float z)
|
||||||
CVector3f(float x, float y, float z) {assign(x, y, 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)
|
CVector3f(const CVector2f& other)
|
||||||
{
|
{
|
||||||
|
@ -103,10 +113,8 @@ public:
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool operator ==(const CVector3f& rhs) const
|
inline bool operator==(const CVector3f& rhs) const { return (x == rhs.x && y == rhs.y && z == rhs.z); }
|
||||||
{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 !(*this == rhs);}
|
|
||||||
inline CVector3f operator+(const CVector3f& rhs) const
|
inline CVector3f operator+(const CVector3f& rhs) const
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
|
@ -199,41 +207,49 @@ public:
|
||||||
return CVector3f(x / val, y / val, z / val);
|
return CVector3f(x / val, y / val, z / val);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
inline const CVector3f& operator +=(const CVector3f& rhs)
|
inline const CVector3f& operator+=(const CVector3f& rhs)
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
mVec128 = _mm_add_ps(mVec128, rhs.mVec128);
|
mVec128 = _mm_add_ps(mVec128, rhs.mVec128);
|
||||||
#elif __GEKKO_PS__
|
#elif __GEKKO_PS__
|
||||||
mVec128 = _mm_gekko_add_ps(mVec128, rhs.mVec128);
|
mVec128 = _mm_gekko_add_ps(mVec128, rhs.mVec128);
|
||||||
#else
|
#else
|
||||||
x += rhs.x; y += rhs.y; z += rhs.z;
|
x += rhs.x;
|
||||||
|
y += rhs.y;
|
||||||
|
z += rhs.z;
|
||||||
#endif
|
#endif
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
inline const CVector3f& operator -=(const CVector3f& rhs)
|
inline const CVector3f& operator-=(const CVector3f& rhs)
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
mVec128 = _mm_sub_ps(mVec128, rhs.mVec128);
|
mVec128 = _mm_sub_ps(mVec128, rhs.mVec128);
|
||||||
#else
|
#else
|
||||||
x -= rhs.x; y -= rhs.y; z -= rhs.z;
|
x -= rhs.x;
|
||||||
|
y -= rhs.y;
|
||||||
|
z -= rhs.z;
|
||||||
#endif
|
#endif
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
inline const CVector3f& operator *=(const CVector3f& rhs)
|
inline const CVector3f& operator*=(const CVector3f& rhs)
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
mVec128 = _mm_mul_ps(mVec128, rhs.mVec128);
|
mVec128 = _mm_mul_ps(mVec128, rhs.mVec128);
|
||||||
#else
|
#else
|
||||||
x *= rhs.x; y *= rhs.y; z *= rhs.z;
|
x *= rhs.x;
|
||||||
|
y *= rhs.y;
|
||||||
|
z *= rhs.z;
|
||||||
#endif
|
#endif
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
inline const CVector3f& operator /=(const CVector3f& rhs)
|
inline const CVector3f& operator/=(const CVector3f& rhs)
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
mVec128 = _mm_div_ps(mVec128, rhs.mVec128);
|
mVec128 = _mm_div_ps(mVec128, rhs.mVec128);
|
||||||
#else
|
#else
|
||||||
x /= rhs.x; y /= rhs.y; z /= rhs.z;
|
x /= rhs.x;
|
||||||
|
y /= rhs.y;
|
||||||
|
z /= rhs.z;
|
||||||
#endif
|
#endif
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -250,7 +266,9 @@ public:
|
||||||
return *this * mag;
|
return *this * mag;
|
||||||
}
|
}
|
||||||
inline CVector3f cross(const CVector3f& rhs) const
|
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
|
inline float dot(const CVector3f& rhs) const
|
||||||
{
|
{
|
||||||
|
@ -285,19 +303,21 @@ public:
|
||||||
result.mVec128 = _mm_mul_ps(mVec128, mVec128);
|
result.mVec128 = _mm_mul_ps(mVec128, mVec128);
|
||||||
return result.v[0] + result.v[1] + result.v[2];
|
return result.v[0] + result.v[1] + result.v[2];
|
||||||
#else
|
#else
|
||||||
return x*x + y*y + z*z;
|
return x * x + y * y + z * z;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
inline float magnitude() const
|
inline float magnitude() const { return sqrtF(magSquared()); }
|
||||||
{ return sqrtF(magSquared()); }
|
|
||||||
|
|
||||||
inline void zeroOut()
|
inline void zeroOut()
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
mVec128 = _mm_xor_ps(mVec128, mVec128);
|
mVec128 = _mm_xor_ps(mVec128, mVec128);
|
||||||
#else
|
#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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -307,26 +327,24 @@ public:
|
||||||
TVectorUnion splat = {{xyz, xyz, xyz, 0.0f}};
|
TVectorUnion splat = {{xyz, xyz, xyz, 0.0f}};
|
||||||
mVec128 = splat.mVec128;
|
mVec128 = splat.mVec128;
|
||||||
#else
|
#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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static float getAngleDiff(const CVector3f& a, const CVector3f& b);
|
static float getAngleDiff(const CVector3f& a, const CVector3f& b);
|
||||||
|
|
||||||
static inline CVector3f lerp(const CVector3f& a, const CVector3f& b, float t)
|
static inline CVector3f lerp(const CVector3f& a, const CVector3f& b, float t) { return (a + (b - a) * t); }
|
||||||
{ return (a + (b - a) * t); }
|
static inline CVector3f nlerp(const CVector3f& a, const CVector3f& b, float t) { return lerp(a, b, t).normalized(); }
|
||||||
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);
|
static CVector3f slerp(const CVector3f& a, const CVector3f& b, float t);
|
||||||
|
|
||||||
inline bool isNormalized() const
|
inline bool isNormalized() const { return std::fabs(1.f - magSquared()) < 0.01f; }
|
||||||
{ return std::fabs(1.f - magSquared()) < 0.01f; }
|
|
||||||
|
|
||||||
inline bool canBeNormalized() const
|
inline bool canBeNormalized() const { return !isNormalized(); }
|
||||||
{ return !isNormalized(); }
|
|
||||||
|
|
||||||
inline bool isZero() const
|
inline bool isZero() const { return magSquared() <= 1.1920929e-7f; }
|
||||||
{ return magSquared() <= 1.1920929e-7f; }
|
|
||||||
|
|
||||||
inline void scaleToLength(float newLength)
|
inline void scaleToLength(float newLength)
|
||||||
{
|
{
|
||||||
|
@ -349,21 +367,20 @@ public:
|
||||||
return v;
|
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;
|
const CVector3f diffVec = other - *this;
|
||||||
return (diffVec.x <= epsilon && diffVec.y <= epsilon && diffVec.z <= epsilon);
|
return (diffVec.x <= epsilon && diffVec.y <= epsilon && diffVec.z <= epsilon);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline float& operator[](size_t idx) {return (&x)[idx];}
|
inline float& operator[](size_t idx) { return (&x)[idx]; }
|
||||||
inline const float& operator[](size_t idx) const {return (&x)[idx];}
|
inline const float& operator[](size_t idx) const { return (&x)[idx]; }
|
||||||
|
|
||||||
static const CVector3f skOne;
|
static const CVector3f skOne;
|
||||||
static const CVector3f skNegOne;
|
static const CVector3f skNegOne;
|
||||||
static const CVector3f skZero;
|
static const CVector3f skZero;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static inline CVector3f operator+(float lhs, const CVector3f& rhs)
|
static inline CVector3f operator+(float lhs, const CVector3f& rhs)
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
|
@ -412,9 +429,8 @@ extern const CVector3f kForwardVec;
|
||||||
extern const CVector3f kBackVec;
|
extern const CVector3f kBackVec;
|
||||||
extern const CVector3f kRadToDegVec;
|
extern const CVector3f kRadToDegVec;
|
||||||
extern const CVector3f kDegToRadVec;
|
extern const CVector3f kDegToRadVec;
|
||||||
inline CVector3f radToDeg(const CVector3f& rad) {return rad * kRadToDegVec;}
|
inline CVector3f radToDeg(const CVector3f& rad) { return rad * kRadToDegVec; }
|
||||||
inline CVector3f degToRad(const CVector3f& deg) {return deg * kDegToRadVec;}
|
inline CVector3f degToRad(const CVector3f& deg) { return deg * kDegToRadVec; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // CVECTOR3F_HPP
|
#endif // CVECTOR3F_HPP
|
||||||
|
|
|
@ -21,8 +21,7 @@ class alignas(16) CVector4f
|
||||||
#endif
|
#endif
|
||||||
public:
|
public:
|
||||||
ZE_DECLARE_ALIGNED_ALLOCATOR();
|
ZE_DECLARE_ALIGNED_ALLOCATOR();
|
||||||
union
|
union {
|
||||||
{
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
float x, y, z, w;
|
float x, y, z, w;
|
||||||
|
@ -33,14 +32,16 @@ public:
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
inline CVector4f() {zeroOut();}
|
inline CVector4f() { zeroOut(); }
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
CVector4f(const __m128& mVec128) : mVec128(mVec128) {}
|
CVector4f(const __m128& mVec128) : mVec128(mVec128) {}
|
||||||
#endif
|
#endif
|
||||||
#if ZE_ATHENA_TYPES
|
#if ZE_ATHENA_TYPES
|
||||||
CVector4f(const atVec4f& vec)
|
CVector4f(const atVec4f& vec)
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
: mVec128(vec.mVec128){}
|
: mVec128(vec.mVec128)
|
||||||
|
{
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
{
|
{
|
||||||
x = vec.vec[0], y = vec.vec[1], z = vec.vec[2], w = vec.vec[3];
|
x = vec.vec[0], y = vec.vec[1], z = vec.vec[2], w = vec.vec[3];
|
||||||
|
@ -77,9 +78,15 @@ public:
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
CVector4f(float xyzw) {splat(xyzw);}
|
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;}
|
void assign(float x, float y, float z, float w)
|
||||||
CVector4f(float x, float y, float z, float w) {assign(x, y, z, 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 CColor& other);
|
||||||
|
|
||||||
CVector4f(const CVector3f& other)
|
CVector4f(const CVector3f& other)
|
||||||
|
@ -104,7 +111,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
CVector4f& operator=(const CColor& other);
|
CVector4f& operator=(const CColor& other);
|
||||||
inline bool operator ==(const CVector4f& rhs) const
|
inline bool operator==(const CVector4f& rhs) const
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
TVectorUnion vec;
|
TVectorUnion vec;
|
||||||
|
@ -114,7 +121,7 @@ public:
|
||||||
return (x == rhs.x && y == rhs.y && z == rhs.z && w == rhs.w);
|
return (x == rhs.x && y == rhs.y && z == rhs.z && w == rhs.w);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
inline bool operator !=(const CVector4f& rhs) const
|
inline bool operator!=(const CVector4f& rhs) const
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
TVectorUnion vec;
|
TVectorUnion vec;
|
||||||
|
@ -124,7 +131,7 @@ public:
|
||||||
return !(*this == rhs);
|
return !(*this == rhs);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
inline bool operator <(const CVector4f& rhs) const
|
inline bool operator<(const CVector4f& rhs) const
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
TVectorUnion vec;
|
TVectorUnion vec;
|
||||||
|
@ -134,7 +141,7 @@ public:
|
||||||
return (x < rhs.x || y < rhs.y || z < rhs.z || w < rhs.w);
|
return (x < rhs.x || y < rhs.y || z < rhs.z || w < rhs.w);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
inline bool operator <=(const CVector4f& rhs) const
|
inline bool operator<=(const CVector4f& rhs) const
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
TVectorUnion vec;
|
TVectorUnion vec;
|
||||||
|
@ -144,7 +151,7 @@ public:
|
||||||
return (x <= rhs.x || y <= rhs.y || z <= rhs.z || w <= rhs.w);
|
return (x <= rhs.x || y <= rhs.y || z <= rhs.z || w <= rhs.w);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
inline bool operator >(const CVector4f& rhs) const
|
inline bool operator>(const CVector4f& rhs) const
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
TVectorUnion vec;
|
TVectorUnion vec;
|
||||||
|
@ -154,7 +161,7 @@ public:
|
||||||
return (x > rhs.x || y > rhs.y || z > rhs.z || w > rhs.w);
|
return (x > rhs.x || y > rhs.y || z > rhs.z || w > rhs.w);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
inline bool operator >=(const CVector4f& rhs) const
|
inline bool operator>=(const CVector4f& rhs) const
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
TVectorUnion vec;
|
TVectorUnion vec;
|
||||||
|
@ -240,39 +247,51 @@ public:
|
||||||
return CVector4f(x / val, y / val, z / val, w / val);
|
return CVector4f(x / val, y / val, z / val, w / val);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
inline const CVector4f& operator +=(const CVector4f& rhs)
|
inline const CVector4f& operator+=(const CVector4f& rhs)
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
mVec128 = _mm_add_ps(mVec128, rhs.mVec128);
|
mVec128 = _mm_add_ps(mVec128, rhs.mVec128);
|
||||||
#else
|
#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
|
#endif
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
inline const CVector4f& operator -=(const CVector4f& rhs)
|
inline const CVector4f& operator-=(const CVector4f& rhs)
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
mVec128 = _mm_sub_ps(mVec128, rhs.mVec128);
|
mVec128 = _mm_sub_ps(mVec128, rhs.mVec128);
|
||||||
#else
|
#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
|
#endif
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
inline const CVector4f& operator *=(const CVector4f& rhs)
|
inline const CVector4f& operator*=(const CVector4f& rhs)
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
mVec128 = _mm_mul_ps(mVec128, rhs.mVec128);
|
mVec128 = _mm_mul_ps(mVec128, rhs.mVec128);
|
||||||
#else
|
#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
|
#endif
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
inline const CVector4f& operator /=(const CVector4f& rhs)
|
inline const CVector4f& operator/=(const CVector4f& rhs)
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
mVec128 = _mm_div_ps(mVec128, rhs.mVec128);
|
mVec128 = _mm_div_ps(mVec128, rhs.mVec128);
|
||||||
#else
|
#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
|
#endif
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -321,20 +340,20 @@ public:
|
||||||
result.mVec128 = _mm_mul_ps(mVec128, mVec128);
|
result.mVec128 = _mm_mul_ps(mVec128, mVec128);
|
||||||
return result.v[0] + result.v[1] + result.v[2];
|
return result.v[0] + result.v[1] + result.v[2];
|
||||||
#else
|
#else
|
||||||
return x*x + y*y + z*z + w*w;
|
return x * x + y * y + z * z + w * w;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
inline float magnitude() const
|
inline float magnitude() const { return std::sqrt(magSquared()); }
|
||||||
{
|
|
||||||
return std::sqrt(magSquared());
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void zeroOut()
|
inline void zeroOut()
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
mVec128 = _mm_xor_ps(mVec128, mVec128);
|
mVec128 = _mm_xor_ps(mVec128, mVec128);
|
||||||
#else
|
#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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -344,41 +363,34 @@ public:
|
||||||
TVectorUnion splat = {{xyzw, xyzw, xyzw, xyzw}};
|
TVectorUnion splat = {{xyzw, xyzw, xyzw, xyzw}};
|
||||||
mVec128 = splat.mVec128;
|
mVec128 = splat.mVec128;
|
||||||
#else
|
#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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline CVector4f lerp(const CVector4f& a, const CVector4f& b, float t)
|
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(); }
|
||||||
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
|
inline bool isNormalized() const { return std::fabs(1.f - magSquared()) < 0.01f; }
|
||||||
{ return std::fabs(1.f - magSquared()) < 0.01f; }
|
|
||||||
|
|
||||||
inline bool canBeNormalized() const
|
inline bool canBeNormalized() const { return !isNormalized(); }
|
||||||
{ 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;
|
const CVector4f diffVec = other - *this;
|
||||||
return (diffVec.x <= epsilon && diffVec.y <= epsilon && diffVec.z <= epsilon && diffVec.w <= epsilon);
|
return (diffVec.x <= epsilon && diffVec.y <= epsilon && diffVec.z <= epsilon && diffVec.w <= epsilon);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline float& operator[](size_t idx) {return (&x)[idx];}
|
inline float& operator[](size_t idx) { return (&x)[idx]; }
|
||||||
inline const float& operator[](size_t idx) const {return (&x)[idx];}
|
inline const float& operator[](size_t idx) const { return (&x)[idx]; }
|
||||||
|
|
||||||
|
|
||||||
static const CVector4f skOne;
|
static const CVector4f skOne;
|
||||||
static const CVector4f skNegOne;
|
static const CVector4f skNegOne;
|
||||||
static const CVector4f skZero;
|
static const CVector4f skZero;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static inline CVector4f operator+(float lhs, const CVector4f& rhs)
|
static inline CVector4f operator+(float lhs, const CVector4f& rhs)
|
||||||
{
|
{
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
|
|
|
@ -2,47 +2,47 @@
|
||||||
#define ZEUS_GLOBAL_HPP
|
#define ZEUS_GLOBAL_HPP
|
||||||
|
|
||||||
#if _M_IX86_FP >= 1 || _M_X64
|
#if _M_IX86_FP >= 1 || _M_X64
|
||||||
# define __SSE__ 1
|
#define __SSE__ 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
# include <immintrin.h>
|
#include <immintrin.h>
|
||||||
# ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
# include <mm_malloc.h>
|
#include <mm_malloc.h>
|
||||||
# endif
|
#endif
|
||||||
# define zeAlloc(sz, align) _mm_malloc(sz, align)
|
#define zeAlloc(sz, align) _mm_malloc(sz, align)
|
||||||
# define zeFree(ptr) _mm_free(ptr)
|
#define zeFree(ptr) _mm_free(ptr)
|
||||||
#elif GEKKO
|
#elif GEKKO
|
||||||
# include <ps_intrins.h>
|
#include <ps_intrins.h>
|
||||||
# define zeAlloc(sz, align) _ps_malloc(sz, align)
|
#define zeAlloc(sz, align) _ps_malloc(sz, align)
|
||||||
# define zeFree(ptr) _ps_free(ptr)
|
#define zeFree(ptr) _ps_free(ptr)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if __SSE__ || __GEKKO_PS__
|
#if __SSE__ || __GEKKO_PS__
|
||||||
# define ZE_DECLARE_ALIGNED_ALLOCATOR() \
|
#define ZE_DECLARE_ALIGNED_ALLOCATOR() \
|
||||||
inline void* operator new(size_t sizeInBytes) { return zeAlloc(sizeInBytes,16); } \
|
inline void* operator new(size_t sizeInBytes) { return zeAlloc(sizeInBytes, 16); } \
|
||||||
inline void operator delete(void* ptr) { zeFree(ptr); } \
|
inline void operator delete(void* ptr) { zeFree(ptr); } \
|
||||||
inline void* operator new(size_t, void* ptr) { return ptr; } \
|
inline void* operator new(size_t, void* ptr) { return ptr; } \
|
||||||
inline void operator delete(void*, void*) { } \
|
inline void operator delete(void*, void*) {} \
|
||||||
inline void* operator new[](size_t sizeInBytes) { return zeAlloc(sizeInBytes,16); } \
|
inline void* operator new[](size_t sizeInBytes) { return zeAlloc(sizeInBytes, 16); } \
|
||||||
inline void operator delete[](void* ptr) { zeFree(ptr); } \
|
inline void operator delete[](void* ptr) { zeFree(ptr); } \
|
||||||
inline void* operator new[](size_t, void* ptr) { return ptr; } \
|
inline void* operator new[](size_t, void* ptr) { return ptr; } \
|
||||||
inline void operator delete[](void*, void*) { } \
|
inline void operator delete[](void*, void*) {} \
|
||||||
void __unused__()
|
void __unused__()
|
||||||
#else
|
#else
|
||||||
# define ZE_DECLARE_ALIGNED_ALLOCATOR() void __unused__()
|
#define ZE_DECLARE_ALIGNED_ALLOCATOR() void __unused__()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
# define ZE_SHUFFLE(x,y,z,w) ((w)<<6 | (z)<<4 | (y)<<2 | (x))
|
#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_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_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) )
|
#define ze_splat_ps(_a, _i) ze_pshufd_ps((_a), ZE_SHUFFLE(_i, _i, _i, _i))
|
||||||
# if _WIN32
|
#if _WIN32
|
||||||
# define zeCastiTo128f(a) (_mm_castsi128_ps(a))
|
#define zeCastiTo128f(a) (_mm_castsi128_ps(a))
|
||||||
# else
|
#else
|
||||||
# define zeCastiTo128f(a) ((__m128) (a))
|
#define zeCastiTo128f(a) ((__m128)(a))
|
||||||
# endif
|
#endif
|
||||||
#elif __GEKKO_PS__
|
#elif __GEKKO_PS__
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -50,6 +50,4 @@
|
||||||
inline int rotr(int x, int n) { return ((x >> n) | (x << (32 - n))); }
|
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))); }
|
inline int rotl(int x, int n) { return ((x << n) | (x >> (32 - n))); }
|
||||||
|
|
||||||
|
#endif // ZEUS_GLOBAL_HPP
|
||||||
#endif //ZEUS_GLOBAL_HPP
|
|
||||||
|
|
||||||
|
|
|
@ -29,17 +29,17 @@ namespace zeus
|
||||||
{
|
{
|
||||||
struct CPUInfo
|
struct CPUInfo
|
||||||
{
|
{
|
||||||
const char cpuBrand [48] = {0};
|
const char cpuBrand[48] = {0};
|
||||||
const char cpuVendor[32] = {0};
|
const char cpuVendor[32] = {0};
|
||||||
const bool isIntel = false;
|
const bool isIntel = false;
|
||||||
const bool SSE1 = false;
|
const bool SSE1 = false;
|
||||||
const bool SSE2 = false;
|
const bool SSE2 = false;
|
||||||
const bool SSE3 = false;
|
const bool SSE3 = false;
|
||||||
const bool SSSE3 = false;
|
const bool SSSE3 = false;
|
||||||
const bool SSE41 = false;
|
const bool SSE41 = false;
|
||||||
const bool SSE42 = false;
|
const bool SSE42 = false;
|
||||||
const bool SSE4a = false;
|
const bool SSE4a = false;
|
||||||
const bool AESNI = false;
|
const bool AESNI = false;
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* Detects CPU capabilities and returns true if SSE4.1 or SSE4.2 is available
|
* Detects CPU capabilities and returns true if SSE4.1 or SSE4.2 is available
|
||||||
|
@ -49,28 +49,34 @@ const CPUInfo& cpuFeatures();
|
||||||
class CVector3f;
|
class CVector3f;
|
||||||
class CTransform;
|
class CTransform;
|
||||||
|
|
||||||
template<typename T>
|
template <typename T>
|
||||||
inline T min(T a, T b) { return a < b ? a : b; }
|
inline T min(T a, T b)
|
||||||
template<typename T>
|
{
|
||||||
inline T max(T a, T b) { return a > b ? a : b; }
|
return a < b ? a : b;
|
||||||
|
}
|
||||||
|
template <typename T>
|
||||||
|
inline T max(T a, T b)
|
||||||
|
{
|
||||||
|
return a > b ? a : b;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T>
|
template <typename T>
|
||||||
inline T clamp(T a, T val, T b) {return max<T>(a, min<T>(b, val));}
|
inline T clamp(T a, T val, T b)
|
||||||
inline float radToDeg(float rad) {return rad * (180.f / M_PIF);}
|
{
|
||||||
inline float degToRad(float deg) {return deg * (M_PIF / 180.f);}
|
return max<T>(a, min<T>(b, val));
|
||||||
inline double radToDeg(double rad) {return rad * (180.0 / M_PI);}
|
}
|
||||||
inline double degToRad(double deg) {return deg * (M_PI / 180.0);}
|
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 baryToWorld(const CVector3f& p0, const CVector3f& p1, const CVector3f& p2, const CVector3f& bary);
|
||||||
|
|
||||||
CVector3f getBezierPoint(const CVector3f& a, const CVector3f& b,
|
CVector3f getBezierPoint(const CVector3f& a, const CVector3f& b, const CVector3f& c, const CVector3f& d, float t);
|
||||||
const CVector3f& c, const CVector3f& d, float t);
|
float getCatmullRomSplinePoint(float a, float b, float c, float d, float t);
|
||||||
float getCatmullRomSplinePoint(float a, float b,
|
CVector3f getCatmullRomSplinePoint(const CVector3f& a, const CVector3f& b, const CVector3f& c, const CVector3f& d, float t);
|
||||||
float c, float d, float t);
|
CVector3f getRoundCatmullRomSplinePoint(const CVector3f& a, const CVector3f& b, const CVector3f& c, const CVector3f& d,
|
||||||
CVector3f getCatmullRomSplinePoint(const CVector3f& a, const CVector3f& b,
|
float t);
|
||||||
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 powF(float a, float b) { return std::pow(a, b); }
|
||||||
inline float floorF(float val) { return std::floor(val); }
|
inline float floorF(float val) { return std::floor(val); }
|
||||||
|
@ -96,27 +102,24 @@ int floorPowerOfTwo(int x);
|
||||||
int ceilingPowerOfTwo(int x);
|
int ceilingPowerOfTwo(int x);
|
||||||
|
|
||||||
template <typename U>
|
template <typename U>
|
||||||
typename std::enable_if<!std::is_enum<U>::value && std::is_integral<U>::value, int>::type
|
typename std::enable_if<!std::is_enum<U>::value && std::is_integral<U>::value, int>::type PopCount(U x)
|
||||||
PopCount(U x)
|
|
||||||
{
|
{
|
||||||
const U m1 = U(0x5555555555555555); //binary: 0101...
|
const U m1 = U(0x5555555555555555); // binary: 0101...
|
||||||
const U m2 = U(0x3333333333333333); //binary: 00110011..
|
const U m2 = U(0x3333333333333333); // binary: 00110011..
|
||||||
const U m4 = U(0x0f0f0f0f0f0f0f0f); //binary: 4 zeros, 4 ones ...
|
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 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 >> 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 & 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
|
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) + ...
|
return (x * h01) >> ((sizeof(U) - 1) * 8); // returns left 8 bits of x + (x<<8) + (x<<16) + (x<<24) + ...
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename E>
|
template <typename E>
|
||||||
typename std::enable_if<std::is_enum<E>::value, int>::type
|
typename std::enable_if<std::is_enum<E>::value, int>::type PopCount(E e)
|
||||||
PopCount(E e)
|
|
||||||
{
|
{
|
||||||
return PopCount(static_cast<typename std::underlying_type<E>::type>(e));
|
return PopCount(static_cast<typename std::underlying_type<E>::type>(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // MATH_HPP
|
#endif // MATH_HPP
|
||||||
|
|
|
@ -3,16 +3,14 @@
|
||||||
|
|
||||||
namespace zeus
|
namespace zeus
|
||||||
{
|
{
|
||||||
typedef union
|
typedef union {
|
||||||
{
|
|
||||||
float v[4];
|
float v[4];
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
__m128 mVec128;
|
__m128 mVec128;
|
||||||
#endif
|
#endif
|
||||||
} TVectorUnion;
|
} TVectorUnion;
|
||||||
|
|
||||||
typedef union
|
typedef union {
|
||||||
{
|
|
||||||
double v[4];
|
double v[4];
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
__m128d mVec128[2];
|
__m128d mVec128[2];
|
||||||
|
@ -21,4 +19,3 @@ typedef union
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // TVECTORUNION
|
#endif // TVECTORUNION
|
||||||
|
|
||||||
|
|
|
@ -6,5 +6,4 @@ namespace zeus
|
||||||
|
|
||||||
const CAABox CAABox::skInvertedBox = CAABox();
|
const CAABox CAABox::skInvertedBox = CAABox();
|
||||||
const CAABox CAABox::skNullBox = CAABox(CVector3f::skZero, CVector3f::skZero);
|
const CAABox CAABox::skNullBox = CAABox(CVector3f::skZero, CVector3f::skZero);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,16 +3,16 @@
|
||||||
|
|
||||||
namespace zeus
|
namespace zeus
|
||||||
{
|
{
|
||||||
const CColor CColor::skRed (Comp32(0xFF0000FFul));
|
const CColor CColor::skRed(Comp32(0xFF0000FFul));
|
||||||
const CColor CColor::skBlack (Comp32(0x000000FFul));
|
const CColor CColor::skBlack(Comp32(0x000000FFul));
|
||||||
const CColor CColor::skBlue (Comp32(0x0000FFFFul));
|
const CColor CColor::skBlue(Comp32(0x0000FFFFul));
|
||||||
const CColor CColor::skGreen (Comp32(0x00FF00FFul));
|
const CColor CColor::skGreen(Comp32(0x00FF00FFul));
|
||||||
const CColor CColor::skGrey (Comp32(0x808080FFul));
|
const CColor CColor::skGrey(Comp32(0x808080FFul));
|
||||||
const CColor CColor::skOrange(Comp32(0xFF7000FFul));
|
const CColor CColor::skOrange(Comp32(0xFF7000FFul));
|
||||||
const CColor CColor::skPurple(Comp32(0xA000FFFFul));
|
const CColor CColor::skPurple(Comp32(0xA000FFFFul));
|
||||||
const CColor CColor::skYellow(Comp32(0xFFFF00FFul));
|
const CColor CColor::skYellow(Comp32(0xFFFF00FFul));
|
||||||
const CColor CColor::skWhite (Comp32(0xFFFFFFFFul));
|
const CColor CColor::skWhite(Comp32(0xFFFFFFFFul));
|
||||||
const CColor CColor::skClear (Comp32(0x00000000ul));
|
const CColor CColor::skClear(Comp32(0x00000000ul));
|
||||||
|
|
||||||
float hueToRgb(float p, float q, float t)
|
float hueToRgb(float p, float q, float t)
|
||||||
{
|
{
|
||||||
|
@ -20,17 +20,22 @@ float hueToRgb(float p, float q, float t)
|
||||||
t += 1.0f;
|
t += 1.0f;
|
||||||
if (t > 1.0f)
|
if (t > 1.0f)
|
||||||
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;
|
return p + (q - p) * 6.f * t;
|
||||||
if (t < 1.f/2.f)
|
if (t < 1.f / 2.f)
|
||||||
return q;
|
return q;
|
||||||
if (t < 2.f/3.f)
|
if (t < 2.f / 3.f)
|
||||||
return p + (q - p) * (2.f/3.f - t) * 6.f;
|
return p + (q - p) * (2.f / 3.f - t) * 6.f;
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
CColor::CColor(const CVector4f& other)
|
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)
|
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 t = v * (1 - (1 - f) * s);
|
||||||
float _r, _g, _b;
|
float _r, _g, _b;
|
||||||
|
|
||||||
switch(i % 6)
|
switch (i % 6)
|
||||||
{
|
{
|
||||||
case 0: _r = v, _g = t, _b = p; break;
|
case 0:
|
||||||
case 1: _r = q, _g = v, _b = p; break;
|
_r = v, _g = t, _b = p;
|
||||||
case 2: _r = p, _g = v, _b = t; break;
|
break;
|
||||||
case 3: _r = p, _g = q, _b = v; break;
|
case 1:
|
||||||
case 4: _r = t, _g = p, _b = v; break;
|
_r = q, _g = v, _b = p;
|
||||||
case 5: _r = v, _g = p, _b = q; break;
|
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;
|
r = _r;
|
||||||
|
@ -66,7 +83,7 @@ void CColor::fromHSV(float h, float s, float v, float _a)
|
||||||
a = _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 min = std::min(r, std::min(g, b));
|
||||||
float max = std::max(r, std::max(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 q = l < 0.5f ? l * (1.f + s) : l + s - 1.f * s;
|
||||||
const float p = 2 * l - q;
|
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);
|
g = hueToRgb(p, q, h);
|
||||||
b = hueToRgb(p, q, h - 1.f/3);
|
b = hueToRgb(p, q, h - 1.f / 3);
|
||||||
}
|
}
|
||||||
a = _a;
|
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 min = std::min(r, std::min(g, b));
|
||||||
const float max = std::max(r, std::max(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;
|
h /= 6;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,26 +96,17 @@ CMatrix3f CMatrix3f::transposed() const
|
||||||
|
|
||||||
CMatrix3f CMatrix3f::inverted() const
|
CMatrix3f CMatrix3f::inverted() const
|
||||||
{
|
{
|
||||||
float det =
|
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][0] * m[1][1] * m[2][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];
|
||||||
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)
|
if (det == 0.0)
|
||||||
return CMatrix3f();
|
return CMatrix3f();
|
||||||
|
|
||||||
det = 1.0f / det;
|
det = 1.0f / det;
|
||||||
return CMatrix3f((m[1][1]*m[2][2] - m[1][2]*m[2][1]) * 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][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[1][0]*m[2][1] - m[1][1]*m[2][0]) * 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[2][2] - m[0][2]*m[2][1]) * 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[2][2] - m[0][2]*m[2][0]) * det,
|
(m[0][0] * m[1][1] - m[0][1] * m[1][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
|
#endif
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1 @@
|
||||||
#include "zeus/CPlane.hpp"
|
#include "zeus/CPlane.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -36,12 +36,12 @@ void CProjection::_updateCachedMatrix()
|
||||||
}
|
}
|
||||||
else if (m_projType == EProjType::Perspective)
|
else if (m_projType == EProjType::Perspective)
|
||||||
{
|
{
|
||||||
float cot,tmp;
|
float cot, tmp;
|
||||||
float t_fovy = std::tan(m_persp.fov / 2.0f);
|
float t_fovy = std::tan(m_persp.fov / 2.0f);
|
||||||
|
|
||||||
cot = 1.0f / t_fovy;
|
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[1][0] = 0.0f;
|
||||||
m_mtx.m[2][0] = 0.0f;
|
m_mtx.m[2][0] = 0.0f;
|
||||||
m_mtx.m[3][0] = 0.0f;
|
m_mtx.m[3][0] = 0.0f;
|
||||||
|
@ -64,4 +64,3 @@ void CProjection::_updateCachedMatrix()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,22 +34,14 @@ CQuaternion& CQuaternion::operator=(const CQuaternion& q)
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
CQuaternion CQuaternion::operator+(const CQuaternion& q) const
|
CQuaternion CQuaternion::operator+(const CQuaternion& q) const { return CQuaternion(w + q.w, x + q.x, y + q.y, z + q.z); }
|
||||||
{
|
|
||||||
return CQuaternion(w + q.w, x + q.x, y + q.y, z + q.z);
|
|
||||||
}
|
|
||||||
|
|
||||||
CQuaternion CQuaternion::operator-(const CQuaternion& q) const
|
CQuaternion CQuaternion::operator-(const CQuaternion& q) const { return CQuaternion(w - q.w, x - q.x, y - q.y, z - q.z); }
|
||||||
{
|
|
||||||
return CQuaternion(w - q.w, x - q.x, y - q.y, z - q.z);
|
|
||||||
}
|
|
||||||
|
|
||||||
CQuaternion CQuaternion::operator*(const CQuaternion& q) const
|
CQuaternion CQuaternion::operator*(const CQuaternion& q) const
|
||||||
{
|
{
|
||||||
return CQuaternion(w*q.w - CVector3f(x, y, z).dot({q.x, q.y, q.z}),
|
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,
|
||||||
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);
|
||||||
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
|
CQuaternion CQuaternion::operator/(const CQuaternion& q) const
|
||||||
|
@ -59,20 +51,11 @@ CQuaternion CQuaternion::operator/(const CQuaternion& q) const
|
||||||
return *this * p;
|
return *this * p;
|
||||||
}
|
}
|
||||||
|
|
||||||
CQuaternion CQuaternion::operator*(float scale) const
|
CQuaternion CQuaternion::operator*(float scale) const { return CQuaternion(w * scale, x * scale, y * scale, z * scale); }
|
||||||
{
|
|
||||||
return CQuaternion(w*scale, x*scale, y*scale, z*scale);
|
|
||||||
}
|
|
||||||
|
|
||||||
CQuaternion CQuaternion::operator/(float scale) const
|
CQuaternion CQuaternion::operator/(float scale) const { return CQuaternion(w / scale, x / scale, y / scale, z / scale); }
|
||||||
{
|
|
||||||
return CQuaternion(w/scale, x/scale, y/scale, z/scale);
|
|
||||||
}
|
|
||||||
|
|
||||||
CQuaternion CQuaternion::operator-() const
|
CQuaternion CQuaternion::operator-() const { return CQuaternion(-w, -x, -y, -z); }
|
||||||
{
|
|
||||||
return CQuaternion(-w, -x, -y, -z);
|
|
||||||
}
|
|
||||||
|
|
||||||
const CQuaternion& CQuaternion::operator+=(const CQuaternion& q)
|
const CQuaternion& CQuaternion::operator+=(const CQuaternion& q)
|
||||||
{
|
{
|
||||||
|
@ -92,17 +75,17 @@ const CQuaternion& CQuaternion::operator-=(const CQuaternion& q)
|
||||||
return *this;
|
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});
|
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;
|
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;
|
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;
|
z = x * q.y - y * q.x + w * q.z + z * q.w;
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CQuaternion& CQuaternion::operator *=(float scale)
|
const CQuaternion& CQuaternion::operator*=(float scale)
|
||||||
{
|
{
|
||||||
w *= scale;
|
w *= scale;
|
||||||
x *= scale;
|
x *= scale;
|
||||||
|
@ -120,25 +103,13 @@ const CQuaternion& CQuaternion::operator/=(float scale)
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
float CQuaternion::magnitude() const
|
float CQuaternion::magnitude() const { return std::sqrt(magSquared()); }
|
||||||
{
|
|
||||||
return std::sqrt(magSquared());
|
|
||||||
}
|
|
||||||
|
|
||||||
float CQuaternion::magSquared() const
|
float CQuaternion::magSquared() const { return w * w + x * x + y * y + z * z; }
|
||||||
{
|
|
||||||
return w*w + x*x + y*y + z*z;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CQuaternion::normalize()
|
void CQuaternion::normalize() { *this /= magnitude(); }
|
||||||
{
|
|
||||||
*this /= magnitude();
|
|
||||||
}
|
|
||||||
|
|
||||||
CQuaternion CQuaternion::normalized() const
|
CQuaternion CQuaternion::normalized() const { return *this / magnitude(); }
|
||||||
{
|
|
||||||
return *this/magnitude();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CQuaternion::invert()
|
void CQuaternion::invert()
|
||||||
{
|
{
|
||||||
|
@ -147,25 +118,22 @@ void CQuaternion::invert()
|
||||||
z = -z;
|
z = -z;
|
||||||
}
|
}
|
||||||
|
|
||||||
CQuaternion CQuaternion::inverse() const
|
CQuaternion CQuaternion::inverse() const { return CQuaternion(w, -x, -y, -z); }
|
||||||
{
|
|
||||||
return CQuaternion(w, -x, -y, -z);
|
|
||||||
}
|
|
||||||
|
|
||||||
CAxisAngle CQuaternion::toAxisAngle()
|
CAxisAngle CQuaternion::toAxisAngle()
|
||||||
{
|
{
|
||||||
// CAxisAngle ret;
|
// CAxisAngle ret;
|
||||||
// ret.angle = std::acos(r);
|
// 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.x = v.x * thetaInv;
|
||||||
// ret.axis.y = v.y * thetaInv;
|
// ret.axis.y = v.y * thetaInv;
|
||||||
// ret.axis.z = v.z * thetaInv;
|
// ret.axis.z = v.z * thetaInv;
|
||||||
|
|
||||||
// ret.angle *= 2.f;
|
// ret.angle *= 2.f;
|
||||||
|
|
||||||
// return ret;
|
// return ret;
|
||||||
return CAxisAngle();
|
return CAxisAngle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,20 +185,11 @@ CQuaternion CQuaternion::exp() const
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
float CQuaternion::dot(const CQuaternion& b) const
|
float CQuaternion::dot(const CQuaternion& b) const { return x * b.x + y * b.y + z * b.z + w * b.w; }
|
||||||
{
|
|
||||||
return x * b.x + y * b.y + z * b.z + w * b.w;
|
|
||||||
}
|
|
||||||
|
|
||||||
CQuaternion CQuaternion::lerp(const CQuaternion& a, const CQuaternion& b, double t)
|
CQuaternion CQuaternion::lerp(const CQuaternion& a, const CQuaternion& b, double t) { return (a + t * (b - a)); }
|
||||||
{
|
|
||||||
return (a + t * (b - a));
|
|
||||||
}
|
|
||||||
|
|
||||||
CQuaternion CQuaternion::nlerp(const CQuaternion& a, const CQuaternion& b, double t)
|
CQuaternion CQuaternion::nlerp(const CQuaternion& a, const CQuaternion& b, double t) { return lerp(a, b, t).normalized(); }
|
||||||
{
|
|
||||||
return lerp(a, b, t).normalized();
|
|
||||||
}
|
|
||||||
|
|
||||||
CQuaternion CQuaternion::slerp(const CQuaternion& a, const CQuaternion& b, double t)
|
CQuaternion CQuaternion::slerp(const CQuaternion& a, const CQuaternion& b, double t)
|
||||||
{
|
{
|
||||||
|
|
|
@ -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 sign = (prod < 0.0f) ? -1.0f : 1.0f;
|
||||||
|
|
||||||
const double theta = acos(sign * prod);
|
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 d = 1.0 / sin(theta);
|
||||||
const double s0 = sin((1.0 - t) * theta);
|
const double s0 = sin((1.0 - t) * theta);
|
||||||
|
|
||||||
|
|
|
@ -3,10 +3,7 @@
|
||||||
|
|
||||||
namespace zeus
|
namespace zeus
|
||||||
{
|
{
|
||||||
CVector4f::CVector4f(const zeus::CColor& other)
|
CVector4f::CVector4f(const zeus::CColor& other) : x(other.r), y(other.g), z(other.b), w(other.a) {}
|
||||||
: x(other.r), y(other.g), z(other.b), w(other.a)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
CVector4f& CVector4f::operator=(const CColor& other)
|
CVector4f& CVector4f::operator=(const CColor& other)
|
||||||
{
|
{
|
||||||
|
|
39
src/Math.cpp
39
src/Math.cpp
|
@ -44,9 +44,9 @@ void detectCPU()
|
||||||
// Interpret CPU brand string and cache information.
|
// Interpret CPU brand string and cache information.
|
||||||
if (i == 0x80000002)
|
if (i == 0x80000002)
|
||||||
memcpy((char*)g_cpuFeatures.cpuBrand, regs, sizeof(regs));
|
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));
|
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));
|
memcpy((char*)g_cpuFeatures.cpuBrand + 32, regs, sizeof(regs));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,17 +61,15 @@ void detectCPU()
|
||||||
memset((bool*)&g_cpuFeatures.SSE41, ((regs[2] & 0x00080000) != 0), 1);
|
memset((bool*)&g_cpuFeatures.SSE41, ((regs[2] & 0x00080000) != 0), 1);
|
||||||
memset((bool*)&g_cpuFeatures.SSE42, ((regs[2] & 0x00100000) != 0), 1);
|
memset((bool*)&g_cpuFeatures.SSE42, ((regs[2] & 0x00100000) != 0), 1);
|
||||||
|
|
||||||
|
|
||||||
isInit = true;
|
isInit = true;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const CPUInfo& cpuFeatures() { return g_cpuFeatures; }
|
const CPUInfo& cpuFeatures() { return g_cpuFeatures; }
|
||||||
|
|
||||||
CTransform lookAt(const CVector3f& pos, const CVector3f& lookPos, const CVector3f& up)
|
CTransform lookAt(const CVector3f& pos, const CVector3f& lookPos, const CVector3f& up)
|
||||||
{
|
{
|
||||||
CVector3f vLook,vRight,vUp;
|
CVector3f vLook, vRight, vUp;
|
||||||
|
|
||||||
vLook = lookPos - pos;
|
vLook = lookPos - pos;
|
||||||
if (vLook.magnitude() < FLT_EPSILON)
|
if (vLook.magnitude() < FLT_EPSILON)
|
||||||
|
@ -89,10 +87,8 @@ 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)
|
CVector3f getBezierPoint(const CVector3f& a, const CVector3f& b, const CVector3f& c, const CVector3f& d, float t)
|
||||||
{
|
{
|
||||||
const float oneMinusTime= (1.0 - t);
|
const float oneMinusTime = (1.0 - t);
|
||||||
return (a * oneMinusTime * oneMinusTime) +
|
return (a * oneMinusTime * oneMinusTime) + (b * 3.f * t * oneMinusTime) + (c * 3.f * t * t * oneMinusTime) +
|
||||||
(b * 3.f * t * oneMinusTime) +
|
|
||||||
(c * 3.f * t * t * oneMinusTime) +
|
|
||||||
(d * t * t * t);
|
(d * t * t * t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,17 +105,15 @@ double sqrtD(double val)
|
||||||
}
|
}
|
||||||
double q;
|
double q;
|
||||||
#if __SSE__
|
#if __SSE__
|
||||||
union
|
union {
|
||||||
{
|
|
||||||
__m128d v;
|
__m128d v;
|
||||||
double d[2];
|
double d[2];
|
||||||
} qv = { val };
|
} qv = {val};
|
||||||
qv.v = _mm_sqrt_sd(qv.v, qv.v);
|
qv.v = _mm_sqrt_sd(qv.v, qv.v);
|
||||||
q = qv.d[0];
|
q = qv.d[0];
|
||||||
#else
|
#else
|
||||||
// le sigh, let's use Carmack's inverse square -.-
|
// le sigh, let's use Carmack's inverse square -.-
|
||||||
union
|
union {
|
||||||
{
|
|
||||||
double v;
|
double v;
|
||||||
int i;
|
int i;
|
||||||
} p;
|
} p;
|
||||||
|
@ -269,10 +263,8 @@ float getCatmullRomSplinePoint(float a, float b, float c, float d, float t)
|
||||||
const float t2 = t * t;
|
const float t2 = t * t;
|
||||||
const float t3 = t2 * t;
|
const float t3 = t2 * t;
|
||||||
|
|
||||||
return (a * (-0.5f * t3 + t2 - 0.5f * 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) +
|
||||||
b * ( 1.5f * t3 + -2.5f * t2 + 1.0f) +
|
d * (0.5f * t3 - 0.5f * t2));
|
||||||
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)
|
CVector3f getCatmullRomSplinePoint(const CVector3f& a, const CVector3f& b, const CVector3f& c, const CVector3f& d, float t)
|
||||||
|
@ -285,10 +277,8 @@ CVector3f getCatmullRomSplinePoint(const CVector3f& a, const CVector3f& b, const
|
||||||
const float t2 = t * t;
|
const float t2 = t * t;
|
||||||
const float t3 = t2 * t;
|
const float t3 = t2 * t;
|
||||||
|
|
||||||
return (a * (-0.5f * t3 + t2 - 0.5f * 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) +
|
||||||
b * ( 1.5f * t3 + -2.5f * t2 + 1.0f) +
|
d * (0.5f * t3 - 0.5f * t2));
|
||||||
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)
|
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)
|
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
|
#endif
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,9 +5,11 @@
|
||||||
// This is only for testing, do NOT do this normally
|
// This is only for testing, do NOT do this normally
|
||||||
using namespace zeus;
|
using namespace zeus;
|
||||||
|
|
||||||
union Color
|
union Color {
|
||||||
{
|
struct
|
||||||
struct { zeus::Comp8 r, g, b, a; };
|
{
|
||||||
|
zeus::Comp8 r, g, b, a;
|
||||||
|
};
|
||||||
zeus::Comp32 rgba;
|
zeus::Comp32 rgba;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -52,13 +54,13 @@ int main()
|
||||||
std::cout << powF(6.66663489, 2) << std::endl;
|
std::cout << powF(6.66663489, 2) << std::endl;
|
||||||
std::cout << invSqrtF(1) << std::endl;
|
std::cout << invSqrtF(1) << std::endl;
|
||||||
std::cout << floorPowerOfTwo(256) << std::endl;
|
std::cout << floorPowerOfTwo(256) << std::endl;
|
||||||
std::cout << " Test 1 " << ( aabb.intersects(s1) ? "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 2 " << (aabb.intersects(s2) ? "succeeded" : "failed") << std::endl;
|
||||||
std::cout << " Test 3 " << ( aabb.intersects(s3) ? "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});
|
CLineSeg line({-89.120926f, 59.328712f, 3.265882f}, {-90.120926f, 59.328712f, 3.265882f});
|
||||||
|
|
||||||
CColor ctest1;
|
CColor ctest1;
|
||||||
ctest1.fromHSV(0, 255/255.f, .5);
|
ctest1.fromHSV(0, 255 / 255.f, .5);
|
||||||
float h, s, v;
|
float h, s, v;
|
||||||
ctest1.toHSV(h, s, v);
|
ctest1.toHSV(h, s, v);
|
||||||
std::cout << (int)ctest1.r << " " << (int)ctest1.g << " " << (int)ctest1.b << " " << (int)ctest1.a << std::endl;
|
std::cout << (int)ctest1.r << " " << (int)ctest1.g << " " << (int)ctest1.b << " " << (int)ctest1.a << std::endl;
|
||||||
|
|
Loading…
Reference in New Issue