unproject_ray.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 "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::PlainObjectBase<Derivedpos> & pos,
  19. const Eigen::PlainObjectBase<Derivedmodel> & model,
  20. const Eigen::PlainObjectBase<Derivedproj> & proj,
  21. const Eigen::PlainObjectBase<Derivedviewport> & viewport,
  22. Eigen::PlainObjectBase<Deriveds> & s,
  23. Eigen::PlainObjectBase<Deriveddir> & dir)
  24. {
  25. using namespace igl;
  26. using namespace std;
  27. using namespace Eigen;
  28. // Source and direction on screen
  29. typedef Eigen::Matrix<typename Deriveds::Scalar,3,1> Vec3;
  30. Vec3 win_s(pos(0),pos(1),0);
  31. Vec3 win_d(pos(0),pos(1),1);
  32. // Source, destination and direction in world
  33. Vec3 d;
  34. igl::unproject(win_s,model,proj,viewport,s);
  35. igl::unproject(win_d,model,proj,viewport,d);
  36. dir = d-s;
  37. }
  38. #ifdef IGL_STATIC_LIBRARY
  39. 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::PlainObjectBase<Eigen::Matrix<float, 2, 1, 0, 2, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, 4, 4, 0, 4, 4> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, 4, 4, 0, 4, 4> > const&, Eigen::PlainObjectBase<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> >&);
  40. #endif