project.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include "project.h"
  2. #include <iostream>
  3. #include "report_gl_error.h"
  4. #ifdef __APPLE__
  5. # include <OpenGL/gl.h>
  6. # include <OpenGL/glu.h>
  7. #else
  8. # ifdef _WIN32
  9. # define NOMINMAX
  10. # include <Windows.h>
  11. # undef NOMINMAX
  12. # endif
  13. # include <GL/gl.h>
  14. # include <GL/glu.h>
  15. #endif
  16. IGL_INLINE int igl::project(
  17. const double objX,
  18. const double objY,
  19. const double objZ,
  20. double* winX,
  21. double* winY,
  22. double* winZ)
  23. {
  24. using namespace std;
  25. #ifdef EXTREME_VERBOSE
  26. cout<<"project();"<<endl;
  27. #endif
  28. // Put model, projection, and viewport matrices into double arrays
  29. double MV[16];
  30. double P[16];
  31. int VP[4];
  32. glGetDoublev(GL_MODELVIEW_MATRIX, MV);
  33. #ifdef EXTREME_VERBOSE
  34. cout<<"MV=["<<endl<<
  35. MV[0]<<" "<< MV[1]<<" "<< MV[2]<<" "<< MV[3]<<" "<<endl<<
  36. MV[4]<<" "<< MV[5]<<" "<< MV[6]<<" "<< MV[7]<<" "<<endl<<
  37. MV[8]<<" "<< MV[9]<<" "<< MV[10]<<" "<< MV[11]<<" "<<endl<<
  38. MV[12]<<" "<< MV[13]<<" "<< MV[14]<<" "<< MV[15]<<" "<<endl<<
  39. "];"<<endl;
  40. #endif
  41. #ifndef NDEBUG
  42. igl::report_gl_error();
  43. #endif
  44. glGetDoublev(GL_PROJECTION_MATRIX, P);
  45. #ifdef EXTREME_VERBOSE
  46. cout<<"P=["<<endl<<
  47. P[0]<<" "<< P[1]<<" "<< P[2]<<" "<< P[3]<<" "<<endl<<
  48. P[4]<<" "<< P[5]<<" "<< P[6]<<" "<< P[7]<<" "<<endl<<
  49. P[8]<<" "<< P[9]<<" "<< P[10]<<" "<< P[11]<<" "<<endl<<
  50. P[12]<<" "<< P[13]<<" "<< P[14]<<" "<< P[15]<<" "<<endl<<
  51. "];"<<endl;
  52. #endif
  53. #ifndef NDEBUG
  54. igl::report_gl_error();
  55. #endif
  56. glGetIntegerv(GL_VIEWPORT, VP);
  57. #ifdef EXTREME_VERBOSE
  58. cout<<"VP=["<<endl<<
  59. VP[0]<<" "<< VP[1]<<" "<< VP[2]<<" "<< VP[3]<<" "<<endl<<
  60. "];"<<endl;
  61. #endif
  62. #ifndef NDEBUG
  63. igl::report_gl_error();
  64. #endif
  65. return gluProject(objX,objY,objZ,MV,P,VP,winX,winY,winZ);
  66. }