2 * Copyright (C) 2021-2022 Mt.ZERO Software, Harry Godden - All Rights Reserved
15 k_walkspeed
= 7.0f
, /* no longer used */
17 k_board_radius
= 0.3f
,
18 k_board_length
= 0.45f
,
19 k_board_allowance
= 0.04f
,
20 k_friction_lat
= 8.8f
,
21 k_friction_resistance
= 0.01f
,
22 k_max_push_speed
= 16.0f
,
24 k_push_cycle_rate
= 8.0f
,
25 k_steer_ground
= 2.5f
,
27 k_steer_air_lerp
= 0.3f
,
30 k_jump_charge_speed
= (1.0f
/1.0f
),
35 k_walk_friction
= 8.0f
;
37 static int freecam
= 0;
38 static int walk_grid_iterations
= 1;
39 static float fc_speed
= 10.0f
;
42 * -----------------------------------------------------------------------------
44 * -----------------------------------------------------------------------------
50 rigidbody collide_front
, collide_back
;
54 rigidbody rb
, rb_gate_frame
;
55 float iY
, siY
; /* Yaw inertia */
57 v3f a
, v_last
, m
, bob
, vl
;
60 float vswitch
, slip
, slip_last
,
64 int in_air
, on_board
, jump_charge
, jump_dir
;
71 float pushing
, push_time
;
75 v3f land_target_log
[22];
76 u32 land_target_colours
[22];
79 v3f handl_target
, handr_target
,
85 v3f camera_pos
, smooth_localcam
;
87 m4x3f camera
, camera_inverse
;
109 struct skeleton_anim
*anim_stand
,
113 *anim_push
, *anim_push_reverse
,
114 *anim_ollie
, *anim_ollie_reverse
,
115 *anim_grabs
, *anim_stop
,
116 *anim_walk
, *anim_run
, *anim_idle
;
147 .collide_front
= { .type
= k_rb_shape_sphere
, .inf
.sphere
.radius
= 0.3f
},
148 .collide_back
= { .type
= k_rb_shape_sphere
, .inf
.sphere
.radius
= 0.3f
}
154 static float *player_get_pos(void);
155 static void player_kill(void);
156 static float *player_cam_pos(void);
157 static void player_save_frame(void);
158 static void player_restore_frame(void);
163 #include "player_physics.h"
164 #include "player_ragdoll.h"
165 #include "player_model.h"
166 #include "player_animation.h"
167 #include "player_audio.h"
170 * -----------------------------------------------------------------------------
172 * -----------------------------------------------------------------------------
175 static void player_init(void) /* 1 */
177 rb_init( &player
.phys
.rb
);
178 rb_init( &player
.collide_front
);
179 rb_init( &player
.collide_back
);
181 vg_convar_push( (struct vg_convar
){
182 .name
= "walk_speed",
183 .data
= &k_walkspeed
,
184 .data_type
= k_convar_dtype_f32
,
185 .opt_f32
= { .clamp
= 0 },
189 vg_convar_push( (struct vg_convar
){
192 .data_type
= k_convar_dtype_f32
,
193 .opt_f32
= { .clamp
= 0 },
197 vg_convar_push( (struct vg_convar
){
198 .name
= "walk_accel",
199 .data
= &k_walk_accel
,
200 .data_type
= k_convar_dtype_f32
,
201 .opt_f32
= { .clamp
= 0 },
205 vg_convar_push( (struct vg_convar
){
208 .data_type
= k_convar_dtype_i32
,
209 .opt_i32
= { .min
=0, .max
=1, .clamp
=1 },
213 vg_convar_push( (struct vg_convar
){
216 .data_type
= k_convar_dtype_f32
,
217 .opt_f32
= { .clamp
= 0 },
221 vg_function_push( (struct vg_cmd
){
223 .function
= reset_player
227 vg_loader_highwater( player_model_init
, player_model_free
, NULL
);
230 static void player_update(void) /* 2 */
232 struct player_phys
*phys
= &player
.phys
;
234 for( int i
=0; i
<player
.land_log_count
; i
++ )
235 vg_line_cross( player
.land_target_log
[i
],
236 player
.land_target_colours
[i
], 0.25f
);
238 if( vg_get_axis("grabl")>0.0f
)
241 player_restore_frame();
243 if( !phys
->on_board
)
245 player
.angles
[0] = atan2f( -phys
->rb
.forward
[2],
246 -phys
->rb
.forward
[0] );
249 player
.mdl
.shoes
[0] = 1;
250 player
.mdl
.shoes
[1] = 1;
252 world_routes_notify_reset();
255 if( vg_get_button_down( "switchmode" ) )
257 phys
->on_board
^= 0x1;
261 if( (glfwGetKey( vg_window
, GLFW_KEY_O
) ))
263 player_ragdoll_copy_model( phys
->rb
.v
);
270 player_ragdoll_iter();
271 player_debug_ragdoll();
274 player_animate_death_cam();
282 player_animate_camera();
288 player_camera_update();
292 static void draw_player(void) /* 3 */
295 player_model_copy_ragdoll();
297 shader_viewchar_use();
298 vg_tex2d_bind( &tex_characters
, 0 );
299 shader_viewchar_uTexMain( 0 );
300 shader_viewchar_uCamera( player
.camera
[3] );
301 shader_viewchar_uPv( vg_pv
);
302 shader_link_standard_ub( _shader_viewchar
.id
, 2 );
303 glUniformMatrix4x3fv( _uniform_viewchar_uTransforms
,
304 player
.mdl
.sk
.bone_count
,
306 (float *)player
.mdl
.sk
.final_mtx
);
308 mesh_bind( &player
.mdl
.mesh
);
309 mesh_draw( &player
.mdl
.mesh
);
313 * -----------------------------------------------------------------------------
315 * -----------------------------------------------------------------------------
318 static float *player_get_pos(void)
320 return player
.phys
.rb
.co
;
323 static void player_kill(void)
326 player_ragdoll_copy_model( player
.phys
.rb
.v
);
329 static float *player_cam_pos(void)
331 return player
.camera_pos
;
335 #endif /* PLAYER_H */