summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorRay <[email protected]>2021-03-18 13:38:56 +0100
committerRay <[email protected]>2021-03-18 13:38:56 +0100
commit2b9d81c9bca663a42696eaf0eafd531c7fb2c8a4 (patch)
tree77ed091da9a6bfd247812283a80d115af090ac09 /src
parente5834210d39879d1fb8ade50a6f043aa2e6e3f73 (diff)
downloadraylib-2b9d81c9bca663a42696eaf0eafd531c7fb2c8a4.tar.gz
raylib-2b9d81c9bca663a42696eaf0eafd531c7fb2c8a4.zip
REVIEWED: QuaternionFromEuler() #1651
Diffstat (limited to 'src')
-rw-r--r--src/raymath.h25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/raymath.h b/src/raymath.h
index c1c20c66..0e3b6042 100644
--- a/src/raymath.h
+++ b/src/raymath.h
@@ -1439,21 +1439,22 @@ RMDEF void QuaternionToAxisAngle(Quaternion q, Vector3 *outAxis, float *outAngle
}
// Returns he quaternion equivalent to Euler angles
-RMDEF Quaternion QuaternionFromEuler(float roll, float pitch, float yaw)
+// NOTE: Rotation order is ZYX
+RMDEF Quaternion QuaternionFromEuler(float yaw, float pitch, float roll)
{
Quaternion q = { 0 };
- float x0 = cosf(roll*0.5f);
- float x1 = sinf(roll*0.5f);
- float y0 = cosf(pitch*0.5f);
- float y1 = sinf(pitch*0.5f);
- float z0 = cosf(yaw*0.5f);
- float z1 = sinf(yaw*0.5f);
-
- q.x = x1*y0*z0 - x0*y1*z1;
- q.y = x0*y1*z0 + x1*y0*z1;
- q.z = x0*y0*z1 - x1*y1*z0;
- q.w = x0*y0*z0 + x1*y1*z1;
+ float cy = cosf(yaw*0.5f);
+ float sy = sinf(yaw*0.5f);
+ float cp = cosf(pitch*0.5f);
+ float sp = sinf(pitch*0.5f);
+ float cr = cosf(roll*0.5f);
+ float sr = sinf(roll*0.5f);
+
+ q.x = sr*cp*cy - cr*sp*sy;
+ q.y = cr*sp*cy + sr*cp*sy;
+ q.z = cr*cp*sy - sr*sp*cy;
+ q.w = cr*cp*cy + sr*sp*sy;
return q;
}