1. Cliff Biffle
  2. kinect-viewer

Commits

Cliff Biffle  committed 78b0573

Rearranged KVDepthView's implementation, now that the "private category" no longer constraints method ordering.

  • Participants
  • Parent commits ef6df26
  • Branches default

Comments (0)

Files changed (1)

File KVDepthView.m

View file
  • Ignore whitespace
   [self updateColorTransform];
 }
 
+// Used internally to apply color transform changes.
+- (void) updateColorTransform {
+  renderer.colorTransform = colorTransform;
+  [self setNeedsDisplay: YES];
+}
+
 - (void) setRenderer: (NSObject <KVRenderer> *)newRenderer {
   NSObject <KVRenderer> *currentRenderer = renderer;
   renderer = [newRenderer retain];
 @synthesize anaglyph;
 @synthesize recording;
 
-#pragma mark --- NSView Overrides ---
+#pragma mark --- Trivial NSView Overrides ---
 
 - (BOOL) acceptsFirstResponder {
   return YES;
   return YES;
 }
 
+#pragma mark --- Initialization ---
+
 - (void) awakeFromNib {
   deviceWhite = [[NSColor colorWithDeviceRed: 1.F green: 1.F blue: 1.F alpha: 1.F] retain];
   
   [self selectStaticDepthMap: nil];
 }
 
-#pragma mark --- NSOpenGLView Overrides ---
+#pragma mark --- GL Stuff ---
 
 - (void) prepareOpenGL {
   // Sync to vertical blank.
   [self resetCamera];
 }
 
+- (void) resetCamera {
+  camera = (camera_t) {
+    .fov = 57,
+    .pivot = { 0, 0, 0 },
+    .pos = { 0, 0, -3 },
+    .target = { 0, 0, 0 },
+    .up = { 0, 1, 0 },
+  };
+}
+
+- (void) resizeGL {
+  NSRect bounds = [self bounds];
+  
+  // Note: this always happens on the first drawing call.
+  if (camera.viewHeight != bounds.size.height
+      || camera.viewWidth != bounds.size.width) {
+    camera.viewHeight = (float) bounds.size.height;
+    camera.viewWidth = (float) bounds.size.width;
+    
+    glViewport(0, 0, camera.viewWidth, camera.viewHeight);
+    [self updateProjection];
+  }
+}
+
+#define MAXIMUM_DEPTH (16.0F)
+
+- (void) updateProjection {
+  [[self openGLContext] makeCurrentContext];
+  
+  glMatrixMode(GL_PROJECTION);
+  glLoadIdentity();
+  
+  GLdouble near = -camera.pos.z - MAXIMUM_DEPTH;  
+  GLdouble far = -camera.pos.z + MAXIMUM_DEPTH * 16;
+  
+  // 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.fov / aspectRatio, aspectRatio, near, far);
+}
+
+- (void) updateModelView {
+  [[self openGLContext] makeCurrentContext];
+  
+  glMatrixMode(GL_MODELVIEW);
+  glLoadIdentity();
+  
+  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]);
+  glRotatef(spinY, 0, 1, 0);
+  glRotatef(spinX, 1, 0, 0);
+  
+  GLfloat lightPos[4] = { 0, 0, -1, 1 };
+  glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
+}
+
 #define INTEROCULAR_DISTANCE (0.0635F)
 - (void) drawRect: (NSRect)dirtyRect {
   [self resizeGL];
   [[self openGLContext] flushBuffer];
 }
 
+#pragma mark --- User Interaction ---
+
 - (void) mouseDown: (NSEvent *)theEvent {
   NSPoint location = [self convertPoint: [theEvent locationInWindow] fromView: nil];
   location.y = camera.viewHeight - location.y;  // Flip Y axis
 	}
 }
 
-- (void) depthFieldUpdated: (const depth_t *)buffer from: (KFKinect *)kinect {
-  @synchronized (self) {
-    if (recording) {
-      fwrite(buffer, sizeof(uint16_t), 640*480, depthOutput);
-    }
-  }
-      
-  if (!self.frozen) {
-    [depthMap updateDepth: buffer];
-    [self setNeedsDisplay: YES];
-  }
-}
-
-- (void) colorFieldUpdated: (const colors_t *)buffer from: (KFKinect *)kinect {
-  if (!self.frozen) {
-    [depthMap updateColor: buffer];
-    [self setNeedsDisplay: YES];
-  }
-}
-
 #pragma mark --- Actions ---
 
 - (IBAction) selectPointCloudRenderer: sender {
   [sender setState: renderer.textured? NSOnState : NSOffState];
 }
 
-- (void) resetCamera {
-  camera = (camera_t) {
-    .fov = 57,
-    .pivot = { 0, 0, 0 },
-    .pos = { 0, 0, -3 },
-    .target = { 0, 0, 0 },
-    .up = { 0, 1, 0 },
-  };
-}
+#pragma mark --- KFKinect Delegate Implementation ---
 
-- (void) resizeGL {
-  NSRect bounds = [self bounds];
-  
-  // Note: this always happens on the first drawing call.
-  if (camera.viewHeight != bounds.size.height
-      || camera.viewWidth != bounds.size.width) {
-    camera.viewHeight = (float) bounds.size.height;
-    camera.viewWidth = (float) bounds.size.width;
-    
-    glViewport(0, 0, camera.viewWidth, camera.viewHeight);
-    [self updateProjection];
+- (void) depthFieldUpdated: (const depth_t *)buffer from: (KFKinect *)kinect {
+  @synchronized (self) {
+    if (recording) {
+      fwrite(buffer, sizeof(uint16_t), 640*480, depthOutput);
+    }
+  }
+      
+  if (!self.frozen) {
+    [depthMap updateDepth: buffer];
+    [self setNeedsDisplay: YES];
   }
 }
 
-#define MAXIMUM_DEPTH (16.0F)
-
-- (void) updateProjection {
-  [[self openGLContext] makeCurrentContext];
-  
-  glMatrixMode(GL_PROJECTION);
-  glLoadIdentity();
-  
-  GLdouble near = -camera.pos.z - MAXIMUM_DEPTH;  
-  GLdouble far = -camera.pos.z + MAXIMUM_DEPTH * 16;
-  
-  // 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.fov / aspectRatio, aspectRatio, near, far);
+- (void) colorFieldUpdated: (const colors_t *)buffer from: (KFKinect *)kinect {
+  if (!self.frozen) {
+    [depthMap updateColor: buffer];
+    [self setNeedsDisplay: YES];
+  }
 }
 
-- (void) updateModelView {
-  [[self openGLContext] makeCurrentContext];
-  
-  glMatrixMode(GL_MODELVIEW);
-  glLoadIdentity();
-  
-  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]);
-  glRotatef(spinY, 0, 1, 0);
-  glRotatef(spinX, 1, 0, 0);
-  
-  GLfloat lightPos[4] = { 0, 0, -1, 1 };
-  glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
-}
-
-- (void) updateColorTransform {
-  renderer.colorTransform = colorTransform;
-  [self setNeedsDisplay: YES];
-}
 @end