Skip to content

Instantly share code, notes, and snippets.

@gaplegth
Forked from keijiro/AngleAxis3x3.hlsl
Created June 8, 2020 23:51
Show Gist options
  • Save gaplegth/2174d85fcab7af7a867b4e6e1b3a3a2e to your computer and use it in GitHub Desktop.
Save gaplegth/2174d85fcab7af7a867b4e6e1b3a3a2e to your computer and use it in GitHub Desktop.
3x3 Rotation matrix with an angle and an arbitrary vector
// Rotation with angle (in radians) and axis
float3x3 AngleAxis3x3(float angle, float3 axis)
{
float c, s;
sincos(angle, s, c);
float t = 1 - c;
float x = axis.x;
float y = axis.y;
float z = axis.z;
return float3x3(
t * x * x + c, t * x * y - s * z, t * x * z + s * y,
t * x * y + s * z, t * y * y + c, t * y * z - s * x,
t * x * z - s * y, t * y * z + s * x, t * z * z + c
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment