Commits

Cliff Biffle committed 4a99bba

Cleaned up the camera/projection code a little.

  • Participants
  • Parent commits 15c2e95

Comments (0)

Files changed (2)

File KVDepthView.h

 } vec3f_t;
 
 typedef struct {
-  vec3f_t viewPos;
-  vec3f_t viewDir;
-  vec3f_t viewUp;
+  vec3f_t pos;
+  vec3f_t target;
+  vec3f_t up;
   vec3f_t pivot;
-  GLdouble aperture;
+  GLdouble fov;
   GLint viewWidth, viewHeight;
 } camera_t;
 

File KVDepthView.m

 
 - (void) resetCamera {
   camera = (camera_t) {
-    .aperture = 57,
+    .fov = 57,
     .pivot = { 0, 0, 0 },
-    .viewPos = { 0, 0, -7.5 },
-    .viewDir = { 0, 0, 10 },
-    .viewUp = { 0, 1, 0 },
+    .pos = { 0, 0, -7.5 },
+    .target = { 0, 0, 0 },
+    .up = { 0, 1, 0 },
   };
 }
 
   }
 }
 
-#define SHAPE_SIZE (8.0F)
+#define MAXIMUM_DEPTH (16.0F)
 
 - (void) updateProjection {
   [[self openGLContext] makeCurrentContext];
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   
-  GLdouble near = -camera.viewPos.z - SHAPE_SIZE * 0.5;
-  if (near < 0.00001) near = 0.00001;
+  GLdouble near = -camera.pos.z - MAXIMUM_DEPTH;  
+  GLdouble far = -camera.pos.z + MAXIMUM_DEPTH * 2;
   
-  GLdouble far = -camera.viewPos.z + SHAPE_SIZE * 0.5;
+  // I do not fully understand this.
+  if (near < 0.0001) near = 0.0001;
   if (far < 1.0) far = 1.0;
   
   GLdouble aspectRatio = camera.viewWidth / (GLdouble) camera.viewHeight;
 
-  gluPerspective(camera.aperture/aspectRatio, aspectRatio, near, far);
+  gluPerspective(camera.fov / aspectRatio, aspectRatio, near, far);
 }
 
 - (void) updateModelView {
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();
   
-  gluLookAt(camera.viewPos.x, camera.viewPos.y, camera.viewPos.z,
-            camera.viewPos.x + camera.viewDir.x,
-            camera.viewPos.y + camera.viewDir.y,
-            camera.viewPos.z + camera.viewDir.z,
-            camera.viewUp.x, camera.viewUp.y, camera.viewUp.z);
+  gluLookAt(camera.pos.x, camera.pos.y, camera.pos.z,
+            camera.target.x, camera.target.y, camera.target.z,
+            camera.up.x, camera.up.y, camera.up.z);
   
   glRotatef(trackballRotation[0], trackballRotation[1], trackballRotation[2], trackballRotation[3]);
   glRotatef(worldRotation[0], worldRotation[1], worldRotation[2], worldRotation[3]);