physics
[carveJwlIkooP6JGAAIwe30JlM.git] / player_physics.h
index 5d1843305adec22610548dbf833d714aa8ea9ce4..b93ac0394b32aa8211cc0f7490b2134fa5cbd5c7 100644 (file)
@@ -6,6 +6,7 @@
 #define PLAYER_PHYSICS_H
 
 #include "player.h"
+#include "camera.h"
 
 static void apply_gravity( v3f vel, float const timestep )
 {
@@ -520,6 +521,7 @@ static void player_physics(void)
 
    if( !phys->in_air )
    {
+#if 0
       v3f axis;
       float angle = v3_dot( phys->rb.up, surface_avg );
       v3_cross( phys->rb.up, surface_avg, axis );
@@ -533,6 +535,34 @@ static void player_physics(void)
          q_axis_angle( correction, axis, acosf(angle)*18.0f*VG_TIMESTEP_FIXED );
          q_mul( correction, phys->rb.q, phys->rb.q );
       }
+#else
+      
+      /* 20/10/22: make this only go axisways instead, may effect velocities. */
+
+      v3f projected, axis;
+
+      float d = v3_dot( phys->rb.forward, surface_avg );
+      v3_muladds( surface_avg, phys->rb.forward, -d, projected );
+      v3_normalize( projected );
+
+      float angle = v3_dot( phys->rb.up, projected );
+      v3_cross( phys->rb.up, projected, axis );
+
+      v3f p0, p1;
+      v3_add( phys->rb.co, projected, p0 );
+      v3_add( phys->rb.co, phys->rb.up, p1 );
+      vg_line( phys->rb.co, p0, 0xff00ff00 );
+      vg_line( phys->rb.co, p1, 0xff000fff );
+
+      if( fabsf(angle) < 0.999f )
+      {
+         v4f correction;
+         q_axis_angle( correction, axis, acosf(angle)*4.0f*VG_TIMESTEP_FIXED );
+         q_mul( correction, phys->rb.q, phys->rb.q );
+      }
+
+
+#endif
 
       float const DOWNFORCE = -k_downforce*VG_TIMESTEP_FIXED;
       v3_muladds( phys->rb.v, phys->rb.up, DOWNFORCE, phys->rb.v );
@@ -682,6 +712,8 @@ static void player_do_motion(void)
             player.angles[0] = atan2f( fwd_dir[2], fwd_dir[0] );
          }
          
+         player.rewind_length = 0;
+         player.rewind_incrementer = 10000;
          player_save_frame();
 
          audio_lock();
@@ -717,9 +749,6 @@ static void player_mouseview(void)
       v2_muladds( view_vel, delta, 0.06f*vg.time_delta, view_vel );
    }
    
-   v2_muladds( view_vel, (v2f){ vg_get_axis("h1"), vg_get_axis("v1") }, 
-                         3.0f * vg.time_delta, view_vel );
-
    v2_muls( view_vel, 1.0f-4.2f*vg.time_delta, view_vel );
    v2_add( view_vel, player.angles, player.angles );
    player.angles[1] = vg_clampf( player.angles[1], -VG_PIf*0.5f, VG_PIf*0.5f );
@@ -733,8 +762,8 @@ static void player_freecam(void)
    v3f lookdir = { 0.0f, 0.0f, -1.0f },
        sidedir = { 1.0f, 0.0f,  0.0f };
    
-   m3x3_mulv( player.camera, lookdir, lookdir );
-   m3x3_mulv( player.camera, sidedir, sidedir );
+   m3x3_mulv( camera_mtx, lookdir, lookdir );
+   m3x3_mulv( camera_mtx, sidedir, sidedir );
    
    static v3f move_vel = { 0.0f, 0.0f, 0.0f };
    if( vg_get_button( "forward" ) )
@@ -750,20 +779,6 @@ static void player_freecam(void)
    v3_add( move_vel, player.camera_pos, player.camera_pos );
 }
 
-static void player_camera_update(void)
-{
-   /* Update camera matrices */
-   v4f qyaw, qpitch, qcam;
-   q_axis_angle( qyaw, (v3f){ 0.0f, 1.0f, 0.0f }, -player.angles[0] ); 
-   q_axis_angle( qpitch, (v3f){ 1.0f, 0.0f, 0.0f }, -player.angles[1] ); 
-
-   q_mul( qyaw, qpitch, qcam );
-   q_m3x3( qcam, player.camera );
-
-   v3_copy( player.camera_pos, player.camera[3] );
-   m4x3_invert_affine( player.camera, player.camera_inverse );
-}
-
 static int reset_player( int argc, char const *argv[] )
 {
    struct player_phys *phys = &player.phys;