another api change
[carveJwlIkooP6JGAAIwe30JlM.git] / player_device_common.h
1 #ifndef PLAYER_DEVICE_COMMON_H
2 #define PLAYER_DEVICE_COMMON_H
3
4 #define VG_GAME
5 #include "vg/vg.h"
6 #include "common.h"
7 #include "player_interface.h"
8
9 struct mixedcam_state
10 {
11 v3f vl, vt, pos, post, dir;
12 struct teleport_gate *gate;
13 };
14
15 /*
16 * this is a little yucky but needs to be done so we can use this 'prediction'
17 * in the pose function. its unfortunate. too bad
18 */
19 VG_STATIC void followcam_nextpos( player_interface *player,
20 struct mixedcam_state *mc,
21 v3f next_pos, v3f d )
22 {
23 }
24
25
26 VG_STATIC int followcam_will_hit_gate( player_interface *player,
27 struct mixedcam_state *mc )
28 {
29 if( mc->gate )
30 {
31 v3f next_pos, d, _;
32 followcam_nextpos( player, mc, next_pos, d );
33
34 return gate_intersect_plane( mc->gate, next_pos, mc->pos, _ );
35 }
36
37 return 0;
38 }
39
40 VG_STATIC void mixedcam_transport( struct mixedcam_state *mc,
41 teleport_gate *gate )
42 {
43 m3x3_mulv( gate->transport, mc->vl, mc->vl );
44 mc->gate = gate;
45
46 #if 0
47 if( !cl_thirdperson )
48 player_apply_transport_to_cam( gate->transport );
49 #endif
50 }
51
52 VG_STATIC void mixedcam_reset( player_interface *player,
53 struct mixedcam_state *mc )
54 {
55 mc->gate = NULL;
56 }
57
58
59 VG_STATIC void mixedcam_set_targets( struct mixedcam_state *mc, v3f v, v3f co )
60 {
61 v3_copy( v, mc->vt );
62 v3_copy( co, mc->post );
63 }
64
65
66 VG_STATIC void mixedcam_iterate_firstperson_frame( player_interface *player,
67 struct mixedcam_state *mc )
68 {
69 v3_lerp( mc->vl, mc->vt, 4.0f*vg.time_delta, mc->vl );
70 }
71
72 VG_STATIC void mixedcam_iterate_thirdperson_frame( player_interface *player,
73 struct mixedcam_state *mc )
74 {
75 v3f prev_pos, origin, target, dir;
76
77 v3_copy( mc->pos, prev_pos );
78
79 if( mc->gate )
80 {
81 m4x3f inverse;
82 m4x3_invert_affine( mc->gate->transport, inverse );
83 m4x3_mulv( inverse, mc->post, origin );
84 }
85 else
86 {
87 v3_copy( mc->post, origin );
88 }
89
90 /* TODO: Remove? */
91 v3_add( origin, (v3f){0.0f,1.35f,0.0f}, origin );
92 v3_sub( origin, mc->pos, dir );
93
94 if( v3_length2( dir ) < 0.1f*0.1f )
95 v3_copy( (v3f){ 0.0f, 0.0f, 1.0f }, dir ); /* FIXME */
96 else
97 v3_normalize( dir );
98
99 v3_muladds( origin, dir, -2.0f, target );
100 v3_lerp( mc->pos, target, vg.frame_delta * 12.0f, mc->pos );
101 v3_copy( dir, mc->dir );
102
103 if( mc->gate )
104 {
105 v2f _;
106 if( gate_intersect_plane( mc->gate, mc->pos, prev_pos, _ ) )
107 {
108 m4x3_mulv( mc->gate->transport, mc->pos, mc->pos );
109 m3x3_mulv( mc->gate->transport, mc->dir, mc->dir );
110 //player_apply_transport_to_cam( mc->gate->transport );
111
112 mc->gate = NULL;
113 }
114 }
115 }
116
117 VG_STATIC void mixedcam_iterate_frame( player_interface *player,
118 struct mixedcam_state *mc )
119 {
120 if( cl_thirdperson )
121 mixedcam_iterate_thirdperson_frame( player, mc );
122 else
123 mixedcam_iterate_firstperson_frame( player, mc );
124 }
125
126 VG_STATIC void mixedcam_get_camera( struct mixedcam_state *mc )
127 {
128
129 }
130
131 #endif /* PLAYER_DEVICE_COMMON_H */