Skip to content

Instantly share code, notes, and snippets.

@BitPuffin
Created December 5, 2013 18:03
Show Gist options
  • Save BitPuffin/7810239 to your computer and use it in GitHub Desktop.
Save BitPuffin/7810239 to your computer and use it in GitHub Desktop.
proc rotate(axis: TVector, angle: float): TMat4 =
let cosine = cos(angle).float32
let sine = sin(angle).float32
let oneminuscos = 1 - cosine
let xsquared = axis[0].pow(2.0)
let ysquared = axis[1].pow(2.0)
let zsquared = axis[2].pow(2.0)
result = [[cosine + oneminuscos*xsquared, oneminuscos*axis[0]*axis[1] - axis[2]*sine, oneminuscos*axis[0]*axis[2] + axis[1]*sine, 0],
[oneminuscos*axis[0]*axis[1] + axis[2]*sine, cosine + oneminuscos*ysquared, oneminuscos*axis[1]*axis[2] - axis[0]*sine, 0],
[oneminuscos*axis[0]*axis[2] - axis[1]*sine, oneminuscos*axis[1]*axis[2] + axis[0]*sine, cosine + oneminuscos*zsquared, 0],
[0f32, 0f32, 0f32, 1f32]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment