8#include <Common/assertion.h>
21 :
Base(
std::array<T, 4>{vx, vy, vz, vw})
28 static_cast<T>(other.x()),
29 static_cast<T>(other.y()),
30 static_cast<T>(other.z()),
31 static_cast<T>(other.w()))
38 TQuaternion<U>(xyzwValues[0], xyzwValues[1], xyzwValues[2], xyzwValues[3]))
45 setRot(normalizedAxis, radians);
54 const T trace = m.
m[0][0] + m.
m[1][1] + m.
m[2][2];
57 const T s =
static_cast<T
>(0.5) / std::sqrt(trace + 1);
58 x() = (m.
m[2][1] - m.
m[1][2]) * s;
59 y() = (m.
m[0][2] - m.
m[2][0]) * s;
60 z() = (m.
m[1][0] - m.
m[0][1]) * s;
61 w() =
static_cast<T
>(0.25) / s;
65 if(m.
m[0][0] > m.
m[1][1] && m.
m[0][0] > m.
m[2][2])
67 const T s =
static_cast<T
>(0.5) / std::sqrt(1 + m.
m[0][0] - m.
m[1][1] - m.
m[2][2]);
68 x() =
static_cast<T
>(0.25) / s;
69 y() = (m.
m[0][1] + m.
m[1][0]) * s;
70 z() = (m.
m[0][2] + m.
m[2][0]) * s;
71 w() = (m.
m[2][1] - m.
m[1][2]) * s;
73 else if(m.
m[1][1] > m.
m[2][2])
75 const T s =
static_cast<T
>(0.5) / std::sqrt(1 + m.
m[1][1] - m.
m[0][0] - m.
m[2][2]);
76 x() = (m.
m[0][1] + m.
m[1][0]) * s;
77 y() =
static_cast<T
>(0.25) / s;
78 z() = (m.
m[1][2] + m.
m[2][1]) * s;
79 w() = (m.
m[0][2] - m.
m[2][0]) * s;
83 const T s =
static_cast<T
>(0.5) / std::sqrt(1 + m.
m[2][2] - m.
m[0][0] - m.
m[1][1]);
84 x() = (m.
m[0][2] + m.
m[2][0]) * s;
85 y() = (m.
m[1][2] + m.
m[2][1]) * s;
86 z() =
static_cast<T
>(0.25) / s;
87 w() = (m.
m[1][0] - m.
m[0][1]) * s;
147 w() * xyz.
y() - x() * xyz.
z() + z() * xyz.
x(),
148 w() * xyz.
z() + x() * xyz.
y() - y() * xyz.
x(),
149 -x() * xyz.
x() - y() * xyz.
y() - z() * xyz.
z());
169 return ::ph::math::length(m);
181 PH_ASSERT(out_result);
206 const T _x = w() * rhs.
x() + x() * rhs.
w() + y() * rhs.
z() - z() * rhs.
y();
207 const T _y = w() * rhs.
y() - x() * rhs.
z() + y() * rhs.
w() + z() * rhs.
x();
208 const T _z = w() * rhs.
z() + x() * rhs.
y() - y() * rhs.
x() + z() * rhs.
w();
209 const T _w = w() * rhs.
w() - x() * rhs.
x() - y() * rhs.
y() - z() * rhs.
z();
222 return TQuaternion(x() * rhs, y() * rhs, z() * rhs, w() * rhs);
228 return TQuaternion(x() - rhs.
x(), y() - rhs.
y(), z() - rhs.
z(), w() - rhs.
w());
234 return TQuaternion(x() + rhs.
x(), y() + rhs.
y(), z() + rhs.
z(), w() + rhs.
w());
240 return ::ph::math::dot_product(m, rhs.
m);
246 const T sinHalfAngle = std::sin(radians / 2);
247 const T cosHalfAngle = std::cos(radians / 2);
249 x() = normalizedAxis.
x() * sinHalfAngle;
250 y() = normalizedAxis.
y() * sinHalfAngle;
251 z() = normalizedAxis.
z() * sinHalfAngle;
258 PH_ASSERT(out_result);
260 out_result->
m[0][0] = 1 - 2 * (y() * y() + z() * z());
261 out_result->
m[0][1] = 2 * (x() * y() - z() * w());
262 out_result->
m[0][2] = 2 * (y() * w() + x() * z());
263 out_result->
m[0][3] = 0;
265 out_result->
m[1][0] = 2 * (x() * y() + z() * w());
266 out_result->
m[1][1] = 1 - 2 * (x() * x() + z() * z());
267 out_result->
m[1][2] = 2 * (y() * z() - x() * w());
268 out_result->
m[1][3] = 0;
270 out_result->
m[2][0] = 2 * (x() * z() - y() * w());
271 out_result->
m[2][1] = 2 * (y() * z() + x() * w());
272 out_result->
m[2][2] = 1 - 2 * (x() * x() + y() * y());
273 out_result->
m[2][3] = 0;
275 out_result->
m[3][0] = 0;
276 out_result->
m[3][1] = 0;
277 out_result->
m[3][2] = 0;
278 out_result->
m[3][3] = 1;
std::array< T, N > m
Definition TArithmeticArrayBase.h:217
Represents a 4x4 matrix.
Definition TMatrix4.h:17
Elements m
Definition TMatrix4.h:24
Represents a quaternion.
Definition TQuaternion.h:17
void toRotationMatrix(TMatrix4< T > *out_result) const
Definition TQuaternion.ipp:256
TQuaternion conjugate() const
Definition TQuaternion.ipp:173
T & x()
Definition TQuaternion.ipp:95
TQuaternion add(const TQuaternion &rhs) const
Definition TQuaternion.ipp:232
TQuaternion & mulLocal(const TQuaternion &rhs)
Definition TQuaternion.ipp:204
T & z()
Definition TQuaternion.ipp:107
T & w()
Definition TQuaternion.ipp:113
T length() const
Definition TQuaternion.ipp:167
T dot(const TQuaternion &rhs) const
Definition TQuaternion.ipp:238
void setRot(const TVector3< T > &normalizedAxis, T radians)
Definition TQuaternion.ipp:244
TQuaternion sub(const TQuaternion &rhs) const
Definition TQuaternion.ipp:226
TQuaternion & conjugateLocal()
Definition TQuaternion.ipp:188
TQuaternion normalize() const
Definition TQuaternion.ipp:153
TQuaternion & normalizeLocal()
Definition TQuaternion.ipp:159
TQuaternion(T vx, T vy, T vz, T vw)
Definition TQuaternion.ipp:20
static TQuaternion makeNoRotation()
Definition TQuaternion.ipp:14
TQuaternion mul(const TVector3< T > &xyz) const
Quaternion multiplication (treating the input's w component as 0).
Definition TQuaternion.ipp:143
T & y()
Definition TQuaternion.ipp:101
Represents a 3-D vector.
Definition TVector3.h:17
T & y()
Definition TVector3.ipp:189
T & z()
Definition TVector3.ipp:195
T & x()
Definition TVector3.ipp:183
Miscellaneous math utilities.
Math functions and utilities.
Definition TransformInfo.h:10
void normalize(std::array< T, N > &vec)
Treating input values as a vector and normalize it. Notice that normalizing a integer typed vector wi...
Definition math.ipp:142