expand_aabb_aabb
[vg.git] / vg_m.h
diff --git a/vg_m.h b/vg_m.h
index 950ebd792574240c5b3aa289b39fc695d5120056..91282f0f3d25e90249e97ac8cd052c83e52f3938 100644 (file)
--- a/vg_m.h
+++ b/vg_m.h
@@ -399,8 +399,7 @@ static inline void v3_normalize( v3f a )
    v3_muls( a, 1.f / v3_length( a ), a );
 }
 
-static inline f32 vg_lerpf( f32 a, f32 b, f32 t )
-{
+static inline f32 vg_lerpf( f32 a, f32 b, f32 t ){
    return a + t*(b-a);
 }
 
@@ -409,6 +408,17 @@ static inline f64 vg_lerp( f64 a, f64 b, f64 t )
    return a + t*(b-a);
 }
 
+static inline void vg_slewf( f32 *a, f32 b, f32 speed ){
+   f32 d = vg_signf( b-*a ),
+       c = *a + d*speed;
+   *a = vg_minf( b*d, c*d ) * d;
+}
+
+static inline f32 vg_smoothstepf( f32 x ){
+   return x*x*(3.0f - 2.0f*x);
+}
+
+
 /* correctly lerp around circular period -pi -> pi */
 static f32 vg_alerpf( f32 a, f32 b, f32 t )
 {
@@ -618,11 +628,11 @@ static inline void q_inv( v4f q, v4f d )
    d[3] =  q[3]*s;
 }
 
-static inline void q_nlerp( v4f a, v4f b, f32 t, v4f d )
-{
+static inline void q_nlerp( v4f a, v4f b, f32 t, v4f d ){
    if( v4_dot(a,b) < 0.0f ){
-      v4_muls( b, -1.0f, d );
-      v4_lerp( a, d, t, d );
+      v4f c;
+      v4_muls( b, -1.0f, c );
+      v4_lerp( a, c, t, d );
    }
    else
       v4_lerp( a, b, t, d );
@@ -1184,8 +1194,7 @@ static void m4x3_decompose( m4x3f m, v3f co, v4f q, v3f s )
    m3x3_q( rot, q );
 }
 
-static void m4x3_expand_aabb_point( m4x3f m, boxf box, v3f point )
-{
+static void m4x3_expand_aabb_point( m4x3f m, boxf box, v3f point ){
    v3f v;
    m4x3_mulv( m, point, v );
 
@@ -1193,26 +1202,19 @@ static void m4x3_expand_aabb_point( m4x3f m, boxf box, v3f point )
    v3_maxv( box[1], v, box[1] );
 }
 
-static void m4x3_transform_aabb( m4x3f m, boxf box )
-{
+static void m4x3_expand_aabb_aabb( m4x3f m, boxf boxa, boxf boxb ){
    v3f a; v3f b;
-   
-   v3_copy( box[0], a );
-   v3_copy( box[1], b );
-   v3_fill( box[0],  INFINITY );
-   v3_fill( box[1], -INFINITY );
-
-   m4x3_expand_aabb_point( m, box, (v3f){ a[0], a[1], a[2] } );
-   m4x3_expand_aabb_point( m, box, (v3f){ a[0], b[1], a[2] } );
-   m4x3_expand_aabb_point( m, box, (v3f){ b[0], b[1], a[2] } );
-   m4x3_expand_aabb_point( m, box, (v3f){ b[0], a[1], a[2] } );
-
-   m4x3_expand_aabb_point( m, box, (v3f){ a[0], a[1], b[2] } );
-   m4x3_expand_aabb_point( m, box, (v3f){ a[0], b[1], b[2] } );
-   m4x3_expand_aabb_point( m, box, (v3f){ b[0], b[1], b[2] } );
-   m4x3_expand_aabb_point( m, box, (v3f){ b[0], a[1], b[2] } );
+   v3_copy( boxb[0], a );
+   v3_copy( boxb[1], b );
+   m4x3_expand_aabb_point( m, boxa, (v3f){ a[0], a[1], a[2] } );
+   m4x3_expand_aabb_point( m, boxa, (v3f){ a[0], b[1], a[2] } );
+   m4x3_expand_aabb_point( m, boxa, (v3f){ b[0], b[1], a[2] } );
+   m4x3_expand_aabb_point( m, boxa, (v3f){ b[0], a[1], a[2] } );
+   m4x3_expand_aabb_point( m, boxa, (v3f){ a[0], a[1], b[2] } );
+   m4x3_expand_aabb_point( m, boxa, (v3f){ a[0], b[1], b[2] } );
+   m4x3_expand_aabb_point( m, boxa, (v3f){ b[0], b[1], b[2] } );
+   m4x3_expand_aabb_point( m, boxa, (v3f){ b[0], a[1], b[2] } );
 }
-
 static inline void m4x3_lookat( m4x3f m, v3f pos, v3f target, v3f up )
 {
    v3f dir;
@@ -1447,8 +1449,7 @@ static int box_within( boxf greater, boxf lesser )
    return 0;
 }
 
-static inline void box_init_inf( boxf box )
-{
+static inline void box_init_inf( boxf box ){
    v3_fill( box[0],  INFINITY );
    v3_fill( box[1], -INFINITY );
 }