+/*
+ * Copyright (C) 2021-2022 Mt.ZERO Software, Harry Godden - All Rights Reserved
+ */
+
#ifndef PHYSICS_TEST_H
#define PHYSICS_TEST_H
.co = {0.0f, 0.0f, 0.0f},
.q = {0.0f,0.0f,0.0f,1.0f},
.is_world = 1 };
+
+rigidbody blocky =
+ {
+ .type = k_rb_shape_box,
+ .bbx = {{-2.0f,-1.0f,-3.0f},{2.0f,1.0f,2.0f}},
+ .co = {30.0f,2.0f,30.0f},
+ .q = {0.0f,0.0f,0.0f,1.0f},
+ .is_world = 1
+ };
+
+rigidbody marko =
+{
+ .type = k_rb_shape_box,
+ .bbx = {{-0.5f,-0.5f,-0.5f},{0.5f,0.5f,0.5f}},
+ .co = {-36.0f,8.0f,-36.0f},
+ .q = {0.0f,0.0f,0.0f,1.0f},
+ .is_world = 0
+};
+
+scene epic_scene;
+
+rigidbody epic_scene_rb =
+{
+ .type = k_rb_shape_scene,
+ .co = {0.0f,0.0f,0.0f},
+ .q = {0.0f,0.0f,0.0f,1.0f},
+ .is_world = 1,
+ .inf.scene = { .pscene = &epic_scene }
+};
+
rigidbody funnel[4] = {
{
.type = k_rb_shape_box,
}
};
+rigidbody jeff1 = { .type = k_rb_shape_capsule,
+ .inf.capsule = { .radius = 0.75f, .height = 3.0f },
+ .co = {30.0f, 4.0f, 30.0f },
+ .q = {1.0f,0.0f,0.0f,0.0f}
+};
rigidbody ball = { .type = k_rb_shape_sphere,
.inf.sphere = { .radius = 2.0f },
- .co = {0.0f,6.0f,0.0f},
+ .co = {0.0f,20.0f,2.0f},
.q = {0.0f,0.0f,0.0f,1.0f}},
ball1= { .type = k_rb_shape_sphere,
- .inf.sphere = { .radius = 1.0f },
- .co = {0.1f,9.0f,0.2f},
+ .inf.sphere = { .radius = 2.0f },
+ .co = {0.1f,25.0f,0.2f},
.q = {0.0f,0.0f,0.0f,1.0f}};
+rigidbody jeffs[16];
+
+static void reorg_jeffs(void)
+{
+ for( int i=0; i<vg_list_size(jeffs); i++ )
+ {
+ v3_copy( (v3f){ (vg_randf()-0.5f) * 10.0f,
+ (vg_randf()-0.5f) * 10.0f + 17.0f,
+ (vg_randf()-0.5f) * 10.0f }, jeffs[i].co );
+ v4_copy( (v4f){ vg_randf(), vg_randf(), vg_randf(), vg_randf() },
+ jeffs[i].q );
+ q_normalize( jeffs[i].q );
+
+ jeffs[i].type = k_rb_shape_capsule;
+ jeffs[i].inf.capsule.radius = 0.75f;
+ jeffs[i].inf.capsule.height = 3.0f;
+
+ rb_init( &jeffs[i] );
+ }
+}
+
static void physics_test_start(void)
{
- q_axis_angle( funnel[0].q, (v3f){1.0f,0.0f,0.0f}, 0.3f );
- q_axis_angle( funnel[1].q, (v3f){1.0f,0.0f,0.0f}, -0.3f );
- q_axis_angle( funnel[2].q, (v3f){0.0f,0.0f,1.0f}, 0.3f );
- q_axis_angle( funnel[3].q, (v3f){0.0f,0.0f,1.0f}, -0.3f );
+ q_axis_angle( funnel[0].q, (v3f){1.0f,0.0f,0.0f}, 0.6f );
+ q_axis_angle( funnel[1].q, (v3f){1.0f,0.0f,0.0f}, -0.6f );
+ q_axis_angle( funnel[2].q, (v3f){0.0f,0.0f,1.0f}, 0.6f );
+ q_axis_angle( funnel[3].q, (v3f){0.0f,0.0f,1.0f}, -0.6f );
for( int i=0; i<4; i++ )
rb_init( &funnel[i] );
+ reorg_jeffs();
+
rb_init( &ground );
rb_init( &ball );
rb_init( &ball1 );
+ rb_init( &jeff1 );
+ rb_init( &blocky );
+
+ scene_init( &epic_scene );
+
+ mdl_header *mdl = mdl_load( "models/epic_scene.mdl" );
+
+ m4x3f transform;
+ m4x3_identity( transform );
+
+ for( int i=0; i<mdl->node_count; i++ )
+ {
+ mdl_node *pnode = mdl_node_from_id( mdl, i );
+
+ for( int j=0; j<pnode->submesh_count; j++ )
+ {
+ mdl_submesh *sm = mdl_node_submesh( mdl, pnode, j );
+ scene_add_submesh( &epic_scene, mdl, sm, transform );
+ }
+ }
+
+ vg_free( mdl );
+ scene_bh_create( &epic_scene );
+
+ rb_init( &epic_scene_rb );
+ rb_init( &marko );
}
static void physics_test_update(void)
player_freecam();
player_camera_update();
- {
+ for( int i=0; i<4; i++ )
+ rb_debug( &funnel[i], 0xff0060e0 );
+ rb_debug( &ground, 0xff00ff00 );
+ rb_debug( &ball, 0xffe00040 );
+ rb_debug( &ball1, 0xff00e050 );
- rb_iter( &ball );
- rb_iter( &ball1 );
+ rb_debug( &blocky, 0xffcccccc );
+ rb_debug( &jeff1, 0xff00ffff );
+
+ rb_debug( &epic_scene_rb, 0xffcccccc );
+ rb_debug( &marko, 0xffffcc00 );
+
+ {
rb_solver_reset();
for( int i=0; i<4; i++ )
{
- rb_contact_count += rb_sphere_vs_box( &ball, &funnel[i], rb_global_ct());
- rb_contact_count += rb_sphere_vs_box( &ball1, &funnel[i], rb_global_ct());
+ rigidbody *fn = &funnel[i];
+ rb_collide( &ball, fn );
+ rb_collide( &ball1, fn );
+ rb_collide( &jeff1, fn );
+
+ for( int i=0; i<vg_list_size(jeffs); i++ )
+ rb_collide( jeffs+i, fn );
}
- rb_contact_count += rb_sphere_vs_box( &ball, &ground, rb_global_ct() );
- rb_contact_count += rb_sphere_vs_box( &ball1, &ground, rb_global_ct() );
- rb_contact_count += rb_sphere_vs_sphere( &ball, &ball1, rb_global_ct() );
+ for( int i=0; i<vg_list_size(jeffs)-1; i++ )
+ {
+ for( int j=i+1; j<vg_list_size(jeffs); j++ )
+ {
+ rb_collide( jeffs+i, jeffs+j );
+ }
+ }
- rb_presolve_contacts();
+ for( int i=0; i<vg_list_size(jeffs); i++ )
+ {
+ rb_collide( jeffs+i, &ground );
+ rb_collide( jeffs+i, &ball );
+ rb_collide( jeffs+i, &ball1 );
+ rb_collide( jeffs+i, &jeff1 );
+ }
- for( int i=0; i<5; i++ )
- rb_solve_contacts();
+ rb_collide( &jeff1, &ground );
+ rb_collide( &jeff1, &blocky );
+ rb_collide( &jeff1, &ball );
+ rb_collide( &jeff1, &ball1 );
- rb_update_transform( &ball );
- rb_update_transform( &ball1 );
+ rb_collide( &ball, &ground );
+ rb_collide( &ball1, &ground );
+ rb_collide( &ball1, &ball );
+ rb_collide( &marko, &epic_scene_rb );
+ rb_presolve_contacts( rb_contact_buffer, rb_contact_count );
+ for( int i=0; i<8; i++ )
+ rb_solve_contacts( rb_contact_buffer, rb_contact_count );
+
+
+ /* ITERATE */
+ {
+ for( int i=0; i<vg_list_size(jeffs); i++ )
+ {
+ rb_debug( &jeffs[i], (u32[]){ 0xff0000ff, 0xff00ff00, 0xff00ffff,
+ 0xffff0000, 0xffff00ff, 0xffffff00,
+ }[i%6] );
+ rb_iter( jeffs+i );
}
- if(glfwGetKey( vg_window, GLFW_KEY_L ))
+ rb_iter( &ball );
+ rb_iter( &ball1 );
+ rb_iter( &jeff1 );
+ rb_iter( &marko );
+ }
+
+ /* POSITION OVERRIDE */
{
- v3_copy( player.camera_pos, ball.co );
+ if(glfwGetKey( vg.window, GLFW_KEY_L ))
+ {
+ m4x3_mulv( player.camera, (v3f){0.0f,0.0f,-5.0f}, marko.co );
+ v3_zero( marko.v );
+ v3_zero( marko.w );
+ }
+ if(glfwGetKey( vg.window, GLFW_KEY_K ))
+ {
+ m4x3_mulv( player.camera, (v3f){0.0f,0.0f,-5.0f}, ball.co );
v3_zero( ball.v );
v3_zero( ball.w );
}
+ if(glfwGetKey( vg.window, GLFW_KEY_J ))
+ {
+ m4x3_mulv( player.camera, (v3f){0.0f,0.0f,-5.0f}, ball1.co );
+ v3_zero( ball1.v );
+ v3_zero( ball1.w );
+ }
+
+ if(glfwGetKey( vg.window, GLFW_KEY_H ))
+ {
+ reorg_jeffs();
+ }
+ }
- for( int i=0; i<4; i++ )
- rb_debug( &funnel[i], 0xff0060e0 );
- rb_debug( &ground, 0xff00ff00 );
- rb_debug( &ball, 0xffe00040 );
- rb_debug( &ball1, 0xff00e050 );
+ /* UPDATE TRANSFORMS */
+ for( int i=0; i<vg_list_size(jeffs); i++ )
+ {
+ rb_update_transform(jeffs+i);
+ }
+
+ rb_update_transform( &ball );
+ rb_update_transform( &ball1 );
+ rb_update_transform( &jeff1 );
+ rb_update_transform( &marko );
+
+ }
}
static void physics_test_render(void)
m4x4f world_4x4;
m4x3_expand( player.camera_inverse, world_4x4 );
- gpipeline.fov = freecam? 60.0f: 135.0f; /* 120 */
+ gpipeline.fov = 60.0f;
m4x4_projection( vg_pv, gpipeline.fov,
(float)vg_window_x / (float)vg_window_y,
0.1f, 2100.0f );