project.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. #endif