4a5958e3cc6ad3b12be4e7fc70e22701e6a09b3b
[carveJwlIkooP6JGAAIwe30JlM.git] / player_glide.c
1 #include "player_glide.h"
2 #include "vg/vg_rigidbody.h"
3 #include "scene_rigidbody.h"
4 #include "shaders/model_board_view.h"
5 #include "shaders/model_entity.h"
6 #include "input.h"
7 #include "skaterift.h"
8
9 #include "player_dead.h"
10 #include "player_skate.h"
11
12 trail_system trails_glider[] = {
13 {
14 .width = 0.035f,
15 .lifetime = 5.0f,
16 .min_dist = 0.5f
17 },
18 {
19 .width = 0.035f,
20 .lifetime = 5.0f,
21 .min_dist = 0.5f
22 },
23 };
24
25 struct player_glide player_glide =
26 {
27 .parts = {
28 {
29 .co = { 1.0f, 0.5f, -1.0f },
30 .euler = { VG_TAUf*0.25f, VG_TAUf*0.125f, 0.0f },
31 .shape = k_rb_shape_capsule,
32 .inf = { .h = 2.82842712475f, .r = 0.25f },
33 },
34 {
35 .co = { -1.0f, 0.5f, -1.0f },
36 .euler = { VG_TAUf*0.25f, -VG_TAUf*0.125f, 0.0f },
37 .shape = k_rb_shape_capsule,
38 .inf = { .h = 2.82842712475f, .r = 0.25f },
39 },
40 {
41 .co = { 0.0f, 0.5f, 1.0f },
42 .euler = { VG_TAUf*0.25f, VG_TAUf*0.25f, 0.0f },
43 .shape = k_rb_shape_capsule,
44 .inf = { .h = 6.0f, .r = 0.25f },
45 },
46 {
47 .co = { 0.0f, -0.5f, 0.0f },
48 .euler = { VG_TAUf*0.25f, VG_TAUf*0.25f, 0.0f },
49 .shape = k_rb_shape_capsule,
50 .inf = { .h = 2.0f, .r = 0.25f },
51 .is_damage = 1,
52 },
53 }
54 };
55
56 struct player_subsystem_interface player_subsystem_glide =
57 {
58 .pre_update = player_glide_pre_update,
59 .update = player_glide_update,
60 .post_update = player_glide_post_update,
61 .animate = player_glide_animate,
62 .pose = player_glide_pose,
63 .post_animate = player_glide_post_animate,
64 .network_animator_exchange = player_glide_animator_exchange,
65 .im_gui = player_glide_im_gui,
66 .bind = player_glide_bind,
67
68 .animator_data = &player_glide.animator,
69 .animator_size = sizeof(player_glide.animator),
70 .name = "Glide"
71 };
72
73 static f32 k_glide_steer = 2.0f,
74 k_glide_cl = 0.04f,
75 k_glide_cs = 0.02f,
76 k_glide_drag = 0.0001f,
77 k_glide_slip_yaw = 0.1f,
78 k_glide_lift_pitch = 0.0f,
79 k_glide_wing_orient = -0.1f,
80 k_glide_balance = 1.0f;
81
82 static i32 k_glide_pause = 0;
83
84 void player_glide_pre_update(void)
85 {
86 if( button_down(k_srbind_use) ){
87 localplayer.subsystem = k_player_subsystem_skate;
88 localplayer.glider_orphan = 1;
89
90 player_skate.state.activity = k_skate_activity_air;
91 player_skate.state.activity_prev = k_skate_activity_air;
92
93 q_mulv( localplayer.rb.q, (v3f){0.0f,1.0f,0.0f}, player_skate.state.cog );
94 v3_add( player_skate.state.cog, localplayer.rb.co,
95 player_skate.state.cog );
96 v3_copy( localplayer.rb.v, player_skate.state.cog_v );
97
98 player__begin_holdout( (v3f){0.0f,0.0f,0.0f} );
99 player__skate_reset_animator();
100 player__skate_clear_mechanics();
101 v3_copy( (v3f){0.0f,0.0f,0.0f}, player_skate.state.trick_euler );
102
103 player__approximate_best_trajectory();
104 }
105 }
106
107 static void massless_accel( rigidbody *rb, v3f delta, v3f impulse ){
108 /* linear */
109 v3_muladds( rb->v, impulse, vg.time_fixed_delta, rb->v );
110
111 /* Angular velocity */
112 v3f wa;
113 v3_cross( delta, impulse, wa );
114 v3_muladds( rb->w, wa, vg.time_fixed_delta, rb->w );
115 }
116
117 static void calculate_lift( v3f vl, f32 aoa_bias,
118 v3f axis, v3f back, f32 power,
119 v3f out_force ){
120 v3f up;
121 v3_cross( back, axis, up );
122
123 v3f wind;
124 v3_muladds( vl, axis, -v3_dot(axis,vl), wind );
125
126 f32 windv2 = v3_length2(wind),
127 aoa = atan2f( v3_dot( up, wind ), v3_dot( back, wind ) ) + aoa_bias,
128 cl = aoa / VG_PIf,
129 L = windv2 * cl * power;
130
131 v3f lift_dir;
132 v3_normalize( wind );
133 v3_cross( wind, axis, lift_dir );
134
135 /* this is where induced drag (from the flappy things) would go */
136
137 v3_muls( lift_dir, L, out_force );
138 }
139
140 static void calculate_drag( v3f vl, f32 cd, v3f out_force ){
141 f32 v2 = v3_length2( vl );
142 v3f dir;
143 v3_copy( vl, dir );
144 v3_normalize( dir );
145 v3_muls( vl, -cd*v2, out_force );
146 }
147
148 /*
149 * Returns true if the bottom sphere is hit
150 */
151 bool glider_physics( v2f steer )
152 {
153 rigidbody *rb = &player_glide.rb;
154
155 /* lift */
156 v3f vl, wl;
157 m3x3_mulv( rb->to_local, rb->v, vl );
158 m3x3_mulv( rb->to_local, rb->w, wl );
159
160 v3f F, Flift, Fslip, Fdrag, FslipW, FliftW;
161
162 calculate_lift( vl, steer[1]*k_glide_steer,
163 (v3f){1,0,0},
164 (v3f){0,sinf(k_glide_wing_orient),cosf(k_glide_wing_orient)},
165 k_glide_cl, Flift );
166 v3_copy( Flift, player_glide.info_lift );
167 v3_cross( (v3f){0,0,0}, Flift, FliftW );
168
169 calculate_lift( vl, 0.0f,
170 (v3f){0,1,0},(v3f){0,0,1},
171 k_glide_cs, Fslip );
172 v3_copy( Fslip, player_glide.info_slip );
173 v3_cross( (v3f){0,k_glide_lift_pitch,k_glide_slip_yaw}, Fslip, FslipW );
174
175 calculate_drag( vl, k_glide_drag, Fdrag );
176 v3_copy( Fdrag, player_glide.info_drag );
177
178 v3f balance = {0.0f,-k_glide_balance,0.0f};
179 m3x3_mulv( rb->to_local, balance, balance );
180
181 v3f Fw = {
182 steer[1]*k_glide_steer - balance[2],
183 0.0f,
184 -steer[0]*k_glide_steer + balance[0],
185 };
186
187 if( player_glide.ticker ){
188 player_glide.ticker --;
189 return 0;
190 }
191 player_glide.ticker += k_glide_pause;
192
193 /* apply forces */
194 v3_add( Flift, Fslip, F );
195 v3_add( F, Fdrag, F );
196
197 m3x3_mulv( rb->to_world, F, F );
198 v3_muladds( rb->v, F, vg.time_fixed_delta, rb->v );
199
200 v3_add( Fw, FslipW, Fw );
201 v3_add( Fw, FliftW, Fw );
202 m3x3_mulv( rb->to_world, Fw, Fw );
203 v3_muladds( rb->w, Fw, vg.time_fixed_delta, rb->w );
204
205
206 /*
207 * collisions & constraints
208 */
209 world_instance *world = world_current_instance();
210 rb_solver_reset();
211
212 bool bottom_hit = 0;
213
214 rigidbody _null = {0};
215 _null.inv_mass = 0.0f;
216 m3x3_zero( _null.iI );
217 for( u32 i=0; i < vg_list_size(player_glide.parts); i ++ ){
218 m4x3f mmdl;
219 m4x3_mul( rb->to_world, player_glide.parts[i].mdl, mmdl );
220
221 if( player_glide.parts[i].shape == k_rb_shape_capsule ){
222 vg_line_capsule( mmdl,
223 player_glide.parts[i].inf.r,
224 player_glide.parts[i].inf.h,
225 VG__BLACK );
226 }
227 else if( player_glide.parts[i].shape == k_rb_shape_sphere ){
228 vg_line_sphere( mmdl, player_glide.parts[i].r, 0 );
229 }
230
231 if( rb_global_has_space() ){
232 rb_ct *buf = rb_global_buffer();
233
234 u32 l = 0;
235
236 if( player_glide.parts[i].shape == k_rb_shape_capsule ){
237 l = rb_capsule__scene( mmdl, &player_glide.parts[i].inf,
238 NULL, world->geo_bh, buf,
239 k_material_flag_ghosts );
240 }
241 else if( player_glide.parts[i].shape == k_rb_shape_sphere ){
242 l = rb_sphere__scene( mmdl, player_glide.parts[i].r,
243 NULL, world->geo_bh, buf,
244 k_material_flag_ghosts );
245 }
246
247 if( player_glide.parts[i].is_damage && l ){
248 bottom_hit = 1;
249 }
250
251 for( u32 j=0; j<l; j ++ ){
252 buf[j].rba = rb;
253 buf[j].rbb = &_null;
254 }
255
256 rb_contact_count += l;
257 }
258 }
259
260 rb_presolve_contacts( rb_contact_buffer,
261 vg.time_fixed_delta, rb_contact_count );
262 for( u32 i=0; i<10; i ++ )
263 rb_solve_contacts( rb_contact_buffer, rb_contact_count );
264
265 rb_iter( rb );
266 rb_update_matrices( rb );
267
268 return bottom_hit;
269 }
270
271 void player_glide_update(void)
272 {
273 v2f steer;
274 joystick_state( k_srjoystick_steer, steer );
275
276 if( glider_physics( steer ) ){
277 vg_info( "player fell off due to glider hitting ground\n" );
278 player__dead_transition( k_player_die_type_generic );
279 localplayer.glider_orphan = 1;
280 }
281 }
282
283 void player_glide_post_update(void)
284 {
285 v3_copy( player_glide.rb.co, localplayer.rb.co );
286 v4_copy( player_glide.rb.q, localplayer.rb.q );
287 v3_copy( player_glide.rb.v, localplayer.rb.v );
288 v3_copy( player_glide.rb.w, localplayer.rb.w );
289 rb_update_matrices( &localplayer.rb );
290 }
291
292 void player_glide_animate(void)
293 {
294 struct player_glide *g = &player_glide;
295 struct player_glide_animator *animator = &g->animator;
296 rb_extrapolate( &localplayer.rb, animator->root_co, animator->root_q );
297 }
298
299 void player_glide_pose( void *_animator, player_pose *pose )
300 {
301 struct skeleton *sk = &localplayer.skeleton;
302 struct player_glide_animator *animator = _animator;
303 pose->type = k_player_pose_type_ik;
304 pose->board.lean = 0.0f;
305
306 skeleton_sample_anim( sk, player_glide.anim_glide, 0.0f, pose->keyframes );
307
308 v3f temp;
309 q_mulv( animator->root_q, (v3f){0,-0.5f,0}, temp );
310 v3_add( animator->root_co, temp, pose->root_co );
311
312 v4_copy( animator->root_q, pose->root_q );
313 }
314
315 void player_glide_post_animate(void)
316 {
317 if( localplayer.cam_control.camera_mode == k_cam_firstperson )
318 localplayer.cam_velocity_influence = 0.0f;
319 else
320 localplayer.cam_velocity_influence = 0.0f;
321
322 v3f fwd;
323 v3_muls( localplayer.rb.to_world[2], -1.0f, fwd );
324 v3_angles( fwd, localplayer.angles );
325
326 localplayer.cam_dist = 2.0f + v3_length( localplayer.rb.v )*0.2f;
327 }
328
329 void player_glide_animator_exchange( bitpack_ctx *ctx, void *data )
330 {
331 struct player_glide_animator *animator = data;
332
333 bitpack_qv3f( ctx, 24, -1024.0f, 1024.0f, animator->root_co );
334 bitpack_qquat( ctx, animator->root_q );
335 }
336
337 void player_glide_remote_animator_exchange( bitpack_ctx *ctx, void *data )
338 {
339 struct remote_glider_animator *animator = data;
340
341 bitpack_qv3f( ctx, 24, -1024.0f, 1024.0f, animator->root_co );
342 bitpack_qf32( ctx, 8, 0.0f, 1.0f, &animator->s );
343 bitpack_qquat( ctx, animator->root_q );
344 }
345
346 void player_glide_im_gui(void)
347 {
348 player__debugtext( 1, "Nothing here" );
349 player__debugtext( 1, " lift: %.2f %.2f %.2f",
350 player_glide.info_lift[0],
351 player_glide.info_lift[1],
352 player_glide.info_lift[2] );
353 player__debugtext( 1, " slip: %.2f %.2f %.2f",
354 player_glide.info_slip[0],
355 player_glide.info_slip[1],
356 player_glide.info_slip[2] );
357 player__debugtext( 1, " drag: %.2f %.2f %.2f",
358 player_glide.info_drag[0],
359 player_glide.info_drag[1],
360 player_glide.info_drag[2] );
361 }
362
363 void player_glide_equip_glider(void)
364 {
365 if( !localplayer.have_glider ){
366 localplayer.have_glider = 1;
367 localplayer.glider_orphan = 0;
368 player_glide.t = -1.0f;
369 }
370 }
371
372 static int ccmd_player_glider_spawn( int argc, const char *argv[] ){
373 if( vg_console.cheats ){
374 player_glide_equip_glider();
375 }
376 else {
377 vg_error( "Can't spawn without cheats enabled.\n" );
378 }
379 return 0;
380 }
381
382 void player_glide_bind(void)
383 {
384 u32 mask = VG_VAR_CHEAT|VG_VAR_PERSISTENT;
385 VG_VAR_F32( k_glide_steer, flags=mask );
386 VG_VAR_F32( k_glide_cl, flags=mask );
387 VG_VAR_F32( k_glide_cs, flags=mask );
388 VG_VAR_F32( k_glide_drag, flags=mask );
389 VG_VAR_F32( k_glide_slip_yaw, flags=mask );
390 VG_VAR_F32( k_glide_lift_pitch, flags=mask );
391 VG_VAR_I32( k_glide_pause, flags=mask );
392 VG_VAR_F32( k_glide_balance, flags=mask );
393 VG_VAR_F32( k_glide_wing_orient, flags=mask );
394
395 vg_console_reg_cmd( "spawn_glider", ccmd_player_glider_spawn, NULL );
396
397 f32 mass = 0.0f,k_density = 8.0f;
398 m3x3f I;
399 m3x3_zero( I );
400
401 for( u32 i=0; i<vg_list_size(player_glide.parts); i ++ ){
402 /* create part transform matrix */
403 v4f qp, qy, qr, q;
404 q_axis_angle( qp, (v3f){1,0,0}, player_glide.parts[i].euler[0] );
405 q_axis_angle( qy, (v3f){0,1,0}, player_glide.parts[i].euler[1] );
406 q_axis_angle( qr, (v3f){0,0,1}, player_glide.parts[i].euler[2] );
407
408 q_mul( qr, qy, q );
409 q_mul( q, qp, q );
410
411 q_m3x3( q, player_glide.parts[i].mdl );
412 v3_copy( player_glide.parts[i].co, player_glide.parts[i].mdl[3] );
413
414 /* add it to inertia model */
415
416 if( player_glide.parts[i].shape == k_rb_shape_capsule ){
417 f32 r = player_glide.parts[i].inf.r,
418 h = player_glide.parts[i].inf.h,
419 pv = vg_capsule_volume( r, h ),
420 pm = pv * k_density;
421
422 mass += pm;
423
424 m3x3f pI;
425 vg_capsule_inertia( r, h, pm, pI );
426 vg_rotate_inertia( pI, player_glide.parts[i].mdl );
427 vg_translate_inertia( pI, pm, player_glide.parts[i].co );
428 m3x3_add( I, pI, I );
429 }
430 else if( player_glide.parts[i].shape == k_rb_shape_sphere ){
431 f32 r = player_glide.parts[i].r,
432 pv = vg_sphere_volume( r ),
433 pm = pv * k_density;
434
435 mass += pm;
436 m3x3f pI;
437 vg_sphere_inertia( r, pm, pI );
438 vg_translate_inertia( pI, pm, player_glide.parts[i].co );
439 m3x3_add( I, pI, I );
440 }
441 }
442
443 /* set inverses */
444 m3x3_inv( I, player_glide.rb.iI );
445 player_glide.rb.inv_mass = 1.0f / mass;
446
447 /* resources */
448 struct skeleton *sk = &localplayer.skeleton;
449 player_glide.anim_glide = skeleton_get_anim( sk, "glide_pose" );
450
451 void *alloc = vg_mem.rtmemory;
452 mdl_context *mdl = &player_glide.glider;
453
454 mdl_open( mdl, "models/glider.mdl", alloc );
455 mdl_load_metadata_block( mdl, alloc );
456 mdl_async_full_load_std( mdl );
457
458 /* load trail positions */
459 mdl_array_ptr markers;
460 MDL_LOAD_ARRAY( mdl, &markers, ent_marker, vg_mem.scratch );
461 mdl_close( mdl );
462
463 for( u32 i=0; i<mdl_arrcount( &markers ); i ++ )
464 {
465 ent_marker *marker = mdl_arritm( &markers, i );
466 v3_copy( marker->transform.co,
467 player_glide.trail_positions[ player_glide.trail_count ++ ] );
468
469 if( player_glide.trail_count == vg_list_size(trails_glider) )
470 break;
471 }
472
473 /* allocate effects */
474 for( u32 i=0; i<vg_list_size(trails_glider); i ++ )
475 {
476 trail_alloc( &trails_glider[i], 200 );
477 }
478 }
479
480 void player_glide_transition(void)
481 {
482 localplayer.subsystem = k_player_subsystem_glide;
483 localplayer.have_glider = 0;
484 world_static.challenge_target = NULL;
485 world_static.challenge_timer = 0.0f;
486 world_static.focused_entity = 0;
487 world_static.last_use = 0.0;
488 for( u32 i=0; i<vg_list_size(world_static.instances); i++ ){
489 world_instance *instance = &world_static.instances[i];
490 if( instance->status == k_world_status_loaded ){
491 world_routes_clear( instance );
492 }
493 }
494
495 v3_copy( localplayer.rb.co, player_glide.rb.co );
496
497 f32 dir = v3_dot( localplayer.rb.v, localplayer.rb.to_world[2] );
498
499 if( dir > 0.0f ){
500 v4f qyaw;
501 q_axis_angle( qyaw, (v3f){0,1,0}, VG_TAUf*0.5f );
502 q_mul( qyaw, localplayer.rb.q, player_glide.rb.q );
503 q_normalize( player_glide.rb.q );
504 }
505 else
506 v4_copy( localplayer.rb.q, player_glide.rb.q );
507
508 v3_copy( localplayer.rb.v, player_glide.rb.v );
509 v3_copy( localplayer.rb.w, player_glide.rb.w );
510 rb_update_matrices( &player_glide.rb );
511
512 player__begin_holdout( (v3f){0,0,0} );
513 }
514
515 void render_glider_model( vg_camera *cam, world_instance *world,
516 m4x3f mmdl, enum board_shader shader )
517 {
518 u32 current_mat = 0xffffffff;
519 glActiveTexture( GL_TEXTURE0 );
520
521 mdl_context *mdl = &player_glide.glider;
522 mesh_bind( &player_glide.glider.mesh );
523
524 for( u32 i=0; i<mdl_arrcount(&mdl->meshs); i ++ )
525 {
526 mdl_mesh *mesh = mdl_arritm( &mdl->meshs, i );
527
528 m4x3f mmmdl;
529 mdl_transform_m4x3( &mesh->transform, mmmdl );
530 m4x3_mul( mmdl, mmmdl, mmmdl );
531
532 if( shader == k_board_shader_player )
533 shader_model_board_view_uMdl( mmmdl );
534 else if( shader == k_board_shader_entity )
535 {
536 m4x4f m4mmmdl;
537 m4x3_expand( mmmdl, m4mmmdl );
538 m4x4_mul( cam->mtx_prev.pv, m4mmmdl, m4mmmdl );
539
540 shader_model_entity_uMdl( mmmdl );
541 shader_model_entity_uPvmPrev( m4mmmdl );
542 }
543
544 for( u32 j=0; j<mesh->submesh_count; j ++ )
545 {
546 mdl_submesh *sm = mdl_arritm( &mdl->submeshs, mesh->submesh_start+j );
547 if( !sm->material_id )
548 {
549 vg_error( "Invalid material ID 0\n" );
550 continue;
551 }
552
553 if( sm->material_id != current_mat )
554 {
555 mdl_material *mat = mdl_arritm( &mdl->materials,sm->material_id-1 );
556 GLuint tex = vg.tex_missing;
557
558 if( mat->shader == k_shader_standard )
559 {
560 struct shader_props_standard *props = mat->props.compiled;
561
562 u32 index = props->tex_diffuse-1;
563 mdl_texture *ptex = mdl_arritm( &mdl->textures, index );
564 tex = ptex->glname;
565 }
566
567 glBindTexture( GL_TEXTURE_2D, tex );
568 current_mat = sm->material_id;
569 }
570
571 mdl_draw_submesh( sm );
572 }
573 }
574 }
575
576 /*
577 * TODO: more flexible way to call
578 * - this depends on the current state, but we need to pass a struct in
579 * that can hold that information instead so we can save it into
580 * the replay
581 */
582 void player_glide_render( vg_camera *cam, world_instance *world,
583 player_pose *pose )
584 {
585 if( !((localplayer.subsystem == k_player_subsystem_glide) ||
586 (localplayer.observing_system == k_player_subsystem_glide) ||
587 localplayer.have_glider ||
588 localplayer.glider_orphan) )
589 return;
590
591 shader_model_board_view_use();
592 shader_model_board_view_uTexMain( 0 );
593 shader_model_board_view_uCamera( cam->transform[3] );
594 shader_model_board_view_uPv( cam->mtx.pv );
595 shader_model_board_view_uDepthMode(1);
596 depth_compare_bind(
597 shader_model_board_view_uTexSceneDepth,
598 shader_model_board_view_uInverseRatioDepth,
599 shader_model_board_view_uInverseRatioMain,
600 cam );
601
602 WORLD_BIND_LIGHT_BUFFERS_UB0_TEX234( world, model_board_view );
603
604 mdl_keyframe kf_res;
605 if( localplayer.glider_orphan ){
606 rb_extrapolate( &player_glide.rb, kf_res.co, kf_res.q );
607 v3_fill( kf_res.s, 1.0f );
608
609 v3f temp;
610 q_mulv( kf_res.q, (v3f){0,-0.5f,0}, temp );
611 v3_add( temp, kf_res.co, kf_res.co );
612 }
613 else {
614 f32 target;
615 if( localplayer.subsystem == k_player_subsystem_glide ) target = 1.0f;
616 else target = 0.0f;
617
618 /* TODO: TEMP */
619 if( skaterift.activity != k_skaterift_replay )
620 vg_slewf( &player_glide.t, target, vg.time_frame_delta * 4.0f );
621
622 mdl_keyframe kf_backpack;
623
624 struct skeleton *sk = &localplayer.skeleton;
625 m4x3_mulv( localplayer.final_mtx[localplayer.id_chest ],
626 sk->bones[localplayer.id_chest].co,
627 kf_backpack.co );
628
629 v4f qyaw, qpitch, qchest, q;
630 q_axis_angle( qyaw, (v3f){0,1,0}, VG_TAUf*0.25f );
631 q_axis_angle( qpitch, (v3f){1,0,0}, VG_TAUf*0.25f );
632 m3x3_q( localplayer.final_mtx[ localplayer.id_chest ], qchest );
633
634 q_mul( qyaw, qpitch, q );
635 q_mul( qchest, q, kf_backpack.q );
636 q_normalize( kf_backpack.q );
637
638 f32 scale;
639 if( player_glide.t <= 0.0f ){
640 f32 st = player_glide.t + 1.0f,
641 sst = vg_smoothstepf(st),
642 isst= 1.0f - sst;
643 scale = vg_lerpf( 0.0f, 0.2f, sst );
644
645 v4f qspin;
646 q_axis_angle( qspin, (v3f){0,0,1}, VG_TAUf * isst * 0.5f );
647 q_mul( kf_backpack.q, qspin, kf_backpack.q );
648 kf_backpack.co[1] += isst * 1.0f;
649 v3_muladds( kf_backpack.co,
650 localplayer.final_mtx[ localplayer.id_chest ][0],
651 isst * 0.25f,
652 kf_backpack.co );
653 }
654 else{
655 scale = vg_lerpf( 0.2f, 1.0f, vg_smoothstepf(player_glide.t) );
656 }
657
658
659 v3_fill( kf_backpack.s, scale );
660
661 v3_copy( pose->root_co, kf_res.co );
662 v4_copy( pose->root_q, kf_res.q );
663 v3_fill( kf_res.s, scale );
664
665 f32 blend = vg_smoothstepf( vg_maxf( 0, player_glide.t ) );
666 keyframe_lerp( &kf_backpack, &kf_res, blend, &kf_res );
667 }
668
669 m4x3f mmdl;
670 q_m3x3( kf_res.q, mmdl );
671 m3x3_scale( mmdl, kf_res.s );
672 v3_copy( kf_res.co, mmdl[3] );
673
674 render_glider_model( cam, world, mmdl, k_board_shader_player );
675
676 /* totally FUCKED */
677 v4_copy( kf_res.q, player_glide.remote_animator.root_q );
678 v3_copy( kf_res.co, player_glide.remote_animator.root_co );
679 player_glide.remote_animator.s = kf_res.s[0];
680 }
681
682 void player_glide_render_effects( vg_camera *cam )
683 {
684 v3f co, temp;
685 v4f q;
686 rb_extrapolate( &player_glide.rb, co, q );
687 q_mulv( q, (v3f){0,-0.5f,0}, temp );
688 v3_add( temp, co, co );
689
690 f32 alpha = vg_maxf( (fabsf(player_glide.info_lift[2])-1.0f), 0.0f ) /18.0f;
691
692 for( u32 i=0; i<player_glide.trail_count; i ++ ){
693 v3f vvert;
694 q_mulv( q, player_glide.trail_positions[i], vvert );
695 v3_add( co, vvert, vvert );
696
697 trail_system_update( &trails_glider[i], vg.time_delta, vvert,
698 localplayer.rb.to_world[1], alpha );
699
700 trail_system_prerender( &trails_glider[i] );
701 trail_system_render( &trails_glider[i], &skaterift.cam );
702 }
703 }