Commits

Cliff Biffle committed 9cf6763

Added scroll wheel motion control. Used it to discover that the mesh was wrong. Fixed mesh.

Comments (0)

Files changed (1)

   return YES;
 }
 
+- (void) awakeFromNib {
+  rawDepthField = [[NSData alloc] initWithBytes: calloc(640 * 480, sizeof(uint16_t))
+                                         length: (640 * 480 * sizeof(uint16_t))];
+}
 
 #pragma mark --- NSOpenGLView Overrides ---
 
   }
 }
 
+- (void) scrollWheel: (NSEvent *)theEvent {
+  float deltaV = [theEvent deltaY];
+  BOOL changes = NO;
+  if (deltaV) {
+    camera.pos.z += deltaV / 100.;
+    changes = YES;
+  }
+  
+  float deltaH = [theEvent deltaX];
+  if (deltaH) {
+    camera.pos.x += deltaH / 100.;
+    camera.target.x += deltaH / 100.;
+    changes = YES;
+  }
+  
+  if (changes) {
+    [self updateProjection];
+    [self setNeedsDisplay: YES];
+  }
+}
+
 #pragma mark --- Properties ---
 
 @synthesize rawDepthField;
   glVertex3f(0, 0, 1);
   glEnd();
   
+  const uint16_t *depths = [rawDepthField bytes];
   glBegin(GL_LINES);
   glColor3f (1.0, 0.5, 0.0);
   for (int y = 0; y < 479; y++) {
     for (int x = 0; x < 639; x++) {
-      GLfloat d1 = sin(x*3.14159/180), d2 = sin((x+1)*3.14159/180);
+      GLfloat d1 = depths[y * 640 + x], d2 = depths[y * 640 + x + 1];
       glVertex3f(x, y, d1);
       glVertex3f(x, y+1, d1);
+
+      glVertex3f(x, y+1, d1);
+      glVertex3f(x+1, y+1, d2);
+      
       glVertex3f(x+1, y+1, d2);
       glVertex3f(x+1, y, d2);
+      
+      glVertex3f(x+1, y, d2);
+      glVertex3f(x, y, d1);
     }
   }
   glEnd();