Created
May 12, 2020 23:48
-
-
Save hiroakioishi/70d258ecf20aff86ebb4c4a6d944b835 to your computer and use it in GitHub Desktop.
Quaternionwo
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
// Quaterion to Rotation Matrix4x4 | |
float4x4 quaternion_to_rotation_matrix(float4 q) | |
{ | |
float n = 1.0 / sqrt(q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w); | |
q.x *= n; | |
q.y *= n; | |
q.z *= n; | |
q.w *= n; | |
return float4x4( | |
1.0 - 2.0 * q.y * q.y - 2.0 * q.z * q.z, 2.0 * q.x * q.y - 2.0 * q.z * q.w, 2.0 * q.x * q.z + 2.0 * q.y * q.w, 0.0, | |
2.0 * q.x * q.y + 2.0 * q.z * q.w, 1.0 - 2.0 * q.x * q.x - 2.0 * q.z * q.z, 2.0 * q.y * q.z - 2.0 * q.x * q.w, 0.0, | |
2.0 * q.x * q.z - 2.0 * q.y * q.w, 2.0 * q.y * q.z + 2.0 * q.x * q.w, 1.0 - 2.0 * q.x * q.x - 2.0 * q.y * q.y, 0.0, | |
0.0 , 0.0, 0.0, 1.0 | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment