unproject.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 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. #ifndef IGL_UNPROJECT_H
  9. #define IGL_UNPROJECT_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Core>
  12. namespace igl
  13. {
  14. /// Eigen reimplementation of gluUnproject
  15. ///
  16. /// @param[in] win #P by 3 or 3-vector (#P=1) of screen space x, y, and z coordinates
  17. /// @param[in] model 4x4 model-view matrix
  18. /// @param[in] proj 4x4 projection matrix
  19. /// @param[in] viewport 4-long viewport vector
  20. /// @param[out] scene #P by 3 or 3-vector (#P=1) the unprojected x, y, and z coordinates
  21. ///
  22. /// \bug The compiler will not complain if V and P are Vector3d, but the
  23. /// result will be incorrect.
  24. template <
  25. typename Derivedwin,
  26. typename Derivedmodel,
  27. typename Derivedproj,
  28. typename Derivedviewport,
  29. typename Derivedscene>
  30. IGL_INLINE void unproject(
  31. const Eigen::MatrixBase<Derivedwin>& win,
  32. const Eigen::MatrixBase<Derivedmodel>& model,
  33. const Eigen::MatrixBase<Derivedproj>& proj,
  34. const Eigen::MatrixBase<Derivedviewport>& viewport,
  35. Eigen::PlainObjectBase<Derivedscene> & scene);
  36. /// \overload
  37. template <typename Scalar>
  38. IGL_INLINE Eigen::Matrix<Scalar,3,1> unproject(
  39. const Eigen::Matrix<Scalar,3,1>& win,
  40. const Eigen::Matrix<Scalar,4,4>& model,
  41. const Eigen::Matrix<Scalar,4,4>& proj,
  42. const Eigen::Matrix<Scalar,4,1>& viewport);
  43. }
  44. #ifndef IGL_STATIC_LIBRARY
  45. # include "unproject.cpp"
  46. #endif
  47. #endif