look_at.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2015 Alec Jacobson <alecjacobson@gmail.com>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #include "look_at.h"
  9. template <
  10. typename Derivedeye,
  11. typename Derivedcenter,
  12. typename Derivedup,
  13. typename DerivedR>
  14. IGL_INLINE void igl::look_at(
  15. const Eigen::PlainObjectBase<Derivedeye> & eye,
  16. const Eigen::PlainObjectBase<Derivedcenter> & center,
  17. const Eigen::PlainObjectBase<Derivedup> & up,
  18. Eigen::PlainObjectBase<DerivedR> & R)
  19. {
  20. typedef Eigen::Matrix<typename DerivedR::Scalar,3,1> Vector3S;
  21. Vector3S f = (center - eye).normalized();
  22. Vector3S s = f.cross(up).normalized();
  23. Vector3S u = s.cross(f);
  24. R = Eigen::Matrix<typename DerivedR::Scalar,4,4>::Identity();
  25. R(0,0) = s(0);
  26. R(0,1) = s(1);
  27. R(0,2) = s(2);
  28. R(1,0) = u(0);
  29. R(1,1) = u(1);
  30. R(1,2) = u(2);
  31. R(2,0) =-f(0);
  32. R(2,1) =-f(1);
  33. R(2,2) =-f(2);
  34. R(0,3) =-s.transpose() * eye;
  35. R(1,3) =-u.transpose() * eye;
  36. R(2,3) = f.transpose() * eye;
  37. }
  38. #ifdef IGL_STATIC_LIBRARY
  39. // Explicit template specialization
  40. // generated by autoexplicit.sh
  41. 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> >&);
  42. #endif