look_at.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #include "look_at.h"
  2. template <
  3. typename Derivedeye,
  4. typename Derivedcenter,
  5. typename Derivedup,
  6. typename DerivedR>
  7. IGL_INLINE void igl::look_at(
  8. const Eigen::PlainObjectBase<Derivedeye> & eye,
  9. const Eigen::PlainObjectBase<Derivedcenter> & center,
  10. const Eigen::PlainObjectBase<Derivedup> & up,
  11. Eigen::PlainObjectBase<DerivedR> & R)
  12. {
  13. typedef Eigen::Matrix<typename DerivedR::Scalar,3,1> Vector3S;
  14. Vector3S f = (center - eye).normalized();
  15. Vector3S s = f.cross(up).normalized();
  16. Vector3S u = s.cross(f);
  17. R = Eigen::Matrix<typename DerivedR::Scalar,4,4>::Identity();
  18. R(0,0) = s(0);
  19. R(0,1) = s(1);
  20. R(0,2) = s(2);
  21. R(1,0) = u(0);
  22. R(1,1) = u(1);
  23. R(1,2) = u(2);
  24. R(2,0) =-f(0);
  25. R(2,1) =-f(1);
  26. R(2,2) =-f(2);
  27. R(0,3) =-s.transpose() * eye;
  28. R(1,3) =-u.transpose() * eye;
  29. R(2,3) = f.transpose() * eye;
  30. }
  31. #ifdef IGL_STATIC_LIBRARY
  32. template void igl::look_at<Eigen::Matrix<float, 3, 1, 0, 3, 1>, Eigen::Matrix<float, 3, 1, 0, 3, 1>, Eigen::Matrix<float, 3, 1, 0, 3, 1>, Eigen::Matrix<float, 4, 4, 0, 4, 4> >(Eigen::PlainObjectBase<Eigen::Matrix<float, 3, 1, 0, 3, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, 3, 1, 0, 3, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, 3, 1, 0, 3, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, 4, 4, 0, 4, 4> >&);
  33. #endif