unproject.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. #ifndef IGL_HEADER_ONLY
  38. // Explicit template instanciation
  39. 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> >&);
  40. 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> >&);
  41. #endif
  42. #endif