a71806ccab935a1eba73743b41dce46ea0243455
[carveJwlIkooP6JGAAIwe30JlM.git] / testing.c
1 #pragma once
2 #include "vg/vg_m.h"
3 #include "vg/vg_rigidbody.h"
4 #include "vg/vg_input.h"
5 #include "scene_rigidbody.h"
6
7 struct {
8 rigidbody rb;
9 boxf box;
10 }
11 static baller = {
12 .rb.q = { 0,0,0,1 },
13 .box = {{ -0.1f, -0.2f, -0.1f },
14 { 0.1f, 1.0f, 0.1f }},
15 };
16
17 static void testing_update(void){
18 if( !vg_console.cheats )
19 return;
20
21 if( vg_getkey( SDLK_9 ) ){
22 v3_add( localplayer.rb.co, (v3f){0,1,0}, baller.rb.co );
23 v3_zero( baller.rb.w );
24 v3_zero( baller.rb.v );
25 q_identity( baller.rb.q );
26 rb_update_matrices( &baller.rb );
27 }
28
29 if( vg_getkey( SDLK_8 ) ){
30 localplayer.have_glider = 1;
31 localplayer.glider_orphan = 0;
32 player_glide.t = -1.0f;
33 }
34
35 vg_line_boxf_transformed( baller.rb.to_world, baller.box, VG__RED );
36
37 world_instance *world = world_current_instance();
38
39 rigidbody _null = {0};
40 _null.inv_mass = 0.0f;
41 m3x3_zero( _null.iI );
42
43 rb_solver_reset();
44 rb_ct *buf = rb_global_buffer();
45 rb_contact_count += rb_box__scene( baller.rb.to_world, baller.box,
46 NULL, world->geo_bh, buf,
47 k_material_flag_ghosts );
48 for( u32 j=0; j<rb_contact_count; j++ ){
49 buf[j].rba = &baller.rb;
50 buf[j].rbb = &_null;
51 }
52
53 rb_presolve_contacts( rb_contact_buffer,
54 vg.time_fixed_delta, rb_contact_count );
55
56 for( u32 i=0; i<8; i ++ )
57 rb_solve_contacts( rb_contact_buffer, rb_contact_count );
58
59 rb_iter( &baller.rb );
60 rb_update_matrices( &baller.rb );
61 }
62
63 static void testing_init(void){
64 rb_setbody_box( &baller.rb, baller.box, 8.0f, 1.0f );
65 }