update helpers/location to 'frosted' ui
[carveJwlIkooP6JGAAIwe30JlM.git] / physics_test.h
index 8143c1d02d4bc4814423cb3cc8389675e70ba48e..243de364933859c3d08881c5584fcf9295cfba08 100644 (file)
@@ -1,3 +1,7 @@
+/*
+ * Copyright (C) 2021-2022 Mt.ZERO Software, Harry Godden - All Rights Reserved
+ */
+
 #ifndef PHYSICS_TEST_H
 #define PHYSICS_TEST_H
 
@@ -19,6 +23,26 @@ rigidbody blocky =
       .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,
@@ -100,6 +124,30 @@ static void physics_test_start(void)
    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)
@@ -107,7 +155,6 @@ 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 );
@@ -117,97 +164,110 @@ static void physics_test_update(void)
    rb_debug( &blocky, 0xffcccccc );
    rb_debug( &jeff1, 0xff00ffff );
 
-   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 );
-   }
+   rb_debug( &epic_scene_rb, 0xffcccccc );
+   rb_debug( &marko, 0xffffcc00 );
 
    {
 
-   rb_iter( &ball );
-   rb_iter( &ball1 );
-   rb_iter( &jeff1 );
-
    rb_solver_reset();
 
    for( int i=0; i<4; i++ )
    {
       rigidbody *fn = &funnel[i];
-      rb_contact_count += rb_sphere_vs_box( &ball, fn, rb_global_ct());
-      rb_contact_count += rb_sphere_vs_box( &ball1, fn, rb_global_ct());
-      rb_contact_count += rb_capsule_vs_box( &jeff1, fn, rb_global_ct() );
+      rb_collide( &ball, fn );
+      rb_collide( &ball1, fn );
+      rb_collide( &jeff1, fn );
 
       for( int i=0; i<vg_list_size(jeffs); i++ )
-         rb_contact_count += rb_capsule_vs_box( jeffs+i, fn, rb_global_ct() );
+         rb_collide( jeffs+i, fn );
    }
 
    for( int i=0; i<vg_list_size(jeffs)-1; i++ )
    {
       for( int j=i+1; j<vg_list_size(jeffs); j++ )
       {
-         rb_contact_count += rb_capsule_vs_capsule( jeffs+i, jeffs+j, 
-               rb_global_ct() );
+         rb_collide( jeffs+i, jeffs+j );
       }
    }
 
    for( int i=0; i<vg_list_size(jeffs); i++ )
    {
-      rb_contact_count += rb_capsule_vs_box( jeffs+i, &ground, rb_global_ct() );
-      rb_contact_count += rb_capsule_vs_sphere( jeffs+i, &ball, rb_global_ct() );
-      rb_contact_count += rb_capsule_vs_sphere( jeffs+i, &ball1, rb_global_ct() );
-      rb_contact_count += rb_capsule_vs_capsule( jeffs+i, &jeff1, rb_global_ct() );
+      rb_collide( jeffs+i, &ground );
+      rb_collide( jeffs+i, &ball );
+      rb_collide( jeffs+i, &ball1 );
+      rb_collide( jeffs+i, &jeff1 );
    }
 
-   rb_contact_count += rb_capsule_vs_box( &jeff1, &ground, rb_global_ct() );
-   rb_contact_count += rb_capsule_vs_box( &jeff1, &blocky, rb_global_ct() );
-   rb_contact_count += rb_capsule_vs_sphere( &jeff1, &ball, rb_global_ct() );
-   rb_contact_count += rb_capsule_vs_sphere( &jeff1, &ball1, rb_global_ct() );
+   rb_collide( &jeff1, &ground );
+   rb_collide( &jeff1, &blocky );
+   rb_collide( &jeff1, &ball );
+   rb_collide( &jeff1, &ball1 );
 
-   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( &ball1, &ball, rb_global_ct() );
+   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_update_transform(jeffs+i);
+      rb_debug( &jeffs[i], (u32[]){ 0xff0000ff, 0xff00ff00, 0xff00ffff,
+                                   0xffff0000, 0xffff00ff, 0xffffff00,
+                                   }[i%6] );
+      rb_iter( jeffs+i );
    }
 
-   rb_update_transform( &ball );
-   rb_update_transform( &ball1 );
-   rb_update_transform( &jeff1 );
-
+   rb_iter( &ball );
+   rb_iter( &ball1 );
+   rb_iter( &jeff1 );
+   rb_iter( &marko );
    }
-
-   if(glfwGetKey( vg_window, GLFW_KEY_L ))
+   
+   /* POSITION OVERRIDE */
    {
-      m4x3_mulv( player.camera, (v3f){0.0f,0.0f,-5.0f}, jeff1.co );
-      v3_zero( jeff1.v );
-      v3_zero( jeff1.w );
+   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 ))
+   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 ))
+   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 ))
+   if(glfwGetKey( vg.window, GLFW_KEY_H ))
    {
       reorg_jeffs();
    }
+   }
+   
+   /* 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)