7 static int freecam
= 0;
12 v3f co
, v
, a
, v_last
, m
, bob
;
14 float vswitch
, slip
, slip_last
,
17 float iY
; /* Yaw inertia */
18 int in_air
, is_dead
, on_board
;
28 v3f land_target_log
[22];
29 u32 land_target_colours
[22];
33 m4x3f to_world
, to_local
;
37 v3f handl_target
, handr_target
,
43 v3f camera_pos
, smooth_localcam
;
45 m4x3f camera
, camera_inverse
;
49 static void player_transform_update(void)
51 q_normalize( player
.rot
);
52 q_m3x3( player
.rot
, player
.to_world
);
53 v3_copy( player
.co
, player
.to_world
[3] );
55 m4x3_invert_affine( player
.to_world
, player
.to_local
);
58 static int reset_player( int argc
, char const *argv
[] )
64 if( !strcmp( argv
[0], "tutorial" ))
65 v3_copy( world
.tutorial
, player
.co
);
68 v3_copy( (v3f
){ 0.0f
, 0.0f
, -0.2f
}, player
.v
);
69 q_identity( player
.rot
);
70 player
.vswitch
= 1.0f
;
71 player
.slip_last
= 0.0f
;
74 m3x3_identity( player
.vr
);
76 player
.mdl
.shoes
[0] = 1;
77 player
.mdl
.shoes
[1] = 1;
79 player_transform_update();
83 static void player_mouseview(void)
85 static v2f mouse_last
,
86 view_vel
= { 0.0f
, 0.0f
};
88 if( vg_get_button_down( "primary" ) )
89 v2_copy( vg_mouse
, mouse_last
);
90 else if( vg_get_button( "primary" ) )
93 v2_sub( vg_mouse
, mouse_last
, delta
);
94 v2_copy( vg_mouse
, mouse_last
);
96 v2_muladds( view_vel
, delta
, 0.005f
, view_vel
);
99 v2_muls( view_vel
, 0.7f
, view_vel
);
100 v2_add( view_vel
, player
.angles
, player
.angles
);
101 player
.angles
[1] = vg_clampf( player
.angles
[1], -VG_PIf
*0.5f
, VG_PIf
*0.5f
);
105 static void player_freecam(void)
109 float movespeed
= 25.0f
;
110 v3f lookdir
= { 0.0f
, 0.0f
, -1.0f
},
111 sidedir
= { 1.0f
, 0.0f
, 0.0f
};
113 m3x3_mulv( player
.camera
, lookdir
, lookdir
);
114 m3x3_mulv( player
.camera
, sidedir
, sidedir
);
116 static v3f move_vel
= { 0.0f
, 0.0f
, 0.0f
};
117 if( vg_get_button( "forward" ) )
118 v3_muladds( move_vel
, lookdir
, ktimestep
* movespeed
, move_vel
);
119 if( vg_get_button( "back" ) )
120 v3_muladds( move_vel
, lookdir
, ktimestep
*-movespeed
, move_vel
);
121 if( vg_get_button( "left" ) )
122 v3_muladds( move_vel
, sidedir
, ktimestep
*-movespeed
, move_vel
);
123 if( vg_get_button( "right" ) )
124 v3_muladds( move_vel
, sidedir
, ktimestep
* movespeed
, move_vel
);
126 v3_muls( move_vel
, 0.7f
, move_vel
);
127 v3_add( move_vel
, player
.camera_pos
, player
.camera_pos
);
130 static void apply_gravity( v3f vel
, float const timestep
)
132 v3f gravity
= { 0.0f
, -9.6f
, 0.0f
};
133 v3_muladds( vel
, gravity
, timestep
, vel
);
136 static void player_start_air(void)
140 float pstep
= ktimestep
*10.0f
;
142 float best_velocity_mod
= 0.0f
,
143 best_velocity_delta
= -9999.9f
;
146 m3x3_mulv( player
.to_world
, (v3f
){0.0f
,1.0f
,0.0f
}, vup
);
147 v3_cross( vup
, player
.v
, axis
);
148 v3_normalize( axis
);
149 player
.land_log_count
= 0;
151 m3x3_identity( player
.vr
);
153 for( int m
=-3;m
<=12; m
++ )
155 float vmod
= ((float)m
/ 15.0f
)*0.09f
;
158 v3_copy( player
.co
, pco
);
159 v3_copy( player
.v
, pv
);
162 * Try different 'rotations' of the velocity to find the best possible
163 * landing normal. This conserves magnitude at the expense of slightly
164 * unrealistic results
170 q_axis_angle( vr_q
, axis
, vmod
);
173 m3x3_mulv( vr
, pv
, pv
);
174 v3_muladds( pco
, pv
, ktimestep
, pco
);
176 for( int i
=0; i
<50; i
++ )
178 v3_copy( pco
, pco1
);
179 apply_gravity( pv
, pstep
);
181 m3x3_mulv( vr
, pv
, pv
);
182 v3_muladds( pco
, pv
, pstep
, pco
);
187 v3_sub( pco
, pco1
, vdir
);
188 contact
.dist
= v3_length( vdir
);
189 v3_divs( vdir
, contact
.dist
, vdir
);
191 if( ray_world( pco1
, vdir
, &contact
))
193 float land_delta
= v3_dot( pv
, contact
.normal
);
194 u32 scolour
= (u8
)(vg_minf(-land_delta
* 2.0f
, 255.0f
));
196 /* Bias prediction towords ramps */
197 if( ray_hit_is_ramp( &contact
) )
200 scolour
|= 0x0000a000;
203 if( (land_delta
< 0.0f
) && (land_delta
> best_velocity_delta
) )
205 best_velocity_delta
= land_delta
;
206 best_velocity_mod
= vmod
;
208 v3_copy( contact
.pos
, player
.land_target
);
210 q_axis_angle( vr_q
, axis
, vmod
*0.1f
);
211 q_m3x3( vr_q
, player
.vr
);
214 v3_copy( contact
.pos
,
215 player
.land_target_log
[player
.land_log_count
] );
216 player
.land_target_colours
[player
.land_log_count
] =
217 0xff000000 | scolour
;
219 player
.land_log_count
++;
226 //v3_rotate( player.v, best_velocity_mod, axis, player.v );
229 v3_muls( player
.v
, best_velocity_mod
, player
.v
);
232 static int sample_if_resistant( v3f pos
)
235 v3_copy( pos
, ground
);
241 if( ray_world( ground
, (v3f
){0.0f
,-1.0f
,0.0f
}, &hit
))
244 v3_copy( player
.v
, angle
);
245 v3_normalize( angle
);
246 float resistance
= v3_dot( hit
.normal
, angle
);
248 if( resistance
< 0.25f
)
250 v3_copy( hit
.pos
, pos
);
258 static float stable_force( float current
, float diff
)
260 float new = current
+ diff
;
262 if( new * current
< 0.0f
)
268 static void player_physics_ground(void)
271 * Getting surface collision points,
272 * the contact manifold is a triangle for simplicity.
274 v3f contact_front
, contact_back
, contact_norm
, vup
, vside
,
277 float klength
= 0.65f
;
278 m4x3_mulv( player
.to_world
, (v3f
){ 0.15f
,0.0f
,-klength
}, contact_norm
);
279 m4x3_mulv( player
.to_world
, (v3f
){-0.15f
,0.0f
,-klength
}, contact_front
);
280 m4x3_mulv( player
.to_world
, (v3f
){ 0.00f
,0.0f
, klength
}, contact_back
);
281 m3x3_mulv( player
.to_world
, (v3f
){ 0.0f
, 1.0f
, 0.0f
}, vup
);
282 m3x3_mulv( player
.to_world
, (v3f
){ 1.0f
, 0.0f
, 0.0f
}, vside
);
287 sample_if_resistant( contact_front
) +
288 sample_if_resistant( contact_back
) +
289 sample_if_resistant( contact_norm
);
291 if( contact_count
< 3 )
299 v3_sub( contact_norm
, contact_front
, v0
);
300 v3_sub( contact_back
, contact_front
, v1
);
301 v3_cross( v1
, v0
, norm
);
302 v3_normalize( norm
);
304 vg_line( contact_norm
, contact_front
, 0xff00ff00 );
305 vg_line( contact_back
, contact_front
, 0xff0000ff );
307 /* Surface alignment */
308 float angle
= v3_dot( vup
, norm
);
309 v3_cross( vup
, norm
, axis
);
314 q_axis_angle( correction
, axis
, acosf(angle
) );
315 q_mul( correction
, player
.rot
, player
.rot
);
318 float resistance
= v3_dot( norm
, player
.v
);
319 if( resistance
>= 0.0f
)
326 v3_muladds( player
.v
, norm
, -resistance
, player
.v
);
329 /* This is where velocity integration used to be */
333 player
.co
[1] = (contact_front
[1]+contact_back
[1])*0.5f
;
336 m3x3_mulv( player
.to_local
, player
.v
, vel
);
338 /* Calculate local forces */
340 if( fabsf(vel
[2]) > 0.01f
)
341 slip
= fabsf(-vel
[0] / vel
[2]) * vg_signf(vel
[0]);
343 if( fabsf( slip
) > 1.2f
)
344 slip
= vg_signf( slip
) * 1.2f
;
346 player
.reverse
= -vg_signf(vel
[2]);
348 float substep
= ktimestep
* 0.2f
;
349 float fwd_resistance
= (vg_get_button( "break" )? 5.0f
: 0.02f
) * -substep
;
351 for( int i
=0; i
<5; i
++ )
353 vel
[2] = stable_force( vel
[2], vg_signf( vel
[2] ) * fwd_resistance
);
354 vel
[0] = stable_force( vel
[0], vg_signf( vel
[0] ) * -7.0f
*substep
);
357 static double start_push
= 0.0;
358 if( vg_get_button_down( "push" ) )
359 start_push
= vg_time
;
361 if( !vg_get_button("break") && vg_get_button( "push" ) )
363 float const k_maxpush
= 16.0f
,
366 float cycle_time
= vg_time
-start_push
,
367 amt
= k_pushaccel
* (sinf( cycle_time
* 8.0f
)*0.5f
+0.5f
)*ktimestep
,
368 current
= v3_length( vel
),
369 new_vel
= vg_minf( current
+ amt
, k_maxpush
);
370 new_vel
-= vg_minf(current
, k_maxpush
);
371 vel
[2] -= new_vel
* player
.reverse
;
374 m3x3_mulv( player
.to_world
, vel
, player
.v
);
376 if( vg_get_button( "yawl" ) )
377 player
.iY
+= 3.6f
* ktimestep
;
378 if( vg_get_button( "yawr" ) )
379 player
.iY
-= 3.6f
* ktimestep
;
381 float steer
= vg_get_axis( "horizontal" );
382 player
.iY
-= vg_signf(steer
)*powf(steer
,2.0f
) * 1.5f
* ktimestep
;
384 /* Too much lean and it starts to look like a snowboard here */
385 v2_lerp( player
.board_xy
, (v2f
){ slip
*0.25f
, 0.0f
},
386 ktimestep
*5.0f
, player
.board_xy
);
389 static void draw_cross(v3f pos
,u32 colour
, float scale
)
392 v3_add( (v3f
){ scale
,0.0f
,0.0f
}, pos
, p0
);
393 v3_add( (v3f
){-scale
,0.0f
,0.0f
}, pos
, p1
);
394 vg_line( p0
, p1
, colour
);
395 v3_add( (v3f
){0.0f
, scale
,0.0f
}, pos
, p0
);
396 v3_add( (v3f
){0.0f
,-scale
,0.0f
}, pos
, p1
);
397 vg_line( p0
, p1
, colour
);
398 v3_add( (v3f
){0.0f
,0.0f
, scale
}, pos
, p0
);
399 v3_add( (v3f
){0.0f
,0.0f
,-scale
}, pos
, p1
);
400 vg_line( p0
, p1
, colour
);
403 static void player_physics_air(void)
405 m3x3_mulv( player
.vr
, player
.v
, player
.v
);
406 for( int i
=0; i
<player
.land_log_count
; i
++ )
407 draw_cross( player
.land_target_log
[i
], player
.land_target_colours
[i
], 1);
409 draw_cross( player
.land_target
, 0xff0000ff, 1 );
412 v3_copy( player
.co
, ground_pos
);
413 ground_pos
[1] += 4.0f
;
417 if( ray_world( ground_pos
, (v3f
){0.0f
,-1.0f
,0.0f
}, &hit
))
419 if( hit
.pos
[1] > player
.co
[1] )
423 if( !ray_hit_is_ramp( &hit
) )
426 character_ragdoll_copypose( &player
.mdl
, player
.v
);
435 * TODO: Find best landing surface and guide player towords it
437 float pstep
= ktimestep
*10.0f
;
440 v3_copy( player
.co
, pco
);
441 v3_copy( player
.v
, pv
);
443 float time_to_impact
= 0.0f
;
444 float limiter
= 1.0f
;
446 for( int i
=0; i
<50; i
++ )
448 v3_copy( pco
, pco1
);
449 apply_gravity( pv
, pstep
);
450 v3_muladds( pco
, pv
, pstep
, pco
);
452 //vg_line( pco, pco1, i&0x1?0xff000000:0xffffffff );
457 v3_sub( pco
, pco1
, vdir
);
458 contact
.dist
= v3_length( vdir
);
459 v3_divs( vdir
, contact
.dist
, vdir
);
461 float orig_dist
= contact
.dist
;
462 if( ray_world( pco1
, vdir
, &contact
))
465 m3x3_mulv( player
.to_world
, (v3f
){0.0f
,1.0f
,0.0f
}, localup
);
467 float angle
= v3_dot( localup
, contact
.normal
);
469 v3_cross( localup
, contact
.normal
, axis
);
471 time_to_impact
+= (contact
.dist
/orig_dist
)*pstep
;
472 limiter
= vg_minf( 5.0f
, time_to_impact
)/5.0f
;
473 limiter
= 1.0f
-limiter
;
475 limiter
= 1.0f
-limiter
;
480 q_axis_angle( correction
, axis
, acosf(angle
)*0.05f
*(1.0f
-limiter
) );
481 q_mul( correction
, player
.rot
, player
.rot
);
484 draw_cross( contact
.pos
, 0xffff0000, 1 );
487 time_to_impact
+= pstep
;
490 player
.iY
-= vg_get_axis( "horizontal" ) * 3.6f
* ktimestep
;
493 float iX
= vg_get_axis( "vertical" ) * 3.6f
* limiter
* ktimestep
;
494 static float siX
= 0.0f
;
495 siX
= vg_lerpf( siX
, iX
, 0.3f
);
500 m3x3_mulv( player
.to_world
, (v3f
){1.0f
,0.0f
,0.0f
}, vside
);
502 q_axis_angle( rotate
, vside
, siX
);
503 q_mul( rotate
, player
.rot
, player
.rot
);
506 v2f target
= {0.0f
,0.0f
};
507 v2_muladds( target
, (v2f
){ vg_get_axis("h1"), vg_get_axis("v1") },
508 player
.grab
, target
);
509 v2_lerp( player
.board_xy
, target
, ktimestep
*3.0f
, player
.board_xy
);
512 static void player_do_motion(void)
514 float horizontal
= vg_get_axis("horizontal"),
515 vertical
= vg_get_axis("vertical");
517 player
.joy_l
[0] = vg_signf(horizontal
) * powf( horizontal
, 2.0f
);
518 player
.joy_l
[1] = vg_signf(vertical
) * powf( vertical
, 2.0f
);
521 player_physics_air();
524 player_physics_ground();
526 /* Integrate velocity */
528 v3_copy( player
.co
, prevco
);
530 apply_gravity( player
.v
, ktimestep
);
531 v3_muladds( player
.co
, player
.v
, ktimestep
, player
.co
);
533 /* Integrate inertia */
534 v4f rotate
; v3f vup
= {0.0f
,1.0f
,0.0f
};
535 m3x3_mulv( player
.to_world
, vup
, vup
);
537 static float siY
= 0.0f
;
539 float lerpq
= player
.in_air
? 0.04f
: 0.3f
;
540 siY
= vg_lerpf( siY
, player
.iY
, lerpq
);
542 q_axis_angle( rotate
, vup
, siY
);
543 q_mul( rotate
, player
.rot
, player
.rot
);
545 player
.iY
= 0.0f
; /* temp */
549 if( gate_intersect( &gate_a
, player
.co
, prevco
) )
551 teleport_gate
*gate
= &gate_a
;
554 m4x3_mul( gate
->other
->to_world
, gate
->to_local
, transport
);
555 m4x3_mulv( transport
, player
.co
, player
.co
);
556 m3x3_mulv( transport
, player
.v
, player
.v
);
557 m3x3_mulv( transport
, player
.v_last
, player
.v_last
);
558 m3x3_mulv( transport
, player
.m
, player
.m
);
559 m3x3_mulv( transport
, player
.bob
, player
.bob
);
561 v4f transport_rotation
;
562 m3x3_q( transport
, transport_rotation
);
563 q_mul( transport_rotation
, player
.rot
, player
.rot
);
567 /* Camera and character */
568 player_transform_update();
570 player
.angles
[0] = atan2f( player
.v
[0], -player
.v
[2] );
571 player
.angles
[1] = atan2f( -player
.v
[1], sqrtf(player
.v
[0]*player
.v
[0]+
572 player
.v
[2]*player
.v
[2]) ) * 0.3f
;
574 player
.air_blend
= vg_lerpf( player
.air_blend
, player
.in_air
, 0.04f
);
575 v3_muladds( player
.camera_pos
, player
.v
, -0.05f
*player
.air_blend
,
579 static void player_walkgrid(void)
581 float const k_gridscale
= 0.5f
;
582 float const k_stepheight
= 0.5f
;
583 float const k_walkspeed
= 6.0f
;
584 float const k_miny
= 0.6f
;
585 float const k_height
= 1.78f
;
586 int const k_gridamt
= 8;
589 v3_muls( player
.co
, 1.0f
/k_gridscale
, cell
);
590 v3_floor( cell
, cell
);
591 v3_muls( cell
, k_gridscale
, cell
);
598 samples
[ k_gridamt
][ k_gridamt
];
601 v3_muladds( cell
, (v3f
){ -1.0f
,0.0f
,-1.0f
},
602 (float)(k_gridamt
/2) * k_gridscale
, grid_origin
);
607 for( int y
=0; y
<k_gridamt
; y
++ )
609 for( int x
=0; x
<k_gridamt
; x
++ )
612 v3_muladds( grid_origin
, (v3f
){ x
, 0, y
}, k_gridscale
, sample_coord
);
613 sample_coord
[1] += k_height
;
615 struct grid_sample
*sample
= &samples
[y
][x
];
617 sample
->hit
.dist
= k_stepheight
+k_height
;
619 if( ray_world( sample_coord
, (v3f
){0.0f
,-1.0f
,0.0f
}, &sample
->hit
))
621 if( sample
->hit
.normal
[1] >= k_miny
&&
622 ray_hit_is_ramp( &sample
->hit
))
625 draw_cross( sample
->hit
.pos
, 0xff00ff00, 0.1f
);
628 draw_cross( sample
->hit
.pos
, 0xff0000ff, 0.1f
);
634 * Clip grid intersections with triangle edges
636 for( int x
=0; x
<k_gridamt
; x
++ )
638 for( int y
=0; y
<k_gridamt
-1; y
++ )
640 struct grid_sample
*sa
= &samples
[y
][x
],
641 *sb
= &samples
[y
+1][x
];
643 if( (sa
->valid
!= sb
->valid
) && (sa
->valid
||sb
->valid
) )
646 ray_world_get_tri( sa
->valid
? &sa
->hit
: &sb
->hit
, tri
);
649 v3_muladds( grid_origin
, (v3f
){ x
, 0, y
},
650 k_gridscale
, sample
);
652 /* Clip triangles until we find an edge inside the cell */
654 float offset
= sample
[axis
==0?0:2],
655 basis
= sample
[axis
==0?2:0];
657 for( int i
=0; i
<3; i
++ )
661 float pa
= tri
[ia
][axis
],
664 vg_line( tri
[ia
],tri
[ib
],0xffaaaaaa );
666 if( (pa
-offset
)*(pb
-offset
) > 0.0f
)
671 h
= qa
*tri
[ib
][2] + (1.0f
-qa
)*tri
[ia
][2],
672 q
= (h
-basis
)/k_gridscale
;
674 if( q
>= 0.0f
&& q
<= 1.0f
)
676 float height
= qa
*tri
[ia
][1] + (1.0f
-qa
)*tri
[ib
][1];
678 v3f intersection
= { offset
, height
, h
};
679 draw_cross( intersection
, 0xffff0000, 0.06f
);
687 v3f fwd
= { -sinf(-player
.angles
[0]), 0.0f
, -cosf(-player
.angles
[0]) },
688 side
= { -fwd
[2], 0.0f
, fwd
[0] };
691 if( glfwGetKey( vg_window
, GLFW_KEY_W
) )
692 v3_muladds( player
.co
, fwd
, ktimestep
*k_walkspeed
, player
.co
);
693 if( glfwGetKey( vg_window
, GLFW_KEY_S
) )
694 v3_muladds( player
.co
, fwd
, -ktimestep
*k_walkspeed
, player
.co
);
696 if( glfwGetKey( vg_window
, GLFW_KEY_A
) )
697 v3_muladds( player
.co
, side
, -ktimestep
*k_walkspeed
, player
.co
);
698 if( glfwGetKey( vg_window
, GLFW_KEY_D
) )
699 v3_muladds( player
.co
, side
, ktimestep
*k_walkspeed
, player
.co
);
701 m4x3_mulv( player
.to_world
, (v3f
){0.0f
,1.8f
,0.0f
}, player
.camera_pos
);
703 player_transform_update();
706 static void player_animate(void)
708 /* Camera position */
709 v3_sub( player
.v
, player
.v_last
, player
.a
);
710 v3_copy( player
.v
, player
.v_last
);
712 v3_add( player
.m
, player
.a
, player
.m
);
713 v3_lerp( player
.m
, (v3f
){0.0f
,0.0f
,0.0f
}, 0.1f
, player
.m
);
716 player
.m
[0] = vg_clampf( player
.m
[0], -2.0f
, 2.0f
);
717 player
.m
[1] = vg_clampf( player
.m
[1], -0.2f
, 5.0f
);
718 player
.m
[2] = vg_clampf( player
.m
[2], -2.0f
, 2.0f
);
719 v3_copy( player
.m
, target
);
720 v3_lerp( player
.bob
, target
, 0.2f
, player
.bob
);
723 float lslip
= fabsf(player
.slip
); //vg_minf( 0.4f, slip );
725 float grabt
= vg_get_axis( "grabr" )*0.5f
+0.5f
;
726 player
.grab
= vg_lerpf( player
.grab
, grabt
, 0.04f
);
728 float kheight
= 2.0f
,
733 head
[1] = (0.3f
+cosf(lslip
)*0.5f
*(1.0f
-player
.grab
*0.7f
)) * kheight
;
737 m3x3_mulv( player
.to_local
, player
.bob
, offset
);
739 offset
[0] *= 0.3333f
;
742 v3_muladds( head
, offset
, 0.7f
, head
);
743 head
[1] = vg_clampf( head
[1], 0.3f
, kheight
);
748 v3_copy( head
, player
.view
);
749 v3f camoffs
= {-0.2f
,-0.6f
,0.00f
};
750 v3_add( player
.view
, camoffs
, player
.view
);
756 * ===========================================
759 static float fslide
= 0.0f
;
760 static float fdirz
= 0.0f
;
761 static float fdirx
= 0.0f
;
762 static float fstand
= 0.0f
;
763 static float ffly
= 0.0f
;
765 float speed
= v3_length( player
.v
);
767 fstand
= vg_lerpf(fstand
, 1.0f
-vg_clampf(speed
*0.03f
,0.0f
,1.0f
),0.1f
);
768 fslide
= vg_lerpf(fslide
, vg_clampf(lslip
+fabsf(offset
[0])*0.2f
,
770 fdirz
= vg_lerpf(fdirz
, player
.reverse
> 0.0f
? 1.0f
: 0.0f
, 0.04f
);
771 fdirx
= vg_lerpf(fdirx
, player
.slip
< 0.0f
? 1.0f
: 0.0f
, 0.04f
);
772 ffly
= vg_lerpf(ffly
, player
.in_air
? 1.0f
: 0.0f
, 0.04f
);
774 character_pose_reset( &player
.mdl
);
776 float amt_air
= ffly
*ffly
,
777 amt_ground
= 1.0f
-amt_air
,
778 amt_std
= (1.0f
-fslide
) * amt_ground
,
779 amt_stand
= amt_std
* fstand
,
780 amt_aero
= amt_std
* (1.0f
-fstand
),
781 amt_slide
= amt_ground
* fslide
;
783 character_final_pose( &player
.mdl
, offset
, &pose_stand
, amt_stand
);
784 character_final_pose( &player
.mdl
, offset
, &pose_aero
, amt_aero
*fdirz
);
785 character_final_pose( &player
.mdl
, offset
,
786 &pose_aero_reverse
, amt_aero
* (1.0f
-fdirz
) );
787 character_final_pose( &player
.mdl
, offset
, &pose_slide
, amt_slide
*fdirx
);
788 character_final_pose( &player
.mdl
, offset
,
789 &pose_slide1
, amt_slide
*(1.0f
-fdirx
) );
791 character_final_pose( &player
.mdl
, (v3f
){0.0f
,0.0f
,0.0f
},
792 &pose_fly
, amt_air
);
794 /* Camera position */
795 v3_lerp( player
.smooth_localcam
, player
.mdl
.cam_pos
, 0.08f
,
796 player
.smooth_localcam
);
797 v3_muladds( player
.smooth_localcam
, offset
, 0.7f
, player
.camera_pos
);
798 player
.camera_pos
[1] = vg_clampf( player
.camera_pos
[1], 0.3f
, kheight
);
799 m4x3_mulv( player
.to_world
, player
.camera_pos
, player
.camera_pos
);
803 * ==========================
805 struct ik_basic
*arm_l
= &player
.mdl
.ik_arm_l
,
806 *arm_r
= &player
.mdl
.ik_arm_r
;
809 m3x3_mulv( player
.to_local
, player
.v
, localv
);
810 v3_muladds( arm_l
->end
, localv
, -0.01f
, arm_l
->end
);
811 v3_muladds( arm_r
->end
, localv
, -0.01f
, arm_r
->end
);
813 /* New board transformation */
814 v4f board_rotation
; v3f board_location
;
817 q_axis_angle( rz
, (v3f
){ 0.0f
, 0.0f
, 1.0f
}, player
.board_xy
[0] );
818 q_axis_angle( rx
, (v3f
){ 1.0f
, 0.0f
, 0.0f
}, player
.board_xy
[1] );
819 q_mul( rx
, rz
, board_rotation
);
821 v3f
*mboard
= player
.mdl
.matrices
[k_chpart_board
];// player.mboard;
822 q_m3x3( board_rotation
, mboard
);
823 m3x3_mulv( mboard
, (v3f
){ 0.0f
, -0.5f
, 0.0f
}, board_location
);
824 v3_add( (v3f
){0.0f
,0.5f
,0.0f
}, board_location
, board_location
);
825 v3_copy( board_location
, mboard
[3] );
828 float wheel_r
= offset
[0]*-0.4f
;
830 q_axis_angle( qwheel
, (v3f
){0.0f
,1.0f
,0.0f
}, wheel_r
);
832 q_m3x3( qwheel
, player
.mdl
.matrices
[k_chpart_wb
] );
834 m3x3_transpose( player
.mdl
.matrices
[k_chpart_wb
],
835 player
.mdl
.matrices
[k_chpart_wf
] );
836 v3_copy( player
.mdl
.offsets
[k_chpart_wb
],
837 player
.mdl
.matrices
[k_chpart_wb
][3] );
838 v3_copy( player
.mdl
.offsets
[k_chpart_wf
],
839 player
.mdl
.matrices
[k_chpart_wf
][3] );
841 m4x3_mul( mboard
, player
.mdl
.matrices
[k_chpart_wb
],
842 player
.mdl
.matrices
[k_chpart_wb
] );
843 m4x3_mul( mboard
, player
.mdl
.matrices
[k_chpart_wf
],
844 player
.mdl
.matrices
[k_chpart_wf
] );
846 m4x3_mulv( mboard
, player
.mdl
.ik_leg_l
.end
, player
.mdl
.ik_leg_l
.end
);
847 m4x3_mulv( mboard
, player
.mdl
.ik_leg_r
.end
, player
.mdl
.ik_leg_r
.end
);
850 v3_copy( player
.mdl
.ik_arm_l
.end
, player
.handl_target
);
851 v3_copy( player
.mdl
.ik_arm_r
.end
, player
.handr_target
);
853 if( 1||player
.in_air
)
855 float tuck
= player
.board_xy
[1],
856 tuck_amt
= fabsf( tuck
) * (1.0f
-fabsf(player
.board_xy
[0]));
858 float crouch
= player
.grab
*0.3f
;
859 v3_muladds( player
.mdl
.ik_body
.base
, (v3f
){0.0f
,-1.0f
,0.0f
},
860 crouch
, player
.mdl
.ik_body
.base
);
861 v3_muladds( player
.mdl
.ik_body
.end
, (v3f
){0.0f
,-1.0f
,0.0f
},
862 crouch
*1.2f
, player
.mdl
.ik_body
.end
);
866 //foot_l *= 1.0f-tuck_amt*1.5f;
868 if( player
.grab
> 0.1f
)
870 m4x3_mulv( mboard
, (v3f
){0.1f
,0.14f
,0.6f
},
871 player
.handl_target
);
876 //foot_r *= 1.0f-tuck_amt*1.4f;
878 if( player
.grab
> 0.1f
)
880 m4x3_mulv( mboard
, (v3f
){0.1f
,0.14f
,-0.6f
},
881 player
.handr_target
);
886 v3_lerp( player
.handl
, player
.handl_target
, 0.1f
, player
.handl
);
887 v3_lerp( player
.handr
, player
.handr_target
, 0.1f
, player
.handr
);
889 v3_copy( player
.handl
, player
.mdl
.ik_arm_l
.end
);
890 v3_copy( player
.handr
, player
.mdl
.ik_arm_r
.end
);
894 static float rhead
= 0.0f
;
895 rhead
= vg_lerpf( rhead
,
896 vg_clampf(atan2f( localv
[2], -localv
[0] ),-1.0f
,1.0f
), 0.04f
);
897 player
.mdl
.rhead
= rhead
;
900 static void player_update(void)
902 if( vg_get_axis("grabl")>0.0f
)
903 reset_player(0,NULL
);
913 character_ragdoll_iter( &player
.mdl
);
914 character_debug_ragdoll( &player
.mdl
);
918 if( player
.on_board
)
930 /* Update camera matrices */
931 m4x3_identity( player
.camera
);
932 m4x3_rotate_y( player
.camera
, -player
.angles
[0] );
933 m4x3_rotate_x( player
.camera
, -0.33f
-player
.angles
[1] );
934 v3_copy( player
.camera_pos
, player
.camera
[3] );
935 m4x3_invert_affine( player
.camera
, player
.camera_inverse
);
938 static void draw_player(void)
941 m4x3_copy( player
.to_world
, player
.mdl
.mroot
);
944 character_mimic_ragdoll( &player
.mdl
);
946 character_eval( &player
.mdl
);
948 character_draw( &player
.mdl
, (player
.is_dead
|player
.in_air
)? 0.0f
: 1.0f
);
951 #endif /* PLAYER_H */