Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. /// Align a matrix to a target, using an up vector
  2. ///
  3. /// @param[in] pos The position we're targeting from
  4. /// @param[in] targetPos The position we're targeting at
  5. /// @param[in] upVector The up vector, to avoid gimbal lock. Defaults to +Y
  6. /// @return A matrix with an offset of 'pos', targeting 'targetPos' with its Z axis.
  7. static inline Matrix Target(const Vector &pos, const Vector &targetPos, const Vector &upVector = Vector(0.0, 1.0, 0.0))
  8. {
  9. Matrix m(DC); // New matrix. Don't call default constructor, as we're filling the values now anyway.
  10. m.off = pos; // Set position
  11. m.v3 = !(targetPos - pos); // Z axis targets 'targetPos'
  12. m.v1 = !Cross(m.v3, upVector); // X axis perpendicular to Z axis and up vector
  13. m.v2 = !Cross(m.v3, m.v1); // Y axis perpendicular to Z and X axis
  14.  
  15. // Return result
  16. return m;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement