Created
March 16, 2019 03:29
-
-
Save Piefayth/69552f8ecb37bd4840ef498b6e0472e8 to your computer and use it in GitHub Desktop.
quaternion to 3x3
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
using Unity.Mathematics; | |
public static class QuaternionTo3x3 { | |
public static float3x3 To3x3(this quaternion quat) { | |
float4 q = quat.value; | |
float4x4 leftConversionMatrix = new float4x4( | |
new float4(q.w, q.z, -q.y, q.x), | |
new float4(-q.z, q.w, q.x, q.y), | |
new float4(q.y, -q.x, q.w, q.z), | |
new float4(-q.x, -q.y, -q.z, q.w) | |
); | |
float4x4 rightConversionMatrix = new float4x4( | |
new float4(q.w, q.z, -q.y, -q.x), | |
new float4(-q.z, q.w, q.x, -q.y), | |
new float4(q.y, -q.x, q.w, -q.z), | |
new float4(q.x, q.y, q.z, q.w) | |
); | |
float4x4 rot = math.mul(leftConversionMatrix, rightConversionMatrix); | |
return new float3x3( | |
new float3(rot.c0.x, rot.c0.y, rot.c0.z), | |
new float3(rot.c1.x, rot.c1.y, rot.c1.z), | |
new float3(rot.c2.x, rot.c2.y, rot.c2.z) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment