Commits

Cliff Biffle committed 409cb78

Vector math functions now pass/return structs by value, not by address. This simplifies the code, and since they're inlined anyway it seems to have no performance impact.

Comments (0)

Files changed (3)

       
       if (lit) {
         // Note: the normal is correct for the upper-left half only.
-        compute_normal(&coords[0], &coords[1], &coords[2], &normal);
+        normal = compute_normal(coords[0], coords[1], coords[2]);
         glNormal3fv(&normal.x);
       }
       

KVTriStripRenderer.m

         projector(self, @selector(projectInto:x:y:z:), &coord, x, y + step, d);
         
         if (lit) {
-          compute_normal(&prev[0], &prev[1], &coord, &normal);
+          normal = compute_normal(prev[0], prev[1], coord);
           glNormal3fv(&normal.x);
         }
 
 
 #include "types.h"
 
-static inline void vector_subtract(const vec3f_t *a, const vec3f_t *b, vec3f_t *out) {
-	*out = (vec3f_t) {
-		a->x - b->x,
-		a->y - b->y,
-		a->z - b->z
+static inline vec3f_t vector_subtract(vec3f_t a, vec3f_t b) {
+	return (vec3f_t) {
+		a.x - b.x,
+		a.y - b.y,
+		a.z - b.z
 	};
 }
 
   };
 }
 
-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,
-		a->z * b->x - a->x * b->z,
-		a->x * b->y - a->y * b->x
+static inline vec3f_t cross_product(vec3f_t a, vec3f_t b) {
+	return (vec3f_t) {
+		a.y * b.z - a.z * b.y,
+		a.z * b.x - a.x * b.z,
+		a.x * b.y - a.y * b.x
 	};		
 }
 
-static inline void compute_normal(const vec3f_t *p1, const vec3f_t *p2, const vec3f_t *p3, vec3f_t *out) {
-	vec3f_t a, b;
-	vector_subtract(p3, p2, &a);
-	vector_subtract(p1, p2, &b);
-	
-	cross_product(&a, &b, out);
+static inline vec3f_t compute_normal(vec3f_t p1, vec3f_t p2, vec3f_t p3) {
+	vec3f_t a = vector_subtract(p3, p2);
+  vec3f_t b = vector_subtract(p1, p2);
+	return cross_product(a, b);
 }
 
 // Converts depth image coordinates to color image coordinates