.......
authorhgn <hgodden00@gmail.com>
Mon, 12 Sep 2022 01:27:14 +0000 (02:27 +0100)
committerhgn <hgodden00@gmail.com>
Mon, 12 Sep 2022 01:27:14 +0000 (02:27 +0100)
gate.h
models_src/ch_new.mdl
models_src/mp_dev.mdl
player.h
player_model.h
skeleton.h
skeleton_animator.h [new file with mode: 0644]
textures_src/graffitibox.png
textures_src/subworld.png [new file with mode: 0644]
vg_config.h
world.h

diff --git a/gate.h b/gate.h
index 270f9d74b36c9993debb141001e97477296c44b3..c3f922967cba1a015584019bc7ce67c138669e3d 100644 (file)
--- a/gate.h
+++ b/gate.h
@@ -233,7 +233,7 @@ static int gate_intersect( teleport_gate *gate, v3f pos, v3f last )
 
    float d = v3_dot(surface, v0);
 
-   if( fabsf(d) > 0.00001f )
+   if( d > 0.00001f )
    {
       float t = v3_dot(delta, surface) / d;
       if( t >= 0.0f && t <= l )
index 2586e0b5239c2faf1bd2d59c24a95fae03919b4d..c9febadfc2c83708edc7f1d23b8702b463d67e4a 100644 (file)
Binary files a/models_src/ch_new.mdl and b/models_src/ch_new.mdl differ
index 8b9200ba8a951e2b702311dcdedeae21782b9992..e5166ff034057863f42217b1a586fcd686214ffd 100644 (file)
Binary files a/models_src/mp_dev.mdl and b/models_src/mp_dev.mdl differ
index 96b9dbaff93a6d6e4410e4767c0d417ad29f6360..febd8e667755db7d6475c14b16cf64052f813aa5 100644 (file)
--- a/player.h
+++ b/player.h
@@ -20,13 +20,15 @@ static float
    k_friction_lat          = 8.8f,
    k_friction_resistance   = 0.01f,
    k_max_push_speed        = 16.0f,
-   k_push_accel            = 5.0f,
+   k_push_accel            = 10.0f,
    k_push_cycle_rate       = 8.0f,
    k_steer_ground          = 2.5f,
    k_steer_air             = 3.6f,
    k_steer_air_lerp        = 0.3f,
    k_pump_force            = 000.0f,
-   k_downforce             = 5.0f;
+   k_downforce             = 5.0f,
+   k_jump_charge_speed     = (1.0f/1.0f),
+   k_jump_force            = 5.0f;
 
 static int freecam = 0;
 static int walk_grid_iterations = 1;
@@ -50,7 +52,9 @@ static struct gplayer
    float grab;
    float pitch;
    float pushing, push_time;
-
+   float jump;
+   int jump_charge;
+   
    v3f land_target;
    v3f land_target_log[22];
    u32 land_target_colours[22];
@@ -68,6 +72,16 @@ static struct gplayer
    v3f camera_pos, smooth_localcam;
    v2f angles;
    m4x3f camera, camera_inverse;
+
+   /* animation */
+   double jump_time;
+   float fslide,
+         fdirz, fdirx,
+         fstand,
+         ffly,
+         fpush,
+         fairdir,
+         fsetup;
 }
 player = 
 {
@@ -296,6 +310,12 @@ static void player_physics_control(void)
    if( vg_get_button_down( "push" ) )
       start_push = vg_time;
 
+   if( vg_get_button( "jump" ) )
+   {
+      player.jump += ktimestep * k_jump_charge_speed;
+      player.jump_charge = 1;
+   }
+
    if( !vg_get_button("break") && vg_get_button( "push" ) )
    {
       player.pushing = 1.0f;
@@ -556,12 +576,28 @@ static void player_physics(void)
 
       v3_muladds( player.rb.v, player.rb.up, 
             -k_downforce*ktimestep, player.rb.v );
+
       player_physics_control();
+
+      if( !player.jump_charge && player.jump > 0.2f )
+      {
+         v3_muladds( player.rb.v, player.rb.up, k_jump_force*player.jump,
+                     player.rb.v );
+
+         player.jump_time = vg_time;
+      }
    }
    else
    {
       player_physics_control_air();
    }
+
+   if( !player.jump_charge )
+   {
+      player.jump -= k_jump_charge_speed * ktimestep;
+   }
+   player.jump_charge = 0;
+   player.jump = vg_clampf( player.jump, 0.0f, 1.0f );
 }
 
 static void player_do_motion(void)
@@ -1636,73 +1672,87 @@ static void player_animate(void)
    offset[1] = 0.0f;
 
    /* 
-    * Player rotation 
+    * Animation blending
+    * ===========================================
     */
-#if 0
-   float angle = v3_dot( player.rb.up, (v3f){0.0f,1.0f,0.0f} );
-   v3f axis; 
-   v3_cross( player.rb.up, (v3f){0.0f,1.0f,0.0f}, axis );
 
-   v4f correction;
-   if( angle < 0.99f && 0 )
+   /* scalar blending information */
+   float speed = v3_length( player.rb.v );
+   
+   /* sliding */
    {
-      m3x3_mulv( player.rb.to_local, axis, axis );
-      q_axis_angle( correction, axis, acosf(angle) );
+      float desired = vg_clampf( lslip, 0.0f, 1.0f );
+      player.fslide = vg_lerpf( player.fslide, desired, 0.04f );
    }
-   else
+   
+   /* movement information */
    {
-      q_identity( correction );
+      float dirz = player.reverse > 0.0f? 0.0f: 1.0f,
+            dirx = player.slip < 0.0f?    0.0f: 1.0f,
+            fly  = player.in_air?         1.0f: 0.0f;
+
+      player.fdirz = vg_lerpf( player.fdirz, dirz, 0.04f );
+      player.fdirx = vg_lerpf( player.fdirx, dirx, 0.01f );
+      player.ffly  = vg_lerpf( player.ffly, fly, 0.04f );
    }
+   
+   struct skeleton *sk = &player.mdl.sk;
 
-   /* 
-    * Animation blending
-    * ===========================================
-    */
-#endif
+   mdl_keyframe apose[32], bpose[32];
+   mdl_keyframe ground_pose[32];
+   {
+      /* when the player is moving fast he will crouch down a little bit */
+      float stand = 1.0f - vg_clampf( speed * 0.03f, 0.0f, 1.0f );
+      player.fstand = vg_lerpf( player.fstand, stand, 0.1f );
 
-   static float fslide = 0.0f;
-   static float fdirz = 0.0f;
-   static float fdirx = 0.0f;
-   static float fstand = 0.0f;
-   static float ffly = 0.0f;
-   static float fpush = 0.0f;
+      /* stand/crouch */
+      float dir_frame   = player.fdirz * (15.0f/30.0f),
+            stand_blend = offset[1]*-2.0f;
+      
+      skeleton_sample_anim( sk, player.mdl.anim_stand, dir_frame, apose );
+      skeleton_sample_anim( sk, player.mdl.anim_highg, dir_frame, bpose );
+      skeleton_lerp_pose( sk, apose, bpose, stand_blend, apose );
 
-   float speed = v3_length( player.rb.v );
-   
-   fstand = vg_lerpf(fstand, 1.0f-vg_clampf(speed*0.03f,0.0f,1.0f),0.1f);
-   fslide = vg_lerpf(fslide, vg_clampf(lslip,0.0f,1.0f), 0.04f);
-   fdirz = vg_lerpf(fdirz, player.reverse > 0.0f? 0.0f: 1.0f, 0.04f );
-   fdirx = vg_lerpf(fdirx, player.slip < 0.0f?    0.0f: 1.0f, 0.01f );
-   ffly = vg_lerpf(ffly, player.in_air?           1.0f: 0.0f, 0.04f );
-   fpush = vg_lerpf(fpush, player.pushing, 0.1f );
-
-   float lr = fdirz * (15.0f/30.0f),
-         st = offset[1]*-2.0f,
-         sa = fdirx * (15.0f/30.0f);
-   
-   mdl_keyframe apose[32], bpose[32];
-   skeleton_sample_anim( &player.mdl.sk, player.mdl.anim_stand, lr, apose );
-   skeleton_sample_anim( &player.mdl.sk, player.mdl.anim_highg, lr, bpose );
-   skeleton_lerp_pose( &player.mdl.sk, apose, bpose, st, apose );
+      /* sliding */
+      float slide_frame = player.fdirx * (15.0f/30.0f);
+      skeleton_sample_anim( sk, player.mdl.anim_slide, slide_frame, bpose );
+      skeleton_lerp_pose( sk, apose, bpose, player.fslide, apose );
 
-   skeleton_sample_anim( &player.mdl.sk, player.mdl.anim_slide, sa, bpose );
-   skeleton_lerp_pose( &player.mdl.sk, apose, bpose, fslide, apose );
-   
-   static float fairdir = 0.0f;
-   fairdir = vg_lerpf( fairdir, -vg_get_axis("horizontal"), 0.04f );
+      /* pushing */
+      player.fpush = vg_lerpf( player.fpush, player.pushing, 0.1f );
+
+      float pt = player.push_time;
+      if( player.reverse > 0.0f )
+         skeleton_sample_anim( sk, player.mdl.anim_push, pt, bpose );
+      else
+         skeleton_sample_anim( sk, player.mdl.anim_push_reverse, pt, bpose );
 
-   /* air anim */
-   float air_dir = (fairdir*0.5f+0.5f)*(15.0f/30.0f);
-   skeleton_sample_anim( &player.mdl.sk, player.mdl.anim_air, air_dir, bpose );
-   skeleton_lerp_pose( &player.mdl.sk, apose, bpose, ffly, apose );
+      skeleton_lerp_pose( sk, apose, bpose, player.fpush, apose );
 
-   /* push anim */
-   skeleton_sample_anim( &player.mdl.sk, player.reverse > 0.0f?
-                                          player.mdl.anim_push:
-                                          player.mdl.anim_push_reverse,
-                                             player.push_time, bpose );
-   skeleton_lerp_pose( &player.mdl.sk, apose, bpose, fpush, apose );
+      /* trick setup */
+      float setup_frame = player.jump * (12.0f/30.0f),
+            setup_blend = vg_minf( player.jump*5.0f, 1.0f );
+      
+      float jump_frame = (vg_time - player.jump_time) + (12.0f/30.0f);
+      if( jump_frame >= (12.0f/30.0f) && jump_frame <= (40.0f/30.0f) )
+         setup_frame = jump_frame;
 
+      skeleton_sample_anim_clamped( sk, player.mdl.anim_ollie, 
+                                       setup_frame, bpose );
+      skeleton_lerp_pose( sk, apose, bpose, setup_blend, ground_pose );
+   }
+   
+   mdl_keyframe air_pose[32];
+   {
+      float target = -vg_get_axis("horizontal");
+      player.fairdir = vg_lerpf( player.fairdir, target, 0.04f );
+      
+      float air_frame = (player.fairdir*0.5f+0.5f) * (15.0f/30.0f);
+      
+      skeleton_sample_anim( sk, player.mdl.anim_air, air_frame, air_pose );
+   }
+
+   skeleton_lerp_pose( sk, ground_pose, air_pose, player.ffly, apose );
 
    /* additive effects */
    apose[player.mdl.id_hip-1].co[0] += offset[0];
@@ -1726,132 +1776,6 @@ static void player_animate(void)
    skeleton_apply_transform( &player.mdl.sk, player.rb.to_world );
 
    skeleton_debug( &player.mdl.sk );
-
-#if 0
-   character_pose_reset( &player.mdl );
-
-   /* TODO */
-   float fstand1 = 1.0f-(1.0f-fstand)*0.0f;
-
-   float amt_air = ffly*ffly,
-         amt_ground = 1.0f-amt_air,
-         amt_std = (1.0f-fslide) * amt_ground,
-         amt_stand = amt_std * fstand1,
-         amt_aero = amt_std * (1.0f-fstand1),
-         amt_slide = amt_ground * fslide;
-
-   character_final_pose( &player.mdl, offset, &pose_stand, amt_stand*fdirz );
-   character_final_pose( &player.mdl, offset, 
-         &pose_stand_reverse, amt_stand * (1.0f-fdirz) );
-
-   character_final_pose( &player.mdl, offset, &pose_aero, amt_aero*fdirz );
-   character_final_pose( &player.mdl, offset, 
-         &pose_aero_reverse, amt_aero * (1.0f-fdirz) );
-
-   character_final_pose( &player.mdl, offset, &pose_slide, amt_slide*fdirx );
-   character_final_pose( &player.mdl, offset, 
-         &pose_slide1, amt_slide*(1.0f-fdirx) );
-
-   character_final_pose( &player.mdl, (v4f){0.0f,0.0f,0.0f,1.0f}, 
-         &pose_fly, amt_air );
-
-   /* 
-    * Additive effects
-    * ==========================
-    */
-   struct ik_basic *arm_l = &player.mdl.ik_arm_l,
-                   *arm_r = &player.mdl.ik_arm_r;
-
-   v3f localv;
-   m3x3_mulv( player.rb.to_local, player.rb.v, localv );
-
-   /* New board transformation */
-   v4f board_rotation; v3f board_location;
-
-   v4f rz, rx;
-   q_axis_angle( rz, (v3f){ 0.0f, 0.0f, 1.0f }, player.board_xy[0] );
-   q_axis_angle( rx, (v3f){ 1.0f, 0.0f, 0.0f }, player.board_xy[1] );
-   q_mul( rx, rz, board_rotation );
-   
-   v3f *mboard = player.mdl.matrices[k_chpart_board];// player.mboard;
-   q_m3x3( board_rotation, mboard );
-   m3x3_mulv( mboard, (v3f){ 0.0f, -0.5f, 0.0f }, board_location );
-   v3_add( (v3f){0.0f,0.5f,0.0f}, board_location, board_location );
-   v3_copy( board_location, mboard[3] );
-
-
-   float wheel_r = offset[0]*-0.4f;
-   v4f qwheel;
-   q_axis_angle( qwheel, (v3f){0.0f,1.0f,0.0f}, wheel_r );
-   
-   q_m3x3( qwheel, player.mdl.matrices[k_chpart_wb] );
-
-   m3x3_transpose( player.mdl.matrices[k_chpart_wb],
-                   player.mdl.matrices[k_chpart_wf] );
-   v3_copy( player.mdl.offsets[k_chpart_wb], 
-         player.mdl.matrices[k_chpart_wb][3] );
-   v3_copy( player.mdl.offsets[k_chpart_wf], 
-         player.mdl.matrices[k_chpart_wf][3] );
-   
-   m4x3_mul( mboard, player.mdl.matrices[k_chpart_wb],
-                     player.mdl.matrices[k_chpart_wb] );
-   m4x3_mul( mboard, player.mdl.matrices[k_chpart_wf],
-                     player.mdl.matrices[k_chpart_wf] );
-
-   m4x3_mulv( mboard, player.mdl.ik_leg_l.end, player.mdl.ik_leg_l.end );
-   m4x3_mulv( mboard, player.mdl.ik_leg_r.end, player.mdl.ik_leg_r.end );
-
-
-   v3_copy( player.mdl.ik_arm_l.end, player.handl_target );
-   v3_copy( player.mdl.ik_arm_r.end, player.handr_target );
-
-   if( 1||player.in_air )
-   {
-      float tuck = player.board_xy[1],
-            tuck_amt = fabsf( tuck ) * (1.0f-fabsf(player.board_xy[0]));
-      
-      float crouch = player.grab*0.3f;
-      v3_muladds( player.mdl.ik_body.base, (v3f){0.0f,-1.0f,0.0f}, 
-            crouch, player.mdl.ik_body.base );
-      v3_muladds( player.mdl.ik_body.end, (v3f){0.0f,-1.0f,0.0f}, 
-            crouch*1.2f, player.mdl.ik_body.end );
-
-      if( tuck < 0.0f )
-      {
-         //foot_l *= 1.0f-tuck_amt*1.5f;
-
-         if( player.grab > 0.1f )
-         {
-            m4x3_mulv( mboard, (v3f){0.1f,0.14f,0.6f}, 
-                  player.handl_target );
-         }
-      }
-      else
-      {
-         //foot_r *= 1.0f-tuck_amt*1.4f;
-
-         if( player.grab > 0.1f )
-         {
-            m4x3_mulv( mboard, (v3f){0.1f,0.14f,-0.6f}, 
-                  player.handr_target );
-         }
-      }
-   }
-
-   v3_lerp( player.handl, player.handl_target, 1.0f, player.handl );
-   v3_lerp( player.handr, player.handr_target, 1.0f, player.handr );
-
-   v3_copy( player.handl, player.mdl.ik_arm_l.end );
-   v3_copy( player.handr, player.mdl.ik_arm_r.end );
-
-   /* Head rotation */
-
-   static float rhead = 0.0f;
-   static const float klook_max = 0.8f;
-   rhead = vg_lerpf( rhead,
-         vg_clampf( atan2f(localv[2],-localv[0]),-klook_max,klook_max), 0.04f );
-   player.mdl.rhead = rhead;
-#endif
 }
 
 static void player_camera_update(void)
index 6483f06d4aeb2cf385e9b25cd47c76ab8673d136..95b5a7624de95832f4ce58b242f925a8e54d9238 100644 (file)
@@ -6,6 +6,7 @@
 #include "rigidbody.h"
 #include "render.h"
 #include "skeleton.h"
+#include "skeleton_animator.h"
 #include "shaders/viewchar.h"
 
 vg_tex2d tex_characters = { .path = "textures/ch_gradient.qoi" };
@@ -28,7 +29,8 @@ struct character
                         *anim_highg,
                         *anim_slide,
                         *anim_air,
-                        *anim_push, *anim_push_reverse;
+                        *anim_push, *anim_push_reverse,
+                        *anim_ollie;
 
    u32 id_hip,
        id_ik_hand_l,
@@ -65,6 +67,7 @@ static int character_load( struct character *ch, const char *name )
    ch->anim_air   = skeleton_get_anim( &ch->sk, "pose_air" );
    ch->anim_push  = skeleton_get_anim( &ch->sk, "push" );
    ch->anim_push_reverse = skeleton_get_anim( &ch->sk, "push_reverse" );
+   ch->anim_ollie = skeleton_get_anim( &ch->sk, "ollie" );
 
    ch->id_hip = skeleton_bone_id( &ch->sk, "hips" );
    ch->id_ik_hand_l = skeleton_bone_id( &ch->sk, "hand.IK.L" );
index 34e1b8e8fba779b0e9c2bb11ca1c068106d6eaee..ce71283b42d9e8c8878edb97285aeb547d450717 100644 (file)
@@ -58,12 +58,29 @@ static u32 skeleton_bone_id( struct skeleton *skele, const char *name )
    return 0;
 }
 
+static void keyframe_copy_pose( mdl_keyframe *kfa, mdl_keyframe *kfb, int num )
+{
+   for( int i=0; i<num; i++ )
+      kfb[i] = kfa[i];
+}
+
 /*
  * Lerp between two sets of keyframes and store in dest. Rotations use Nlerp.
  */
 static void keyframe_lerp_pose( mdl_keyframe *kfa, mdl_keyframe *kfb, float t,
                                 mdl_keyframe *kfd, int count )
 {
+   if( t <= 0.01f )
+   {
+      keyframe_copy_pose( kfa, kfd, count );
+      return;
+   }
+   else if( t >= 0.99f )
+   {
+      keyframe_copy_pose( kfb, kfd, count );
+      return;
+   }
+
    for( int i=0; i<count; i++ )
    {
       v3_lerp( kfa[i].co, kfb[i].co, t, kfd[i].co );
@@ -101,6 +118,20 @@ static void skeleton_sample_anim( struct skeleton *skele,
    skeleton_lerp_pose( skele, base, nbase, t, output );
 }
 
+static int skeleton_sample_anim_clamped( struct skeleton *skele,
+                                         struct skeleton_anim *anim,
+                                         float time,
+                                         mdl_keyframe *output )
+{
+   float end = (float)(anim->length-1) / anim->rate;
+   skeleton_sample_anim( skele, anim, vg_minf( end, time ), output );
+
+   if( time > end )
+      return 0;
+   else
+      return 1;
+}
+
 typedef enum anim_apply
 {
    k_anim_apply_always,
diff --git a/skeleton_animator.h b/skeleton_animator.h
new file mode 100644 (file)
index 0000000..3077084
--- /dev/null
@@ -0,0 +1,7 @@
+#ifndef SKELETON_ANIMATOR_H
+#define SKELETON_ANIMATOR_H
+
+#include "common.h"
+#include "skeleton.h"
+
+#endif /* SKELETON_ANIMATOR_H */
index 29d2d9f646c7e9afe681bbe1084d01e7ee4b6069..064d17eb5067b49fff42e12902e6a8952ec9171b 100644 (file)
Binary files a/textures_src/graffitibox.png and b/textures_src/graffitibox.png differ
diff --git a/textures_src/subworld.png b/textures_src/subworld.png
new file mode 100644 (file)
index 0000000..01eccb1
Binary files /dev/null and b/textures_src/subworld.png differ
index 92fd2e855c88dc9357acef1552859c0d79d138a1..626aef8979837f21b340f603c5bccc201ecc893a 100644 (file)
@@ -21,7 +21,8 @@ static struct button_binding vg_controller_binds[] =
 {
    { "push", GLFW_GAMEPAD_BUTTON_A },
    { "break", GLFW_GAMEPAD_BUTTON_B },
-   { "switchmode", GLFW_GAMEPAD_BUTTON_Y } 
+   { "switchmode", GLFW_GAMEPAD_BUTTON_Y },
+   { "jump", GLFW_GAMEPAD_BUTTON_X }
 };
 
 static struct axis_binding vg_axis_binds[] = 
diff --git a/world.h b/world.h
index 3c20e81e1a87483aa20f3f0565102457073e862a..f970b0a3204f68152656d8fa366db6f9817aad44 100644 (file)
--- a/world.h
+++ b/world.h
@@ -65,7 +65,7 @@ static struct gworld
    /* TODO Maybe make this less hardcoded */
    mdl_submesh sm_geo_std_oob, sm_geo_std, sm_geo_vb,
                sm_foliage_main, sm_foliage_alphatest,
-               sm_graffiti;
+               sm_graffiti, sm_subworld;
 
    glmesh skybox, skydome;
    mdl_submesh dome_upper, dome_lower;
@@ -355,7 +355,8 @@ static void world_load(void)
        mat_surf_oob = 0,
        mat_vertex_blend = 0,
        mat_alphatest = 0,
-       mat_graffiti = 0;
+       mat_graffiti = 0,
+       mat_subworld = 0;
 
    for( int i=1; i<mworld->material_count; i++ )
    {
@@ -372,6 +373,8 @@ static void world_load(void)
          mat_alphatest = i;
       else if( !strcmp( "graffitibox", mat_name ))
          mat_graffiti = i;
+      else if( !strcmp( "subworld", mat_name ))
+         mat_subworld = i;
    }
 
    m4x3f midentity;
@@ -387,6 +390,10 @@ static void world_load(void)
       add_all_if_material( midentity, &world.geo, mworld, mat_surf );
    scene_copy_slice( &world.geo, &world.sm_geo_std );
 
+   if( mat_subworld )
+      add_all_if_material( midentity, &world.geo, mworld, mat_subworld );
+   scene_copy_slice( &world.geo, &world.sm_subworld );
+
    if( mat_vertex_blend )
       add_all_if_material( midentity, &world.geo, mworld, mat_vertex_blend );
    scene_copy_slice( &world.geo, &world.sm_geo_vb );
@@ -630,6 +637,7 @@ static void render_terrain( m4x4f projection, v3f camera )
    scene_bind( &world.geo );
    mdl_draw_submesh( &world.sm_geo_std_oob );
    mdl_draw_submesh( &world.sm_geo_std );
+   mdl_draw_submesh( &world.sm_subworld );
 
    /* TODO: Dont draw in reflection */
    glDisable(GL_CULL_FACE);