project.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include "project.h"
  2. #ifndef IGL_NO_OPENGL
  3. #include <iostream>
  4. #include "report_gl_error.h"
  5. #include "OpenGL_convenience.h"
  6. IGL_INLINE int igl::project(
  7. const double objX,
  8. const double objY,
  9. const double objZ,
  10. double* winX,
  11. double* winY,
  12. double* winZ)
  13. {
  14. using namespace std;
  15. #ifdef EXTREME_VERBOSE
  16. cout<<"project();"<<endl;
  17. #endif
  18. // Put model, projection, and viewport matrices into double arrays
  19. double MV[16];
  20. double P[16];
  21. int VP[4];
  22. glGetDoublev(GL_MODELVIEW_MATRIX, MV);
  23. #ifdef EXTREME_VERBOSE
  24. cout<<"MV=["<<endl<<
  25. MV[0]<<" "<< MV[1]<<" "<< MV[2]<<" "<< MV[3]<<" "<<endl<<
  26. MV[4]<<" "<< MV[5]<<" "<< MV[6]<<" "<< MV[7]<<" "<<endl<<
  27. MV[8]<<" "<< MV[9]<<" "<< MV[10]<<" "<< MV[11]<<" "<<endl<<
  28. MV[12]<<" "<< MV[13]<<" "<< MV[14]<<" "<< MV[15]<<" "<<endl<<
  29. "];"<<endl;
  30. #endif
  31. #ifndef NDEBUG
  32. igl::report_gl_error();
  33. #endif
  34. glGetDoublev(GL_PROJECTION_MATRIX, P);
  35. #ifdef EXTREME_VERBOSE
  36. cout<<"P=["<<endl<<
  37. P[0]<<" "<< P[1]<<" "<< P[2]<<" "<< P[3]<<" "<<endl<<
  38. P[4]<<" "<< P[5]<<" "<< P[6]<<" "<< P[7]<<" "<<endl<<
  39. P[8]<<" "<< P[9]<<" "<< P[10]<<" "<< P[11]<<" "<<endl<<
  40. P[12]<<" "<< P[13]<<" "<< P[14]<<" "<< P[15]<<" "<<endl<<
  41. "];"<<endl;
  42. #endif
  43. #ifndef NDEBUG
  44. igl::report_gl_error();
  45. #endif
  46. glGetIntegerv(GL_VIEWPORT, VP);
  47. #ifdef EXTREME_VERBOSE
  48. cout<<"VP=["<<endl<<
  49. VP[0]<<" "<< VP[1]<<" "<< VP[2]<<" "<< VP[3]<<" "<<endl<<
  50. "];"<<endl;
  51. #endif
  52. #ifndef NDEBUG
  53. igl::report_gl_error();
  54. #endif
  55. return gluProject(objX,objY,objZ,MV,P,VP,winX,winY,winZ);
  56. }
  57. template <typename Derivedobj, typename Derivedwin>
  58. IGL_INLINE int igl::project(
  59. const Eigen::PlainObjectBase<Derivedobj> & obj,
  60. Eigen::PlainObjectBase<Derivedwin> & win)
  61. {
  62. return igl::project(obj(0),obj(1),obj(2),
  63. &win(0),&win(1),&win(2));
  64. }
  65. template <typename Derivedobj>
  66. IGL_INLINE Eigen::PlainObjectBase<Derivedobj> igl::project(
  67. const Eigen::PlainObjectBase<Derivedobj> & obj)
  68. {
  69. Eigen::PlainObjectBase<Derivedobj> win;
  70. project(obj,win);
  71. return win;
  72. }
  73. #ifndef IGL_HEADER_ONLY
  74. // Explicit template instanciations
  75. template int igl::project<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> >&);
  76. template Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 0, 3, 1> > igl::project<Eigen::Matrix<double, 3, 1, 0, 3, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 0, 3, 1> > const&);
  77. #endif
  78. #endif