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
},
22 rigidbody funnel
[4] = {
24 .type
= k_rb_shape_box
,
25 .bbx
= {{-20.0f
,-1.0f
,-20.0f
},{20.0f
,1.0f
,20.0f
}},
26 .co
= {-10.0f
,5.0f
,0.0f
},
30 .type
= k_rb_shape_box
,
31 .bbx
= {{-20.0f
,-1.0f
,-20.0f
},{20.0f
,1.0f
,20.0f
}},
32 .co
= { 10.0f
,5.0f
,0.0f
},
36 .type
= k_rb_shape_box
,
37 .bbx
= {{-20.0f
,-1.0f
,-20.0f
},{20.0f
,1.0f
,20.0f
}},
38 .co
= { 0.0f
,5.0f
,10.0f
},
42 .type
= k_rb_shape_box
,
43 .bbx
= {{-20.0f
,-1.0f
,-20.0f
},{20.0f
,1.0f
,20.0f
}},
44 .co
= {0.0f
,5.0f
,-10.0f
},
49 rigidbody jeff1
= { .type
= k_rb_shape_capsule
,
50 .inf
.capsule
= { .radius
= 0.75f
, .height
= 3.0f
},
51 .co
= {30.0f
, 4.0f
, 30.0f
},
52 .q
= {0.0f
,0.0f
,0.0f
,1.0f
}
55 rigidbody ball
= { .type
= k_rb_shape_sphere
,
56 .inf
.sphere
= { .radius
= 2.0f
},
57 .co
= {0.0f
,6.0f
,0.0f
},
58 .q
= {0.0f
,0.0f
,0.0f
,1.0f
}},
60 ball1
= { .type
= k_rb_shape_sphere
,
61 .inf
.sphere
= { .radius
= 1.0f
},
62 .co
= {0.1f
,9.0f
,0.2f
},
63 .q
= {0.0f
,0.0f
,0.0f
,1.0f
}};
65 static void physics_test_start(void)
67 q_axis_angle( funnel
[0].q
, (v3f
){1.0f
,0.0f
,0.0f
}, 0.3f
);
68 q_axis_angle( funnel
[1].q
, (v3f
){1.0f
,0.0f
,0.0f
}, -0.3f
);
69 q_axis_angle( funnel
[2].q
, (v3f
){0.0f
,0.0f
,1.0f
}, 0.3f
);
70 q_axis_angle( funnel
[3].q
, (v3f
){0.0f
,0.0f
,1.0f
}, -0.3f
);
72 for( int i
=0; i
<4; i
++ )
73 rb_init( &funnel
[i
] );
82 static void physics_test_update(void)
85 player_camera_update();
95 for( int i
=0; i
<4; i
++ )
97 rb_contact_count
+= rb_sphere_vs_box( &ball
, &funnel
[i
], rb_global_ct());
98 rb_contact_count
+= rb_sphere_vs_box( &ball1
, &funnel
[i
], rb_global_ct());
101 rb_contact_count
+= rb_sphere_vs_box( &ball
, &ground
, rb_global_ct() );
102 rb_contact_count
+= rb_sphere_vs_box( &ball1
, &ground
, rb_global_ct() );
103 rb_contact_count
+= rb_sphere_vs_sphere( &ball
, &ball1
, rb_global_ct() );
105 rb_contact_count
+= rb_capsule_vs_box( &jeff1
, &ground
, rb_global_ct() );
106 rb_contact_count
+= rb_capsule_vs_box( &jeff1
, &blocky
, rb_global_ct() );
108 rb_presolve_contacts( rb_contact_buffer
, rb_contact_count
);
110 for( int i
=0; i
<5; i
++ )
111 rb_solve_contacts( rb_contact_buffer
, rb_contact_count
);
113 rb_update_transform( &ball
);
114 rb_update_transform( &ball1
);
115 rb_update_transform( &jeff1
);
119 if(glfwGetKey( vg_window
, GLFW_KEY_L
))
121 v3_copy( player
.camera_pos
, jeff1
.co
);
126 for( int i
=0; i
<4; i
++ )
127 rb_debug( &funnel
[i
], 0xff0060e0 );
128 rb_debug( &ground
, 0xff00ff00 );
129 rb_debug( &ball
, 0xffe00040 );
130 rb_debug( &ball1
, 0xff00e050 );
132 rb_debug( &blocky
, 0xffcccccc );
133 rb_debug( &jeff1
, 0xff00ffff );
136 static void physics_test_render(void)
139 m4x3_expand( player
.camera_inverse
, world_4x4
);
141 gpipeline
.fov
= 60.0f
;
142 m4x4_projection( vg_pv
, gpipeline
.fov
,
143 (float)vg_window_x
/ (float)vg_window_y
,
146 m4x4_mul( vg_pv
, world_4x4
, vg_pv
);
147 glEnable( GL_DEPTH_TEST
);
149 glDisable( GL_DEPTH_TEST
);
150 vg_lines_drawall( (float *)vg_pv
);
153 #endif /* PHYSICS_TEST_H */