add outer product
[vg.git] / vg_m.h
diff --git a/vg_m.h b/vg_m.h
index 68e2304a339c13013eae62c3dd3644a62ae6118e..f5ed4051e1bc9620db00b362186fe693cebd4587 100644 (file)
--- a/vg_m.h
+++ b/vg_m.h
@@ -97,6 +97,10 @@ static inline f32 vg_fractf( f32 a )
    return a - floorf( a );
 }
 
+static inline f64 vg_fractf64( f64 a ){
+   return a - floor( a );
+}
+
 static f32 vg_cfrictf( f32 velocity, f32 F )
 {
    return -vg_signf(velocity) * vg_minf( F, fabsf(velocity) );
@@ -880,6 +884,20 @@ static void m3x3_skew_symetric( m3x3f a, v3f v )
    a[2][2] =  0.0f;
 }
 
+/* aka kronecker product */
+static void m3x3_outer_product( m3x3f out_m, v3f a, v3f b )
+{
+   out_m[0][0] = a[0]*b[0];
+   out_m[0][1] = a[0]*b[1];
+   out_m[0][2] = a[0]*b[2];
+   out_m[1][0] = a[1]*b[0];
+   out_m[1][1] = a[1]*b[1];
+   out_m[1][2] = a[1]*b[2];
+   out_m[2][0] = a[2]*b[0];
+   out_m[2][1] = a[2]*b[1];
+   out_m[2][2] = a[2]*b[2];
+}
+
 static void m3x3_add( m3x3f a, m3x3f b, m3x3f d )
 {
    v3_add( a[0], b[0], d[0] );
@@ -887,6 +905,13 @@ static void m3x3_add( m3x3f a, m3x3f b, m3x3f d )
    v3_add( a[2], b[2], d[2] );
 }
 
+static void m3x3_sub( m3x3f a, m3x3f b, m3x3f d )
+{
+   v3_sub( a[0], b[0], d[0] );
+   v3_sub( a[1], b[1], d[1] );
+   v3_sub( a[2], b[2], d[2] );
+}
+
 static inline void m3x3_copy( m3x3f a, m3x3f b )
 {
    v3_copy( a[0], b[0] );
@@ -900,12 +925,12 @@ static inline void m3x3_identity( m3x3f a )
    m3x3_copy( id, a );
 }
 
-static void m3x3_diagonal( m3x3f a, f32 v )
+static void m3x3_diagonal( m3x3f out_a, f32 v )
 {
-   m3x3_identity( a );
-   a[0][0] = v;
-   a[1][1] = v;
-   a[2][2] = v;
+   m3x3_identity( out_a );
+   out_a[0][0] = v;
+   out_a[1][1] = v;
+   out_a[2][2] = v;
 }
 
 static void m3x3_setdiagonalv3( m3x3f a, v3f v )
@@ -2017,7 +2042,7 @@ int ray_aabb1( boxf box, v3f co, v3f dir_inv, f32 dist )
 
 /* Time of intersection with ray vs triangle */
 static int ray_tri( v3f tri[3], v3f co, 
-                    v3f dir, f32 *dist )
+                    v3f dir, f32 *dist, int backfaces )
 {
    f32 const kEpsilon = 0.00001f;
 
@@ -2033,7 +2058,7 @@ static int ray_tri( v3f tri[3], v3f co,
    v3_cross( dir, v1, h );
    v3_cross( v0, v1, n );
 
-   if( v3_dot( n, dir ) > 0.0f ) /* Backface culling */
+   if( (v3_dot( n, dir ) > 0.0f) && !backfaces ) /* Backface culling */
       return 0;
    
    /* Parralel */
@@ -2171,7 +2196,7 @@ static int spherecast_triangle( v3f tri[3],
    f32 t_min = INFINITY,
          t1;
 
-   if( ray_tri( sum, co, dir, &t1 ) ){
+   if( ray_tri( sum, co, dir, &t1, 0 ) ){
       t_min = vg_minf( t_min, t1 );
       hit = 1;
    }