unproject_on_line.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #ifndef IGL_UNPROJECT_ON_LINE_H
  2. #define IGL_UNPROJECT_ON_LINE_H
  3. #include <Eigen/Dense>
  4. namespace igl
  5. {
  6. /// Given a screen space point (u,v) and the current projection matrix (e.g.
  7. /// gl_proj * gl_modelview) and viewport, _unproject_ the point into the scene
  8. /// so that it lies on given line (origin and dir) and projects as closely as
  9. /// possible to the given screen space point.
  10. ///
  11. /// @param[in] UV 2-long uv-coordinates of screen space point
  12. /// @param[in] M 4 by 4 projection matrix
  13. /// @param[in] VP 4-long viewport: (corner_u, corner_v, width, height)
  14. /// @param[in] origin point on line
  15. /// @param[in] dir vector parallel to line
  16. /// @param[out] t line parameter so that closest poin on line to viewer ray through UV
  17. /// lies at origin+t*dir
  18. template <
  19. typename DerivedUV,
  20. typename DerivedM,
  21. typename DerivedVP,
  22. typename Derivedorigin,
  23. typename Deriveddir>
  24. void unproject_on_line(
  25. const Eigen::MatrixBase<DerivedUV> & UV,
  26. const Eigen::MatrixBase<DerivedM> & M,
  27. const Eigen::MatrixBase<DerivedVP> & VP,
  28. const Eigen::MatrixBase<Derivedorigin> & origin,
  29. const Eigen::MatrixBase<Deriveddir> & dir,
  30. typename DerivedUV::Scalar & t);
  31. /// \overload
  32. /// @param[out] Z 3d position of closest point on line to viewing ray through UV
  33. template <
  34. typename DerivedUV,
  35. typename DerivedM,
  36. typename DerivedVP,
  37. typename Derivedorigin,
  38. typename Deriveddir,
  39. typename DerivedZ>
  40. void unproject_on_line(
  41. const Eigen::MatrixBase<DerivedUV> & UV,
  42. const Eigen::MatrixBase<DerivedM> & M,
  43. const Eigen::MatrixBase<DerivedVP> & VP,
  44. const Eigen::MatrixBase<Derivedorigin> & origin,
  45. const Eigen::MatrixBase<Deriveddir> & dir,
  46. Eigen::PlainObjectBase<DerivedZ> & Z);
  47. }
  48. #ifndef IGL_STATIC_LIBRARY
  49. # include "unproject_on_line.cpp"
  50. #endif
  51. #endif