2 * Copyright (C) 2021-2022 Mt.ZERO Software, Harry Godden - All Rights Reserved
11 rigidbody ground
= { .type
= k_rb_shape_box
,
12 .bbx
= {{-100.0f
,-1.0f
,-100.0f
},{100.0f
,0.0f
,100.0f
}},
13 .co
= {0.0f
, 0.0f
, 0.0f
},
14 .q
= {0.0f
,0.0f
,0.0f
,1.0f
},
19 .type
= k_rb_shape_box
,
20 .bbx
= {{-2.0f
,-1.0f
,-3.0f
},{2.0f
,1.0f
,2.0f
}},
21 .co
= {30.0f
,2.0f
,30.0f
},
22 .q
= {0.0f
,0.0f
,0.0f
,1.0f
},
28 .type
= k_rb_shape_box
,
29 .bbx
= {{-0.5f
,-0.5f
,-0.5f
},{0.5f
,0.5f
,0.5f
}},
30 .co
= {-36.0f
,8.0f
,-36.0f
},
31 .q
= {0.0f
,0.0f
,0.0f
,1.0f
},
37 rigidbody epic_scene_rb
=
39 .type
= k_rb_shape_scene
,
40 .co
= {0.0f
,0.0f
,0.0f
},
41 .q
= {0.0f
,0.0f
,0.0f
,1.0f
},
43 .inf
.scene
= { .pscene
= &epic_scene
}
46 rigidbody funnel
[4] = {
48 .type
= k_rb_shape_box
,
49 .bbx
= {{-20.0f
,-1.0f
,-20.0f
},{20.0f
,1.0f
,20.0f
}},
50 .co
= {-10.0f
,5.0f
,0.0f
},
54 .type
= k_rb_shape_box
,
55 .bbx
= {{-20.0f
,-1.0f
,-20.0f
},{20.0f
,1.0f
,20.0f
}},
56 .co
= { 10.0f
,5.0f
,0.0f
},
60 .type
= k_rb_shape_box
,
61 .bbx
= {{-20.0f
,-1.0f
,-20.0f
},{20.0f
,1.0f
,20.0f
}},
62 .co
= { 0.0f
,5.0f
,10.0f
},
66 .type
= k_rb_shape_box
,
67 .bbx
= {{-20.0f
,-1.0f
,-20.0f
},{20.0f
,1.0f
,20.0f
}},
68 .co
= {0.0f
,5.0f
,-10.0f
},
73 rigidbody jeff1
= { .type
= k_rb_shape_capsule
,
74 .inf
.capsule
= { .radius
= 0.75f
, .height
= 3.0f
},
75 .co
= {30.0f
, 4.0f
, 30.0f
},
76 .q
= {1.0f
,0.0f
,0.0f
,0.0f
}
79 rigidbody ball
= { .type
= k_rb_shape_sphere
,
80 .inf
.sphere
= { .radius
= 2.0f
},
81 .co
= {0.0f
,20.0f
,2.0f
},
82 .q
= {0.0f
,0.0f
,0.0f
,1.0f
}},
84 ball1
= { .type
= k_rb_shape_sphere
,
85 .inf
.sphere
= { .radius
= 2.0f
},
86 .co
= {0.1f
,25.0f
,0.2f
},
87 .q
= {0.0f
,0.0f
,0.0f
,1.0f
}};
91 static void reorg_jeffs(void)
93 for( int i
=0; i
<vg_list_size(jeffs
); i
++ )
95 v3_copy( (v3f
){ (vg_randf()-0.5f
) * 10.0f
,
96 (vg_randf()-0.5f
) * 10.0f
+ 17.0f
,
97 (vg_randf()-0.5f
) * 10.0f
}, jeffs
[i
].co
);
98 v4_copy( (v4f
){ vg_randf(), vg_randf(), vg_randf(), vg_randf() },
100 q_normalize( jeffs
[i
].q
);
102 jeffs
[i
].type
= k_rb_shape_capsule
;
103 jeffs
[i
].inf
.capsule
.radius
= 0.75f
;
104 jeffs
[i
].inf
.capsule
.height
= 3.0f
;
106 rb_init( &jeffs
[i
] );
110 static void physics_test_start(void)
112 q_axis_angle( funnel
[0].q
, (v3f
){1.0f
,0.0f
,0.0f
}, 0.6f
);
113 q_axis_angle( funnel
[1].q
, (v3f
){1.0f
,0.0f
,0.0f
}, -0.6f
);
114 q_axis_angle( funnel
[2].q
, (v3f
){0.0f
,0.0f
,1.0f
}, 0.6f
);
115 q_axis_angle( funnel
[3].q
, (v3f
){0.0f
,0.0f
,1.0f
}, -0.6f
);
117 for( int i
=0; i
<4; i
++ )
118 rb_init( &funnel
[i
] );
128 scene_init( &epic_scene
);
130 mdl_header
*mdl
= mdl_load( "models/epic_scene.mdl" );
133 m4x3_identity( transform
);
135 for( int i
=0; i
<mdl
->node_count
; i
++ )
137 mdl_node
*pnode
= mdl_node_from_id( mdl
, i
);
139 for( int j
=0; j
<pnode
->submesh_count
; j
++ )
141 mdl_submesh
*sm
= mdl_node_submesh( mdl
, pnode
, j
);
142 scene_add_submesh( &epic_scene
, mdl
, sm
, transform
);
147 scene_bh_create( &epic_scene
);
149 rb_init( &epic_scene_rb
);
153 static void physics_test_update(void)
156 player_camera_update();
158 for( int i
=0; i
<4; i
++ )
159 rb_debug( &funnel
[i
], 0xff0060e0 );
160 rb_debug( &ground
, 0xff00ff00 );
161 rb_debug( &ball
, 0xffe00040 );
162 rb_debug( &ball1
, 0xff00e050 );
164 rb_debug( &blocky
, 0xffcccccc );
165 rb_debug( &jeff1
, 0xff00ffff );
167 rb_debug( &epic_scene_rb
, 0xffcccccc );
168 rb_debug( &marko
, 0xffffcc00 );
174 for( int i
=0; i
<4; i
++ )
176 rigidbody
*fn
= &funnel
[i
];
177 rb_collide( &ball
, fn
);
178 rb_collide( &ball1
, fn
);
179 rb_collide( &jeff1
, fn
);
181 for( int i
=0; i
<vg_list_size(jeffs
); i
++ )
182 rb_collide( jeffs
+i
, fn
);
185 for( int i
=0; i
<vg_list_size(jeffs
)-1; i
++ )
187 for( int j
=i
+1; j
<vg_list_size(jeffs
); j
++ )
189 rb_collide( jeffs
+i
, jeffs
+j
);
193 for( int i
=0; i
<vg_list_size(jeffs
); i
++ )
195 rb_collide( jeffs
+i
, &ground
);
196 rb_collide( jeffs
+i
, &ball
);
197 rb_collide( jeffs
+i
, &ball1
);
198 rb_collide( jeffs
+i
, &jeff1
);
201 rb_collide( &jeff1
, &ground
);
202 rb_collide( &jeff1
, &blocky
);
203 rb_collide( &jeff1
, &ball
);
204 rb_collide( &jeff1
, &ball1
);
206 rb_collide( &ball
, &ground
);
207 rb_collide( &ball1
, &ground
);
208 rb_collide( &ball1
, &ball
);
209 rb_collide( &marko
, &epic_scene_rb
);
211 rb_presolve_contacts( rb_contact_buffer
, rb_contact_count
);
212 for( int i
=0; i
<8; i
++ )
213 rb_solve_contacts( rb_contact_buffer
, rb_contact_count
);
218 for( int i
=0; i
<vg_list_size(jeffs
); i
++ )
220 rb_debug( &jeffs
[i
], (u32
[]){ 0xff0000ff, 0xff00ff00, 0xff00ffff,
221 0xffff0000, 0xffff00ff, 0xffffff00,
232 /* POSITION OVERRIDE */
234 if(glfwGetKey( vg
.window
, GLFW_KEY_L
))
236 m4x3_mulv( player
.camera
, (v3f
){0.0f
,0.0f
,-5.0f
}, marko
.co
);
240 if(glfwGetKey( vg
.window
, GLFW_KEY_K
))
242 m4x3_mulv( player
.camera
, (v3f
){0.0f
,0.0f
,-5.0f
}, ball
.co
);
246 if(glfwGetKey( vg
.window
, GLFW_KEY_J
))
248 m4x3_mulv( player
.camera
, (v3f
){0.0f
,0.0f
,-5.0f
}, ball1
.co
);
253 if(glfwGetKey( vg
.window
, GLFW_KEY_H
))
259 /* UPDATE TRANSFORMS */
260 for( int i
=0; i
<vg_list_size(jeffs
); i
++ )
262 rb_update_transform(jeffs
+i
);
265 rb_update_transform( &ball
);
266 rb_update_transform( &ball1
);
267 rb_update_transform( &jeff1
);
268 rb_update_transform( &marko
);
273 static void physics_test_render(void)
276 m4x3_expand( player
.camera_inverse
, world_4x4
);
278 gpipeline
.fov
= 60.0f
;
279 m4x4_projection( vg_pv
, gpipeline
.fov
,
280 (float)vg_window_x
/ (float)vg_window_y
,
283 m4x4_mul( vg_pv
, world_4x4
, vg_pv
);
284 glEnable( GL_DEPTH_TEST
);
286 glDisable( GL_DEPTH_TEST
);
287 vg_lines_drawall( (float *)vg_pv
);
290 #endif /* PHYSICS_TEST_H */