#include "menu.h"
#include "vg/vg_perlin.h"
-VG_STATIC void player_vector_angles( v3f angles, v3f v, float C, float k )
-{
+static void player_vector_angles( v3f angles, v3f v, float C, float k ){
float yaw = atan2f( v[0], -v[2] ),
pitch = atan2f
(
angles[2] = 0.0f;
}
-VG_STATIC float player_get_heading_yaw( player_instance *player )
-{
+static float player_get_heading_yaw(void){
v3f xz;
- q_mulv( player->rb.q, (v3f){ 0.0f,0.0f,1.0f }, xz );
- m3x3_mulv( player->invbasis, xz, xz );
+ q_mulv( localplayer.rb.q, (v3f){ 0.0f,0.0f,1.0f }, xz );
+ m3x3_mulv( localplayer.invbasis, xz, xz );
return atan2f( xz[0], xz[2] );
}
-VG_STATIC void player_camera_portal_correction( player_instance *player )
-{
- if( player->gate_waiting ){
+static void player_camera_portal_correction(void){
+ if( localplayer.gate_waiting ){
/* construct plane equation for reciever gate */
v4f plane;
- q_mulv( player->gate_waiting->q[1], (v3f){0.0f,0.0f,1.0f}, plane );
- plane[3] = v3_dot( plane, player->gate_waiting->co[1] );
+ q_mulv( localplayer.gate_waiting->q[1], (v3f){0.0f,0.0f,1.0f}, plane );
+ plane[3] = v3_dot( plane, localplayer.gate_waiting->co[1] );
- f32 pol = v3_dot( player->cam.pos, plane ) - plane[3];
+ f32 pol = v3_dot( localplayer.cam.pos, plane ) - plane[3];
/* check camera polarity */
if( (pol < 0.0f) || (pol > 5.0f) ) {
vg_success( "Plane cleared\n" );
- player_apply_transport_to_cam( player->gate_waiting->transport );
- player->gate_waiting = NULL;
- player->viewable_world = world_current_instance();
+ player_apply_transport_to_cam( localplayer.gate_waiting->transport );
+ localplayer.gate_waiting = NULL;
+ localplayer.viewable_world = world_current_instance();
}
else{
/* de-transform camera and player back */
m4x3f inverse;
- m4x3_invert_affine( player->gate_waiting->transport, inverse );
- m4x3_mulv( inverse, player->cam.pos, player->cam.pos );
+ m4x3_invert_affine( localplayer.gate_waiting->transport, inverse );
+ m4x3_mulv( inverse, localplayer.cam.pos, localplayer.cam.pos );
- struct skeleton *sk = &player->playeravatar->sk;
- skeleton_apply_transform( sk, inverse );
+ struct skeleton *sk = &localplayer.playeravatar->sk;
+ skeleton_apply_transform( sk, inverse, localplayer.final_mtx );
}
}
}
-VG_STATIC void player__cam_iterate( player_instance *player ){
- struct player_avatar *av = player->playeravatar;
- struct player_cam_controller *cc = &player->cam_control;
+static void player__cam_iterate(void){
+ struct player_avatar *av = localplayer.playeravatar;
+ struct player_cam_controller *cc = &localplayer.cam_control;
- if( player->subsystem == k_player_subsystem_walk ){
+ if( localplayer.subsystem == k_player_subsystem_walk ){
v3_copy( (v3f){-0.1f,1.8f,0.0f}, cc->fpv_viewpoint );
v3_copy( (v3f){0.0f,0.0f,0.0f}, cc->fpv_offset );
v3_copy( (v3f){0.0f,1.4f,0.0f}, cc->tpv_offset );
v3_add( cc->tpv_offset_extra, cc->tpv_offset, cc->tpv_offset );
}
- player->cam_velocity_constant = 0.25f;
- player->cam_velocity_coefficient = 0.7f;
+ localplayer.cam_velocity_constant = 0.25f;
+ localplayer.cam_velocity_coefficient = 0.7f;
/* lerping */
- player->cam_velocity_influence_smooth = vg_lerpf(
- player->cam_velocity_influence_smooth,
- player->cam_velocity_influence,
+ localplayer.cam_velocity_influence_smooth = vg_lerpf(
+ localplayer.cam_velocity_influence_smooth,
+ localplayer.cam_velocity_influence,
vg.time_frame_delta * 8.0f );
- player->cam_velocity_coefficient_smooth = vg_lerpf(
- player->cam_velocity_coefficient_smooth,
- player->cam_velocity_coefficient,
+ localplayer.cam_velocity_coefficient_smooth = vg_lerpf(
+ localplayer.cam_velocity_coefficient_smooth,
+ localplayer.cam_velocity_coefficient,
vg.time_frame_delta * 8.0f );
- player->cam_velocity_constant_smooth = vg_lerpf(
- player->cam_velocity_constant_smooth,
- player->cam_velocity_constant,
+ localplayer.cam_velocity_constant_smooth = vg_lerpf(
+ localplayer.cam_velocity_constant_smooth,
+ localplayer.cam_velocity_constant,
vg.time_frame_delta * 8.0f );
enum camera_mode target_mode = cc->camera_mode;
- if( player->subsystem == k_player_subsystem_dead )
+ if( localplayer.subsystem == k_player_subsystem_dead )
target_mode = k_cam_thirdperson;
cc->camera_type_blend =
float fov_skate = vg_lerpf( 97.0f, 135.0f, k_fov ),
fov_walk = vg_lerpf( 90.0f, 110.0f, k_fov );
- player->cam.fov = vg_lerpf( fov_walk, fov_skate, cc->camera_type_blend );
+ localplayer.cam.fov = vg_lerpf( fov_walk, fov_skate, cc->camera_type_blend );
/*
* first person camera
/* position */
v3f fpv_pos, fpv_offset;
- m4x3_mulv( av->sk.final_mtx[ av->id_head-1 ],
+ m4x3_mulv( localplayer.final_mtx[ av->id_head-1 ],
cc->fpv_viewpoint_smooth, fpv_pos );
- m3x3_mulv( player->rb.to_world, cc->fpv_offset_smooth, fpv_offset );
+ m3x3_mulv( localplayer.rb.to_world, cc->fpv_offset_smooth, fpv_offset );
v3_add( fpv_offset, fpv_pos, fpv_pos );
/* angles */
v3f velocity_angles;
- v3_lerp( cc->cam_velocity_smooth, player->rb.v, 4.0f*vg.time_frame_delta,
+ v3_lerp( cc->cam_velocity_smooth, localplayer.rb.v, 4.0f*vg.time_frame_delta,
cc->cam_velocity_smooth );
v3f velocity_local;
- m3x3_mulv( player->invbasis, cc->cam_velocity_smooth, velocity_local );
+ m3x3_mulv( localplayer.invbasis, cc->cam_velocity_smooth, velocity_local );
player_vector_angles( velocity_angles, velocity_local,
- player->cam_velocity_coefficient_smooth,
- player->cam_velocity_constant_smooth );
+ localplayer.cam_velocity_coefficient_smooth,
+ localplayer.cam_velocity_constant_smooth );
- float inf_fpv = player->cam_velocity_influence_smooth * cc->camera_type_blend,
- inf_tpv = player->cam_velocity_influence_smooth *
+ float inf_fpv = localplayer.cam_velocity_influence_smooth *
+ cc->camera_type_blend,
+ inf_tpv = localplayer.cam_velocity_influence_smooth *
(1.0f-cc->camera_type_blend);
- camera_lerp_angles( player->angles, velocity_angles,
+ camera_lerp_angles( localplayer.angles, velocity_angles,
inf_fpv,
- player->angles );
+ localplayer.angles );
/*
* Third person camera
* it is done in the local basis then transformed back */
v3f future;
- v3_muls( player->rb.v, 0.4f*vg.time_frame_delta, future );
- m3x3_mulv( player->invbasis, future, future );
+ v3_muls( localplayer.rb.v, 0.4f*vg.time_frame_delta, future );
+ m3x3_mulv( localplayer.invbasis, future, future );
v3f camera_follow_dir =
- { -sinf( player->angles[0] ) * cosf( player->angles[1] ),
- sinf( player->angles[1] ),
- cosf( player->angles[0] ) * cosf( player->angles[1] ) };
+ { -sinf( localplayer.angles[0] ) * cosf( localplayer.angles[1] ),
+ sinf( localplayer.angles[1] ),
+ cosf( localplayer.angles[0] ) * cosf( localplayer.angles[1] ) };
v3f v0;
v3_sub( camera_follow_dir, future, v0 );
v3f follow_angles;
- v3_copy( player->angles, follow_angles );
+ v3_copy( localplayer.angles, follow_angles );
follow_angles[0] = atan2f( -v0[0], v0[2] );
follow_angles[1] = 0.3f + velocity_angles[1] * 0.2f;
float ya = atan2f( -velocity_local[1], 30.0f );
follow_angles[1] = 0.3f + ya;
- camera_lerp_angles( player->angles, follow_angles,
+ camera_lerp_angles( localplayer.angles, follow_angles,
inf_tpv,
- player->angles );
+ localplayer.angles );
v3f pco;
v4f pq;
- rb_extrapolate( &player->rb, pco, pq );
+ rb_extrapolate( &localplayer.rb, pco, pq );
+ v3_muladds( pco, localplayer.holdout_pose.root_co,
+ localplayer.holdout_time, pco );
v3_lerp( cc->tpv_lpf, pco, 20.0f*vg.time_frame_delta, cc->tpv_lpf );
/* now move into world */
v3_add( tpv_origin, cc->tpv_lpf, tpv_origin );
/* offset */
- m3x3_mulv( player->basis, camera_follow_dir, camera_follow_dir );
+ m3x3_mulv( localplayer.basis, camera_follow_dir, camera_follow_dir );
v3_muls( camera_follow_dir, 1.8f, tpv_offset );
v3_muladds( tpv_offset, cc->cam_velocity_smooth, -0.025f, tpv_offset );
v3_add( tpv_origin, tpv_offset, tpv_pos );
-#if 0
- f32 t; v3f n;
- if( spherecast_world( world_current_instance(), tpv_origin, tpv_pos,
- 0.2f, &t, n ) != -1 ){
- v3_lerp( tpv_origin, tpv_pos, t, tpv_pos );
- }
-#endif
/*
* Blend cameras
*/
- v3_lerp( tpv_pos, fpv_pos, cc->camera_type_blend, player->cam.pos );
- v3_copy( player->angles, player->cam.angles );
+ v3_lerp( tpv_pos, fpv_pos, cc->camera_type_blend, localplayer.cam.pos );
+ v3_copy( localplayer.angles, localplayer.cam.angles );
/* Camera shake */
- f32 speed = v3_length(player->rb.v),
+ f32 speed = v3_length(localplayer.rb.v),
strength = k_cam_shake_strength * speed;
- player->cam_trackshake += speed*k_cam_shake_trackspeed*vg.time_frame_delta;
+ localplayer.cam_trackshake +=
+ speed*k_cam_shake_trackspeed*vg.time_frame_delta;
- v2f rnd = {perlin1d( player->cam_trackshake, 1.0f, 4, 20 ),
- perlin1d( player->cam_trackshake, 1.0f, 4, 63 ) };
- v2_muladds( player->cam.angles, rnd, strength, player->cam.angles );
+ v2f rnd = {perlin1d( localplayer.cam_trackshake, 1.0f, 4, 20 ),
+ perlin1d( localplayer.cam_trackshake, 1.0f, 4, 63 ) };
+ v2_muladds( localplayer.cam.angles, rnd, strength, localplayer.cam.angles );
v3f Fd, Fs, F;
- v3_muls( player->cam_land_punch_v, -k_cam_damp, Fd );
- v3_muls( player->cam_land_punch, -k_cam_spring, Fs );
- v3_muladds( player->cam_land_punch, player->cam_land_punch_v,
- vg.time_frame_delta, player->cam_land_punch );
+ v3_muls( localplayer.cam_land_punch_v, -k_cam_damp, Fd );
+ v3_muls( localplayer.cam_land_punch, -k_cam_spring, Fs );
+ v3_muladds( localplayer.cam_land_punch, localplayer.cam_land_punch_v,
+ vg.time_frame_delta, localplayer.cam_land_punch );
v3_add( Fd, Fs, F );
- v3_muladds( player->cam_land_punch_v, F, vg.time_frame_delta,
- player->cam_land_punch_v );
- v3_add( player->cam_land_punch, player->cam.pos, player->cam.pos );
+ v3_muladds( localplayer.cam_land_punch_v, F, vg.time_frame_delta,
+ localplayer.cam_land_punch_v );
+ v3_add( localplayer.cam_land_punch, localplayer.cam.pos,
+ localplayer.cam.pos );
if( k_cinema >= 0.0001f ){
ent_camera *cam = NULL;
f32 min_dist = k_cinema;
- world_instance *world = player->viewable_world;
+ world_instance *world = localplayer.viewable_world;
for( u32 i=0; i<mdl_arrcount(&world->ent_camera); i++ ){
ent_camera *c = mdl_arritm(&world->ent_camera,i);
- f32 dist = v3_dist( c->transform.co, player->rb.co );
+ f32 dist = v3_dist( c->transform.co, localplayer.rb.co );
if( dist < min_dist ){
min_dist = dist;
}
if( cam ){
- player->cam.fov = cam->fov;
- v3_copy( cam->transform.co, player->cam.pos );
+ localplayer.cam.fov = cam->fov;
+ v3_copy( cam->transform.co, localplayer.cam.pos );
v3f v0;
if( k_cinema_fixed )
mdl_transform_vector( &cam->transform, (v3f){0.0f,-1.0f,0.0f}, v0 );
- else v3_sub( player->rb.co, cam->transform.co, v0 );
- m3x3_mulv( player->invbasis, v0, v0 );
- player_vector_angles( player->cam.angles, v0, 1.0f, 0.0f );
+ else v3_sub( localplayer.rb.co, cam->transform.co, v0 );
+ m3x3_mulv( localplayer.invbasis, v0, v0 );
+ player_vector_angles( localplayer.cam.angles, v0, 1.0f, 0.0f );
}
}
/* portal transitions */
- player_camera_portal_correction( player );
+ player_camera_portal_correction();
}
-VG_STATIC void player_look( v3f angles, float speed ){
+static void player_look( v3f angles, float speed ){
if( vg_ui.wants_mouse ) return;
angles[2] = 0.0f;