1. Cliff Biffle
  2. kinect-viewer

Commits

Cliff Biffle  committed a7ce3c5

Reworked the GL projection math to avoid the use of gluPerspective. (I need to be able to create skewed frustums to do proper anaglyph, so gluPerspective was cramping my style.)

  • Participants
  • Parent commits bd8b773
  • Branches shaders

Comments (0)

Files changed (1)

File KVDepthView.m

View file
  • Ignore whitespace
   if (near < 0.0001) near = 0.0001;
   if (far < 1.0) far = 1.0;
   
+  GLdouble fovRadians = camera.fov / 180. * M_PI;
+  GLdouble fovYRadians = fovRadians / 4. * 3.;
   GLdouble aspectRatio = camera.viewWidth / (GLdouble) camera.viewHeight;
   
-  gluPerspective(camera.fov / 4.f * 3.f, aspectRatio, near, far);
+  GLdouble left, top;
+  if (aspectRatio > (4./3.)) {  // landscape
+    GLdouble halfHeight = near * tan(fovYRadians / 2);
+    left = -aspectRatio * halfHeight;
+    top = halfHeight;
+  } else {  // portrait
+    GLdouble halfWidth = near * tan(fovRadians / 2);
+    left = -halfWidth;
+    top = halfWidth / aspectRatio;
+  }
+  
+  glFrustum(left, -left, -top, top, near, far);
 }
 
 - (void) updateModelView {