Advertisement
Ember

lookto

Sep 13th, 2015
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. Matrix VFunction Matrix::LookTo(const Vector& position, const Vector& direction, const Vector& up)
  2. {
  3.     Vector vForward = direction;
  4.     Vector vRight = Vector::Normalize3(Vector::Cross(up, vForward));
  5.     Vector vUp = Vector::Cross(vForward, vRight);
  6.  
  7.     Vector vNegativePosition = _mm_mul_ps(position, Vector::Constant::NegativeOne);
  8.     Vector vX = Vector::Dot3(vForward, vNegativePosition);
  9.     Vector vY = Vector::Dot3(vRight, vNegativePosition);
  10.     Vector vZ = Vector::Dot3(vUp, vNegativePosition);
  11.  
  12.     Matrix vResult;
  13.     vResult.z = Vector::Select(vX, vForward, Vector::Constant::Select1110);
  14.     vResult.x = Vector::Select(vY, vRight, Vector::Constant::Select1110);
  15.     vResult.y = Vector::Select(vZ, vUp, Vector::Constant::Select1110);
  16.     vResult.w = Vector::Constant::IdentityR3.v;
  17.  
  18.     return Matrix::Transpose(vResult);
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement