Last active
May 12, 2020 23:49
-
-
Save hiroakioishi/a2f682a06b3b1efd41a81b5ef7d71d3f to your computer and use it in GitHub Desktop.
Quaternionを4x4回転マトリックスに変換
This file contains hidden or 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