33a6b6b7f8c56b70a75470da8e96ea55b3d9eb90
7 rigidbody ground
= { .type
= k_rb_shape_box
,
8 .bbx
= {{-100.0f
,-1.0f
,-100.0f
},{100.0f
,0.0f
,100.0f
}},
9 .co
= {0.0f
, 0.0f
, 0.0f
},
10 .q
= {0.0f
,0.0f
,0.0f
,1.0f
},
15 .type
= k_rb_shape_box
,
16 .bbx
= {{-2.0f
,-1.0f
,-3.0f
},{2.0f
,1.0f
,2.0f
}},
17 .co
= {30.0f
,2.0f
,30.0f
},
18 .q
= {0.0f
,0.0f
,0.0f
,1.0f
},
24 .type
= k_rb_shape_box
,
25 .bbx
= {{-0.5f
,-0.5f
,-0.5f
},{0.5f
,0.5f
,0.5f
}},
26 .co
= {-36.0f
,8.0f
,-36.0f
},
27 .q
= {0.0f
,0.0f
,0.0f
,1.0f
},
33 rigidbody epic_scene_rb
=
35 .type
= k_rb_shape_scene
,
36 .co
= {0.0f
,0.0f
,0.0f
},
37 .q
= {0.0f
,0.0f
,0.0f
,1.0f
},
39 .inf
.scene
= { .pscene
= &epic_scene
}
42 rigidbody funnel
[4] = {
44 .type
= k_rb_shape_box
,
45 .bbx
= {{-20.0f
,-1.0f
,-20.0f
},{20.0f
,1.0f
,20.0f
}},
46 .co
= {-10.0f
,5.0f
,0.0f
},
50 .type
= k_rb_shape_box
,
51 .bbx
= {{-20.0f
,-1.0f
,-20.0f
},{20.0f
,1.0f
,20.0f
}},
52 .co
= { 10.0f
,5.0f
,0.0f
},
56 .type
= k_rb_shape_box
,
57 .bbx
= {{-20.0f
,-1.0f
,-20.0f
},{20.0f
,1.0f
,20.0f
}},
58 .co
= { 0.0f
,5.0f
,10.0f
},
62 .type
= k_rb_shape_box
,
63 .bbx
= {{-20.0f
,-1.0f
,-20.0f
},{20.0f
,1.0f
,20.0f
}},
64 .co
= {0.0f
,5.0f
,-10.0f
},
69 rigidbody jeff1
= { .type
= k_rb_shape_capsule
,
70 .inf
.capsule
= { .radius
= 0.75f
, .height
= 3.0f
},
71 .co
= {30.0f
, 4.0f
, 30.0f
},
72 .q
= {1.0f
,0.0f
,0.0f
,0.0f
}
75 rigidbody ball
= { .type
= k_rb_shape_sphere
,
76 .inf
.sphere
= { .radius
= 2.0f
},
77 .co
= {0.0f
,20.0f
,2.0f
},
78 .q
= {0.0f
,0.0f
,0.0f
,1.0f
}},
80 ball1
= { .type
= k_rb_shape_sphere
,
81 .inf
.sphere
= { .radius
= 2.0f
},
82 .co
= {0.1f
,25.0f
,0.2f
},
83 .q
= {0.0f
,0.0f
,0.0f
,1.0f
}};
87 static void reorg_jeffs(void)
89 for( int i
=0; i
<vg_list_size(jeffs
); i
++ )
91 v3_copy( (v3f
){ (vg_randf()-0.5f
) * 10.0f
,
92 (vg_randf()-0.5f
) * 10.0f
+ 17.0f
,
93 (vg_randf()-0.5f
) * 10.0f
}, jeffs
[i
].co
);
94 v4_copy( (v4f
){ vg_randf(), vg_randf(), vg_randf(), vg_randf() },
96 q_normalize( jeffs
[i
].q
);
98 jeffs
[i
].type
= k_rb_shape_capsule
;
99 jeffs
[i
].inf
.capsule
.radius
= 0.75f
;
100 jeffs
[i
].inf
.capsule
.height
= 3.0f
;
102 rb_init( &jeffs
[i
] );
106 static void physics_test_start(void)
108 q_axis_angle( funnel
[0].q
, (v3f
){1.0f
,0.0f
,0.0f
}, 0.6f
);
109 q_axis_angle( funnel
[1].q
, (v3f
){1.0f
,0.0f
,0.0f
}, -0.6f
);
110 q_axis_angle( funnel
[2].q
, (v3f
){0.0f
,0.0f
,1.0f
}, 0.6f
);
111 q_axis_angle( funnel
[3].q
, (v3f
){0.0f
,0.0f
,1.0f
}, -0.6f
);
113 for( int i
=0; i
<4; i
++ )
114 rb_init( &funnel
[i
] );
124 scene_init( &epic_scene
);
126 mdl_header
*mdl
= mdl_load( "models/epic_scene.mdl" );
129 m4x3_identity( transform
);
131 for( int i
=0; i
<mdl
->node_count
; i
++ )
133 mdl_node
*pnode
= mdl_node_from_id( mdl
, i
);
135 for( int j
=0; j
<pnode
->submesh_count
; j
++ )
137 mdl_submesh
*sm
= mdl_node_submesh( mdl
, pnode
, j
);
138 scene_add_submesh( &epic_scene
, mdl
, sm
, transform
);
143 scene_bh_create( &epic_scene
);
145 rb_init( &epic_scene_rb
);
149 static void physics_test_update(void)
152 player_camera_update();
154 for( int i
=0; i
<4; i
++ )
155 rb_debug( &funnel
[i
], 0xff0060e0 );
156 rb_debug( &ground
, 0xff00ff00 );
157 rb_debug( &ball
, 0xffe00040 );
158 rb_debug( &ball1
, 0xff00e050 );
160 rb_debug( &blocky
, 0xffcccccc );
161 rb_debug( &jeff1
, 0xff00ffff );
163 rb_debug( &epic_scene_rb
, 0xffcccccc );
164 rb_debug( &marko
, 0xffffcc00 );
170 for( int i
=0; i
<4; i
++ )
172 rigidbody
*fn
= &funnel
[i
];
173 rb_collide( &ball
, fn
);
174 rb_collide( &ball1
, fn
);
175 rb_collide( &jeff1
, fn
);
177 for( int i
=0; i
<vg_list_size(jeffs
); i
++ )
178 rb_collide( jeffs
+i
, fn
);
181 for( int i
=0; i
<vg_list_size(jeffs
)-1; i
++ )
183 for( int j
=i
+1; j
<vg_list_size(jeffs
); j
++ )
185 rb_collide( jeffs
+i
, jeffs
+j
);
189 for( int i
=0; i
<vg_list_size(jeffs
); i
++ )
191 rb_collide( jeffs
+i
, &ground
);
192 rb_collide( jeffs
+i
, &ball
);
193 rb_collide( jeffs
+i
, &ball1
);
194 rb_collide( jeffs
+i
, &jeff1
);
197 rb_collide( &jeff1
, &ground
);
198 rb_collide( &jeff1
, &blocky
);
199 rb_collide( &jeff1
, &ball
);
200 rb_collide( &jeff1
, &ball1
);
202 rb_collide( &ball
, &ground
);
203 rb_collide( &ball1
, &ground
);
204 rb_collide( &ball1
, &ball
);
205 rb_collide( &marko
, &epic_scene_rb
);
207 rb_presolve_contacts( rb_contact_buffer
, rb_contact_count
);
208 for( int i
=0; i
<8; i
++ )
209 rb_solve_contacts( rb_contact_buffer
, rb_contact_count
);
214 for( int i
=0; i
<vg_list_size(jeffs
); i
++ )
216 rb_debug( &jeffs
[i
], (u32
[]){ 0xff0000ff, 0xff00ff00, 0xff00ffff,
217 0xffff0000, 0xffff00ff, 0xffffff00,
228 /* POSITION OVERRIDE */
230 if(glfwGetKey( vg_window
, GLFW_KEY_L
))
232 m4x3_mulv( player
.camera
, (v3f
){0.0f
,0.0f
,-5.0f
}, marko
.co
);
236 if(glfwGetKey( vg_window
, GLFW_KEY_K
))
238 m4x3_mulv( player
.camera
, (v3f
){0.0f
,0.0f
,-5.0f
}, ball
.co
);
242 if(glfwGetKey( vg_window
, GLFW_KEY_J
))
244 m4x3_mulv( player
.camera
, (v3f
){0.0f
,0.0f
,-5.0f
}, ball1
.co
);
249 if(glfwGetKey( vg_window
, GLFW_KEY_H
))
255 /* UPDATE TRANSFORMS */
256 for( int i
=0; i
<vg_list_size(jeffs
); i
++ )
258 rb_update_transform(jeffs
+i
);
261 rb_update_transform( &ball
);
262 rb_update_transform( &ball1
);
263 rb_update_transform( &jeff1
);
264 rb_update_transform( &marko
);
269 static void physics_test_render(void)
272 m4x3_expand( player
.camera_inverse
, world_4x4
);
274 gpipeline
.fov
= 60.0f
;
275 m4x4_projection( vg_pv
, gpipeline
.fov
,
276 (float)vg_window_x
/ (float)vg_window_y
,
279 m4x4_mul( vg_pv
, world_4x4
, vg_pv
);
280 glEnable( GL_DEPTH_TEST
);
282 glDisable( GL_DEPTH_TEST
);
283 vg_lines_drawall( (float *)vg_pv
);
286 #endif /* PHYSICS_TEST_H */