project.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #ifndef IGL_PROJECT_H
  2. #define IGL_PROJECT_H
  3. namespace igl
  4. {
  5. // Wrapper for gluProject that uses the current GL_MODELVIEW_MATRIX,
  6. // GL_PROJECTION_MATRIX, and GL_VIEWPORT
  7. // Inputs:
  8. // obj* 3D objects' x, y, and z coordinates respectively
  9. // Outputs:
  10. // win* pointers to screen space x, y, and z coordinates respectively
  11. // Returns return value of gluProject call
  12. inline int project(
  13. const double objX,
  14. const double objY,
  15. const double objZ,
  16. double* winX,
  17. double* winY,
  18. double* winZ);
  19. }
  20. // Implementation
  21. #ifdef __APPLE__
  22. # include <OpenGL/gl.h>
  23. # include <OpenGL/glu.h>
  24. #else
  25. # ifdef _WIN32
  26. # define NOMINMAX
  27. # include <Windows.h>
  28. # undef NOMINMAX
  29. # endif
  30. # include <GL/gl.h>
  31. # include <GL/glu.h>
  32. #endif
  33. inline int igl::project(
  34. const double objX,
  35. const double objY,
  36. const double objZ,
  37. double* winX,
  38. double* winY,
  39. double* winZ)
  40. {
  41. // Put model, projection, and viewport matrices into double arrays
  42. double MV[16];
  43. double P[16];
  44. int VP[4];
  45. glGetDoublev(GL_MODELVIEW_MATRIX, MV);
  46. glGetDoublev(GL_PROJECTION_MATRIX, P);
  47. glGetIntegerv(GL_VIEWPORT, VP);
  48. return gluProject(objX,objY,objZ,MV,P,VP,winX,winY,winZ);
  49. }
  50. #endif