Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hiroakioishi/70d258ecf20aff86ebb4c4a6d944b835 to your computer and use it in GitHub Desktop.
Save hiroakioishi/70d258ecf20aff86ebb4c4a6d944b835 to your computer and use it in GitHub Desktop.
Quaternionwo
// 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