Last active
March 21, 2018 10:47
-
-
Save vurtun/be2695aae07a4aec03780d28e3925c8e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void | |
Quat_FromEulerXYZ(float *euler_quat, float x, float y, float z) | |
{ | |
float sx = (float)sin((double)(x * 0.5f)); | |
float sy = (float)sin((double)(y * 0.5f)); | |
float sz = (float)sin((double)(z * 0.5f)); | |
float cx = (float)cos((double)(x * 0.5f)); | |
float cy = (float)cos((double)(y * 0.5f)); | |
float cz = (float)cos((double)(z * 0.5f)); | |
/* XYZ - Rotation order (Quaternion: |x y z w|) | |
* Multiply each quaternion out: | |
X * Y * Z | |
=> |sx 0 0 cx| * |0 0 sz cz| * |0 sy 0 cy| | |
=> |sx 0 0 cx| * |(sy*sz) (sy*cz) (cy*sz) (cy*cz)| | |
which multiplies to: */ | |
euler_quat[0] = cx*sy*sz + sx*cy*cz; | |
euler_quat[1] = cx*sy*cz - sx*cy*sz; | |
euler_quat[2] = cx*cy*sz + sx*sy*cz; | |
euler_quat[3] = cx*cy*cz - sx*sy*sz; | |
} | |
static void | |
Quat_FromEulerXZY(float *euler_quat, float x, float y, float z) | |
{ | |
float sx = (float)sin((double)(x * 0.5f)); | |
float sy = (float)sin((double)(y * 0.5f)); | |
float sz = (float)sin((double)(z * 0.5f)); | |
float cx = (float)cos((double)(x * 0.5f)); | |
float cy = (float)cos((double)(y * 0.5f)); | |
float cz = (float)cos((double)(z * 0.5f)); | |
/* XZY - Rotation order (Quaternion: |x y z w|) | |
* Multiply each quaternion out: | |
X * Z * Y | |
=> |sx 0 0 cx| * |0 0 sz cz| * |0 sy 0 cy| | |
=> |sx 0 0 cx| * |(-sz*sy) (cz*sy) (sz*cy) (cz*cy)| | |
which multiplies to: */ | |
euler_quat[0] = sx*cz*cy - cx*sz*sy; | |
euler_quat[1] = cx*cz*sy - sx*sz*cy; | |
euler_quat[2] = cx*sz*cy + sx*cz*sy; | |
euler_quat[3] = cx*cz*cy + sx*sz*sy; | |
} | |
static void | |
Quat_FromEulerYXZ(float *euler_quat, float x, float y, float z) | |
{ | |
float sx = (float)sin((double)(x * 0.5f)); | |
float sy = (float)sin((double)(y * 0.5f)); | |
float sz = (float)sin((double)(z * 0.5f)); | |
float cx = (float)cos((double)(x * 0.5f)); | |
float cy = (float)cos((double)(y * 0.5f)); | |
float cz = (float)cos((double)(z * 0.5f)); | |
/* YXZ - Rotation order (Quaternion: |x y z w|) | |
* Multiply each quaternion out: | |
Y * X * Z | |
=> |0 sy 0 cy| * |sx 0 0 cx| * |0 0 sz cz| | |
=> |0 sy 0 cy| * |(sx*cz) (-sx*sz) (cx*sz) (cx*cz)| | |
which multiplies to: */ | |
euler_quat[0] = cy*sx*cz + sy*cx*sz; | |
euler_quat[1] = sy*cx*cz - cy*sx*sz; | |
euler_quat[2] = cy*cx*sz - sy*sx*cz; | |
euler_quat[3] = cy*cx*cz + sy*sx*sz; | |
} | |
static void | |
Quat_FromEulerYZX(float *euler_quat, float x, float y, float z) | |
{ | |
float sx = (float)sin((double)(x * 0.5f)); | |
float sy = (float)sin((double)(y * 0.5f)); | |
float sz = (float)sin((double)(z * 0.5f)); | |
float cx = (float)cos((double)(x * 0.5f)); | |
float cy = (float)cos((double)(y * 0.5f)); | |
float cz = (float)cos((double)(z * 0.5f)); | |
/* YZX - Rotation order (Quaternion: |x y z w|) | |
* Multiply each quaternion out: | |
Y * Z * X | |
=> |0 sy 0 cy| * |0 0 sz cz| * |sx 0 0 cx| | |
=> |0 sy 0 cy| * |(cz*sx) (sz*sx) (sz*cx) (cz*cx)| | |
which multiplies to: */ | |
euler_quat[0] = cy*cz*sx + sy*sz*cx; | |
euler_quat[1] = cy*sz*sx + sy*cz*cx; | |
euler_quat[2] = cy*sz*cx - sy*cz*sx; | |
euler_quat[3] = cy*cz*cx - sy*sz*sx; | |
} | |
static void | |
Quat_FromEulerZYX(float *euler_quat, float x, float y, float z) | |
{ | |
float sx = (float)sin((double)(x * 0.5f)); | |
float sy = (float)sin((double)(y * 0.5f)); | |
float sz = (float)sin((double)(z * 0.5f)); | |
float cx = (float)cos((double)(x * 0.5f)); | |
float cy = (float)cos((double)(y * 0.5f)); | |
float cz = (float)cos((double)(z * 0.5f)); | |
/* ZYX - Rotation order (Quaternion: |x y z w|) | |
* Multiply each quaternion out: | |
Z * Y * X | |
=> |0 0 sz cz| * |0 sy 0 cy| * |sx 0 0 cx| | |
=> |0 0 sz cz| * |(cy*sx) (sy*cx) (-sy*sx) (cy*cx)| | |
which multiplies to: */ | |
euler_quat[0] = cz*cy*sx - sz*sy*cx; | |
euler_quat[1] = cz*sy*cx + sz*cy*sx; | |
euler_quat[2] = sz*cy*cx - cz*sy*sx; | |
euler_quat[3] = cz*cy*cx + sz*sy*sx; | |
} | |
static void | |
Quat_FromEulerZXY(float *euler_quat, float x, float y, float z) | |
{ | |
float sx = (float)sin((double)(x * 0.5f)); | |
float sy = (float)sin((double)(y * 0.5f)); | |
float sz = (float)sin((double)(z * 0.5f)); | |
float cx = (float)cos((double)(x * 0.5f)); | |
float cy = (float)cos((double)(y * 0.5f)); | |
float cz = (float)cos((double)(z * 0.5f)); | |
/* ZXY - Rotation order (Quaternion: |x y z w|) | |
* Multiply each quaternion out: | |
Z * X * Y | |
=> |0 0 sz cz| * |sx 0 0 cx| * |0 sy 0 cy| | |
=> |0 0 sz cz| * |(sx*cy) (cx*sy) (sx*sy) (cx*cy)| | |
which multiplies to: */ | |
euler_quat[0] = cz*sx*cy - sz*cx*sy; | |
euler_quat[1] = cz*cx*sy + sz*sx*cy; | |
euler_quat[2] = cz*sx*sy + sz*cx*cy; | |
euler_quat[3] = cz*cx*cy - sz*sx*sy; | |
} | |
static void | |
Quat_FromEulerXYX(float *euler_quat, float x, float y) | |
{ | |
float sx = (float)sin((double)(x * 0.5f)); | |
float sy = (float)sin((double)(y * 0.5f)); | |
float cx = (float)cos((double)(x * 0.5f)); | |
float cy = (float)cos((double)(y * 0.5f)); | |
/* XYX - Rotation order (Quaternion: |x y z w|) | |
* Multiply each quaternion out: | |
X * Y * X | |
=> |sx 0 0 cx| * |0 sy 0 cy| * |sx 0 0 cx| | |
=> |sx 0 0 cx| * |(cy*sx) (sy*cx) (-sy*sx) (cy*cx)| | |
which multiplies to: */ | |
euler_quat[0] = 2.0f*cx*cy*sx; | |
euler_quat[1] = cx*sy*cx + sx*sy*sx; | |
euler_quat[2] = 0.0f; | |
euler_quat[3] = cx*cy*cx - sx*cy*sx; | |
} | |
static void | |
Quat_FromEulerXZX(float *euler_quat, float x, float z) | |
{ | |
float sx = (float)sin((double)(x * 0.5f)); | |
float sz = (float)sin((double)(z * 0.5f)); | |
float cx = (float)cos((double)(x * 0.5f)); | |
float cz = (float)cos((double)(z * 0.5f)); | |
/* XZX - Rotation order (Quaternion: |x y z w|) | |
* Multiply each quaternion out: | |
X * Z * X | |
=> |sx 0 0 cx| * |0 0 sz cz| * |sx 0 0 cx| | |
=> |sx 0 0 cx| * |(cz*sx) (sz*sx) (sz*cx) (cz*cx)| | |
which multiplies to: */ | |
euler_quat[0] = 2.0f*cx*cz*cx; | |
euler_quat[1] = 0.0f; | |
euler_quat[2] = cx*sz*cx + sx*sz*sx; | |
euler_quat[3] = cx*cz*cx - sx*cz*sx; | |
} | |
static void | |
Quat_FromEulerYXY(float *euler_quat, float x, float y) | |
{ | |
float sx = (float)sin((double)(x * 0.5f)); | |
float sy = (float)sin((double)(y * 0.5f)); | |
float cx = (float)cos((double)(x * 0.5f)); | |
float cy = (float)cos((double)(y * 0.5f)); | |
/* YXY - Rotation order (Quaternion: |x y z w|) | |
* Multiply each quaternion out: | |
Y * X * Y | |
=> |0 sy 0 cy| * |0 0 sz cz| * |0 sy 0 cy| | |
=> |0 sy 0 cy| * |(sx*cy) (cx*sy) (sx*sy) (cx*cy)| | |
which multiplies to: */ | |
euler_quat[0] = cy*sx*cy + sy*sx*sy; | |
euler_quat[1] = 2.0f*cy*cx*sy; | |
euler_quat[2] = 0.0f; | |
euler_quat[3] = cy*cx*cy - sy*cx*sy; | |
} | |
static void | |
Quat_FromEulerYZY(float *euler_quat, float y, float z) | |
{ | |
float sy = (float)sin((double)(y * 0.5f)); | |
float sz = (float)sin((double)(z * 0.5f)); | |
float cy = (float)cos((double)(y * 0.5f)); | |
float cz = (float)cos((double)(z * 0.5f)); | |
/* YZY - Rotation order (Quaternion: |x y z w|) | |
* Multiply each quaternion out: | |
Y * Z * Y | |
=> |0 sy 0 cy| * |0 0 sz cz| * |0 sy 0 cy| | |
=> |0 sy 0 cy| * |(-sz*sy) (cz*sy) (sz*cy) (cz*cy)| | |
which multiplies to: */ | |
euler_quat[0] = 0.0f; | |
euler_quat[1] = 2.0f*cy*cz*sy; | |
euler_quat[2] = cy*sz*cy + sy*sz*sy; | |
euler_quat[3] = cy*cz*cy - sy*cz*sy; | |
} | |
static void | |
Quat_FromEulerZXZ(float *euler_quat, float x, float z) | |
{ | |
float sx = (float)sin((double)(x * 0.5f)); | |
float sz = (float)sin((double)(z * 0.5f)); | |
float cx = (float)cos((double)(x * 0.5f)); | |
float cz = (float)cos((double)(z * 0.5f)); | |
/* ZXZ - Rotation order (Quaternion: |x y z w|) | |
* Multiply each quaternion out: | |
Z * X * Z | |
=> |0 0 sz cz| * |sx 0 0 cx| * |0 0 sz cz| | |
=> |0 0 sz cz| * |(sx*cz) (-sx*sz) (cx*sz) (cx*cz)| | |
which multiplies to: */ | |
euler_quat[0] = cz*sx*cz + sz*sx*sz; | |
euler_quat[1] = 0.0f; | |
euler_quat[2] = 2.0f*cz*cx*sz; | |
euler_quat[3] = cz*cx*cz - sz*cx*sz; | |
} | |
static void | |
Quat_FromEulerZYZ(float *euler_quat, float y, float z) | |
{ | |
float sy = (float)sin((double)(y * 0.5f)); | |
float sz = (float)sin((double)(z * 0.5f)); | |
float cy = (float)cos((double)(y * 0.5f)); | |
float cz = (float)cos((double)(z * 0.5f)); | |
/* ZXZ - Rotation order (Quaternion: |x y z w|) | |
* Multiply each quaternion out: | |
Z * Y * Z | |
=> |0 0 sz cz| * |0 sy 0 cy| * |0 0 sz cz| | |
=> |0 0 sz cz| * |(sy*sz) (sy*cz) (cy*sz) (cy*cz)| | |
which multiplies to: */ | |
euler_quat[0] = 0.0f; | |
euler_quat[1] = cz*sy*cz + sz*sy*sz; | |
euler_quat[2] = 2.0f*cz*cy*sz; | |
euler_quat[3] = cz*cy*cz - sz*cy*sz; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment