Advertisement
Ember

LookAt

Mar 31st, 2015
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. Matrix VFunction Matrix::LookTo(const Vector& position, const Vector& direction, const Vector& up)
  2. {
  3.     //Vector R2 = Vector::Normalize3(direction);
  4.     Vector R2 = direction;
  5.  
  6.     Vector R0 = Vector::Cross(up, R2);
  7.     R0 = Vector::Normalize3(R0);
  8.  
  9.     Vector R1 = Vector::Cross(R2, R0);
  10.  
  11.     Vector NegEyePosition = _mm_sub_ps(_mm_setzero_ps(), position);
  12.  
  13.     Vector D0 = Vector::Dot3(R0, NegEyePosition);
  14.     Vector D1 = Vector::Dot3(R1, NegEyePosition);
  15.     Vector D2 = Vector::Dot3(R2, NegEyePosition);
  16.  
  17.     Matrix M;
  18.     M.x = Vector::Select(D0, R0, Vector::Constant::Select1110);
  19.     M.y = Vector::Select(D1, R1, Vector::Constant::Select1110);
  20.     M.z = Vector::Select(D2, R2, Vector::Constant::Select1110);
  21.     M.w = Vector::Constant::IdentityR3.v;
  22.  
  23.     M = Transpose(M);
  24.  
  25.     return M;
  26. }
  27.  
  28. Matrix VFunction Matrix::LookAt(const Vector& position, const Vector& target, const Vector& up)
  29. {
  30.     return Matrix::LookTo(position, Vector::Normalize3(_mm_sub_ps(target, position)), up);
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement