acf4ed3cd96c6e46183b3995a81093075a51601d
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
= {{-2.0f
,-2.0f
,-2.0f
},{2.0f
,2.0f
,2.0f
}},
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
= 4.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_zero( jeffs
[i
].v
);
92 v3_zero( jeffs
[i
].w
);
93 v3_copy( (v3f
){ (vg_randf()-0.5f
) * 10.0f
,
94 (vg_randf()-0.5f
) * 10.0f
+ 17.0f
,
95 (vg_randf()-0.5f
) * 10.0f
}, jeffs
[i
].co
);
96 v4_copy( (v4f
){ vg_randf(), vg_randf(), vg_randf(), vg_randf() },
98 q_normalize( jeffs
[i
].q
);
100 jeffs
[i
].type
= k_rb_shape_capsule
;
101 jeffs
[i
].inf
.capsule
.radius
= 0.75f
;
102 jeffs
[i
].inf
.capsule
.height
= 8.0f
;
104 rb_init( &jeffs
[i
] );
108 static void physics_test_start(void)
110 q_axis_angle( funnel
[0].q
, (v3f
){1.0f
,0.0f
,0.0f
}, 0.6f
);
111 q_axis_angle( funnel
[1].q
, (v3f
){1.0f
,0.0f
,0.0f
}, -0.6f
);
112 q_axis_angle( funnel
[2].q
, (v3f
){0.0f
,0.0f
,1.0f
}, 0.6f
);
113 q_axis_angle( funnel
[3].q
, (v3f
){0.0f
,0.0f
,1.0f
}, -0.6f
);
115 for( int i
=0; i
<4; i
++ )
116 rb_init( &funnel
[i
] );
126 scene_init( &epic_scene
);
128 mdl_header
*mdl
= mdl_load( "models/epic_scene.mdl" );
131 m4x3_identity( transform
);
133 for( int i
=0; i
<mdl
->node_count
; i
++ )
135 mdl_node
*pnode
= mdl_node_from_id( mdl
, i
);
137 for( int j
=0; j
<pnode
->submesh_count
; j
++ )
139 mdl_submesh
*sm
= mdl_node_submesh( mdl
, pnode
, j
);
140 scene_add_submesh( &epic_scene
, mdl
, sm
, transform
);
145 scene_bh_create( &epic_scene
);
147 rb_init( &epic_scene_rb
);
151 static void physics_test_update(void)
154 player_camera_update();
156 for( int i
=0; i
<4; i
++ )
157 rb_debug( &funnel
[i
], 0xff0060e0 );
158 rb_debug( &ground
, 0xff00ff00 );
159 rb_debug( &ball
, 0xffe00040 );
160 rb_debug( &ball1
, 0xff00e050 );
162 rb_debug( &blocky
, 0xffcccccc );
163 rb_debug( &jeff1
, 0xff00ffff );
165 rb_debug( &epic_scene_rb
, 0xffcccccc );
166 rb_debug( &marko
, 0xffffcc00 );
172 for( int i
=0; i
<4; i
++ )
174 rigidbody
*fn
= &funnel
[i
];
175 rb_collide( &ball
, fn
);
176 rb_collide( &ball1
, fn
);
177 rb_collide( &jeff1
, fn
);
179 for( int i
=0; i
<vg_list_size(jeffs
); i
++ )
180 rb_collide( jeffs
+i
, fn
);
183 for( int i
=0; i
<vg_list_size(jeffs
)-1; i
++ )
185 for( int j
=i
+1; j
<vg_list_size(jeffs
); j
++ )
187 rb_collide( jeffs
+i
, jeffs
+j
);
191 for( int i
=0; i
<vg_list_size(jeffs
); i
++ )
193 rb_collide( jeffs
+i
, &ground
);
194 rb_collide( jeffs
+i
, &ball
);
195 rb_collide( jeffs
+i
, &ball1
);
196 rb_collide( jeffs
+i
, &jeff1
);
199 rb_collide( &jeff1
, &ground
);
200 rb_collide( &jeff1
, &blocky
);
201 rb_collide( &jeff1
, &ball
);
202 rb_collide( &jeff1
, &ball1
);
204 rb_collide( &ball
, &ground
);
205 rb_collide( &ball1
, &ground
);
206 rb_collide( &ball1
, &ball
);
207 rb_collide( &marko
, &epic_scene_rb
);
209 rb_presolve_contacts( rb_contact_buffer
, rb_contact_count
);
210 for( int i
=0; i
<8; i
++ )
211 rb_solve_contacts( rb_contact_buffer
, rb_contact_count
);
216 for( int i
=0; i
<vg_list_size(jeffs
); i
++ )
218 rb_debug( &jeffs
[i
], (u32
[]){ 0xff0000ff, 0xff00ff00, 0xff00ffff,
219 0xffff0000, 0xffff00ff, 0xffffff00,
230 /* POSITION OVERRIDE */
232 if(glfwGetKey( vg_window
, GLFW_KEY_L
))
234 m4x3_mulv( player
.camera
, (v3f
){0.0f
,0.0f
,-5.0f
}, marko
.co
);
238 if(glfwGetKey( vg_window
, GLFW_KEY_K
))
240 m4x3_mulv( player
.camera
, (v3f
){0.0f
,0.0f
,-5.0f
}, ball
.co
);
244 if(glfwGetKey( vg_window
, GLFW_KEY_J
))
246 m4x3_mulv( player
.camera
, (v3f
){0.0f
,0.0f
,-5.0f
}, ball1
.co
);
251 if(glfwGetKey( vg_window
, GLFW_KEY_H
))
257 /* UPDATE TRANSFORMS */
258 for( int i
=0; i
<vg_list_size(jeffs
); i
++ )
260 rb_update_transform(jeffs
+i
);
263 rb_update_transform( &ball
);
264 rb_update_transform( &ball1
);
265 rb_update_transform( &jeff1
);
266 rb_update_transform( &marko
);
271 static void physics_test_render(void)
274 m4x3_expand( player
.camera_inverse
, world_4x4
);
276 gpipeline
.fov
= 60.0f
;
277 m4x4_projection( vg_pv
, gpipeline
.fov
,
278 (float)vg_window_x
/ (float)vg_window_y
,
281 m4x4_mul( vg_pv
, world_4x4
, vg_pv
);
282 glEnable( GL_DEPTH_TEST
);
284 glDisable( GL_DEPTH_TEST
);
285 vg_lines_drawall( (float *)vg_pv
);
288 #endif /* PHYSICS_TEST_H */