unproject.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #ifndef IGL_UNPROJECT_H
  2. #define IGL_UNPROJECT_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. // win* screen space x, y, and z coordinates respectively
  9. // Outputs:
  10. // obj* pointers to 3D objects' x, y, and z coordinates respectively
  11. // Returns return value of gluUnProject call
  12. inline int unproject(
  13. const double winX,
  14. const double winY,
  15. const double winZ,
  16. double* objX,
  17. double* objY,
  18. double* objZ);
  19. }
  20. // Implementation
  21. #ifdef __APPLE__
  22. # include <OpenGL/gl.h>
  23. # include <OpenGL/glu.h>
  24. #else
  25. # include <GL/gl.h>
  26. # include <GL/glu.h>
  27. #endif
  28. inline int igl::unproject(
  29. const double winX,
  30. const double winY,
  31. const double winZ,
  32. double* objX,
  33. double* objY,
  34. double* objZ)
  35. {
  36. // Put model, projection, and viewport matrices into double arrays
  37. double MV[16];
  38. double P[16];
  39. int VP[4];
  40. glGetDoublev(GL_MODELVIEW_MATRIX, MV);
  41. glGetDoublev(GL_PROJECTION_MATRIX, P);
  42. glGetIntegerv(GL_VIEWPORT, VP);
  43. return gluUnProject(winX,winY,winZ,MV,P,VP,objX,objY,objZ);
  44. }
  45. #endif