summaryrefslogtreecommitdiffhomepage
path: root/src/raymath.h
diff options
context:
space:
mode:
authorRay <[email protected]>2021-03-19 18:24:12 +0100
committerRay <[email protected]>2021-03-19 18:24:12 +0100
commitfe9181c1b407cd4edb59b370dd9620040be33491 (patch)
treecd6705a874bf75a54001352d86767f69447d5ae4 /src/raymath.h
parent3e25760950a87854a715449c4d6bbc9c55694a64 (diff)
downloadraylib-fe9181c1b407cd4edb59b370dd9620040be33491.tar.gz
raylib-fe9181c1b407cd4edb59b370dd9620040be33491.zip
REVIEWED: QuaternionFromEuler() #1651
Diffstat (limited to 'src/raymath.h')
-rw-r--r--src/raymath.h28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/raymath.h b/src/raymath.h
index e4aedb51..38d9c4a3 100644
--- a/src/raymath.h
+++ b/src/raymath.h
@@ -1461,24 +1461,24 @@ RMDEF void QuaternionToAxisAngle(Quaternion q, Vector3 *outAxis, float *outAngle
*outAngle = resAngle;
}
-// Returns he quaternion equivalent to Euler angles
+// Returns the quaternion equivalent to Euler angles
// NOTE: Rotation order is ZYX
-RMDEF Quaternion QuaternionFromEuler(float yaw, float pitch, float roll)
+RMDEF Quaternion QuaternionFromEuler(float pitch, float yaw, float roll)
{
Quaternion q = { 0 };
- 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;
-
+ float x0 = cosf(pitch*0.5f);
+ float x1 = sinf(pitch*0.5f);
+ float y0 = cosf(yaw*0.5f);
+ float y1 = sinf(yaw*0.5f);
+ float z0 = cosf(roll*0.5f);
+ float z1 = sinf(roll*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;
+
return q;
}