unproject.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 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. #ifndef IGL_UNPROJECT_H
  9. #define IGL_UNPROJECT_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Core>
  12. namespace igl
  13. {
  14. #ifndef IGL_OPENGL_4
  15. // Wrapper for gluUnproject that uses the current GL_MODELVIEW_MATRIX,
  16. // GL_PROJECTION_MATRIX, and GL_VIEWPORT
  17. // Inputs:
  18. // win* screen space x, y, and z coordinates respectively
  19. // Outputs:
  20. // obj* pointers to 3D objects' x, y, and z coordinates respectively
  21. // Returns return value of gluUnProject call
  22. IGL_INLINE void unproject(
  23. const double winX,
  24. const double winY,
  25. const double winZ,
  26. double* objX,
  27. double* objY,
  28. double* objZ);
  29. template <typename Derivedwin, typename Derivedobj>
  30. IGL_INLINE void unproject(
  31. const Eigen::PlainObjectBase<Derivedwin> & win,
  32. Eigen::PlainObjectBase<Derivedobj> & obj);
  33. template <typename Derivedwin>
  34. IGL_INLINE Eigen::PlainObjectBase<Derivedwin> unproject(
  35. const Eigen::PlainObjectBase<Derivedwin> & win);
  36. #endif
  37. // Eigen reimplementation of gluUnproject
  38. // Inputs:
  39. // win screen space x, y, and z coordinates
  40. // Returns:
  41. // the unprojected x, y, and z coordinates
  42. // Returns return value of gluUnProject call
  43. template <typename Scalar>
  44. IGL_INLINE Eigen::Matrix<Scalar,3,1> unproject(
  45. const Eigen::Matrix<Scalar,3,1>& win,
  46. const Eigen::Matrix<Scalar,4,4>& model,
  47. const Eigen::Matrix<Scalar,4,4>& proj,
  48. const Eigen::Matrix<Scalar,4,1>& viewport);
  49. }
  50. #ifndef IGL_STATIC_LIBRARY
  51. # include "unproject.cpp"
  52. #endif
  53. #endif