+/*
+ * Copyright (C) 2021-2022 Mt.ZERO Software, Harry Godden - All Rights Reserved
+ */
+
/*
* Resources: Box2D - Erin Catto
* qu3e - Randy Gaul
*/
static const float
- k_rb_rate = 60.0f,
- k_rb_delta = (1.0f/k_rb_rate),
+ k_rb_rate = (1.0/VG_TIMESTEP_FIXED),
+ k_rb_delta = (1.0/k_rb_rate),
k_friction = 0.6f,
k_damp_linear = 0.05f, /* scale velocity 1/(1+x) */
k_damp_angular = 0.1f, /* scale angular 1/(1+x) */
rb_update_bounds( rb );
}
+/*
+ * Extrapolate rigidbody into a transform based on vg accumulator.
+ * Useful for rendering
+ */
+static void rb_extrapolate_transform( rigidbody *rb, m4x3f transform )
+{
+ float substep = vg_clampf( vg.accumulator / k_rb_delta, 0.0f, 1.0f );
+
+ v3f co;
+ v4f q;
+
+ v3_muladds( rb->co, rb->v, k_rb_delta*substep, co );
+
+ if( v3_length2( rb->w ) > 0.0f )
+ {
+ v4f rotation;
+ v3f axis;
+ v3_copy( rb->w, axis );
+
+ float mag = v3_length( axis );
+ v3_divs( axis, mag, axis );
+ q_axis_angle( rotation, axis, mag*k_rb_delta*substep );
+ q_mul( rotation, rb->q, q );
+ q_normalize( q );
+ }
+ else
+ {
+ v4_copy( rb->q, q );
+ }
+
+ q_m3x3( q, transform );
+ v3_copy( co, transform[3] );
+}
+
/*
* Initialize rigidbody and calculate masses, inertia
*/
v3_muladds( dest, ac, w, dest );
}
-/* TODO */
static void closest_on_triangle_1( v3f p, v3f tri[3], v3f dest )
{
v3f ab, ac, ap;
v3_sub( c1, p1, d1 );
v3_sub( p1, p0, da );
- /* TODO: ? */
v3_normalize(d0);
v3_normalize(d1);
v3_normalize(da);
axis = 1;
}
- /* TODO: THIS IS WRONG DIRECTION */
float cz = -v3_dot( rba->forward, n );
if( fabsf(cz) > fabsf(best) )
{
}
/*
- * 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 ) )
{
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 );
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 );
+ v3_muladds( ra->v, plane, lambda * k_rb_delta, ra->v );
if( depth < 0.0f )
- v3_muls( ra->v, 1.0f-(drag*ktimestep), ra->v );
+ v3_muls( ra->v, 1.0f-(drag*k_rb_delta), ra->v );
}
/*