Skip to content

Instantly share code, notes, and snippets.

@kvannotten
Created October 2, 2010 16:19
Show Gist options
  • Save kvannotten/607768 to your computer and use it in GitHub Desktop.
Save kvannotten/607768 to your computer and use it in GitHub Desktop.
mat4 LookAt(const vec3& eye, const vec3& target, const vec3& up) {
vec3 z = (eye - target).Normalized();
vec3 x = up.Cross(z).Normalized();
vec3 y = z.Cross(x).Normalized();
mat4 m;
m.x = vec4(x, 0);
m.y = vec4(y, 0);
m.z = vec4(z, 0);
m.w = vec4(0,0,0,1);
vec4 eyePrime = m* -eye;
m = m.Transposed();
m.w = eyePrime;
return m;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment