unproject.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include "unproject.h"
  2. #ifndef IGL_NO_OPENGL
  3. #include "OpenGL_convenience.h"
  4. IGL_INLINE int igl::unproject(
  5. const double winX,
  6. const double winY,
  7. const double winZ,
  8. double* objX,
  9. double* objY,
  10. double* objZ)
  11. {
  12. // Put model, projection, and viewport matrices into double arrays
  13. double MV[16];
  14. double P[16];
  15. int VP[4];
  16. glGetDoublev(GL_MODELVIEW_MATRIX, MV);
  17. glGetDoublev(GL_PROJECTION_MATRIX, P);
  18. glGetIntegerv(GL_VIEWPORT, VP);
  19. return gluUnProject(winX,winY,winZ,MV,P,VP,objX,objY,objZ);
  20. }
  21. template <typename Derivedwin, typename Derivedobj>
  22. IGL_INLINE int igl::unproject(
  23. const Eigen::PlainObjectBase<Derivedwin> & win,
  24. Eigen::PlainObjectBase<Derivedobj> & obj)
  25. {
  26. return unproject(win(0),win(1),win(2),
  27. &obj.data()[0],
  28. &obj.data()[1],
  29. &obj.data()[2]);
  30. }
  31. #ifndef IGL_HEADER_ONLY
  32. // Explicit template instanciation
  33. template int igl::unproject<Eigen::Matrix<double, 3, 1, 0, 3, 1>, Eigen::Matrix<double, 3, 1, 0, 3, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 0, 3, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 0, 3, 1> >&);
  34. #endif
  35. #endif