246af3ca71a458dd3da15f78204c736bf7d64997
[carveJwlIkooP6JGAAIwe30JlM.git] / freecam.c
1 #include "skaterift.h"
2 #include "player_replay.h"
3 #include "input.h"
4
5 void freecam_preupdate(void)
6 {
7 vg_camera *cam = &player_replay.replay_freecam;
8 v3f angles;
9 v3_copy( cam->angles, angles );
10 player_look( angles, 1.0f );
11
12 f32 decay = vg_maxf(0.0f,1.0f-vg.time_frame_delta*10.0f);
13
14 v3f d;
15 v3_sub( angles, cam->angles, d );
16 v3_muladds( player_replay.freecam_w, d, 20.0f, player_replay.freecam_w );
17 v3_muls( player_replay.freecam_w, decay, player_replay.freecam_w );
18 v3_muladds( cam->angles, player_replay.freecam_w, vg.time_frame_delta,
19 cam->angles );
20 cam->angles[1] = vg_clampf( cam->angles[1], -VG_PIf*0.5f,VG_PIf*0.5f);
21
22 vg_camera_update_transform( cam );
23
24 v3f lookdir = { 0.0f, 0.0f, -1.0f },
25 sidedir = { 1.0f, 0.0f, 0.0f };
26
27 m3x3_mulv( cam->transform, lookdir, lookdir );
28 m3x3_mulv( cam->transform, sidedir, sidedir );
29
30 v2f input;
31 joystick_state( k_srjoystick_steer, input );
32 v2_muls( input, vg.time_frame_delta*6.0f*20.0f, input );
33
34 v3_muladds( player_replay.freecam_v, lookdir, -input[1],
35 player_replay.freecam_v );
36 v3_muladds( player_replay.freecam_v, sidedir, input[0],
37 player_replay.freecam_v );
38
39 v3_muls( player_replay.freecam_v, decay, player_replay.freecam_v );
40 v3_muladds( cam->pos,
41 player_replay.freecam_v, vg.time_frame_delta, cam->pos );
42 }
43
44 int freecam_cmd( int argc, const char *argv[] )
45 {
46 if( argc ){
47 player_replay.freecam = atoi(argv[0]);
48
49 if( player_replay.freecam ){
50 vg_camera_copy( &skaterift.cam, &player_replay.replay_freecam );
51 }
52 }
53 return 0;
54 }