1. Cliff Biffle
  2. kinect-viewer

Commits

Cliff Biffle  committed ef84ec2

Ray-field projection is now in 2D, since Z never changed anyway. This saves 300KiB per renderer and shaves 5% off frame times.

  • Participants
  • Parent commits 9b69075
  • Branches default

Comments (0)

Files changed (2)

File KVAbstractRenderer.h

View file
 // Abstract base class for KVRenderers.  Factors out a wee
 // bit of boilerplate code.
 @interface KVAbstractRenderer : NSObject <KVRenderer> {
-  vec3f_t rayField[240][320];
+  vec2f_t rayField[240][320];
 }
 
 // These properties are synthesized for the benefit of

File KVAbstractRenderer.m

View file
     yRay = cy;
     ySign = -1.F;
   }
-  vec3f_t ray = rayField[yRay][xRay];
-  vec3f_t coords = vector_scale(ray, z);
-  coords.x *= xSign;
-  coords.y *= ySign;
-
-  *coord = coords;
+  vec2f_t ray = rayField[yRay][xRay];
+  *coord = (vec3f_t) {
+    ray.x * z * xSign,
+    ray.y * z * ySign,
+    z
+  };
 }
 
 // Pre-computes the projection of each camera X/Y coordinate into OpenGL's
 // the ray, which is what I naïvely expected, but rather distance from the
 // XY plane containing the camera.  The depth can thus be natively used as
 // OpenGL's Z coordinate, and the Z of every projected ray will be 1.
-// We store it anyway because it simplifies rendering later on.
+// Thus, we do not store Z.
 - (void) buildRayField {
   // We assume square pixels, and derive the Y FOV from the X.
   static const float fovXDegrees = 57.F;  // Pretty close to actual?
     float theta = (y / 320.F) * fovX/2.F;
     for (int x = 0; x < 320; x++) {
       float psi = (x / 320.F) * fovX/2.F;
-      rayField[y][x] = (vec3f_t) {
+      rayField[y][x] = (vec2f_t) {
         .x = sinf(psi),
         .y = sinf(theta),
-        .z = 1.F,
       };
     }
   }