Commits

Cliff Biffle committed 643ee81

Renderer colors are now configurable.

  • Participants
  • Parent commits 9fcc386

Comments (0)

Files changed (7)

KVPointCloudRenderer.m

   // (Sending a message doubles our render time.)
   BOOL lights = self.useLighting;
   
-  glColor3f(1, 1, 1);
+  vec3f_t baseColor = [self colorAsRGBVector];
+  glColor3fv(&baseColor.x);
   
   // 0D points can still be lit!
   glNormal3f(0, 0, -1);
       
       if (!lights) {
         GLfloat c = 1.F - (d / 9.F);
-        glColor3f(c, c, c);
+        vec3f_t falseColor = vector_scale(&baseColor, c);
+        glColor3fv(&falseColor.x);
       }
       
       glVertex3fv(&coords.x);
   vec3f_t normal;
   
   glBegin(GL_QUADS);
-  glColor3f(1, 1, 1);
+  vec3f_t baseColor = [self colorAsRGBVector];
+  glColor3fv(&baseColor.x);
   
   for (int y = 0; y < 479; y++) {
     for (int x = 0; x < 639; x++) {
       glNormal3fv(&normal.x);
       
       for (int i = 0; i < 4; i++) {
-        if (!lightsOn) glColor3f(colors[i], colors[i], colors[i]);
+        if (!lightsOn) {
+          vec3f_t falseColor = vector_scale(&baseColor, colors[i]);
+          glColor3fv(&falseColor.x);
+        }
         glVertex3fv(&coords[i].x);
       }
     }
 // data.
 @protocol KVRenderer
 
-// Reconfigures the renderer for a different lighting state.
+// Whether the renderer assumes lighting is enabled.
+// If lighting is disabled, the renderer may apply false
+// colors to emphasize depth.
 // This won't take effect until the next call to
 // -[drawInCurrentOpenGLContext].
 @property(assign, nonatomic) BOOL useLighting;
 
+// Selects the base color for the rendering.  Note that
+// if lighting is disabled, the renderer may transform
+// or even ignore this color.
+@property(retain, nonatomic) NSColor *color;
+
 // Updates the renderer's internal state with a new set
 // of depth samples.  OpenGL will *not* be available when
 // this method is called.

KVSinglePlaneRenderer.h

   GLfloat linearizationTable[2048];
 }
 
-// This property is synthesized for the benefit of
+// These properties are synthesized for the benefit of
 // subclasses.
 @property(assign, nonatomic) BOOL useLighting;
+@property(retain, nonatomic) NSColor *color;
 
 // This implementation simply linearizes all samples
 // into our Z-buffer.
 
 // Subclasses must implement -[drawInCurrentOpenGLContext].
 
+- (vec3f_t) colorAsRGBVector;
+
 @end

KVSinglePlaneRenderer.m

 - init {
   if ((self = [super init])) {
     [self buildLinearizationTable];
+    self.color = [NSColor colorWithDeviceRed: 1.F green: 1.F blue: 1.F alpha: 1.F];
   }
   return self;
 }
 #pragma mark --- KVRenderer implementation (partial)
 
 @synthesize useLighting;
+@synthesize color;
 
 - (void) update: (const depth_t *)rawDepthSamples {
   linear_depth_t *out = &zs;  // Avoid ivar indirection during loop.
   [self doesNotRecognizeSelector: _cmd];  // subclass responsibility
 }
 
+- (vec3f_t) colorAsRGBVector {
+  return (vec3f_t) {
+    [color redComponent],
+    [color greenComponent],
+    [color blueComponent]
+  };
+}
+
 #pragma mark --- Internals
 
 // The Kinect produces 11-bit depth samples.  Z-resolution decreases

KVTriStripRenderer.m

   // Last two points rendered, for normal calculation.
   vec3f_t prev[2];
 
-  glColor3f(1, 1, 1);  // Base color when lighting is on.
+  vec3f_t baseColor = [self colorAsRGBVector];
+  glColor3fv(&baseColor.x);
   
   for (int y = 0; y < 479; y++) {
     glBegin(GL_TRIANGLE_STRIP);
 
         if (!lightsOn) {
           GLfloat color = 1.F - (d / 9.F);
-          glColor3f(color, color, color);
+          vec3f_t falseColor = vector_scale(&baseColor, color);
+          glColor3fv(&falseColor.x);
         }
         glVertex3fv(&coord.x);
         
 	};
 }
 
+static inline vec3f_t vector_scale(const vec3f_t *v, float scale) {
+  return (vec3f_t) {
+    v->x * scale,
+    v->y * scale,
+    v->z * scale,
+  };
+}
+
 static inline void cross_product(const vec3f_t *a, const vec3f_t *b, vec3f_t *out) {
 	*out = (vec3f_t) {
 		a->y * b->z - a->z * b->y,