- float timestep = 1.0f/60.0f;
-
- if( freecam )
- {
- m4x3f cam_rot;
- m4x3_identity( cam_rot );
- m4x3_rotate_y( cam_rot, -player.look_dir[0] );
- m4x3_rotate_x( cam_rot, -player.look_dir[1] );
-
- v3f lookdir = { 0.0f, 0.0f, -1.0f },
- sidedir = { 1.0f, 0.0f, 0.0f };
-
- m4x3_mulv( cam_rot, lookdir, lookdir );
- m4x3_mulv( cam_rot, sidedir, sidedir );
-
- float movespeed = 5.0f;
- static v2f mouse_last,
- view_vel = { 0.0f, 0.0f };
- static v3f move_vel = { 0.0f, 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_muls( view_vel, 0.75f, view_vel );
- v2_add( view_vel, player.look_dir, player.look_dir );
- player.look_dir[1] =
- vg_clampf( player.look_dir[1], -VG_PIf*0.5f, VG_PIf*0.5f );
-
- if( vg_get_button( "forward" ) )
- v3_muladds( move_vel, lookdir, timestep * movespeed, move_vel );
- if( vg_get_button( "back" ) )
- v3_muladds( move_vel, lookdir, timestep *-movespeed, move_vel );
- if( vg_get_button( "left" ) )
- v3_muladds( move_vel, sidedir, timestep *-movespeed, move_vel );
- if( vg_get_button( "right" ) )
- v3_muladds( move_vel, sidedir, timestep * movespeed, move_vel );
-
- v3_muls( move_vel, 0.75f, move_vel );
- v3_add( move_vel, player.view, player.view );
-
- return;
- }
-
- if( vg_get_button( "forward" ) )
- {
- v3f dir = { 0.0f, 0.0f, -1.0f };
-
- m3x3_mulv( player.to_world, dir, dir );
- v3_muladds( player.v, dir, 5.0f * timestep, player.v );
- }
-
- /* Get front and back contact points */
- v3f contact_front, contact_back, fwd, fwd1, contact_norm, vup;
-
- m3x3_mulv( player.to_world, (v3f){0.0f,0.0f,-1.0f}, fwd );
- m3x3_mulv( player.to_world, (v3f){0.03f,0.0f,-1.0f}, fwd1 );
- m3x3_mulv( player.to_world, (v3f){0.0f,1.0f,0.0f}, vup );
-
- v3_muladds( player.co, fwd, 1.0f, contact_front );
- v3_muladds( player.co, fwd,-1.0f, contact_back );
- v3_muladds( player.co, fwd1, 1.0f, contact_norm );
-
- sample_scene_height( &world_scene, contact_front );
- sample_scene_height( &world_scene, contact_back );
- sample_scene_height( &world_scene, contact_norm );
-
- v3f norm;
- v3f v0, v1;
- v3_sub( contact_back, contact_norm, v0 );
- v3_sub( contact_front, contact_norm, v1 );
- v3_cross( v1, v0, norm );
- v3_normalize( norm );
-
- v3f gravity = { 0.0f, -9.6f, 0.0f };
- v3_muladds( player.v, gravity, timestep, player.v );
-
- v3f ground_pos;
- v3_copy( player.co, ground_pos );
- sample_scene_height( &world_scene, ground_pos );
-
- static int in_air = 1;