20 :
w(0),
x(0),
y(0),
z(0)
24 Quat(
const T
w,
const T
x,
const T
y,
const T
z)
29 Quat(
const T yaw,
const T pitch,
const T roll)
30 :
w(0),
x(0),
y(0),
z(0)
33 T c2 = cos(pitch / 2);
36 T s2 = sin(pitch / 2);
39 w = c1 * c2 * c3 - s1 * s2 * s3;
40 x = s1 * s2 * c3 + c1 * c2 * s3;
41 y = s1 * c2 * c3 + c1 * s2 * s3;
42 z = c1 * s2 * c3 - s1 * c2 * s3;
46 :
w(0),
x(0),
y(0),
z(0)
48 T c1 = cos(euler.
x / 2);
49 T c2 = cos(euler.
y / 2);
50 T c3 = cos(euler.
z / 2);
51 T s1 = sin(euler.
x / 2);
52 T s2 = sin(euler.
y / 2);
53 T s3 = sin(euler.
z / 2);
55 w = c1 * c2 * c3 - s1 * s2 * s3;
56 x = s1 * s2 * c3 + c1 * c2 * s3;
57 y = s1 * c2 * c3 + c1 * s2 * s3;
58 z = c1 * s2 * c3 - s1 * c2 * s3;
62 :
w(cosf(a / 2)),
x(n.
x * sinf(a / 2)),
y(n.
y * sinf(a / 2)),
z(n.
z * sinf(a / 2))
67 :
w(0),
x(0),
y(0),
z(0)
73 :
w(quat.
w),
x(quat.
x),
y(quat.
y),
z(quat.
z)
77 explicit Quat(
const T scalar)
78 :
w(scalar),
x(scalar),
y(scalar),
z(scalar)
104 return {
w + other.
w,
x + other.
x,
y + other.
y,
z + other.
z};
109 return {-
w, -
x, -
y, -
z};
114 return {
w - other.
w,
x - other.
x,
y - other.
y,
z - other.
z};
119 return {
w * scalar,
x * scalar,
x * scalar,
x * scalar};
126 w * other.
w -
x * other.
x -
y * other.
y -
z * other.
z,
127 w * other.
x +
x * other.
w +
y * other.
z -
z * other.
y,
128 w * other.
y -
x * other.
z +
y * other.
w +
z * other.
x,
129 w * other.
z +
x * other.
y -
y * other.
x +
z * other.
w
135 Quat tmp(0, vect[0], vect[1], vect[2]);
138 Vec3<T> vcV = tmpVect.CrossProduct(vect);
139 return vect + vcV * (2 *
w) + tmpVect.CrossProduct(vcV) * 2;
156 return w == quat.
w &&
x == quat.
x &&
y == quat.
y &&
z == quat.
z;
161 return w != quat.
w ||
x != quat.
x ||
y != quat.
y ||
z == quat.
z;
202 if (tmp.GetDis2() < 0.0001f)
207 *flAngle = acosf(
w) * 2;
208 *flAngle = Math::Degr<T>(*flAngle);
213 T trace = rotMatrix[0][0] + rotMatrix[1][1] + rotMatrix[2][2];
217 T s = 0.5f / Math::Sqrt<T>(trace + 1.0f);
220 x = (rotMatrix[2][1] - rotMatrix[1][2]) * s;
221 y = (rotMatrix[0][2] - rotMatrix[2][0]) * s;
222 z = (rotMatrix[1][0] - rotMatrix[0][1]) * s;
225 if ((rotMatrix[0][0] > rotMatrix[1][1]) && (rotMatrix[0][0] > rotMatrix[2][2]))
227 T s = 2.0f *
Math::Sqrt(1.0f + rotMatrix[0][0] - rotMatrix[1][1] - rotMatrix[2][2]);
228 w = (rotMatrix[2][1] - rotMatrix[1][2]) / s;
230 y = (rotMatrix[0][1] + rotMatrix[1][0]) / s;
231 z = (rotMatrix[0][2] + rotMatrix[2][0]) / s;
232 }
else if (rotMatrix[1][1] > rotMatrix[2][2])
234 T s = 2.0f * sqrtf(1.0f + rotMatrix[1][1] - rotMatrix[0][0] - rotMatrix[2][2]);
235 w = (rotMatrix[0][2] - rotMatrix[2][0]) / s;
236 x = (rotMatrix[0][1] + rotMatrix[1][0]) / s;
238 z = (rotMatrix[1][2] + rotMatrix[2][1]) / s;
241 T s = 2.0f * sqrtf(1.0f + rotMatrix[2][2] - rotMatrix[0][0] - rotMatrix[1][1]);
242 w = (rotMatrix[1][0] - rotMatrix[0][1]) / s;
243 x = (rotMatrix[0][2] + rotMatrix[2][0]) / s;
244 y = (rotMatrix[1][2] + rotMatrix[2][1]) / s;
291 result[0] = T(1) - (y2y + z2z);
292 result[1] = y2x - z2w;
293 result[2] = z2x + y2w;
296 result[4] = y2x + z2w;
297 result[5] = T(1) - (x2x + z2z);
298 result[6] = z2y - x2w;
301 result[8] = z2x - y2w;
302 result[9] = z2y + x2w;
303 result[10] = T(1) - (x2x + y2y);
316 return Math::Sqrt<T>(Math::Pow<T>(
w, 2) + Math::Pow<T>(
x, 2) + Math::Pow<T>(
y, 2) + Math::Pow<T>(
z, 2));
323 return Quat<T>(
w / mag,
x / mag,
y / mag,
z / mag);
338 return w * other.
w +
x * other.
x +
y * other.
y +
z * other.
z;
367 T cosHalfTheta = start.
Dot(finish);
372 float sinHalfTheta =
Math::Sqrt(1.0f - cosHalfTheta * cosHalfTheta);
376 start.
w * 0.5f + finish.
w * 0.5f,
377 start.
x * 0.5f + finish.
x * 0.5f,
378 start.
y * 0.5f + finish.
y * 0.5f,
379 start.
z * 0.5f + finish.
z * 0.5f
383 float ratioA =
Math::Sin((1 - t) * halfTheta) / sinHalfTheta;
384 float ratioB =
Math::Sin(t * halfTheta) / sinHalfTheta;
387 start.
w * ratioA + finish.
w * ratioB,
388 start.
x * ratioA + finish.
x * ratioB,
389 start.
y * ratioA + finish.
y * ratioB,
390 start.
z * ratioA + finish.
z * ratioB
static R Sin(const R angle, const R precision=0.001)
Definition: Math.h:257
static R ACos(const R xPos, const T precision=10)
Definition: Math.h:328
static T Abs(const T from)
Definition: Math.h:70
static T Sqrt(const T from)
Definition: Math.h:238
Quat operator^(const T t)
Definition: Quat.h:142
T & operator[](const UInt_64 index)
Definition: Quat.h:181
Quat & operator=(const Mat4< T > &rotMatrix)
Definition: Quat.h:95
Quat(const Quat &quat)
Definition: Quat.h:72
Quat(const Mat4< T > &rotMatrix)
Definition: Quat.h:66
Quat< T > GetInverse()
Definition: Quat.h:353
void Inverse()
Definition: Quat.h:358
void ToAxisAngle(Vec3< T > *vectAxis, T *flAngle)
Definition: Quat.h:198
Quat(const T scalar)
Definition: Quat.h:77
Mat4< T > ToMatrix() const
Definition: Quat.h:274
bool operator!=(const Quat &quat) const
Definition: Quat.h:159
Quat operator*(const T scalar)
Definition: Quat.h:117
Quat(const Vec3< T > &n, const T a)
Definition: Quat.h:61
Quat< T > GetConjugate()
Definition: Quat.h:341
static Quat< T > Slerp(Quat< T > start, Quat< T > finish, const T t)
Definition: Quat.h:365
Quat< T > GetNormalized()
Definition: Quat.h:319
Quat(const T w, const T x, const T y, const T z)
Definition: Quat.h:24
Quat operator-(const Quat &other) const
Definition: Quat.h:112
T Dot(const Quat &other) const
Definition: Quat.h:336
Quat operator-() const
Definition: Quat.h:107
bool operator==(const Quat &quat) const
Definition: Quat.h:154
Quat(const Vec3< T > &euler)
Definition: Quat.h:45
void Conjugate()
Definition: Quat.h:346
Vec3< T > operator*(const Vec3< T > &vect)
Definition: Quat.h:133
void ToQuaternion(const Mat4< T > &rotMatrix)
Definition: Quat.h:211
T operator[](const UInt_64 index) const
Definition: Quat.h:164
Quat & operator=(const Quat &quat)
Definition: Quat.h:82
Quat(const T yaw, const T pitch, const T roll)
Definition: Quat.h:29
Quat operator*(const Quat &other)
Definition: Quat.h:122
Quat operator+(const Quat &other) const
Definition: Quat.h:102
void Normalize()
Definition: Quat.h:326
float GetMagnitude()
Definition: Quat.h:314
Quat()
Definition: Quat.h:19
Vec3< T > GetNorm() const
Definition: Vec3.h:313
Quat< float > Quat_f
Definition: Quat.h:395