1 #include "ent_skateshop.h"
5 #include "vg/vg_perlin.h"
7 static float player_get_heading_yaw(void){
9 q_mulv( localplayer
.rb
.q
, (v3f
){ 0.0f
,0.0f
,1.0f
}, xz
);
10 return atan2f( xz
[0], xz
[2] );
13 static void player_camera_portal_correction(void){
14 if( localplayer
.gate_waiting
){
15 /* construct plane equation for reciever gate */
17 q_mulv( localplayer
.gate_waiting
->q
[1], (v3f
){0.0f
,0.0f
,1.0f
}, plane
);
18 plane
[3] = v3_dot( plane
, localplayer
.gate_waiting
->co
[1] );
20 f32 pol
= v3_dot( localplayer
.cam
.pos
, plane
) - plane
[3];
22 int cleared
= (pol
< 0.0f
) || (pol
> 5.0f
);
25 vg_success( "Plane cleared\n" );
29 m4x3_invert_affine( localplayer
.gate_waiting
->transport
, inverse
);
31 /* de-transform camera and player back */
33 m4x3_mulv( inverse
, localplayer
.cam
.pos
, localplayer
.cam
.pos
);
34 v3_angles_vector( localplayer
.cam
.angles
, v0
);
35 m3x3_mulv( inverse
, v0
, v0
);
36 v3_angles( v0
, localplayer
.cam
.angles
);
38 skeleton_apply_transform( &localplayer
.skeleton
, inverse
,
39 localplayer
.final_mtx
);
41 /* record and re-put things again */
44 skaterift_record_frame( &player_replay
.local
, 1 );
45 localplayer
.deferred_frame_record
= 1;
47 skeleton_apply_transform( &localplayer
.skeleton
,
48 localplayer
.gate_waiting
->transport
,
49 localplayer
.final_mtx
);
51 m4x3_mulv( localplayer
.gate_waiting
->transport
,
52 localplayer
.cam
.pos
, localplayer
.cam
.pos
);
53 v3_angles_vector( localplayer
.cam
.angles
, v0
);
54 m3x3_mulv( localplayer
.gate_waiting
->transport
, v0
, v0
);
55 v3_angles( v0
, localplayer
.cam
.angles
);
56 player_apply_transport_to_cam( localplayer
.gate_waiting
->transport
);
57 localplayer
.gate_waiting
= NULL
;
62 static void player__cam_iterate(void){
63 struct player_cam_controller
*cc
= &localplayer
.cam_control
;
65 if( localplayer
.subsystem
== k_player_subsystem_walk
){
66 v3_copy( (v3f
){-0.1f
,1.8f
,0.0f
}, cc
->fpv_viewpoint
);
67 v3_copy( (v3f
){0.0f
,0.0f
,0.0f
}, cc
->fpv_offset
);
68 v3_copy( (v3f
){0.0f
,1.4f
,0.0f
}, cc
->tpv_offset
);
70 else if( localplayer
.subsystem
== k_player_subsystem_glide
){
71 v3_copy( (v3f
){-0.15f
,1.75f
,0.0f
}, cc
->fpv_viewpoint
);
72 v3_copy( (v3f
){0.0f
,0.0f
,0.0f
}, cc
->fpv_offset
);
73 v3_copy( (v3f
){0.0f
,-1.0f
,0.0f
}, cc
->tpv_offset
);
74 v3_add( cc
->tpv_offset_extra
, cc
->tpv_offset
, cc
->tpv_offset
);
77 v3_copy( (v3f
){-0.15f
,1.75f
,0.0f
}, cc
->fpv_viewpoint
);
78 v3_copy( (v3f
){0.0f
,0.0f
,0.0f
}, cc
->fpv_offset
);
80 f32 h
= vg_lerpf( 0.4f
, 1.4f
, k_cam_height
);
81 v3_copy( (v3f
){0.0f
,h
,0.0f
}, cc
->tpv_offset
);
82 v3_add( cc
->tpv_offset_extra
, cc
->tpv_offset
, cc
->tpv_offset
);
85 localplayer
.cam_velocity_constant
= 0.25f
;
86 localplayer
.cam_velocity_coefficient
= 0.7f
;
90 if( localplayer
.cam_dist_smooth
== 0.0f
){
91 localplayer
.cam_dist_smooth
= localplayer
.cam_dist
;
94 localplayer
.cam_dist_smooth
= vg_lerpf(
95 localplayer
.cam_dist_smooth
,
97 vg
.time_frame_delta
* 8.0f
);
100 localplayer
.cam_velocity_influence_smooth
= vg_lerpf(
101 localplayer
.cam_velocity_influence_smooth
,
102 localplayer
.cam_velocity_influence
,
103 vg
.time_frame_delta
* 8.0f
);
105 localplayer
.cam_velocity_coefficient_smooth
= vg_lerpf(
106 localplayer
.cam_velocity_coefficient_smooth
,
107 localplayer
.cam_velocity_coefficient
,
108 vg
.time_frame_delta
* 8.0f
);
110 localplayer
.cam_velocity_constant_smooth
= vg_lerpf(
111 localplayer
.cam_velocity_constant_smooth
,
112 localplayer
.cam_velocity_constant
,
113 vg
.time_frame_delta
* 8.0f
);
115 enum camera_mode target_mode
= cc
->camera_mode
;
117 if( localplayer
.subsystem
== k_player_subsystem_dead
)
118 target_mode
= k_cam_thirdperson
;
120 cc
->camera_type_blend
=
121 vg_lerpf( cc
->camera_type_blend
,
122 (target_mode
== k_cam_firstperson
)? 1.0f
: 0.0f
,
123 5.0f
* vg
.time_frame_delta
);
125 v3_lerp( cc
->fpv_viewpoint_smooth
, cc
->fpv_viewpoint
,
126 vg
.time_frame_delta
* 8.0f
, cc
->fpv_viewpoint_smooth
);
128 v3_lerp( cc
->fpv_offset_smooth
, cc
->fpv_offset
,
129 vg
.time_frame_delta
* 8.0f
, cc
->fpv_offset_smooth
);
131 v3_lerp( cc
->tpv_offset_smooth
, cc
->tpv_offset
,
132 vg
.time_frame_delta
* 8.0f
, cc
->tpv_offset_smooth
);
134 /* fov -- simple blend */
135 float fov_skate
= vg_lerpf( 97.0f
, 135.0f
, k_fov
),
136 fov_walk
= vg_lerpf( 90.0f
, 110.0f
, k_fov
);
138 localplayer
.cam
.fov
= vg_lerpf( fov_walk
, fov_skate
, cc
->camera_type_blend
);
141 * first person camera
145 v3f fpv_pos
, fpv_offset
;
146 m4x3_mulv( localplayer
.final_mtx
[ localplayer
.id_head
-1 ],
147 cc
->fpv_viewpoint_smooth
, fpv_pos
);
148 m3x3_mulv( localplayer
.rb
.to_world
, cc
->fpv_offset_smooth
, fpv_offset
);
149 v3_add( fpv_offset
, fpv_pos
, fpv_pos
);
153 v3_lerp( cc
->cam_velocity_smooth
, localplayer
.rb
.v
, 4.0f
*vg
.time_frame_delta
,
154 cc
->cam_velocity_smooth
);
156 v3_angles( cc
->cam_velocity_smooth
, velocity_angles
);
157 velocity_angles
[1] *= localplayer
.cam_velocity_coefficient_smooth
;
158 velocity_angles
[1] += localplayer
.cam_velocity_constant_smooth
;
160 float inf_fpv
= localplayer
.cam_velocity_influence_smooth
*
161 cc
->camera_type_blend
,
162 inf_tpv
= localplayer
.cam_velocity_influence_smooth
*
163 (1.0f
-cc
->camera_type_blend
);
165 vg_camera_lerp_angles( localplayer
.angles
, velocity_angles
,
167 localplayer
.angles
);
170 * Third person camera
173 /* no idea what this technique is called, it acts like clamped position based
174 * on some derivative of where the final camera would end up ....
176 * it is done in the local basis then transformed back */
179 v3_muls( localplayer
.rb
.v
, 0.4f
*vg
.time_frame_delta
, future
);
181 v3f camera_follow_dir
=
182 { -sinf( localplayer
.angles
[0] ) * cosf( localplayer
.angles
[1] ),
183 sinf( localplayer
.angles
[1] ),
184 cosf( localplayer
.angles
[0] ) * cosf( localplayer
.angles
[1] ) };
187 v3_sub( camera_follow_dir
, future
, v0
);
190 v3_copy( localplayer
.angles
, follow_angles
);
191 follow_angles
[0] = atan2f( -v0
[0], v0
[2] );
192 follow_angles
[1] = 0.3f
+ velocity_angles
[1] * 0.2f
;
194 float ya
= atan2f( -cc
->cam_velocity_smooth
[1], 30.0f
);
196 follow_angles
[1] = 0.3f
+ ya
;
197 vg_camera_lerp_angles( localplayer
.angles
, follow_angles
,
199 localplayer
.angles
);
203 rb_extrapolate( &localplayer
.rb
, pco
, pq
);
204 v3_muladds( pco
, localplayer
.holdout_pose
.root_co
,
205 localplayer
.holdout_time
, pco
);
206 v3_lerp( cc
->tpv_lpf
, pco
, 20.0f
*vg
.time_frame_delta
, cc
->tpv_lpf
);
208 /* now move into world */
209 v3f tpv_pos
, tpv_offset
, tpv_origin
;
211 /* TODO: whats up with CC and not CC but both sets of variables are doing
212 * the same ideas just saved in different places?
215 q_mulv( pq
, cc
->tpv_offset_smooth
, tpv_origin
);
216 v3_add( tpv_origin
, cc
->tpv_lpf
, tpv_origin
);
219 v3_muls( camera_follow_dir
, localplayer
.cam_dist_smooth
, tpv_offset
);
220 v3_muladds( tpv_offset
, cc
->cam_velocity_smooth
, -0.025f
, tpv_offset
);
222 v3_add( tpv_origin
, tpv_offset
, tpv_pos
);
227 v3_lerp( tpv_pos
, fpv_pos
, cc
->camera_type_blend
, localplayer
.cam
.pos
);
228 v3_copy( localplayer
.angles
, localplayer
.cam
.angles
);
231 f32 speed
= v3_length(localplayer
.rb
.v
),
232 strength
= k_cam_shake_strength
* speed
;
233 localplayer
.cam_trackshake
+=
234 speed
*k_cam_shake_trackspeed
*vg
.time_frame_delta
;
236 v2f rnd
= {vg_perlin_fract_1d( localplayer
.cam_trackshake
, 1.0f
, 4, 20 ),
237 vg_perlin_fract_1d( localplayer
.cam_trackshake
, 1.0f
, 4, 63 ) };
238 v2_muladds( localplayer
.cam
.angles
, rnd
, strength
, localplayer
.cam
.angles
);
241 v3_muls( localplayer
.cam_land_punch_v
, -k_cam_damp
, Fd
);
242 v3_muls( localplayer
.cam_land_punch
, -k_cam_spring
, Fs
);
243 v3_muladds( localplayer
.cam_land_punch
, localplayer
.cam_land_punch_v
,
244 vg
.time_frame_delta
, localplayer
.cam_land_punch
);
246 v3_muladds( localplayer
.cam_land_punch_v
, F
, vg
.time_frame_delta
,
247 localplayer
.cam_land_punch_v
);
248 v3_add( localplayer
.cam_land_punch
, localplayer
.cam
.pos
,
249 localplayer
.cam
.pos
);
251 /* portal transitions */
252 player_camera_portal_correction();
255 static void player_look( v3f angles
, float speed
){
256 if( vg_ui
.wants_mouse
) return;
261 v2_copy( vg
.mouse_delta
, mouse_input
);
262 if( k_invert_y
) mouse_input
[1] *= -1.0f
;
263 v2_muladds( angles
, mouse_input
, 0.0025f
* speed
, angles
);
266 joystick_state( k_srjoystick_look
, jlook
);
268 angles
[0] += jlook
[0] * vg
.time_frame_delta
* 4.0f
* speed
;
269 float input_y
= jlook
[1] * vg
.time_frame_delta
* 4.0f
;
270 if( k_invert_y
) input_y
*= -1.0f
;
272 angles
[1] += input_y
* speed
;
273 angles
[1] = vg_clampf( angles
[1], -VG_PIf
*0.5f
, VG_PIf
*0.5f
);