phys,
phys_gate_frame;
- int is_dead;
+ m4x3f visual_transform,
+ inv_visual_transform;
+
+ int is_dead, death_tick_allowance;
v3f land_target;
v3f land_target_log[22];
fsetup,
walk_timer,
fjump,
- fonboard;
+ fonboard,
+ frun;
+ float walk;
int step_phase;
/* player model */
if( vg_get_button_down( "reset" ) )
{
player.is_dead = 0;
+ player.death_tick_allowance = 30;
player_restore_frame();
if( !phys->on_board )
static void player_update_fixed(void) /* 2 */
{
+ if( player.death_tick_allowance )
+ player.death_tick_allowance --;
+
struct player_phys *phys = &player.phys;
if( player.is_dead )
static void player_kill(void)
{
- player.is_dead = 1;
- player_ragdoll_copy_model( player.phys.rb.v );
+ if( player.death_tick_allowance == 0 )
+ {
+ player.is_dead = 1;
+ player_ragdoll_copy_model( player.phys.rb.v );
+ }
}
static float *player_cam_pos(void)
rate = 9.0f;
player.ffly = vg_lerpf( player.ffly, fly, rate*vg.time_delta );
+ player.frun = vg_lerpf( player.frun,
+ vg_get_axis("walk/push")*0.5f+0.5f,
+ 2.0f*vg.time_delta );
}
struct player_phys *phys = &player.phys;
mdl_keyframe apose[32], bpose[32];
struct skeleton *sk = &player.mdl.sk;
+
+ if( player.walk > 0.025f )
+ {
+ /* TODO move */
+ float walk_norm = 30.0f/(float)player.mdl.anim_walk->length,
+ run_norm = 30.0f/(float)player.mdl.anim_run->length,
+ walk_adv = vg_lerpf( walk_norm, run_norm, player.walk );
+
+ player.walk_timer += walk_adv * vg.time_delta;
+ }
+ else
+ {
+ player.walk_timer = 0.0f;
+ }
+
float walk_norm = (float)player.mdl.anim_walk->length/30.0f,
run_norm = (float)player.mdl.anim_run->length/30.0f,
t = player.walk_timer,
- l = vg_get_axis("grabl") * 0.5f + 0.5f;
+ l = vg_clampf( player.frun*15.0f, 0.0f, 1.0f ),
+ idle_walk = vg_clampf( (player.frun-0.1f)/(1.0f-0.1f), 0.0f, 1.0f );
/* walk/run */
skeleton_sample_anim( sk, player.mdl.anim_walk, t*walk_norm, apose );
skeleton_lerp_pose( sk, apose, bpose, l, apose );
/* idle */
- float idle_walk = vg_minf(l * 10.0f, 1.0f);
-
skeleton_sample_anim( sk, player.mdl.anim_idle, vg.time*0.1f, bpose );
skeleton_lerp_pose( sk, apose, bpose, 1.0f-idle_walk, apose );
v4f rot;
q_axis_angle( rot, (v3f){0.0f,1.0f,0.0f}, -player.angles[0] - VG_PIf*0.5f );
q_m3x3( rot, mtx );
- v3_copy( phys->rb.to_world[3], mtx[3] );
+ v3_copy( player.visual_transform[3], mtx[3] );
skeleton_apply_transform( &player.mdl.sk, mtx );
skeleton_debug( &player.mdl.sk );
static void player_animate(void)
{
struct player_phys *phys = &player.phys;
+ rb_extrapolate_transform( &player.phys.rb, player.visual_transform );
+
+ v4f qfake_rot;
+ m3x3f fake_rot;
+ float substep = vg_clampf( vg.accumulator / VG_TIMESTEP_FIXED, 0.0f, 1.0f );
+ q_axis_angle( qfake_rot, phys->rb.up, phys->siY*substep );
+ q_m3x3( qfake_rot, fake_rot );
+ m3x3_mul( fake_rot, player.visual_transform, player.visual_transform );
+
+ m4x3_invert_affine( player.visual_transform, player.inv_visual_transform );
if( !phys->on_board )
{
v3f offset;
v3_zero( offset );
- m3x3_mulv( phys->rb.to_local, phys->bob, offset );
+ m3x3_mulv( player.inv_visual_transform, phys->bob, offset );
static float speed_wobble = 0.0f, speed_wobble_2 = 0.0f;
player.phys.pushing,
6.0f*vg.time_delta );
- float pt = player.phys.push_time;
+ float pt = player.phys.push_time + vg.accumulator;
if( phys->reverse > 0.0f )
skeleton_sample_anim( sk, player.mdl.anim_push, pt, bpose );
else
mdl_keyframe air_pose[32];
{
- float target = -vg_get_axis("horizontal");
+ float target = -vg_get_axis("lookh");
player.fairdir = vg_lerpf( player.fairdir, target, 2.4f*vg.time_delta );
float air_frame = (player.fairdir*0.5f+0.5f) * (15.0f/30.0f);
skeleton_sample_anim( sk, player.mdl.anim_air, air_frame, apose );
static v2f grab_choice;
- v2_lerp( grab_choice, (v2f){ vg_get_axis("h1"), vg_get_axis("v1") },
+ v2_lerp( grab_choice, (v2f){vg_get_axis("grabh"), vg_get_axis("grabv")},
0.04f, grab_choice );
float ang = atan2f( grab_choice[0], grab_choice[1] ),
v3_copy( player.mdl.sk.final_mtx[player.mdl.id_head-1][3],
player.mdl.cam_pos );
skeleton_apply_inverses( &player.mdl.sk );
- skeleton_apply_transform( &player.mdl.sk, phys->rb.to_world );
+ skeleton_apply_transform( &player.mdl.sk, player.visual_transform );
skeleton_debug( &player.mdl.sk );
}
shake_damp[0] *= 0.2f;
v2_muladds( player.angles, shake_damp, 0.1f, player.angles );
- m4x3_mulv( phys->rb.to_world, cam_pos, player.camera_pos );
+ m4x3_mulv( player.visual_transform, cam_pos, player.camera_pos );
}
else
{
float speed = vg.time_delta * k_look_speed;
- player.angles[0] += vg_get_axis( "horizontal" ) * speed;
- player.angles[1] += vg_get_axis( "vertical" ) * speed;
+ player.angles[0] += vg_get_axis( "lookh" ) * speed;
+ player.angles[1] += vg_get_axis( "lookv" ) * speed;
player.angles[1] = vg_clampf( player.angles[1],
-k_pitch_limit, k_pitch_limit );
q_axis_angle( rot, (v3f){0.0f,1.0f,0.0f},
-player.angles[0] -VG_PIf*0.5f );
q_m3x3( rot, mtx );
- v3_copy( phys->rb.to_world[3], mtx[3] );
+ v3_copy( player.visual_transform[3], mtx[3] );
m4x3_mulv( mtx, player.mdl.cam_pos, cam_pos );
v3_add( cam_pos, forward_dir, player.camera_pos );
phys->reverse = -vg_signf(vel[2]);
float substep = VG_TIMESTEP_FIXED * 0.2f;
- float fwd_resistance = (vg_get_button( "break" )? 5.0f: 0.02f) * -substep;
+
+#if 0
+ float fwd_resistance = vg_get_button( "break" )? 5.0f: k_friction_resistance;
+#else
+ float fwd_resistance = k_friction_resistance;
+#endif
for( int i=0; i<5; i++ )
{
- vel[2] = stable_force( vel[2], vg_signf( vel[2] ) * fwd_resistance );
- vel[0] = stable_force( vel[0],
- vg_signf( vel[0] ) * -k_friction_lat*substep );
+ vel[2] = stable_force( vel[2],vg_signf(vel[2]) * -fwd_resistance*substep);
+ vel[0] = stable_force( vel[0],vg_signf(vel[0]) * -k_friction_lat*substep);
}
if( vg_get_button( "jump" ) )
phys->jump_charge = 1;
}
- static int push_button_last = 0;
- int push_button = vg_get_button( "push" );
- push_button_last = push_button;
-
- if( push_button && !push_button_last )
+ static int push_thresh_last = 0;
+ float push_amt = vg_get_axis( "walk/push" ) * 0.5f + 0.5f;
+ int push_thresh = push_amt>0.15f? 1: 0;
+
+ if( push_thresh && !push_thresh_last )
player.phys.start_push = vg.time;
- if( !vg_get_button("break") && vg_get_button( "push" ) )
+ push_thresh_last = push_thresh;
+
+ if( !vg_get_button("break") && push_thresh )
{
player.phys.pushing = 1.0f;
player.phys.push_time = vg.time - player.phys.start_push;
m3x3_mulv( phys->rb.to_world, vel, phys->rb.v );
- float steer = vg_get_axis( "horizontal" ),
+ float steer = vg_get_axis( "lookh" ),
steer_scaled = vg_signf(steer) * powf(steer,2.0f) * k_steer_ground;
phys->iY -= steer_scaled * VG_TIMESTEP_FIXED;
if( angle < 0.99f )
{
v4f correction;
- q_axis_angle( correction, axis, acosf(angle)*0.05f*(1.0f-limiter) );
+ q_axis_angle( correction, axis,
+ acosf(angle)*(1.0f-limiter)*3.0f*VG_TIMESTEP_FIXED );
q_mul( correction, phys->rb.q, phys->rb.q );
}
time_to_impact += pstep;
}
- phys->iY -= vg_get_axis( "horizontal" ) * k_steer_air * VG_TIMESTEP_FIXED;
+ phys->iY -= vg_get_axis( "lookh" ) * k_steer_air * VG_TIMESTEP_FIXED;
{
- float iX = vg_get_axis( "vertical" ) *
+ float iX = vg_get_axis( "lookv" ) *
phys->reverse * k_steer_air * limiter * VG_TIMESTEP_FIXED;
static float siX = 0.0f;
}
v2f target = {0.0f,0.0f};
- v2_muladds( target, (v2f){ vg_get_axis("h1"), vg_get_axis("v1") },
+ v2_muladds( target, (v2f){ vg_get_axis("grabh"), vg_get_axis("grabv") },
phys->grab, target );
}
v3_muladds( phys->rb.co, forward_dir, 2.0f, p1 );
vg_line( phys->rb.co, p1, 0xff0000ff );
- float move_dead = 0.1f,
- move = vg_get_axis("grabl")*0.5f + 0.5f - move_dead;
+ player.walk = powf( vg_get_axis("walk/push")*0.5f + 0.5f, 4.0f );
- if( move > 0.0f )
+ if( player.walk > 0.025f )
{
- float move_norm = move * (1.0f/(1.0f-move_dead)),
- speed = vg_lerpf( 0.1f*k_runspeed, k_runspeed, move_norm ),
+ float
+ speed = vg_lerpf( 0.025f*k_runspeed, k_runspeed, player.walk ),
amt = k_walk_accel * VG_TIMESTEP_FIXED,
zvel = v3_dot( phys->rb.v, forward_dir ),
new_vel = vg_minf( zvel + amt, speed ),
{
v3_muladds( phys->rb.v, forward_dir, diff, phys->rb.v );
}
-
- /* TODO move */
- float walk_norm = 30.0f/(float)player.mdl.anim_walk->length,
- run_norm = 30.0f/(float)player.mdl.anim_run->length,
- walk_adv = vg_lerpf( walk_norm,run_norm,move_norm );
-
- player.walk_timer += walk_adv * VG_TIMESTEP_FIXED;
- }
- else
- {
- player.walk_timer = 0.0f;
}
if( !phys->in_air )
}
}
- float grabt = vg_get_axis( "grabr" )*0.5f+0.5f;
+ float grabt = vg_get_axis( "grab" )*0.5f+0.5f;
phys->grab = vg_lerpf( phys->grab, grabt, 0.14f );
player.phys.pushing = 0.0f;
if( angle < 0.999f )
{
v4f correction;
- q_axis_angle( correction, axis, acosf(angle)*0.3f );
+ q_axis_angle( correction, axis, acosf(angle)*18.0f*VG_TIMESTEP_FIXED );
q_mul( correction, phys->rb.q, phys->rb.q );
}
*/
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
*/
float depth = v3_dot( plane, ra->co ) - plane[3],
lambda = vg_clampf( -depth, 0.0f, 1.0f ) * amt;
- v3_muladds( ra->v, plane, lambda * VG_TIMESTEP_FIXED, ra->v );
+ v3_muladds( ra->v, plane, lambda * k_rb_delta, ra->v );
if( depth < 0.0f )
- v3_muls( ra->v, 1.0f-(drag*VG_TIMESTEP_FIXED), ra->v );
+ v3_muls( ra->v, 1.0f-(drag*k_rb_delta), ra->v );
}
/*
static struct button_binding vg_controller_binds[] =
{
- { "push", GLFW_GAMEPAD_BUTTON_A },
- { "break", GLFW_GAMEPAD_BUTTON_B },
- { "switchmode", GLFW_GAMEPAD_BUTTON_Y },
- { "jump", GLFW_GAMEPAD_BUTTON_X },
- { "reset", GLFW_GAMEPAD_BUTTON_LEFT_BUMPER }
+ { "jump", GLFW_GAMEPAD_BUTTON_A },
+ { "break", GLFW_GAMEPAD_BUTTON_B },
+ { "switchmode", GLFW_GAMEPAD_BUTTON_Y },
+ { "reset", GLFW_GAMEPAD_BUTTON_LEFT_BUMPER }
};
static struct axis_binding vg_axis_binds[] =
{
- { .name = "horizontal", .axis = GLFW_GAMEPAD_AXIS_LEFT_X },
- { .name = "vertical", .axis = GLFW_GAMEPAD_AXIS_LEFT_Y },
- { .name = "grabr", .axis = GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER },
- { .name = "grabl", .axis = GLFW_GAMEPAD_AXIS_LEFT_TRIGGER },
- { .name = "h1", .axis = GLFW_GAMEPAD_AXIS_RIGHT_X },
- { .name = "v1", .axis = GLFW_GAMEPAD_AXIS_RIGHT_Y }
+ { .name = "lookh", .axis = GLFW_GAMEPAD_AXIS_LEFT_X },
+ { .name = "lookv", .axis = GLFW_GAMEPAD_AXIS_LEFT_Y },
+ { .name = "grabh", .axis = GLFW_GAMEPAD_AXIS_RIGHT_X },
+ { .name = "grabv", .axis = GLFW_GAMEPAD_AXIS_RIGHT_Y },
+ { .name = "walk/push", .axis = GLFW_GAMEPAD_AXIS_LEFT_TRIGGER },
+ { .name = "grab", .axis = GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER },
};
static struct vg_achievement vg_achievements[] =
v4_copy( colour, fade_colour );
fade_colour[3] *= 1.0f-fade_amt;
+ /* 1 minute timer */
float timer_delta = (vg.time - world.routes.last_interaction) * (1.0/60.0),
timer_scale = 1.0f - vg_minf( timer_delta, 1.0f );