Advertisement
Guest User

View MAtrix

a guest
Nov 24th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. // Returns a view matrix, ie inverse world
  2. mat4 LookAt(const vec3& position, const vec3& target, const vec3& up) {
  3.     vec3 forward = Normalized(target - position);
  4.     vec3 right = Normalized(Cross(up, forward));
  5.     vec3 newUp = Cross(forward, right);
  6.  
  7.     return
  8.         mat4( // Rotation is transposed
  9.         right.x, newUp.x, forward.x, 0.0f,
  10.         right.y, newUp.y, forward.y, 0.0f,
  11.         right.z, newUp.z, forward.z, 0.0f,
  12.         -Dot(right, position), -Dot(newUp, position), -Dot(forward, position), 1.0f
  13.     );
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement