Commits

Cliff Biffle committed b6acbcd

Fixed renderer lighting bugs: all renderers use depth-color only when lighting is off now; card normals and scaling are fixed; triangles get normals.

Comments (0)

Files changed (2)

 @property(retain) NSMutableData *rawDepthField;
 @property(copy) void (^renderAction)();
 @property(assign) BOOL frozen;
-@property(assign) BOOL lightsOn;
+@property(assign, nonatomic) BOOL lightsOn;
 
 - (void) depthFieldUpdated: (KFKinect *)kinect;
 
   axes();
   
   const GLfloat *depths = [linearDepthField bytes];
+  vec3f_t normal;
   
   glPolygonMode(GL_FRONT, mode);
+  glColor3f(1,1,1);
+
   for (int y = 0; y < 479; y++) {
     glBegin(GL_TRIANGLE_STRIP);
     BOOL inStrip = YES;
     GLfloat lastDepth = depths[y * 640];
+    vec3f_t prev[2];
     for (int x = 0; x < 640; x++) {
       
       for (int step = 0; step < 2; step++) {
         vec3f_t coord = correctPerspective(x, y + step, d);
         GLfloat color = 1.F - (d / 6.F);
         
-        glColor3f(color, color, color);
+        compute_normal(&prev[0], &prev[1], &coord, &normal);
+        glNormal3fv(&normal.x);
+        
+        if (!lightsOn) glColor3f(color, color, color);
         glVertex3fv(&coord.x);
+        
+        prev[step] = coord;
       }
     }
     if (inStrip) glEnd();
       glNormal3fv(&normal.x);
       
       for (int i = 0; i < 4; i++) {
-        //glColor3f(colors[i], colors[i], colors[i]);
+        if (!lightsOn) glColor3f(colors[i], colors[i], colors[i]);
         glVertex3fv((GLfloat *) &coords[i]);
       }
     }
   const GLfloat *depths = [linearDepthField bytes];
   
   glBegin(GL_QUADS);
-  glNormal3f(0, 0, 1);
+  glNormal3f(0, 0, -1);
   for (int y = 0; y < 480; y++) {
     for (int x = 0; x < 640; x++) {
       GLfloat d1 = depths[y * 640 + x];
       vec3f_t coord = correctPerspective(x, y, d1);
       
       GLfloat c = 1.F - (d1/7.F);
-      glColor3f(c, c, c);
+      if (!lightsOn) glColor3f(c, c, c);
       
-      const GLfloat off = 1;
+      const GLfloat off = 1.F + d1;
       glVertex3f(coord.x - off, coord.y - off, d1);
       glVertex3f(coord.x - off, coord.y + off, d1);
       glVertex3f(coord.x + off, coord.y + off, d1);