review: vg_lines.h, vg_m.h
[vg.git] / vg_m.h
diff --git a/vg_m.h b/vg_m.h
index 833f1f01598a628a4c09df3c873c1a7cef7a3644..950ebd792574240c5b3aa289b39fc695d5120056 100644 (file)
--- a/vg_m.h
+++ b/vg_m.h
@@ -18,6 +18,7 @@
  *    5.c Closest points
  *    5.d Raycast & Spherecasts
  *    5.e Curves
+ *    5.f Volumes
  *  6. Statistics
  *    6.a Random numbers
  **/
@@ -62,6 +63,12 @@ static int vg_validf( f32 a )
    return ((vg_ftu32(a)) & 0x7F800000U) != 0x7F800000U;
 }
 
+static int v3_valid( v3f a ){
+   for( u32 i=0; i<3; i++ )
+      if( !vg_validf(a[i]) ) return 0;
+   return 1;
+}
+
 /*
  * -----------------------------------------------------------------------------
  * Section 1.                   Scalar Operations
@@ -480,6 +487,24 @@ static inline void v3_rotate( v3f v, f32 angle, v3f axis, v3f d )
   v3_add( v1, v2, d );
 }
 
+static void v3_tangent_basis( v3f n, v3f tx, v3f ty ){
+   /* Compute tangent basis (box2d) */
+   if( fabsf( n[0] ) >= 0.57735027f ){
+      tx[0] =  n[1];
+      tx[1] = -n[0];
+      tx[2] =  0.0f;
+   }
+   else{
+      tx[0] =  0.0f;
+      tx[1] =  n[2];
+      tx[2] = -n[1];
+   }
+
+   v3_normalize( tx );
+   v3_cross( n, tx, ty );
+}
+
+
 /*
  * -----------------------------------------------------------------------------
  * Section 2.c                   4D Vectors
@@ -2124,6 +2149,17 @@ static void eval_bezier3( v3f p0, v3f p1, v3f p2, f32 t, v3f p )
    v3_muladds( p, p2, t*t, p );
 }
 
+/*
+ * -----------------------------------------------------------------------------
+ * Section 5.f                      Volumes
+ * -----------------------------------------------------------------------------
+ */
+
+static float vg_sphere_volume( float radius ){
+   float r3 = radius*radius*radius;
+   return (4.0f/3.0f) * VG_PIf * r3;
+}
+
 /*
  * -----------------------------------------------------------------------------
  * Section 6.a            PSRNG and some distributions