X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=rigidbody.h;h=b1dc834a76ab710d046ec99f729de9da1703d955;hb=ad89a3e4bba4abe99abc48b1760822ca23d03d82;hp=5796c7aed341b577afad3bc607e40a7b046bcabf;hpb=f99902f513b0ad606437bf32de47405dd4ea5f98;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/rigidbody.h b/rigidbody.h index 5796c7a..b1dc834 100644 --- a/rigidbody.h +++ b/rigidbody.h @@ -375,8 +375,7 @@ VG_STATIC void rb_update_transform( rigidbody *rb ) */ VG_STATIC void rb_extrapolate( rigidbody *rb, v3f co, v4f q ) { - float substep = vg_clampf( vg.accumulator / k_rb_delta, 0.0f, 1.0f ); - + float substep = vg.time_fixed_extrapolate; v3_muladds( rb->co, rb->v, k_rb_delta*substep, co ); if( v3_length2( rb->w ) > 0.0f ){ @@ -467,7 +466,7 @@ VG_STATIC void rb_iter( rigidbody *rb ) !vg_validf( rb->v[1] ) || !vg_validf( rb->v[2] ) ) { - vg_fatal_exit_loop( "NaN velocity" ); + vg_fatal_error( "NaN velocity" ); } v3f gravity = { 0.0f, -9.8f, 0.0f }; @@ -1232,11 +1231,7 @@ VG_STATIC int rb_sphere__triangle( m4x3f mtxA, rb_sphere *b, VG_STATIC int rb_sphere__scene( m4x3f mtxA, rb_sphere *b, m4x3f mtxB, rb_scene *s, rb_ct *buf ) { - scene *sc = s->bh_scene->user; - - bh_iter it; - bh_iter_init( 0, &it ); - int idx; + scene_context *sc = s->bh_scene->user; int count = 0; @@ -1244,8 +1239,12 @@ VG_STATIC int rb_sphere__scene( m4x3f mtxA, rb_sphere *b, boxf box; v3_sub( mtxA[3], (v3f){ r,r,r }, box[0] ); v3_add( mtxA[3], (v3f){ r,r,r }, box[1] ); + + bh_iter it; + i32 idx; + bh_iter_init_box( 0, &it, box ); - while( bh_next( s->bh_scene, &it, box, &idx ) ){ + while( bh_next( s->bh_scene, &it, &idx ) ){ u32 *ptri = &sc->arrindices[ idx*3 ]; v3f tri[3]; @@ -1274,7 +1273,7 @@ VG_STATIC int rb_box__scene( m4x3f mtxA, boxf bbx, m4x3f mtxB, rb_scene *s, rb_ct *buf ) { #if 1 - scene *sc = s->bh_scene->user; + scene_context *sc = s->bh_scene->user; v3f tri[3]; v3f extent, center; @@ -1295,13 +1294,13 @@ VG_STATIC int rb_box__scene( m4x3f mtxA, boxf bbx, m4x3_invert_affine( mtxA, to_local ); bh_iter it; - bh_iter_init( 0, &it ); + bh_iter_init_box( 0, &it, world_bbx ); int idx; int count = 0; vg_line_boxf( world_bbx, VG__RED ); - while( bh_next( s->bh_scene, &it, world_bbx, &idx ) ){ + while( bh_next( s->bh_scene, &it, &idx ) ){ u32 *ptri = &sc->arrindices[ idx*3 ]; for( int j=0; j<3; j++ ) @@ -1518,18 +1517,18 @@ VG_STATIC int rb_capsule__scene( m4x3f mtxA, rb_capsule *c, m4x3f mtxB, rb_scene *s, rb_ct *buf ) { - bh_iter it; - bh_iter_init( 0, &it ); - int idx; int count = 0; boxf bbx; v3_sub( mtxA[3], (v3f){ c->height, c->height, c->height }, bbx[0] ); v3_add( mtxA[3], (v3f){ c->height, c->height, c->height }, bbx[1] ); - scene *sc = s->bh_scene->user; + scene_context *sc = s->bh_scene->user; - while( bh_next( s->bh_scene, &it, bbx, &idx ) ){ + bh_iter it; + bh_iter_init_box( 0, &it, bbx ); + i32 idx; + while( bh_next( s->bh_scene, &it, &idx ) ){ u32 *ptri = &sc->arrindices[ idx*3 ]; v3f tri[3]; @@ -2230,7 +2229,7 @@ VG_STATIC void rb_effect_spring_target_vector( rigidbody *rba, v3f ra, v3f rt, float timestep ) { float d = v3_dot( rt, ra ); - float a = vg_signf( d ) * acosf( vg_clampf( d, -1.0f, 1.0f ) ); + float a = acosf( vg_clampf( d, -1.0f, 1.0f ) ); v3f axis; v3_cross( rt, ra, axis );