-#include "common.h"
-#include "character.h"
-#include "bvh.h"
-
-static int freecam = 0;
-static float k_walkspeed = 2.0f;
-static int walk_grid_iterations = 1;
-
-static struct gplayer
-{
- /* Physics */
- v3f co, v, a, v_last, m, bob, vl;
- v4f rot;
- float vswitch, slip, slip_last,
- reverse;
-
- float iY; /* Yaw inertia */
- int in_air, is_dead, on_board;
-
- /* Input */
- v2f joy_l;
-
- v2f board_xy;
- float grab;
- float pitch;
-
- v3f land_target;
- v3f land_target_log[22];
- u32 land_target_colours[22];
- int land_log_count;
- m3x3f vr,vr_pstep;
-
- m4x3f to_world, to_local;
-
- struct character mdl;
-
- v3f handl_target, handr_target,
- handl, handr;
-
- /* Camera */
- float air_blend;
-
- v3f camera_pos, smooth_localcam;
- v2f angles;
- m4x3f camera, camera_inverse;
-}
-player =
-{
- .on_board = 1
-};
-
-static void player_transform_update(void)
-{
- q_normalize( player.rot );
- q_m3x3( player.rot, player.to_world );
- v3_copy( player.co, player.to_world[3] );
-
- m4x3_invert_affine( player.to_world, player.to_local );
-}
-
-static int reset_player( int argc, char const *argv[] )
-{
- v3_copy( (v3f){ 0.0f, -2.0f, 0.0f }, player.co );
-
- if( argc == 1 )
- {
- if( !strcmp( argv[0], "tutorial" ))
- v3_copy( world.tutorial, player.co );
- }
-
- v3_copy( (v3f){ 0.0f, 0.0f, -0.2f }, player.v );
- q_identity( player.rot );
- player.vswitch = 1.0f;
- player.slip_last = 0.0f;
- player.is_dead = 0;
- player.in_air = 1;
- m3x3_identity( player.vr );
-
- player.mdl.shoes[0] = 1;
- player.mdl.shoes[1] = 1;
-
- player_transform_update();
- return 0;
-}
-
-static void player_mouseview(void)
-{
- static v2f mouse_last,
- view_vel = { 0.0f, 0.0f };
-
- if( vg_get_button_down( "primary" ) )
- v2_copy( vg_mouse, mouse_last );
-
- else if( vg_get_button( "primary" ) )
- {
- v2f delta;
- v2_sub( vg_mouse, mouse_last, delta );
- v2_copy( vg_mouse, mouse_last );
-
- v2_muladds( view_vel, delta, 0.005f, view_vel );
- }
-
- v2_muladds( view_vel,
- (v2f){ vg_get_axis("h1"), vg_get_axis("v1") },
- 0.05f, view_vel );
- v2_muls( view_vel, 0.7f, 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 );
-}
-
-static void player_freecam(void)
-{
- player_mouseview();
-
- float movespeed = 25.0f;
- 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 );
-
- static v3f move_vel = { 0.0f, 0.0f, 0.0f };
- if( vg_get_button( "forward" ) )
- v3_muladds( move_vel, lookdir, ktimestep * movespeed, move_vel );
- if( vg_get_button( "back" ) )
- v3_muladds( move_vel, lookdir, ktimestep *-movespeed, move_vel );
- if( vg_get_button( "left" ) )
- v3_muladds( move_vel, sidedir, ktimestep *-movespeed, move_vel );
- if( vg_get_button( "right" ) )
- v3_muladds( move_vel, sidedir, ktimestep * movespeed, move_vel );
-
- v3_muls( move_vel, 0.7f, move_vel );
- v3_add( move_vel, player.camera_pos, player.camera_pos );
-}
-
-static void apply_gravity( v3f vel, float const timestep )
-{
- v3f gravity = { 0.0f, -9.6f, 0.0f };
- v3_muladds( vel, gravity, timestep, vel );
-}