From: hgn Date: Sat, 27 Jan 2024 08:36:11 +0000 (+0000) Subject: glider stuff X-Git-Url: https://harrygodden.com/git/?p=carveJwlIkooP6JGAAIwe30JlM.git;a=commitdiff_plain;h=f5ab30ae4b7250cc128086261b60f0af47f88f11 glider stuff --- diff --git a/models_src/ch_none.mdl b/models_src/ch_none.mdl index 82927ff..760fda4 100644 Binary files a/models_src/ch_none.mdl and b/models_src/ch_none.mdl differ diff --git a/models_src/glider.mdl b/models_src/glider.mdl new file mode 100644 index 0000000..dc26c94 Binary files /dev/null and b/models_src/glider.mdl differ diff --git a/player.h b/player.h index 41d5274..3ae9df1 100644 --- a/player.h +++ b/player.h @@ -48,6 +48,8 @@ struct player_subsystem_interface{ void(*effects)( void *animator, m4x3f *final_mtx, struct player_board *board, struct player_effects_data *effect_data ); void(*post_animate)(void); + void(*render)( camera *cam, world_instance *world, player_pose *pose ); + void(*network_animator_exchange)( bitpack_ctx *ctx, void *data ); void(*sfx_oneshot)( u8 id, v3f pos, f32 volume ); @@ -80,12 +82,15 @@ struct player_subsystem_interface{ static i32 k_cinema_fixed = 0; static f32 k_cinema = 0.0f; static i32 k_invert_y = 0; +static f32 k_cam_dist = 1.8f; struct { /* transform definition */ rigidbody rb; v3f angles; + bool have_glider; + /* * Camera management * --------------------------- @@ -99,7 +104,9 @@ struct { cam_velocity_constant, cam_velocity_coefficient_smooth, cam_velocity_constant_smooth, - cam_velocity_influence_smooth; + cam_velocity_influence_smooth, + cam_dist, + cam_dist_smooth; v3f cam_land_punch, cam_land_punch_v; ent_gate *gate_waiting; diff --git a/player_common.c b/player_common.c index 07b1f5a..5236ee5 100644 --- a/player_common.c +++ b/player_common.c @@ -69,6 +69,12 @@ static void player__cam_iterate(void){ v3_copy( (v3f){0.0f,0.0f,0.0f}, cc->fpv_offset ); v3_copy( (v3f){0.0f,1.4f,0.0f}, cc->tpv_offset ); } + else if( localplayer.subsystem == k_player_subsystem_glide ){ + v3_copy( (v3f){-0.15f,1.75f,0.0f}, cc->fpv_viewpoint ); + v3_copy( (v3f){0.0f,0.0f,0.0f}, cc->fpv_offset ); + v3_copy( (v3f){0.0f,-1.0f,0.0f}, cc->tpv_offset ); + v3_add( cc->tpv_offset_extra, cc->tpv_offset, cc->tpv_offset ); + } else{ v3_copy( (v3f){-0.15f,1.75f,0.0f}, cc->fpv_viewpoint ); v3_copy( (v3f){0.0f,0.0f,0.0f}, cc->fpv_offset ); @@ -83,6 +89,16 @@ static void player__cam_iterate(void){ /* lerping */ + if( localplayer.cam_dist_smooth == 0.0f ){ + localplayer.cam_dist_smooth = localplayer.cam_dist; + } + else { + localplayer.cam_dist_smooth = vg_lerpf( + localplayer.cam_dist_smooth, + localplayer.cam_dist, + vg.time_frame_delta * 8.0f ); + } + localplayer.cam_velocity_influence_smooth = vg_lerpf( localplayer.cam_velocity_influence_smooth, localplayer.cam_velocity_influence, @@ -194,12 +210,15 @@ static void player__cam_iterate(void){ /* now move into world */ v3f tpv_pos, tpv_offset, tpv_origin; + /* TODO: whats up with CC and not CC but both sets of variables are doing + * the same ideas just saved in different places? + */ /* origin */ q_mulv( pq, cc->tpv_offset_smooth, tpv_origin ); v3_add( tpv_origin, cc->tpv_lpf, tpv_origin ); /* offset */ - v3_muls( camera_follow_dir, 1.8f, tpv_offset ); + v3_muls( camera_follow_dir, localplayer.cam_dist_smooth, tpv_offset ); v3_muladds( tpv_offset, cc->cam_velocity_smooth, -0.025f, tpv_offset ); v3_add( tpv_origin, tpv_offset, tpv_pos ); diff --git a/player_glide.c b/player_glide.c index c8c3858..2343ad1 100644 --- a/player_glide.c +++ b/player_glide.c @@ -6,6 +6,7 @@ #include "vg/vg_rigidbody.h" #include "scene_rigidbody.h" +#include "shaders/model_entity.h" static f32 k_glide_steer = 2.0f, k_glide_cl = 0.04f, @@ -19,6 +20,23 @@ static f32 k_glide_steer = 2.0f, static i32 k_glide_pause = 0; static void player_glide_pre_update(void){ + if( button_down(k_srbind_use) ){ + localplayer.subsystem = k_player_subsystem_skate; + + player_skate.state.activity = k_skate_activity_air; + player_skate.state.activity_prev = k_skate_activity_air; + + q_mulv( localplayer.rb.q, (v3f){0.0f,1.0f,0.0f}, player_skate.state.cog ); + v3_add( player_skate.state.cog, localplayer.rb.co, player_skate.state.cog ); + v3_copy( localplayer.rb.v, player_skate.state.cog_v ); + + player__begin_holdout( (v3f){0.0f,0.0f,0.0f} ); + player__skate_reset_animator(); + player__skate_clear_mechanics(); + v3_copy( (v3f){0.0f,0.0f,0.0f}, player_skate.state.trick_euler ); + + player__approximate_best_trajectory(); + } } static void massless_accel( rigidbody *rb, v3f delta, v3f impulse ){ @@ -192,7 +210,7 @@ static void player_glide_pose( void *_animator, player_pose *pose ){ struct skeleton *sk = &localplayer.skeleton; struct player_glide_animator *animator = _animator; - skeleton_sample_anim( sk, player_glide.anim_temp, 0.0f, pose->keyframes ); + skeleton_sample_anim( sk, player_glide.anim_glide, 0.0f, pose->keyframes ); v3_copy( animator->root_co, pose->root_co ); v4_copy( animator->root_q, pose->root_q ); @@ -207,6 +225,8 @@ static void player_glide_post_animate(void){ v3f fwd; v3_muls( localplayer.rb.to_world[2], -1.0f, fwd ); v3_angles( fwd, localplayer.angles ); + + localplayer.cam_dist = 2.0f + v3_length( localplayer.rb.v )*0.2f; } static void player_glide_im_gui(void){ @@ -226,8 +246,6 @@ static void player_glide_im_gui(void){ } static void player_glide_bind(void){ - struct skeleton *sk = &localplayer.skeleton; - player_glide.anim_temp = skeleton_get_anim( sk, "idle_cycle+y" ); u32 mask = VG_VAR_CHEAT|VG_VAR_PERSISTENT; VG_VAR_F32( k_glide_steer, flags=mask ); @@ -291,6 +309,99 @@ static void player_glide_bind(void){ /* set inverses */ m3x3_inv( I, player_glide.rb.iI ); player_glide.rb.inv_mass = 1.0f / mass; + + /* resources */ + struct skeleton *sk = &localplayer.skeleton; + player_glide.anim_glide = skeleton_get_anim( sk, "glide_pose" ); + + + void *alloc = vg_mem.rtmemory; + mdl_context *mdl = &player_glide.glider; + + mdl_open( mdl, "models/glider.mdl", alloc ); + mdl_load_metadata_block( mdl, alloc ); + + vg_linear_clear( vg_mem.scratch ); + + u32 count = mdl_arrcount( &mdl->textures ); + player_glide.glider_textures = + vg_linear_alloc(alloc,vg_align8(sizeof(GLuint)*(count+1))); + player_glide.glider_textures[0] = vg.tex_missing; + + mdl_async_load_glmesh( mdl, &player_glide.glider_mesh, NULL ); + + for( u32 i=0; itextures, i ); + void *data = vg_linear_alloc( vg_mem.scratch, tex->file.pack_size ); + mdl_fread_pack_file( mdl, &tex->file, data ); + vg_tex2d_load_qoi_async( data, tex->file.pack_size, + VG_TEX2D_LINEAR|VG_TEX2D_CLAMP, + &player_glide.glider_textures[i+1] ); + } + + mdl_close( mdl ); +} + +static void player_glide_transition(void){ + localplayer.subsystem = k_player_subsystem_glide; + localplayer.have_glider = 0; + + v3_copy( localplayer.rb.co, player_glide.rb.co ); + v4_copy( localplayer.rb.q, player_glide.rb.q ); + v3_copy( localplayer.rb.v, player_glide.rb.v ); + v3_copy( localplayer.rb.w, player_glide.rb.w ); + rb_update_matrices( &player_glide.rb ); + + player__begin_holdout( (v3f){0,0,0} ); +} + +static void player_glide_render( camera *cam, world_instance *world, + player_pose *pose ){ + shader_model_entity_use(); + shader_model_entity_uTexMain( 0 ); + shader_model_entity_uCamera( cam->transform[3] ); + shader_model_entity_uPv( cam->mtx.pv ); + + WORLD_BIND_LIGHT_BUFFERS_UB0_TEX234( world, model_entity ); + + m4x3f mmdl; + q_m3x3( pose->root_q, mmdl ); + v3_copy( pose->root_co, mmdl[3] ); + + u32 current_tex = 0xffffffff; + glActiveTexture( GL_TEXTURE0 ); + + mdl_context *mdl = &player_glide.glider; + mesh_bind( &player_glide.glider_mesh ); + + for( u32 i=0; imeshs); i ++ ){ + mdl_mesh *mesh = mdl_arritm( &mdl->meshs, i ); + + m4x3f mmmdl; + mdl_transform_m4x3( &mesh->transform, mmmdl ); + m4x3_mul( mmdl, mmmdl, mmmdl ); + shader_model_entity_uMdl( mmmdl ); + + for( u32 j=0; jsubmesh_count; j ++ ){ + mdl_submesh *sm = mdl_arritm( &mdl->submeshs, mesh->submesh_start+j ); + if( !sm->material_id ) { + vg_error( "Invalid material ID 0\n" ); + continue; + } + + mdl_material *mat = mdl_arritm( &mdl->materials, sm->material_id-1 ); + if( mat->tex_diffuse != current_tex ){ + glBindTexture( GL_TEXTURE_2D, + player_glide.glider_textures[ mat->tex_diffuse ] ); + current_tex = mat->tex_diffuse; + } + + mdl_draw_submesh( sm ); + } + } } #endif /* PLAYER_GLIDE_C */ diff --git a/player_glide.h b/player_glide.h index 0794b1c..163e3ba 100644 --- a/player_glide.h +++ b/player_glide.h @@ -4,7 +4,7 @@ #include "player.h" struct player_glide { - struct skeleton_anim *anim_temp; + struct skeleton_anim *anim_glide; struct player_glide_animator { v3f root_co; @@ -32,6 +32,10 @@ struct player_glide { enum rb_shape shape; } parts[3]; + + mdl_context glider; + GLuint *glider_textures; + glmesh glider_mesh; } static player_glide = { .parts = { @@ -65,6 +69,9 @@ static void player_glide_pose( void *animator, player_pose *pose ); static void player_glide_post_animate(void); static void player_glide_im_gui(void); static void player_glide_bind(void); +static void player_glide_transition(void); +static void player_glide_render( camera *cam, world_instance *world, + player_pose *pose ); struct player_subsystem_interface static player_subsystem_glide = { .pre_update = player_glide_pre_update, @@ -75,6 +82,7 @@ struct player_subsystem_interface static player_subsystem_glide = { .post_animate = player_glide_post_animate, .im_gui = player_glide_im_gui, .bind = player_glide_bind, + .render = player_glide_render, .animator_data = &player_glide.animator, .animator_size = sizeof(player_glide.animator), diff --git a/player_render.c b/player_render.c index 1ade3d7..f1ca753 100644 --- a/player_render.c +++ b/player_render.c @@ -555,6 +555,13 @@ static void player__render( camera *cam ){ &localplayer.pose.board, k_board_shader_player ); SDL_AtomicUnlock( &addon_system.sl_cache_using_resources ); + + struct player_subsystem_interface *sys = + player_subsystems[localplayer.subsystem]; + + if( sys->render ){ + sys->render( cam, world, &localplayer.pose ); + } } static void player_mirror_pose( mdl_keyframe pose[32], diff --git a/player_replay.c b/player_replay.c index f3b4a51..6c7840c 100644 --- a/player_replay.c +++ b/player_replay.c @@ -294,6 +294,7 @@ static void skaterift_record_frame( replay_buffer *replay, memcpy( &gs->cam_control, &localplayer.cam_control, sizeof(struct player_cam_controller) ); v3_copy( localplayer.angles, gs->angles ); + gs->have_glider = localplayer.have_glider; void *dst = replay_frame_data( frame, k_replay_framedata_gamestate ); @@ -389,6 +390,7 @@ void skaterift_restore_frame( replay_frame *frame ){ } localplayer.subsystem = frame->system; + localplayer.have_glider = gs->have_glider; memcpy( &localplayer.rb, &gs->rb, sizeof(rigidbody) ); v3_copy( gs->angles, localplayer.angles ); diff --git a/player_replay.h b/player_replay.h index 38599d4..58bc8d3 100644 --- a/player_replay.h +++ b/player_replay.h @@ -41,6 +41,7 @@ struct replay_frame { struct replay_gamestate { rigidbody rb; v3f angles; + bool have_glider; struct player_cam_controller cam_control; }; diff --git a/player_skate.c b/player_skate.c index c6ed4e0..d9b9c04 100644 --- a/player_skate.c +++ b/player_skate.c @@ -11,6 +11,7 @@ #include "ent_tornado.c" #include "vg/vg_rigidbody.h" #include "scene_rigidbody.h" +#include "player_glide.h" static void player__skate_bind(void){ struct skeleton *sk = &localplayer.skeleton; @@ -1222,16 +1223,9 @@ static void player__skate_pre_update(void){ if( button_down(k_srbind_use) && (v3_length2(state->trick_vel) < 0.01f) ){ localplayer.subsystem = k_player_subsystem_walk; - if( state->activity <= k_skate_activity_air_to_grind ){ - localplayer.subsystem = k_player_subsystem_glide; - - v3_copy( localplayer.rb.co, player_glide.rb.co ); - v4_copy( localplayer.rb.q, player_glide.rb.q ); - v3_copy( localplayer.rb.v, player_glide.rb.v ); - v3_copy( localplayer.rb.w, player_glide.rb.w ); - rb_update_matrices( &player_glide.rb ); - - player__begin_holdout( (v3f){0,0,0} ); + if( (state->activity <= k_skate_activity_air_to_grind) && + localplayer.have_glider ){ + player_glide_transition(); return; } @@ -3509,6 +3503,7 @@ static void player__skate_effects( void *_animator, m4x3f *final_mtx, static void player__skate_post_animate(void){ struct player_skate_state *state = &player_skate.state; localplayer.cam_velocity_influence = 1.0f; + localplayer.cam_dist = 1.8f; v3f head = { 0.0f, 1.8f, 0.0f }; m4x3_mulv( localplayer.final_mtx[ localplayer.id_head ], diff --git a/player_walk.c b/player_walk.c index 87bb9ca..cd5e52c 100644 --- a/player_walk.c +++ b/player_walk.c @@ -894,6 +894,13 @@ static void player__walk_animate(void){ } else localplayer.cam_velocity_influence = 0.0f; + + if( w->state.activity == k_walk_activity_sit ){ + localplayer.cam_dist = 3.8f; + } + else { + localplayer.cam_dist = 1.8f; + } } static void player_walk_pose_sit( struct player_walk_animator *animator, diff --git a/testing.c b/testing.c index af79381..c057c9f 100644 --- a/testing.c +++ b/testing.c @@ -21,6 +21,11 @@ static void testing_update(void){ q_identity( baller.rb.q ); rb_update_matrices( &baller.rb ); } + + if( vg_getkey( SDLK_8 ) ){ + localplayer.have_glider = 1; + } + vg_line_boxf_transformed( baller.rb.to_world, baller.box, VG__RED ); world_instance *world = world_current_instance();