Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// Align a matrix to a target, using an up vector
- ///
- /// @param[in] pos The position we're targeting from
- /// @param[in] targetPos The position we're targeting at
- /// @param[in] upVector The up vector, to avoid gimbal lock. Defaults to +Y
- /// @return A matrix with an offset of 'pos', targeting 'targetPos' with its Z axis.
- static inline Matrix Target(const Vector &pos, const Vector &targetPos, const Vector &upVector = Vector(0.0, 1.0, 0.0))
- {
- Matrix m(DC); // New matrix. Don't call default constructor, as we're filling the values now anyway.
- m.off = pos; // Set position
- m.v3 = !(targetPos - pos); // Z axis targets 'targetPos'
- m.v1 = !Cross(m.v3, upVector); // X axis perpendicular to Z axis and up vector
- m.v2 = !Cross(m.v3, m.v1); // Y axis perpendicular to Z and X axis
- // Return result
- return m;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement