X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=player_device_walk.h;fp=player_device_walk.h;h=3b30d061fa040d808fe4bea56ae1e78d415ef079;hb=ff8fcac9582d07bc1ccbf08421d6ffec1758a755;hp=94f436821cdbad67bf3e9f328b5dd15d3dc3eef8;hpb=f82c365a9144c3e5e57df88cb57ef273e9e9d47b;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/player_device_walk.h b/player_device_walk.h index 94f4368..3b30d06 100644 --- a/player_device_walk.h +++ b/player_device_walk.h @@ -12,6 +12,7 @@ struct player_device_walk struct { v3f angles; + v3f prev_pos; enum walk_activity { @@ -99,6 +100,8 @@ VG_STATIC void player_walk_update( player_interface *player, player_attachment *at ) { struct player_device_walk *w = at->storage; + v3_copy( player->rb.co, w->state.prev_pos ); + w->collider.height = 2.0f; w->collider.radius = 0.3f; @@ -283,31 +286,21 @@ VG_STATIC void player_walk_update( player_interface *player, v3_add( player->rb.co, (v3f){0.0f, 1.0f, 0.0f}, mtx[3] ); debug_capsule( mtx, w->collider.radius, w->collider.height, VG__GREEN ); -} - -VG_STATIC void player_walk_post_update( player_interface *player, - player_attachment *at ) -{ - struct player_device_walk *w = at->storage; - - m4x3f mtx; - m3x3_identity( mtx ); - v3_add( player->rb.co, (v3f){0.0f, 1.0f, 0.0f}, mtx[3] ); - - float substep = vg_clampf( vg.accumulator / k_rb_delta, 0.0f, 1.0f ); - v3_muladds( mtx[3], player->rb.v, k_rb_delta*substep, mtx[3] ); - debug_capsule( mtx, w->collider.radius, w->collider.height, VG__YELOW ); - + /* + * CCD routine + * --------------------------------------------------- + * + */ v3f lwr_prev, lwr_now, lwr_offs = { 0.0f, w->collider.radius, 0.0f }; - v3_add( lwr_offs, player->prev_position, lwr_prev ); + v3_add( lwr_offs, w->state.prev_pos, lwr_prev ); v3_add( lwr_offs, player->rb.co, lwr_now ); v3f movedelta; - v3_sub( player->rb.co, player->prev_position, movedelta ); + v3_sub( player->rb.co, w->state.prev_pos, movedelta ); float movedist = v3_length( movedelta ); @@ -326,35 +319,49 @@ VG_STATIC void player_walk_post_update( player_interface *player, debug_capsule( mtx, w->collider.radius, w->collider.height, VG__RED ); } } -} -VG_STATIC void player_walk_ui( player_interface *player, - player_attachment *at ) -{ - player_debugtext( 1, "V: %5.2f %5.2f %5.2f",player->rb.v[0], - player->rb.v[1], - player->rb.v[2] ); - player_debugtext( 1, "CO: %5.2f %5.2f %5.2f",player->rb.co[0], - player->rb.co[1], - player->rb.co[2] ); + teleport_gate *gate; + if( (gate = world_intersect_gates( player->rb.co, w->state.prev_pos )) ) + { + struct player_device_walk *w = at->storage; + + m4x3_mulv( gate->transport, player->rb.co, player->rb.co ); + m3x3_mulv( gate->transport, player->rb.v, player->rb.v ); + rb_update_transform( &player->rb ); + + /* analytical rotation of yaw */ + v3f fwd_dir = { cosf(w->state.angles[0]), + 0.0f, + sinf(w->state.angles[0])}; + m3x3_mulv( gate->transport, fwd_dir, fwd_dir ); + w->state.angles[0] = atan2f( fwd_dir[2], fwd_dir[0] ); + + w->state_gate_storage = w->state; + player_pass_gate( player, gate ); + } } -VG_STATIC void player_walk_bind( player_interface *player, - player_attachment *at ) +VG_STATIC void player_walk_post_update( player_interface *player, + player_attachment *at ) { struct player_device_walk *w = at->storage; - struct player_avatar *av = player->playeravatar; - struct skeleton *sk = &av->sk; - w->anim_idle = skeleton_get_anim( sk, "idle_cycle" ); - w->anim_walk = skeleton_get_anim( sk, "walk" ); - w->anim_run = skeleton_get_anim( sk, "run" ); - w->anim_jump = skeleton_get_anim( sk, "jump" ); + m4x3f mtx; + m3x3_identity( mtx ); + v3_add( player->rb.co, (v3f){0.0f, 1.0f, 0.0f}, mtx[3] ); + + float substep = vg_clampf( vg.accumulator / k_rb_delta, 0.0f, 1.0f ); + v3_muladds( mtx[3], player->rb.v, k_rb_delta*substep, mtx[3] ); + debug_capsule( mtx, w->collider.radius, w->collider.height, VG__YELOW ); + +#if 0 + player_apply_transport_to_cam( gate->transport ); +#endif + } -VG_STATIC void player_walk_pose( player_interface *player, - player_attachment *at, - player_pose pose, m4x3f transform ) +VG_STATIC void player_walk_animate( player_interface *player, + player_attachment *at ) { struct player_device_walk *w = at->storage; struct skeleton *sk = &player->playeravatar->sk; @@ -409,49 +416,73 @@ VG_STATIC void player_walk_pose( player_interface *player, /* air */ skeleton_sample_anim( sk, w->anim_jump, vg.time*0.6f, bpose ); - skeleton_lerp_pose( sk, apose, bpose, w->blend_fly, pose ); - - /* Create transform matrix */ - m3x3f rotation_mtx; - v4f rot; - q_axis_angle( rot, (v3f){0.0f,1.0f,0.0f}, -w->state.angles[0]-VG_PIf*0.5f ); - q_m3x3( rot, rotation_mtx ); + skeleton_lerp_pose( sk, apose, bpose, w->blend_fly, at->pose ); - rb_extrapolate_transform( &player->rb, transform ); - m3x3_copy( rotation_mtx, transform ); + /* Create transform */ + rb_extrapolate( &player->rb, at->pose_root_co, at->pose_root_q ); + q_axis_angle( at->pose_root_q, (v3f){0.0f,1.0f,0.0f}, + -w->state.angles[0]-VG_PIf*0.5f ); } -VG_STATIC void player_walk_get_camera( player_interface *player, - player_attachment *at, camera *cam ) +VG_STATIC void player_walk_post_animate( player_interface *player, + player_attachment *at ) { + /* + * Camera + */ struct player_device_walk *w = at->storage; struct player_avatar *av = player->playeravatar; + /* 3RD */ + m3x3f angles; + euler_m3x3( w->state.angles, angles ); + + v3f cast_dir, origin; + + v3_add( player->rb.co, (v3f){0.0f,2.0f,0.0f}, origin ); + + v3_muladds( origin, angles[2], 2.0f, at->cam_3rd.pos ); + v3_muladds( at->cam_3rd.pos, angles[0], 0.5f, at->cam_3rd.pos ); + + float t; + v3f n; + if( spherecast_world( origin, at->cam_3rd.pos, 0.1f, &t, n ) != -1 ) + v3_lerp( origin, at->cam_3rd.pos, t, at->cam_3rd.pos ); + v3_copy( w->state.angles, at->cam_3rd.angles ); + at->cam_3rd.fov = 90.0f; + + + /* 1ST */ /* FIXME: viewpoint entity */ v3f vp = {-0.1f,1.8f,0.0f}; - m4x3_mulv( av->sk.final_mtx[ av->id_head-1 ], vp, cam->pos ); - v3_copy( w->state.angles, cam->angles ); - cam->fov = 90.0f; + m4x3_mulv( av->sk.final_mtx[ av->id_head-1 ], vp, at->cam_1st.pos ); + v3_copy( w->state.angles, at->cam_1st.angles ); + at->cam_1st.fov = 90.0f; } -VG_STATIC void player_walk_transport( player_interface *player, - player_attachment *at, - teleport_gate *gate ) -{ - struct player_device_walk *w = at->storage; - m4x3_mulv( gate->transport, player->rb.co, player->rb.co ); - m3x3_mulv( gate->transport, player->rb.v, player->rb.v ); +VG_STATIC void player_walk_ui( player_interface *player, + player_attachment *at ) +{ + player_debugtext( 1, "V: %5.2f %5.2f %5.2f",player->rb.v[0], + player->rb.v[1], + player->rb.v[2] ); + player_debugtext( 1, "CO: %5.2f %5.2f %5.2f",player->rb.co[0], + player->rb.co[1], + player->rb.co[2] ); +} - /* analytical rotation of yaw */ - v3f fwd_dir = { cosf(w->state.angles[0]), - 0.0f, - sinf(w->state.angles[0])}; - m3x3_mulv( gate->transport, fwd_dir, fwd_dir ); - w->state.angles[0] = atan2f( fwd_dir[2], fwd_dir[0] ); +VG_STATIC void player_walk_bind( player_interface *player, + player_attachment *at ) +{ + struct player_device_walk *w = at->storage; + struct player_avatar *av = player->playeravatar; + struct skeleton *sk = &av->sk; - w->state_gate_storage = w->state; - player_apply_transport_to_cam( gate->transport ); + w->anim_idle = skeleton_get_anim( sk, "idle_cycle" ); + w->anim_walk = skeleton_get_anim( sk, "walk" ); + w->anim_run = skeleton_get_anim( sk, "run" ); + w->anim_jump = skeleton_get_anim( sk, "jump" ); } VG_STATIC player_device player_device_walk = @@ -459,11 +490,10 @@ VG_STATIC player_device player_device_walk = .pre_update = player_walk_pre_update, .update = player_walk_update, .post_update = player_walk_post_update, - .get_camera = player_walk_get_camera, .debug_ui = player_walk_ui, .bind = player_walk_bind, - .pose = player_walk_pose, - .gate_transport= player_walk_transport + .animate = player_walk_animate, + .post_animate = player_walk_post_animate }; #endif /* PLAYER_DEVICE_WALK_H */