unproject_ray.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2015 Alec Jacobson <[email protected]>
  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 "unproject_ray.h"
  9. #include "unproject.h"
  10. template <
  11. typename Derivedpos,
  12. typename Derivedmodel,
  13. typename Derivedproj,
  14. typename Derivedviewport,
  15. typename Deriveds,
  16. typename Deriveddir>
  17. IGL_INLINE void igl::unproject_ray(
  18. const Eigen::MatrixBase<Derivedpos> & pos,
  19. const Eigen::MatrixBase<Derivedmodel> & model,
  20. const Eigen::MatrixBase<Derivedproj> & proj,
  21. const Eigen::MatrixBase<Derivedviewport> & viewport,
  22. Eigen::PlainObjectBase<Deriveds> & s,
  23. Eigen::PlainObjectBase<Deriveddir> & dir)
  24. {
  25. // Source and direction on screen
  26. typedef Eigen::Matrix<typename Deriveds::Scalar,3,1> Vec3;
  27. Vec3 win_s(pos(0, 0),pos(1, 0),0);
  28. Vec3 win_d(pos(0, 0),pos(1, 0),1);
  29. // Source, destination and direction in world
  30. Vec3 d;
  31. igl::unproject(win_s,model,proj,viewport,s);
  32. igl::unproject(win_d,model,proj,viewport,d);
  33. dir = d-s;
  34. }
  35. #ifdef IGL_STATIC_LIBRARY
  36. template void igl::unproject_ray<Eigen::Matrix<float, 2, 1, 0, 2, 1>, Eigen::Matrix<float, 4, 4, 0, 4, 4>, Eigen::Matrix<float, 4, 4, 0, 4, 4>, Eigen::Matrix<float, 4, 1, 0, 4, 1>, Eigen::Matrix<float, 3, 1, 0, 3, 1>, Eigen::Matrix<float, 3, 1, 0, 3, 1> >(Eigen::MatrixBase<Eigen::Matrix<float, 2, 1, 0, 2, 1> > const&, Eigen::MatrixBase<Eigen::Matrix<float, 4, 4, 0, 4, 4> > const&, Eigen::MatrixBase<Eigen::Matrix<float, 4, 4, 0, 4, 4> > const&, Eigen::MatrixBase<Eigen::Matrix<float, 4, 1, 0, 4, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, 3, 1, 0, 3, 1> >&, Eigen::PlainObjectBase<Eigen::Matrix<float, 3, 1, 0, 3, 1> >&);
  37. #endif