resolution fix
[vg.git] / vg_m.h
diff --git a/vg_m.h b/vg_m.h
index e70222ef1bb6b51de5948ecaa257bce90cef92a0..4844eeb20b2664eb5521a86065f309f92cb2ce5a 100644 (file)
--- a/vg_m.h
+++ b/vg_m.h
@@ -1256,41 +1256,53 @@ static inline void tri_to_plane( double a[3], double b[3],
    p[2] = p[2] / l;
 }
 
-static inline int plane_intersect( double a[4], double b[4], 
-      double c[4], double p[4] )
+static int plane_intersect3( v4f a, v4f b, v4f c, v3f p )
 {
-   double const epsilon = 1e-8f;
+   float const epsilon = 1e-6f;
    
-   double x[3];
-   double d;
+   v3f x;
+   v3_cross( a, b, x );
+   float d = v3_dot( x, c );
    
-   x[0] = a[1] * b[2] - a[2] * b[1];
-   x[1] = a[2] * b[0] - a[0] * b[2];
-   x[2] = a[0] * b[1] - a[1] * b[0];
-   
-   d = x[0] * c[0] + x[1] * c[1] + x[2] * c[2];
-   
-   if( d < epsilon && d > -epsilon ) return 0;
-   
-   p[0] = (b[1] * c[2] - b[2] * c[1]) * -a[3];
-   p[1] = (b[2] * c[0] - b[0] * c[2]) * -a[3];
-   p[2] = (b[0] * c[1] - b[1] * c[0]) * -a[3];
-   
-   p[0] += (c[1] * a[2] - c[2] * a[1]) * -b[3];
-   p[1] += (c[2] * a[0] - c[0] * a[2]) * -b[3];
-   p[2] += (c[0] * a[1] - c[1] * a[0]) * -b[3];
-   
-   p[0] += (a[1] * b[2] - a[2] * b[1]) * -c[3];
-   p[1] += (a[2] * b[0] - a[0] * b[2]) * -c[3];
-   p[2] += (a[0] * b[1] - a[1] * b[0]) * -c[3];
-   
-   p[0] = -p[0] / d;
-   p[1] = -p[1] / d;
-   p[2] = -p[2] / d;
+   if( (d < epsilon) && (d > -epsilon) ) return 0;
+
+   v3f v0, v1, v2;
+   v3_cross( b, c, v0 );
+   v3_cross( c, a, v1 );
+   v3_cross( a, b, v2 );
+
+   v3_muls(       v0, a[3], p );
+   v3_muladds( p, v1, b[3], p );
+   v3_muladds( p, v2, c[3], p );
+   v3_divs( p, d, p );
    
    return 1;
 }
 
+int plane_intersect2( v4f a, v4f b, v3f p, v3f n )
+{
+   float const epsilon = 1e-6f;
+
+   v4f c;
+   v3_cross( a, b, c );
+   float d = v3_length2( c );
+
+   if( (d < epsilon) && (d > -epsilon) ) 
+      return 0;
+
+   v3f v0, v1, vx;
+   v3_cross( c, b, v0 );
+   v3_cross( a, c, v1 );
+
+   v3_muls( v0, a[3], vx );
+   v3_muladds( vx, v1, b[3], vx );
+   v3_divs( vx, d, p );
+   v3_copy( c, n );
+
+   return 1;
+}
+
+
 static inline double plane_polarity( double p[4], double a[3] )
 {
    return