Created
June 15, 2022 14:05
-
-
Save pezcode/150eb97dd41b67b611d0de7bae273e98 to your computer and use it in GitHub Desktop.
GLSL quaternion to 3x3 matrix
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
mat3 quat_to_mat3(vec4 q) { | |
// multiply by sqrt(2) to get rid of all the 2.0 factors in the matrix | |
q *= 1.414214; | |
float xx = q.x*q.x; | |
float xy = q.x*q.y; | |
float xz = q.x*q.z; | |
float xw = q.x*q.w; | |
float yy = q.y*q.y; | |
float yz = q.y*q.z; | |
float yw = q.y*q.w; | |
float zz = q.z*q.z; | |
float zw = q.z*q.w; | |
return mat3( | |
1.0 - yy - zz, | |
xy + zw, | |
xz - yw, | |
xy - zw, | |
1.0 - xx - zz, | |
yz + xw, | |
xz + yw, | |
yz - xw, | |
1.0 - xx - yy); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment