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) );
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] );
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] );
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 )
/* 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;
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 */
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;
}