unproject.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. Eigen::Vector3d dwin(win(0),win(1),win(2));
  27. Eigen::Vector3d dobj;
  28. int ret = unproject(dwin(0),dwin(1),dwin(2),
  29. &dobj.data()[0],
  30. &dobj.data()[1],
  31. &dobj.data()[2]);
  32. obj(0) = dobj(0);
  33. obj(1) = dobj(1);
  34. obj(2) = dobj(2);
  35. return ret;
  36. }
  37. template <typename Derivedwin>
  38. IGL_INLINE Eigen::PlainObjectBase<Derivedwin> igl::unproject(
  39. const Eigen::PlainObjectBase<Derivedwin> & win)
  40. {
  41. Eigen::PlainObjectBase<Derivedwin> obj;
  42. unproject(win,obj);
  43. return obj;
  44. }
  45. #ifndef IGL_HEADER_ONLY
  46. // Explicit template instanciation
  47. 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> >&);
  48. template int igl::unproject<Eigen::Matrix<float, 3, 1, 0, 3, 1>, Eigen::Matrix<float, 3, 1, 0, 3, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<float, 3, 1, 0, 3, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, 3, 1, 0, 3, 1> >&);
  49. template Eigen::PlainObjectBase<Eigen::Matrix<float, 3, 1, 0, 3, 1> > igl::unproject<Eigen::Matrix<float, 3, 1, 0, 3, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<float, 3, 1, 0, 3, 1> > const&);
  50. #endif
  51. #endif