ebcb55e32a3de4bacb70e7bdbbddf380e12c8edf
2 * Copyright 2021-2022 (C) Mount0 Software, Harry Godden - All Rights Reserved
3 * -----------------------------------------------------------------------------
5 * Player physics and control submodule
6 * contains main physics models, input, and player control.
8 * -----------------------------------------------------------------------------
11 #ifndef PLAYER_PHYSICS_H
12 #define PLAYER_PHYSICS_H
16 static void apply_gravity( v3f vel
, float const timestep
)
18 v3f gravity
= { 0.0f
, -9.6f
, 0.0f
};
19 v3_muladds( vel
, gravity
, timestep
, vel
);
23 * Called when launching into the air to predict and adjust trajectories
25 static void player_start_air(void)
27 struct player_phys
*phys
= &player
.phys
;
34 float pstep
= ktimestep
*10.0f
;
35 float best_velocity_delta
= -9999.9f
;
39 v3_cross( phys
->rb
.up
, phys
->rb
.v
, axis
);
41 player
.land_log_count
= 0;
43 m3x3_identity( phys
->vr
);
45 for( int m
=-3;m
<=12; m
++ )
47 float vmod
= ((float)m
/ 15.0f
)*0.09f
;
50 v3_copy( phys
->rb
.co
, pco
);
51 v3_muls( phys
->rb
.v
, k_bias
, pv
);
54 * Try different 'rotations' of the velocity to find the best possible
55 * landing normal. This conserves magnitude at the expense of slightly
62 q_axis_angle( vr_q
, axis
, vmod
);
65 m3x3_mulv( vr
, pv
, pv
);
66 v3_muladds( pco
, pv
, pstep
, pco
);
68 for( int i
=0; i
<50; i
++ )
71 apply_gravity( pv
, pstep
);
73 m3x3_mulv( vr
, pv
, pv
);
74 v3_muladds( pco
, pv
, pstep
, pco
);
79 v3_sub( pco
, pco1
, vdir
);
80 contact
.dist
= v3_length( vdir
);
81 v3_divs( vdir
, contact
.dist
, vdir
);
83 if( ray_world( pco1
, vdir
, &contact
))
85 float land_delta
= v3_dot( pv
, contact
.normal
);
86 u32 scolour
= (u8
)(vg_minf(-land_delta
* 2.0f
, 255.0f
));
88 /* Bias prediction towords ramps */
89 if( ray_hit_is_ramp( &contact
) )
92 scolour
|= 0x0000a000;
95 if( (land_delta
< 0.0f
) && (land_delta
> best_velocity_delta
) )
97 best_velocity_delta
= land_delta
;
99 v3_copy( contact
.pos
, player
.land_target
);
101 m3x3_copy( vr
, phys
->vr_pstep
);
102 q_axis_angle( vr_q
, axis
, vmod
*0.1f
);
103 q_m3x3( vr_q
, phys
->vr
);
106 v3_copy( contact
.pos
,
107 player
.land_target_log
[player
.land_log_count
] );
108 player
.land_target_colours
[player
.land_log_count
] =
109 0xff000000 | scolour
;
111 player
.land_log_count
++;
120 * Main friction interface model
122 static void player_physics_control(void)
124 struct player_phys
*phys
= &player
.phys
;
127 * Computing localized friction forces for controlling the character
128 * Friction across X is significantly more than Z
132 m3x3_mulv( phys
->rb
.to_local
, phys
->rb
.v
, vel
);
135 if( fabsf(vel
[2]) > 0.01f
)
136 slip
= fabsf(-vel
[0] / vel
[2]) * vg_signf(vel
[0]);
138 if( fabsf( slip
) > 1.2f
)
139 slip
= vg_signf( slip
) * 1.2f
;
141 phys
->reverse
= -vg_signf(vel
[2]);
143 float substep
= ktimestep
* 0.2f
;
144 float fwd_resistance
= (vg_get_button( "break" )? 5.0f
: 0.02f
) * -substep
;
146 for( int i
=0; i
<5; i
++ )
148 vel
[2] = stable_force( vel
[2], vg_signf( vel
[2] ) * fwd_resistance
);
149 vel
[0] = stable_force( vel
[0],
150 vg_signf( vel
[0] ) * -k_friction_lat
*substep
);
153 static double start_push
= 0.0;
154 if( vg_get_button_down( "push" ) )
155 start_push
= vg_time
;
157 if( vg_get_button( "jump" ) )
159 phys
->jump
+= ktimestep
* k_jump_charge_speed
;
161 if( !phys
->jump_charge
)
162 phys
->jump_dir
= phys
->reverse
> 0.0f
? 1: 0;
164 phys
->jump_charge
= 1;
167 if( !vg_get_button("break") && vg_get_button( "push" ) )
169 player
.pushing
= 1.0f
;
170 player
.push_time
= vg_time
-start_push
;
172 float cycle_time
= player
.push_time
*k_push_cycle_rate
,
173 amt
= k_push_accel
* (sinf(cycle_time
)*0.5f
+0.5f
)*ktimestep
,
174 current
= v3_length( vel
),
175 new_vel
= vg_minf( current
+ amt
, k_max_push_speed
);
177 new_vel
-= vg_minf(current
, k_max_push_speed
);
178 vel
[2] -= new_vel
* phys
->reverse
;
182 static float previous
= 0.0f
;
183 float delta
= previous
- phys
->grab
,
184 pump
= delta
* k_pump_force
*ktimestep
;
185 previous
= phys
->grab
;
188 v3_muladds( phys
->rb
.co
, phys
->rb
.up
, pump
, p1
);
189 vg_line( phys
->rb
.co
, p1
, 0xff0000ff );
194 m3x3_mulv( phys
->rb
.to_world
, vel
, phys
->rb
.v
);
196 float steer
= vg_get_axis( "horizontal" );
197 phys
->iY
-= vg_signf(steer
)*powf(steer
,2.0f
) * k_steer_ground
* ktimestep
;
201 * Air control, no real physics
203 static void player_physics_control_air(void)
205 struct player_phys
*phys
= &player
.phys
;
207 m3x3_mulv( phys
->vr
, phys
->rb
.v
, phys
->rb
.v
);
208 vg_line_cross( player
.land_target
, 0xff0000ff, 0.25f
);
215 float pstep
= ktimestep
*10.0f
;
218 v3_copy( phys
->rb
.co
, pco
);
219 v3_copy( phys
->rb
.v
, pv
);
221 float time_to_impact
= 0.0f
;
222 float limiter
= 1.0f
;
224 for( int i
=0; i
<50; i
++ )
226 v3_copy( pco
, pco1
);
227 m3x3_mulv( phys
->vr_pstep
, pv
, pv
);
228 apply_gravity( pv
, pstep
);
229 v3_muladds( pco
, pv
, pstep
, pco
);
234 v3_sub( pco
, pco1
, vdir
);
235 contact
.dist
= v3_length( vdir
);
236 v3_divs( vdir
, contact
.dist
, vdir
);
238 float orig_dist
= contact
.dist
;
239 if( ray_world( pco1
, vdir
, &contact
))
241 float angle
= v3_dot( phys
->rb
.up
, contact
.normal
);
243 v3_cross( phys
->rb
.up
, contact
.normal
, axis
);
245 time_to_impact
+= (contact
.dist
/orig_dist
)*pstep
;
246 limiter
= vg_minf( 5.0f
, time_to_impact
)/5.0f
;
247 limiter
= 1.0f
-limiter
;
249 limiter
= 1.0f
-limiter
;
254 q_axis_angle( correction
, axis
, acosf(angle
)*0.05f
*(1.0f
-limiter
) );
255 q_mul( correction
, phys
->rb
.q
, phys
->rb
.q
);
258 vg_line_cross( contact
.pos
, 0xffff0000, 0.25f
);
261 time_to_impact
+= pstep
;
264 phys
->iY
-= vg_get_axis( "horizontal" ) * k_steer_air
* ktimestep
;
266 float iX
= vg_get_axis( "vertical" ) *
267 phys
->reverse
* k_steer_air
* limiter
* ktimestep
;
269 static float siX
= 0.0f
;
270 siX
= vg_lerpf( siX
, iX
, k_steer_air_lerp
);
273 q_axis_angle( rotate
, phys
->rb
.right
, siX
);
274 q_mul( rotate
, phys
->rb
.q
, phys
->rb
.q
);
277 v2f target
= {0.0f
,0.0f
};
278 v2_muladds( target
, (v2f
){ vg_get_axis("h1"), vg_get_axis("v1") },
279 phys
->grab
, target
);
283 * Entire Walking physics model
284 * TODO: sleep when under certain velotiy
286 static void player_walk_physics(void)
288 struct player_phys
*phys
= &player
.phys
;
289 rigidbody
*rbf
= &player
.collide_front
,
290 *rbb
= &player
.collide_back
;
292 m3x3_copy( phys
->rb
.to_world
, player
.collide_front
.to_world
);
293 m3x3_copy( phys
->rb
.to_world
, player
.collide_back
.to_world
);
298 m4x3_mulv( phys
->rb
.to_world
, (v3f
){0.0f
,h0
,0.0f
}, rbf
->co
);
299 v3_copy( rbf
->co
, rbf
->to_world
[3] );
300 m4x3_mulv( phys
->rb
.to_world
, (v3f
){0.0f
,h1
,0.0f
}, rbb
->co
);
301 v3_copy( rbb
->co
, rbb
->to_world
[3] );
303 m4x3_invert_affine( rbf
->to_world
, rbf
->to_local
);
304 m4x3_invert_affine( rbb
->to_world
, rbb
->to_local
);
306 rb_update_bounds( rbf
);
307 rb_update_bounds( rbb
);
309 rb_debug( rbf
, 0xff0000ff );
310 rb_debug( rbb
, 0xff0000ff );
315 len
+= rb_sphere_scene( rbf
, &world
.rb_geo
, manifold
+len
);
316 len
+= rb_sphere_scene( rbb
, &world
.rb_geo
, manifold
+len
);
318 rb_presolve_contacts( manifold
, len
);
320 for( int j
=0; j
<5; j
++ )
322 for( int i
=0; i
<len
; i
++ )
324 struct contact
*ct
= &manifold
[i
];
327 float vn
= -v3_dot( phys
->rb
.v
, ct
->n
);
330 float temp
= ct
->norm_impulse
;
331 ct
->norm_impulse
= vg_maxf( temp
+ vn
, 0.0f
);
332 vn
= ct
->norm_impulse
- temp
;
335 v3_muls( ct
->n
, vn
, impulse
);
337 v3_add( impulse
, phys
->rb
.v
, phys
->rb
.v
);
340 for( int j
=0; j
<2; j
++ )
342 float f
= k_friction
* ct
->norm_impulse
,
343 vt
= v3_dot( phys
->rb
.v
, ct
->t
[j
] ),
346 float temp
= ct
->tangent_impulse
[j
];
347 ct
->tangent_impulse
[j
] = vg_clampf( temp
+ lambda
, -f
, f
);
348 lambda
= ct
->tangent_impulse
[j
] - temp
;
350 v3_muladds( phys
->rb
.v
, ct
->t
[j
], lambda
, phys
->rb
.v
);
355 phys
->in_air
= len
==0?1:0;
357 v3_zero( phys
->rb
.w
);
358 q_axis_angle( phys
->rb
.q
, (v3f
){0.0f
,1.0f
,0.0f
}, -player
.angles
[0] );
360 v3f forward_dir
= { sinf(player
.angles
[0]),0.0f
,-cosf(player
.angles
[0]) };
363 v3_muladds( phys
->rb
.co
, forward_dir
, 2.0f
, p1
);
364 vg_line( phys
->rb
.co
, p1
, 0xff0000ff );
366 float move_dead
= 0.1f
,
367 move
= vg_get_axis("grabr")*0.5f
+ 0.5f
- move_dead
;
371 float move_norm
= move
* (1.0f
/(1.0f
-move_dead
)),
372 speed
= vg_lerpf( 0.1f
*k_runspeed
, k_runspeed
, move_norm
),
373 amt
= k_walk_accel
* ktimestep
,
374 zvel
= v3_dot( phys
->rb
.v
, forward_dir
),
375 new_vel
= vg_minf( zvel
+ amt
, speed
),
376 diff
= new_vel
- vg_minf( zvel
, speed
);
378 v3_muladds( phys
->rb
.v
, forward_dir
, diff
, phys
->rb
.v
);
381 float walk_norm
= 30.0f
/(float)player
.mdl
.anim_walk
->length
,
382 run_norm
= 30.0f
/(float)player
.mdl
.anim_run
->length
;
384 player
.walk_timer
+= ktimestep
* vg_lerpf( walk_norm
,run_norm
,move_norm
);
388 player
.walk_timer
= 0.0f
;
391 phys
->rb
.v
[0] *= 1.0f
- (ktimestep
*k_walk_friction
);
392 phys
->rb
.v
[2] *= 1.0f
- (ktimestep
*k_walk_friction
);
396 * Physics collision detection, and control
398 static void player_physics(void)
400 struct player_phys
*phys
= &player
.phys
;
402 * Update collision fronts
405 rigidbody
*rbf
= &player
.collide_front
,
406 *rbb
= &player
.collide_back
;
408 m3x3_copy( phys
->rb
.to_world
, player
.collide_front
.to_world
);
409 m3x3_copy( phys
->rb
.to_world
, player
.collide_back
.to_world
);
411 player
.air_blend
= vg_lerpf( player
.air_blend
, phys
->in_air
, 0.1f
);
412 float h
= player
.air_blend
*0.2f
;
414 m4x3_mulv( phys
->rb
.to_world
, (v3f
){0.0f
,h
,-k_board_length
}, rbf
->co
);
415 v3_copy( rbf
->co
, rbf
->to_world
[3] );
416 m4x3_mulv( phys
->rb
.to_world
, (v3f
){0.0f
,h
, k_board_length
}, rbb
->co
);
417 v3_copy( rbb
->co
, rbb
->to_world
[3] );
419 m4x3_invert_affine( rbf
->to_world
, rbf
->to_local
);
420 m4x3_invert_affine( rbb
->to_world
, rbb
->to_local
);
422 rb_update_bounds( rbf
);
423 rb_update_bounds( rbb
);
425 rb_debug( rbf
, 0xff00ffff );
426 rb_debug( rbb
, 0xffffff00 );
431 len
+= rb_sphere_scene( rbf
, &world
.rb_geo
, manifold
+len
);
432 len
+= rb_sphere_scene( rbb
, &world
.rb_geo
, manifold
+len
);
434 rb_presolve_contacts( manifold
, len
);
435 v3f surface_avg
= {0.0f
, 0.0f
, 0.0f
};
443 for( int i
=0; i
<len
; i
++ )
445 v3_add( manifold
[i
].n
, surface_avg
, surface_avg
);
448 v3_normalize( surface_avg
);
450 if( v3_dot( phys
->rb
.v
, surface_avg
) > 0.5f
)
458 for( int j
=0; j
<5; j
++ )
460 for( int i
=0; i
<len
; i
++ )
462 struct contact
*ct
= &manifold
[i
];
465 v3_sub( ct
->co
, phys
->rb
.co
, delta
);
466 v3_cross( phys
->rb
.w
, delta
, dv
);
467 v3_add( phys
->rb
.v
, dv
, dv
);
469 float vn
= -v3_dot( dv
, ct
->n
);
472 float temp
= ct
->norm_impulse
;
473 ct
->norm_impulse
= vg_maxf( temp
+ vn
, 0.0f
);
474 vn
= ct
->norm_impulse
- temp
;
477 v3_muls( ct
->n
, vn
, impulse
);
479 if( fabsf(v3_dot( impulse
, phys
->rb
.forward
)) > 10.0f
||
480 fabsf(v3_dot( impulse
, phys
->rb
.up
)) > 50.0f
)
486 v3_add( impulse
, phys
->rb
.v
, phys
->rb
.v
);
487 v3_cross( delta
, impulse
, impulse
);
490 * W Impulses are limited to the Y and X axises, we don't really want
491 * roll angular velocities being included.
493 * Can also tweak the resistance of each axis here by scaling the wx,wy
497 float wy
= v3_dot( phys
->rb
.up
, impulse
),
498 wx
= v3_dot( phys
->rb
.right
, impulse
)*1.5f
;
500 v3_muladds( phys
->rb
.w
, phys
->rb
.up
, wy
, phys
->rb
.w
);
501 v3_muladds( phys
->rb
.w
, phys
->rb
.right
, wx
, phys
->rb
.w
);
505 float grabt
= vg_get_axis( "grabr" )*0.5f
+0.5f
;
506 phys
->grab
= vg_lerpf( phys
->grab
, grabt
, 0.14f
);
507 player
.pushing
= 0.0f
;
512 float angle
= v3_dot( phys
->rb
.up
, surface_avg
);
513 v3_cross( phys
->rb
.up
, surface_avg
, axis
);
515 //float cz = v3_dot( player.rb.forward, axis );
516 //v3_muls( player.rb.forward, cz, axis );
521 q_axis_angle( correction
, axis
, acosf(angle
)*0.3f
);
522 q_mul( correction
, phys
->rb
.q
, phys
->rb
.q
);
525 v3_muladds( phys
->rb
.v
, phys
->rb
.up
,
526 -k_downforce
*ktimestep
, phys
->rb
.v
);
528 player_physics_control();
530 if( !phys
->jump_charge
&& phys
->jump
> 0.2f
)
534 /* Launch more up if alignment is up else improve velocity */
535 float aup
= fabsf(v3_dot( (v3f
){0.0f
,1.0f
,0.0f
}, phys
->rb
.up
)),
537 dir
= mod
+ aup
*(1.0f
-mod
);
539 v3_copy( phys
->rb
.v
, jumpdir
);
540 v3_normalize( jumpdir
);
541 v3_muls( jumpdir
, 1.0f
-dir
, jumpdir
);
542 v3_muladds( jumpdir
, phys
->rb
.up
, dir
, jumpdir
);
543 v3_normalize( jumpdir
);
545 float force
= k_jump_force
*phys
->jump
;
546 v3_muladds( phys
->rb
.v
, jumpdir
, force
, phys
->rb
.v
);
549 player
.jump_time
= vg_time
;
551 /* TODO: Move to audio file */
553 audio_player_set_flags( &audio_player_extra
, AUDIO_FLAG_SPACIAL_3D
);
554 audio_player_set_position( &audio_player_extra
, phys
->rb
.co
);
555 audio_player_set_vol( &audio_player_extra
, 20.0f
);
556 audio_player_playclip( &audio_player_extra
, &audio_jumps
[rand()%4] );
562 player_physics_control_air();
565 if( !phys
->jump_charge
)
567 phys
->jump
-= k_jump_charge_speed
* ktimestep
;
569 phys
->jump_charge
= 0;
570 phys
->jump
= vg_clampf( phys
->jump
, 0.0f
, 1.0f
);
573 static void player_save_frame(void)
575 player
.phys_gate_frame
= player
.phys
;
578 static void player_restore_frame(void)
580 player
.phys
= player
.phys_gate_frame
;
581 rb_update_transform( &player
.phys
.rb
);
584 static void player_do_motion(void)
586 struct player_phys
*phys
= &player
.phys
;
588 float horizontal
= vg_get_axis("horizontal"),
589 vertical
= vg_get_axis("vertical");
591 if( (phys
->rb
.co
[1] < 0.0f
) && !player
.is_dead
)
594 audio_player_set_flags( &audio_player_extra
, AUDIO_FLAG_SPACIAL_3D
);
595 audio_player_set_position( &audio_player_extra
, phys
->rb
.co
);
596 audio_player_set_vol( &audio_player_extra
, 20.0f
);
597 audio_player_playclip( &audio_player_extra
, &audio_splash
);
606 player_walk_physics();
608 /* Integrate velocity */
610 v3_copy( phys
->rb
.co
, prevco
);
612 apply_gravity( phys
->rb
.v
, ktimestep
);
613 v3_muladds( phys
->rb
.co
, phys
->rb
.v
, ktimestep
, phys
->rb
.co
);
615 /* Real angular velocity integration */
616 v3_lerp( phys
->rb
.w
, (v3f
){0.0f
,0.0f
,0.0f
}, 0.125f
, phys
->rb
.w
);
617 if( v3_length2( phys
->rb
.w
) > 0.0f
)
621 v3_copy( phys
->rb
.w
, axis
);
623 float mag
= v3_length( axis
);
624 v3_divs( axis
, mag
, axis
);
625 q_axis_angle( rotation
, axis
, mag
*k_rb_delta
);
626 q_mul( rotation
, phys
->rb
.q
, phys
->rb
.q
);
629 /* Faux angular velocity */
632 float lerpq
= phys
->in_air
? 0.04f
: 0.3f
;
633 phys
->siY
= vg_lerpf( phys
->siY
, phys
->iY
, lerpq
);
635 q_axis_angle( rotate
, phys
->rb
.up
, phys
->siY
);
636 q_mul( rotate
, phys
->rb
.q
, phys
->rb
.q
);
640 * Gate intersection, by tracing a line over the gate planes
642 for( int i
=0; i
<world
.routes
.gate_count
; i
++ )
644 struct route_gate
*rg
= &world
.routes
.gates
[i
];
645 teleport_gate
*gate
= &rg
->gate
;
647 if( gate_intersect( gate
, phys
->rb
.co
, prevco
) )
649 m4x3_mulv( gate
->transport
, phys
->rb
.co
, phys
->rb
.co
);
650 m3x3_mulv( gate
->transport
, phys
->rb
.v
, phys
->rb
.v
);
651 m3x3_mulv( gate
->transport
, phys
->vl
, phys
->vl
);
652 m3x3_mulv( gate
->transport
, phys
->v_last
, phys
->v_last
);
653 m3x3_mulv( gate
->transport
, phys
->m
, phys
->m
);
654 m3x3_mulv( gate
->transport
, phys
->bob
, phys
->bob
);
656 v4f transport_rotation
;
657 m3x3_q( gate
->transport
, transport_rotation
);
658 q_mul( transport_rotation
, phys
->rb
.q
, phys
->rb
.q
);
660 world_routes_activate_gate( i
);
662 if( !phys
->on_board
)
664 v3f fwd_dir
= {cosf(player
.angles
[0]),
666 sinf(player
.angles
[0])};
667 m3x3_mulv( gate
->transport
, fwd_dir
, fwd_dir
);
669 player
.angles
[0] = atan2f( fwd_dir
[2], fwd_dir
[0] );
675 audio_play_oneshot( &audio_gate_pass
, 1.0f
);
681 rb_update_transform( &phys
->rb
);
685 * Free camera movement
687 static void player_mouseview(void)
689 if( gui_want_mouse() )
692 static v2f mouse_last
,
693 view_vel
= { 0.0f
, 0.0f
};
695 if( vg_get_button_down( "primary" ) )
696 v2_copy( vg_mouse
, mouse_last
);
698 else if( vg_get_button( "primary" ) )
701 v2_sub( vg_mouse
, mouse_last
, delta
);
702 v2_copy( vg_mouse
, mouse_last
);
704 v2_muladds( view_vel
, delta
, 0.001f
, view_vel
);
707 v2_muladds( view_vel
,
708 (v2f
){ vg_get_axis("h1"), vg_get_axis("v1") },
710 v2_muls( view_vel
, 0.93f
, view_vel
);
711 v2_add( view_vel
, player
.angles
, player
.angles
);
712 player
.angles
[1] = vg_clampf( player
.angles
[1], -VG_PIf
*0.5f
, VG_PIf
*0.5f
);
715 static void player_freecam(void)
719 float movespeed
= fc_speed
;
720 v3f lookdir
= { 0.0f
, 0.0f
, -1.0f
},
721 sidedir
= { 1.0f
, 0.0f
, 0.0f
};
723 m3x3_mulv( player
.camera
, lookdir
, lookdir
);
724 m3x3_mulv( player
.camera
, sidedir
, sidedir
);
726 static v3f move_vel
= { 0.0f
, 0.0f
, 0.0f
};
727 if( vg_get_button( "forward" ) )
728 v3_muladds( move_vel
, lookdir
, ktimestep
* movespeed
, move_vel
);
729 if( vg_get_button( "back" ) )
730 v3_muladds( move_vel
, lookdir
, ktimestep
*-movespeed
, move_vel
);
731 if( vg_get_button( "left" ) )
732 v3_muladds( move_vel
, sidedir
, ktimestep
*-movespeed
, move_vel
);
733 if( vg_get_button( "right" ) )
734 v3_muladds( move_vel
, sidedir
, ktimestep
* movespeed
, move_vel
);
736 v3_muls( move_vel
, 0.7f
, move_vel
);
737 v3_add( move_vel
, player
.camera_pos
, player
.camera_pos
);
740 static void player_camera_update(void)
742 /* Update camera matrices */
743 v4f qyaw
, qpitch
, qcam
;
744 q_axis_angle( qyaw
, (v3f
){ 0.0f
, 1.0f
, 0.0f
}, -player
.angles
[0] );
745 q_axis_angle( qpitch
, (v3f
){ 1.0f
, 0.0f
, 0.0f
}, -player
.angles
[1] );
747 q_mul( qyaw
, qpitch
, qcam
);
748 q_m3x3( qcam
, player
.camera
);
750 v3_copy( player
.camera_pos
, player
.camera
[3] );
751 m4x3_invert_affine( player
.camera
, player
.camera_inverse
);
754 static int reset_player( int argc
, char const *argv
[] )
756 struct player_phys
*phys
= &player
.phys
;
757 struct respawn_point
*rp
= NULL
, *r
;
761 for( int i
=0; i
<world
.spawn_count
; i
++ )
763 r
= &world
.spawns
[i
];
764 if( !strcmp( r
->name
, argv
[0] ) )
772 vg_warn( "No spawn named '%s'\n", argv
[0] );
777 float min_dist
= INFINITY
;
779 for( int i
=0; i
<world
.spawn_count
; i
++ )
781 r
= &world
.spawns
[i
];
782 float d
= v3_dist2( r
->co
, phys
->rb
.co
);
784 vg_info( "Dist %s : %f\n", r
->name
, d
);
795 vg_error( "No spawn found\n" );
796 if( !world
.spawn_count
)
799 rp
= &world
.spawns
[0];
804 v4_copy( rp
->q
, phys
->rb
.q
);
805 v3_copy( rp
->co
, phys
->rb
.co
);
806 v3_zero( phys
->rb
.v
);
808 phys
->vswitch
= 1.0f
;
809 phys
->slip_last
= 0.0f
;
812 m3x3_identity( phys
->vr
);
814 player
.mdl
.shoes
[0] = 1;
815 player
.mdl
.shoes
[1] = 1;
817 rb_update_transform( &phys
->rb
);
822 #endif /* PLAYER_PHYSICS_H */