7 float scale = sinf(halfRotation);
10 cosf(halfRotation / 2.0f),
11 axisAngle.
Axis.
X * scale,
12 axisAngle.
Axis.
Y * scale,
13 axisAngle.
Axis.
Z * scale
31 rotatedRight = rotationChange.
RotateVector(rightAngleRotated);
32 rotatedForward = rotationChange.
RotateVector(forwardAngleRotated);
44 float matrixTrace = X.
X + Y.
Y + Z.
Z;
48 square = sqrtf(1.0f + matrixTrace) * 2.0f;
51 q.
X = (Z.
Y - Y.
Z) / square;
52 q.
Y = (X.
Z - Z.
X) / square;
53 q.
Z = (Y.
X - X.
Y) / square;
55 else if ((X.
X > Y.
Y) && (X.
X > Z.
Z)){
56 square = sqrtf(1.0f + X.
X - Y.
Y - Z.
Z) * 2.0f;
58 q.
W = (Z.
Y - Y.
Z) / square;
60 q.
Y = (X.
Y + Y.
X) / square;
61 q.
Z = (X.
Z + Z.
X) / square;
64 square = sqrtf(1.0f + Y.
Y - X.
X - Z.
Z) * 2.0f;
66 q.
W = (X.
Z - Z.
X) / square;
67 q.
X = (X.
Y + Y.
X) / square;
69 q.
Z = (Y.
Z + Z.
Y) / square;
72 square = sqrtf(1.0f + Z.
Z - X.
X - Y.
Y) * 2.0f;
74 q.
W = (Y.
X - X.
Y) / square;
75 q.
X = (X.
Z + Z.
X) / square;
76 q.
Y = (Y.
Z + Z.
Y) / square;
86 float sx, sy, sz, cx, cy, cz;
98 sx = sinf(eA.
X * 0.5f);
99 sy = sinf(eA.
Y * 0.5f);
100 sz = sinf(eA.
Z * 0.5f);
101 cx = cosf(eA.
X * 0.5f);
102 cy = cosf(eA.
Y * 0.5f);
103 cz = cosf(eA.
Z * 0.5f);
162 if (dot < -0.999999f)
175 else if (dot > 0.999999f)
246 float quaternionCheck = sqrtf(1.0f - powf(q.
W, 2.0f));
248 if (quaternionCheck >= 0.001f)
251 axisAngle.
Axis.
X = q.
X / quaternionCheck;
252 axisAngle.
Axis.
Y = q.
Y / quaternionCheck;
253 axisAngle.
Axis.
Z = q.
Z / quaternionCheck;
258 axisAngle.
Axis.
X = 0.0f;
259 axisAngle.
Axis.
Y = 1.0f;
260 axisAngle.
Axis.
Z = 0.0f;
282 float angle = rightAngle - rightRotatedAngle;
303 float sqx = q.
X * q.
X;
304 float sqy = q.
Y * q.
Y;
305 float sqz = q.
Z * q.
Z;
309 eulerAngles.
Angles.
Y = asinf(-2.0f * (q.
X * q.
Z - q.
W * q.
Y));
310 if (fabs(eulerAngles.
Angles.
Y) < 0.499f) {
311 eulerAngles.
Angles.
X = atan2f(q.
Y * q.
Z + q.
W * q.
X, 0.5f - sqx - sqy);
312 eulerAngles.
Angles.
Z = atan2f(q.
X * q.
Y + q.
W * q.
Z, 0.5f - sqy - sqz);
314 eulerAngles.
Angles.
X = atan2f(q.
X * q.
Y - q.
W * q.
Z, 0.5f - sqx - sqz);
319 eulerAngles.
Angles.
Z = asinf(2.0f * (q.
X * q.
Y + q.
W * q.
Z));
320 if (fabs(eulerAngles.
Angles.
Z) < 0.499f) {
321 eulerAngles.
Angles.
X = atan2f(q.
Y * q.
Z - q.
W * q.
X, 0.5f - sqx - sqz);
322 eulerAngles.
Angles.
Y = atan2f(q.
X * q.
Z - q.
W * q.
Y, 0.5f - sqy - sqz);
324 eulerAngles.
Angles.
X = atan2f(-q.
X * q.
Y + q.
W * q.
Z, 0.5f - sqx - sqy);
329 eulerAngles.
Angles.
X = asinf(2.0f * (q.
Y * q.
Z + q.
W * q.
X));
330 if (fabs(eulerAngles.
Angles.
X) < 0.499f) {
331 eulerAngles.
Angles.
Y = atan2f(q.
X * q.
Z - q.
W * q.
Y, 0.5f - sqx - sqy);
332 eulerAngles.
Angles.
Z = atan2f(q.
Y * q.
Z - q.
W * q.
X, 0.5f - sqy - sqz);
334 eulerAngles.
Angles.
Y = atan2f(-q.
X * q.
Y + q.
W * q.
Z, 0.5f - sqx - sqz);
339 eulerAngles.
Angles.
Z = asinf(-2.0f * (q.
Y * q.
X - q.
W * q.
Z));
340 if (fabs(eulerAngles.
Angles.
Z) < 0.499f) {
341 eulerAngles.
Angles.
Y = atan2f(q.
X * q.
Z + q.
W * q.
Y, 0.5f - sqx - sqz);
342 eulerAngles.
Angles.
X = atan2f(q.
Y * q.
X + q.
W * q.
Z, 0.5f - sqy - sqz);
344 eulerAngles.
Angles.
Y = atan2f(-q.
X * q.
Y + q.
W * q.
Z, 0.5f - sqx - sqy);
349 eulerAngles.
Angles.
X = asinf(2.0f * (q.
Z * q.
Y + q.
W * q.
X));
350 if (fabs(eulerAngles.
Angles.
X) < 0.499f) {
351 eulerAngles.
Angles.
Z = atan2f(q.
X * q.
Z - q.
W * q.
Y, 0.5f - sqx - sqy);
352 eulerAngles.
Angles.
Y = atan2f(q.
Z * q.
Y - q.
W * q.
X, 0.5f - sqy - sqz);
354 eulerAngles.
Angles.
Z = atan2f(-q.
X * q.
Y + q.
W * q.
Z, 0.5f - sqx - sqz);
359 eulerAngles.
Angles.
Y = asinf(-2.0f * (q.
Z * q.
X - q.
W * q.
Y));
360 if (fabs(eulerAngles.
Angles.
Y) < 0.499f) {
361 eulerAngles.
Angles.
Z = atan2f(q.
X * q.
Y + q.
W * q.
Z, 0.5f - sqx - sqy);
362 eulerAngles.
Angles.
X = atan2f(q.
Z * q.
Y + q.
W * q.
X, 0.5f - sqy - sqz);
364 eulerAngles.
Angles.
Z = atan2f(-q.
X * q.
Y + q.
W * q.
Z, 0.5f - sqx - sqz);
369 eulerAngles.
Angles.
Y = asinf(-2.0f * (q.
X * q.
Z - q.
W * q.
Y));
370 if (fabs(eulerAngles.
Angles.
Y) < 0.499f) {
371 eulerAngles.
Angles.
X = atan2f(q.
Y * q.
Z + q.
W * q.
X, 0.5f - sqx - sqy);
372 eulerAngles.
Angles.
Z = atan2f(q.
X * q.
Y + q.
W * q.
Z, 0.5f - sqy - sqz);
374 eulerAngles.
Angles.
X = atan2f(q.
X * q.
Y - q.
W * q.
Z, 0.5f - sqx - sqz);
387 float t = eulerAngles.
Angles.
X;
401 float yaw = atan2f( 2.0f * (q.
Y * q.
Z + q.
W * q.
X), powf(q.
W, 2) - powf(q.
X, 2) - powf(q.
Y, 2) + powf(q.
Z, 2));
402 float pitch = asinf(-2.0f * (q.
X * q.
Z - q.
W * q.
Y));
403 float roll = atan2f( 2.0f * (q.
X * q.
Y + q.
W * q.
Z), powf(q.
W, 2) + powf(q.
X, 2) - powf(q.
Y, 2) - powf(q.
Z, 2));
Provides a collection of mathematical utility functions and constants.
Defines the Rotation class for handling 3D rotations using various representations.
Defines a rotation in 3D space using an axis and an angle.
Vector3D Axis
The axis of rotation, represented as a 3D vector.
float Rotation
The angle of rotation in degrees (or radians, depending on usage).
Defines a rotation in 3D space using a direction vector and a rotation angle.
float Rotation
The angle of rotation in degrees (or radians, depending on usage).
Vector3D Direction
The direction vector defining the axis of rotation.
Encapsulates a 3D rotation using Euler angles and a specific order of application.
Vector3D Angles
The three rotation angles (pitch, yaw, roll) in degrees (or radians based on usage).
EulerOrder Order
The order in which the angles are applied (e.g., XYZ, ZYX, etc.).
Specifies the order and frame of reference for Euler rotations.
AxisFrame FrameTaken
The frame of reference (static or rotating).
Vector3D Permutation
Permutation vector for axis reordering.
@ YZX
Y → Z → X rotation order.
@ XZY
X → Z → Y rotation order.
@ ZYX
Z → Y → X rotation order.
@ YXZ
Y → X → Z rotation order.
@ ZXY
Z → X → Y rotation order.
@ XYZ
X → Y → Z rotation order.
Axis AxisOrder
The sequence of axes for the rotation order.
@ Rotating
Rotations relative to a rotating frame.
static T RadiansToDegrees(T radians)
Converts radians to degrees.
static const float MPI
Mathematical constant (3.14159265358979323846...).
static T DegreesToRadians(T degrees)
Converts degrees to radians.
A mathematical construct representing a rotation in 3D space.
Quaternion Conjugate() const
Returns the conjugate of this quaternion (W stays the same, X/Y/Z get negated).
Quaternion UnitQuaternion() const
Returns a unit quaternion (normalized) version of this quaternion.
Vector2D RotateVector(const Vector2D &v) const
Rotates a 2D vector by this quaternion, projecting it in 2D.
float W
Scalar part of the quaternion.
float Z
Z component of the quaternion's vector part.
float X
X component of the quaternion's vector part.
float Y
Y component of the quaternion's vector part.
Vector2D UnrotateVector(const Vector2D &coordinate) const
Applies the inverse of this quaternion's rotation to a 2D vector.
Represents a 3D rotation matrix and provides operations for rotation and matrix manipulation.
Vector3D YAxis
Y-axis vector of the rotation matrix.
Vector3D XAxis
X-axis vector of the rotation matrix.
Vector3D ZAxis
Z-axis vector of the rotation matrix.
static Vector3D RotateVector(Vector3D rotate, Vector3D coordinates)
Rotates a vector using the rotation matrix.
EulerAngles RotationMatrixToEulerAngles(const RotationMatrix &rM, const EulerOrder &order)
Converts a RotationMatrix to Euler angles.
YawPitchRoll GetYawPitchRoll()
Gets the yaw-pitch-roll representation of the rotation.
RotationMatrix EulerAnglesToRotationMatrix(const EulerAngles &eulerAngles)
Converts Euler angles to a RotationMatrix.
Quaternion EulerAnglesToQuaternion(const EulerAngles &eulerAngles)
Converts Euler angles to a Quaternion.
Quaternion YawPitchRollToQuaternion(const YawPitchRoll &ypr)
Converts a YawPitchRoll representation to a Quaternion.
AxisAngle GetAxisAngle()
Gets the axis-angle representation of the rotation.
RotationMatrix GetRotationMatrix()
Gets the rotation matrix representation of the rotation.
EulerAngles GetEulerAngles(const EulerOrder &order)
Gets the Euler angles representation of the rotation.
Rotation()
Default constructor.
Quaternion GetQuaternion()
Gets the quaternion representation of the rotation.
DirectionAngle GetDirectionAngle()
Gets the direction-angle representation of the rotation.
Quaternion RotationMatrixToQuaternion(const RotationMatrix &rM)
Converts a RotationMatrix to a Quaternion.
Quaternion quaternionRotation
Quaternion representation of the rotation.
Quaternion DirectionAngleToQuaternion(const DirectionAngle &directionAngle)
Converts a DirectionAngle to a Quaternion.
Quaternion AxisAngleToQuaternion(const AxisAngle &axisAngle)
Converts an AxisAngle to a Quaternion.
Quaternion QuaternionFromDirectionVectors(const Vector3D &initial, const Vector3D &target)
Creates a Quaternion from direction vectors.
Represents a 3D vector (X, Y, Z) and provides methods for vector arithmetic.
Vector3D CrossProduct(const Vector3D &vector) const
Computes the cross product of this vector with another Vector3D.
float Z
The Z-component of the 3D vector.
Vector3D UnitSphere() const
Normalizes this vector such that its magnitude is 1 (if non-zero).
Vector3D Permutate(const Vector3D &permutation) const
Permutates the components of this vector using another Vector3D as an index/offset.
float X
The X-component of the 3D vector.
float Y
The Y-component of the 3D vector.
float DotProduct(const Vector3D &vector) const
Computes the dot product of this vector with another Vector3D.
float Magnitude() const
Computes the magnitude (length) of this vector using the formula sqrt(X^2 + Y^2 + Z^2).
A class to represent yaw, pitch, and roll angles for orientation.