more physics shapes
[carveJwlIkooP6JGAAIwe30JlM.git] / physics_test.h
index bd8bc073acaf68a392495b40ceac7765a12aa173..8143c1d02d4bc4814423cb3cc8389675e70ba48e 100644 (file)
@@ -49,29 +49,52 @@ rigidbody funnel[4] = {
 rigidbody jeff1 = { .type = k_rb_shape_capsule,
                     .inf.capsule = { .radius = 0.75f, .height = 3.0f },
                     .co = {30.0f, 4.0f, 30.0f },
-                    .q = {0.0f,0.0f,0.0f,1.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 );
@@ -84,6 +107,24 @@ 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_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_iter( &ball );
@@ -94,22 +135,50 @@ static void physics_test_update(void)
 
    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_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() );
+
+      for( int i=0; i<vg_list_size(jeffs); i++ )
+         rb_contact_count += rb_capsule_vs_box( jeffs+i, fn, rb_global_ct() );
    }
 
-   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_contact_count += rb_capsule_vs_capsule( jeffs+i, jeffs+j, 
+               rb_global_ct() );
+      }
+   }
+
+   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_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_presolve_contacts( rb_contact_buffer, rb_contact_count );
+   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() );
 
-   for( int i=0; i<5; i++ )
+   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 );
 
+   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 );
@@ -118,19 +187,27 @@ static void physics_test_update(void)
 
    if(glfwGetKey( vg_window, GLFW_KEY_L ))
    {
-      v3_copy( player.camera_pos, jeff1.co );
+      m4x3_mulv( player.camera, (v3f){0.0f,0.0f,-5.0f}, jeff1.co );
       v3_zero( jeff1.v );
       v3_zero( jeff1.w );
    }
-   
-   for( int i=0; i<4; i++ )
-      rb_debug( &funnel[i], 0xff0060e0 );
-   rb_debug( &ground, 0xff00ff00 );
-   rb_debug( &ball, 0xffe00040 );
-   rb_debug( &ball1, 0xff00e050 );
+   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 );
+   }
 
-   rb_debug( &blocky, 0xffcccccc );
-   rb_debug( &jeff1, 0xff00ffff );
+   if(glfwGetKey( vg_window, GLFW_KEY_H ))
+   {
+      reorg_jeffs();
+   }
 }
 
 static void physics_test_render(void)