use bullet_physics::dynamics::{PhysicsWorld, RigidBody};
use bullet_physics::math::{Real, Vector3};
use bullet_physics::shapes::CollisionShape;
fn main() {
let mut world = PhysicsWorld::new();
world.set_gravity(Vector3::new(0.0, -9.81, 0.0));
world.solver_info_mut().num_iterations = 20;
let ground = RigidBody::new_static(CollisionShape::plane(Vector3::Y, 0.0), Vector3::ZERO);
world.add_body(ground);
let capsule = RigidBody::new_dynamic(
CollisionShape::capsule(0.5, 1.0),
Vector3::new(0.0, 5.0, 0.0),
1.0,
)
.friction(0.6);
let capsule = world.add_body(capsule);
let sphere = RigidBody::new_dynamic(
CollisionShape::sphere(0.5),
Vector3::new(1.0, 6.0, 0.0),
1.0,
)
.friction(0.6);
let sphere = world.add_body(sphere);
let dt: Real = 1.0 / 60.0;
let mut time: Real = 0.0;
println!("t cap_y sph_y");
while time < 5.0 {
world.step_simulation(dt);
time += dt;
let cy = world.body(capsule).position.y;
let sy = world.body(sphere).position.y;
if (time * 60.0).round() as i64 % 30 == 0 {
println!("{:.2} {:6.3} {:6.3}", time, cy, sy);
}
}
let cy = world.body(capsule).position.y;
let sy = world.body(sphere).position.y;
println!("final cap_y = {cy:.4} (expected ~1.5), sph_y = {sy:.4} (expected ~0.5)");
assert!((cy - 1.5).abs() < 0.1, "capsule did not settle: y = {cy}");
assert!((sy - 0.5).abs() < 0.1, "sphere did not settle: y = {sy}");
println!("OK: capsule and sphere settled on the plane.");
}