1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 #pragma once19 20 #ifdef MATH_ENABLE_STL_SUPPORT21 #include <string>22 #endif23 #include "[Math/MathFwd.h]"24 25 #ifdef MATH_QT_INTEROP26 #include <QQuaternion>27 #endif28 29 30 31 32 33 #ifdef MATH_OGRE_INTEROP34 #include <OgreQuaternion.h>35 #endif36 37 [MATH_BEGIN_NAMESPACE]38 39 40 class [Quat]41 {42 public:43 float [x]; 44 float [y]; 45 float [z]; 46 float [w]; 47 48 49 [Quat]() {}50 51 52 [Quat](const [Quat] &rhs) { [x] = rhs.[x]; [y] = rhs.[y]; [z] = rhs.[z]; [w] = rhs.[w]; }53 54 55 56 57 explicit [Quat](const float *data);58 59 explicit [Quat](const [float3x3] &rotationMatrix);60 explicit [Quat](const [float3x4] &rotationMatrix);61 explicit [Quat](const [float4x4] &rotationMatrix);62 63 64 65 66 67 68 [Quat](float [x], float [y], float [z], float [w]);69 70 71 72 73 [Quat](const [float3] &rotationAxis, float rotationAngleRadians);74 75 76 [float3] [WorldX]() const;77 78 [float3] [WorldY]() const;79 80 [float3] [WorldZ]() const;81 82 83 [float3] [Axis]() const;84 85 86 float [Angle]() const;87 88 89 90 float [Dot](const [Quat] &rhs) const;91 92 float [LengthSq]() const;93 94 float [Length]() const;95 96 97 98 float [Normalize]();99 100 101 [Quat] [Normalized]() const;102 103 104 bool [IsNormalized](float epsilon = 1[e]-3f) const;105 106 bool [IsInvertible](float epsilon = 1[e]-3f) const;107 108 109 bool [IsFinite]() const;110 111 112 bool [Equals](const [Quat] &rhs, float epsilon = 1[e]-3f) const;113 114 115 116 float *[ptr]();117 const float *[ptr]() const;118 119 120 121 122 123 void [Inverse]();124 125 126 [Quat] [Inverted]() const;127 128 129 130 131 132 133 float [InverseAndNormalize]();134 135 136 void [Conjugate]();137 138 139 [Quat] [Conjugated]() const;140 141 142 [float3] [Transform](float [x], float [y], float [z]) const;143 [float3] [Transform](const [float3] &vec) const;144 145 146 [float4] [Transform](const [float4] &vec) const;147 148 [Quat] [Lerp](const [Quat] &target, float t) const;149 static [Quat] [Lerp](const [Quat] &source, const [Quat] &target, float t);150 [Quat] [Slerp](const [Quat] &target, float t) const;151 static [Quat] [Slerp](const [Quat] &source, const [Quat] &target, float t);152 153 154 float [AngleBetween](const [Quat] &target) const;155 156 [float3] [AxisFromTo](const [Quat] &target) const;157 158 159 void [ToAxisAngle]([float3] &rotationAxis, float &rotationAngleRadians) const;160 161 162 163 void [SetFromAxisAngle](const [float3] &rotationAxis, float rotationAngleRadians);164 165 166 void [Set](const [float3x3] &matrix);167 void [Set](const [float3x4] &matrix);168 void [Set](const [float4x4] &matrix);169 170 171 172 void [Set](float [x], float [y], float [z], float [w]);173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 static [Quat] [LookAt](const [float3] &localForward, const [float3] &targetDirection, const [float3] &localUp, const [float3] &worldUp);201 202 203 static [Quat] [RotateX](float angleRadians);204 205 static [Quat] [RotateY](float angleRadians);206 207 static [Quat] [RotateZ](float angleRadians);208 209 210 static [Quat] [RotateAxisAngle](const [float3] &axisDirection, float angleRadians);211 212 213 214 215 216 217 218 static [Quat] [RotateFromTo](const [float3] &sourceDirection, const [float3] &targetDirection);219 220 221 222 223 224 static [Quat] [RotateFromTo](const [float3] &sourceDirection, const [float3] &targetDirection,225 const [float3] &sourceDirection2, const [float3] &targetDirection2);226 227 228 229 230 static [Quat] [FromEulerXYX](float x2, float [y], float [x]);231 static [Quat] [FromEulerXZX](float x2, float [z], float [x]); 232 static [Quat] [FromEulerYXY](float y2, float [x], float [y]); 233 static [Quat] [FromEulerYZY](float y2, float [z], float [y]); 234 static [Quat] [FromEulerZXZ](float z2, float [x], float [z]); 235 static [Quat] [FromEulerZYZ](float z2, float [y], float [z]); 236 static [Quat] [FromEulerXYZ](float [x], float [y], float [z]); 237 static [Quat] [FromEulerXZY](float [x], float [z], float [y]); 238 static [Quat] [FromEulerYXZ](float [y], float [x], float [z]); 239 static [Quat] [FromEulerYZX](float [y], float [z], float [x]); 240 static [Quat] [FromEulerZXY](float [z], float [x], float [y]); 241 static [Quat] [FromEulerZYX](float [z], float [y], float [x]); 242 243 244 static [Quat] [RandomRotation]([LCG] &lcg);245 246 247 248 249 250 251 252 253 254 255 256 257 258 [float3] [ToEulerXYX]() const;259 [float3] [ToEulerXZX]() const; 260 [float3] [ToEulerYXY]() const; 261 [float3] [ToEulerYZY]() const; 262 [float3] [ToEulerZXZ]() const; 263 [float3] [ToEulerZYZ]() const; 264 [float3] [ToEulerXYZ]() const; 265 [float3] [ToEulerXZY]() const; 266 [float3] [ToEulerYXZ]() const; 267 [float3] [ToEulerYZX]() const; 268 [float3] [ToEulerZXY]() const; 269 [float3] [ToEulerZYX]() const; 270 271 [float3x3] [ToFloat3x3]() const;272 [float3x4] [ToFloat3x4]() const;273 [float4x4] [ToFloat4x4]() const;274 275 #ifdef MATH_ENABLE_STL_SUPPORT276 277 std::string ToString() const;278 279 280 std::string ToString2() const;281 282 283 std::string SerializeToString() const;284 #endif285 286 static [Quat] [FromString](const char *str);287 #ifdef MATH_ENABLE_STL_SUPPORT288 static [Quat] [FromString](const std::string &str) { return [FromString](str.c_str()); }289 #endif290 291 292 293 294 [Quat] [operator *](const [Quat] &rhs) const;295 296 297 298 299 300 [float3] [operator *](const [float3] &rhs) const;301 302 303 304 static const [Quat] [identity];305 306 307 308 309 static const [Quat] [nan];310 311 312 [Quat] [operator /](const [Quat] &rhs) const;313 314 #ifdef MATH_OGRE_INTEROP315 [Quat](const Ogre::Quaternion &other) { [w] = other.w; [x] = other.x; [y] = other.y; [z] = other.z; }316 operator Ogre::Quaternion() const { return Ogre::Quaternion([w], [x], [y], [z]); }317 #endif318 319 320 321 322 323 324 #ifdef MATH_QT_INTEROP325 [Quat](const QQuaternion &other) { [w] = other.scalar(); [x] = other.x(); [y] = other.y(); [z] = other.z(); }326 operator QQuaternion() const { return QQuaternion([w], [x], [y], [z]); }327 operator QString() const { return toString(); }328 QString toString() const { return ToString2().c_str(); }329 QQuaternion ToQQuaternion() const { return (QQuaternion)*this; }330 static [Quat] FromQQuaternion(const QQuaternion &q) { return ([Quat])q; }331 static [Quat] [FromString](const QString &str) { return [FromString](str.toStdString()); }332 #endif333 #ifdef MATH_BULLET_INTEROP334 [Quat](const btQuaternion &other) { [w] = other.w(); [x] = other.x(); [y] = other.y(); [z] = other.z(); }335 operator btQuaternion() const { return btQuaternion([x], [y], [z], [w]); }336 #endif337 338 339 340 [Quat] [Mul](const [Quat] &rhs) const;341 342 [Quat] [Mul](const [float3x3] &rhs) const;343 344 345 346 347 [float3] [Mul](const [float3] &vector) const;348 [float4] [Mul](const [float4] &vector) const;349 350 private: 351 352 353 354 355 356 357 [Quat] [operator *](float scalar) const;358 359 [Quat] [operator /](float scalar) const;360 361 362 363 [Quat] operator +(const [Quat] &rhs) const;364 365 [Quat] operator -(const [Quat] &rhs) const;366 367 368 369 [Quat] operator -() const;370 };371 372 #ifdef MATH_ENABLE_STL_SUPPORT373 374 std::ostream &operator <<(std::ostream &out, const [Quat] &rhs);375 #endif376 377 [Quat] [Lerp](const [Quat] &a, const [Quat] &b, float t);378 [Quat] [Slerp](const [Quat] &a, const [Quat] &b, float t);379 380 [MATH_END_NAMESPACE]381 382 #ifdef MATH_QT_INTEROP383 Q_DECLARE_METATYPE([Quat])384 Q_DECLARE_METATYPE([Quat]*)385 #endif Go back to previous page