X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;ds=sidebyside;f=rigidbody.h;h=0a95bddf014430f4ac7c53bab13113c4ba6296b0;hb=b9dedb4dd2a1e94ae76a3986716ee3c57e568213;hp=5d5ffdfa4290c10ba4b7f692ed5dec0801e717d3;hpb=def76bcdaea4e73faab70c60d8ee48a00f2fb48a;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/rigidbody.h b/rigidbody.h index 5d5ffdf..0a95bdd 100644 --- a/rigidbody.h +++ b/rigidbody.h @@ -25,10 +25,11 @@ static const float k_friction = 0.6f, k_damp_linear = 0.05f, /* scale velocity 1/(1+x) */ k_damp_angular = 0.1f, /* scale angular 1/(1+x) */ - k_limit_bias = 0.04f, + k_limit_bias = 0.02f, k_joint_bias = 0.08f, /* positional joints */ k_joint_correction = 0.01f, - k_penetration_slop = 0.01f; + k_penetration_slop = 0.01f, + k_inertia_scale = 4.0f; /* * ----------------------------------------------------------------------------- @@ -337,17 +338,12 @@ static void rb_init( rigidbody *rb ) v3f dims; v3_sub( rb->bbx[1], rb->bbx[0], dims ); volume = dims[0]*dims[1]*dims[2]; - - if( !rb->is_world ) - vg_info( "Box volume: %f\n", volume ); } else if( rb->type == k_rb_shape_sphere ) { volume = sphere_volume( rb->inf.sphere.radius ); v3_fill( rb->bbx[0], -rb->inf.sphere.radius ); v3_fill( rb->bbx[1], rb->inf.sphere.radius ); - - vg_info( "Sphere volume: %f\n", volume ); } else if( rb->type == k_rb_shape_capsule ) { @@ -382,7 +378,7 @@ static void rb_init( rigidbody *rb ) v3_muls( extent, 0.5f, extent ); /* local intertia tensor */ - float scale = 4.0f; + float scale = k_inertia_scale; float ex2 = scale*extent[0]*extent[0], ey2 = scale*extent[1]*extent[1], ez2 = scale*extent[2]*extent[2]; @@ -633,7 +629,6 @@ static void closest_on_triangle( v3f p, v3f tri[3], v3f dest ) v3_muladds( dest, ac, w, dest ); } -/* TODO */ static void closest_on_triangle_1( v3f p, v3f tri[3], v3f dest ) { v3f ab, ac, ap; @@ -1077,7 +1072,6 @@ static int rb_capsule_box( rigidbody *rba, rigidbody *rbb, rb_ct *buf ) v3_sub( c1, p1, d1 ); v3_sub( p1, p0, da ); - /* TODO: ? */ v3_normalize(d0); v3_normalize(d1); v3_normalize(da); @@ -1335,7 +1329,6 @@ static int rb_box_scene( rigidbody *rba, rigidbody *rbb, rb_ct *buf ) axis = 1; } - /* TODO: THIS IS WRONG DIRECTION */ float cz = -v3_dot( rba->forward, n ); if( fabsf(cz) > fabsf(best) ) { @@ -1481,7 +1474,7 @@ static int rb_collide( rigidbody *rba, rigidbody *rbb ) } /* - * TODO: Replace this with a more dedicated broad phase pass + * FUTURE: Replace this with a more dedicated broad phase pass */ if( box_overlap( rba->bbx_world, rbb->bbx_world ) ) { @@ -1742,7 +1735,6 @@ static void rb_limit_cure( rigidbody *ra, rigidbody *rb, v3f axis, float d ) static void rb_constraint_limits( rigidbody *ra, v3f lca, rigidbody *rb, v3f lcb, v3f limits[2] ) { - /* TODO: Code dupe remover */ v3f ax, ay, az, bx, by, bz; m3x3_mulv( ra->to_world, (v3f){1.0f,0.0f,0.0f}, ax ); m3x3_mulv( ra->to_world, (v3f){0.0f,1.0f,0.0f}, ay ); @@ -1859,6 +1851,23 @@ static void rb_constraint_position( rigidbody *ra, v3f lca, } } +/* + * Effectors + */ + +static void rb_effect_simple_bouyency( rigidbody *ra, v4f plane, + float amt, float drag ) +{ + /* float */ + float depth = v3_dot( plane, ra->co ) - plane[3], + lambda = vg_clampf( -depth, 0.0f, 1.0f ) * amt; + + v3_muladds( ra->v, plane, lambda * ktimestep, ra->v ); + + if( depth < 0.0f ) + v3_muls( ra->v, 1.0f-(drag*ktimestep), ra->v ); +} + /* * ----------------------------------------------------------------------------- * BVH implementation, this is ONLY for static rigidbodies, its to slow for