unproject.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. // Wrapper for gluUnproject that uses the current GL_MODELVIEW_MATRIX,
  15. // GL_PROJECTION_MATRIX, and GL_VIEWPORT
  16. // Inputs:
  17. // win* screen space x, y, and z coordinates respectively
  18. // Outputs:
  19. // obj* pointers to 3D objects' x, y, and z coordinates respectively
  20. // Returns return value of gluUnProject call
  21. IGL_INLINE int unproject(
  22. const double winX,
  23. const double winY,
  24. const double winZ,
  25. double* objX,
  26. double* objY,
  27. double* objZ);
  28. template <typename Derivedwin, typename Derivedobj>
  29. IGL_INLINE int unproject(
  30. const Eigen::PlainObjectBase<Derivedwin> & win,
  31. Eigen::PlainObjectBase<Derivedobj> & obj);
  32. template <typename Derivedwin>
  33. IGL_INLINE Eigen::PlainObjectBase<Derivedwin> unproject(
  34. const Eigen::PlainObjectBase<Derivedwin> & win);
  35. // Eigen reimplementation of gluUnproject
  36. // Inputs:
  37. // win screen space x, y, and z coordinates
  38. // Returns:
  39. // the unprojected x, y, and z coordinates
  40. // Returns return value of gluUnProject call
  41. IGL_INLINE Eigen::Vector3f unproject(
  42. const Eigen::Vector3f& win,
  43. const Eigen::Matrix4f& model,
  44. const Eigen::Matrix4f& proj,
  45. const Eigen::Vector4f& viewport);
  46. template <typename Derivedwin, typename Derivedobj>
  47. IGL_INLINE int unproject(
  48. const Eigen::PlainObjectBase<Derivedwin> & win,
  49. Eigen::PlainObjectBase<Derivedobj> & obj);
  50. template <typename Derivedwin>
  51. IGL_INLINE Eigen::PlainObjectBase<Derivedwin> unproject(
  52. const Eigen::PlainObjectBase<Derivedwin> & win);
  53. }
  54. #ifndef IGL_STATIC_LIBRARY
  55. # include "unproject.cpp"
  56. #endif
  57. #endif