Commits

Cliff Biffle committed 24a5525

Factored perspective correction into a separate static-inline routine.

Comments (0)

Files changed (1)

   glEnd();
 }
 
+static inline vec3f_t correctPerspective(int x, int y, GLfloat z) {
+  GLfloat dr = 1.F + z;
+  return (vec3f_t) {
+    .x = (x - 320.F) * dr + 320.F,
+    .y = (y - 240.F) * dr + 240.F,
+    .z = z
+  };
+}
+
 - (void) drawDepthFieldAsQuads {
   axes();
   
         GLfloat d = depths[ys[i] * 640 + xs[i]];
         if (d < 0.1F) skip = YES;
         
-        GLfloat dr = 1.F + d;
-        coords[i].x = (xs[i] - 320.F) * dr + 320.F;
-        coords[i].y = (ys[i] - 240.F) * dr + 240.F;
-        coords[i].z = d;
+        coords[i] = correctPerspective(xs[i], ys[i], d);
         colors[i] = 1.F - (d / 6.F);
       }
       
         GLfloat d = depths[ys[i] * 640 + xs[i]];
         if (d < 0.1F) skip = YES;
         
-        GLfloat dr = 1.F + d;
-        coords[i].x = (xs[i] - 320.F) * dr + 320.F;
-        coords[i].y = (ys[i] - 240.F) * dr + 240.F;
-        coords[i].z = d;
+        coords[i] = correctPerspective(xs[i], ys[i], d);
         colors[i] = 1.F - (d / 6.F);
       }
       
       for (int i = 0; i < 4; i++) {
         int i2 = (i + 1) % 4;
         glColor3f(colors[i], colors[i], colors[i]);
-        glVertex3fv((GLfloat *) &coords[i]);
+        glVertex3fv(&coords[i].x);
         
         glColor3f(colors[i2], colors[i2], colors[i2]);
-        glVertex3fv((GLfloat *) &coords[i2]);
+        glVertex3fv(&coords[i2].x);
       }
     }
   }
   for (int y = 0; y < 480; y++) {
     for (int x = 0; x < 640; x++) {
       GLfloat d1 = depths[y * 640 + x];
-      if (d1 < 0.1) continue;
+      if (d1 < 0.1F) continue;
       
-      GLfloat dr = 1 + (d1 / 1);
-      GLfloat px = (x - 320) * dr + 320;
-      GLfloat py = (y - 240) * dr + 240;
+      vec3f_t coord = correctPerspective(x, y, d1);
       
-      GLfloat c = 1 - (d1/7.);
+      GLfloat c = 1.F - (d1/7.F);
       glColor3f(c, c, c);
       
-      const GLfloat off = dr;
-      glVertex3f(px - off, py - off, d1);
-      glVertex3f(px - off, py + off, d1);
-      glVertex3f(px + off, py + off, d1);
-      glVertex3f(px + off, py - off, d1);
+      const GLfloat off = 1;
+      glVertex3f(coord.x - off, coord.y - off, 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);
     }
   }
   glEnd();
       GLfloat d1 = depths[y * 640 + x];
       if (d1 < 0.1F) continue;
       
-      GLfloat dr = 1.F + d1;
-      GLfloat px = (x - 320.F) * dr + 320.F;
-      GLfloat py = (y - 240.F) * dr + 240.F;
+      vec3f_t coords = correctPerspective(x, y, d1);
       
       GLfloat c = 1.F - (d1 / 6.F);
       glColor3f(c, c, c);
-      glVertex3f(px, py, d1);
+      
+      glVertex3fv(&coords.x);
     }
   }
   glEnd();