Skip to content

Instantly share code, notes, and snippets.

@jaburns
Created March 1, 2017 18:01
Show Gist options
  • Save jaburns/583d1193a00531dc1dd1576fe5319a8c to your computer and use it in GitHub Desktop.
Save jaburns/583d1193a00531dc1dd1576fe5319a8c to your computer and use it in GitHub Desktop.
Convert quaternion to rotation matrix
float3x3 quaternionToRotationMatrix(float4 q)
{
return float3x3(
1 - 2*q.y*q.y - 2*q.z*q.z , 2*q.x*q.y - 2*q.z*q.w , 2*q.x*q.z + 2*q.y*q.w,
2*q.x*q.y + 2*q.z*q.w , 1 - 2*q.x*q.x - 2*q.z*q.z , 2*q.y*q.z - 2*q.x*q.w,
2*q.x*q.z - 2*q.y*q.w , 2*q.y*q.z + 2*q.x*q.w , 1 - 2*q.x*q.x - 2*q.y*q.y
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment