use oxiphysics::pipeline::PhysicsPipeline;
use oxiphysics_core::{Transform, math::Vec3};
use oxiphysics_geometry::{BoxShape, Shape, Sphere};
use oxiphysics_rigid::{Collider, ColliderSet, RigidBody, RigidBodySet};
use std::sync::Arc;
fn main() {
let mut pipeline = PhysicsPipeline::new();
let mut bodies = RigidBodySet::new();
let mut colliders = ColliderSet::new();
let mut floor_body = RigidBody::new_static();
floor_body.transform = Transform::from_position(Vec3::new(0.0, -0.5, 0.0));
let floor_h = bodies.insert(floor_body);
let floor_shape: Arc<dyn Shape> = Arc::new(BoxShape::new(Vec3::new(50.0, 0.5, 50.0)));
colliders.insert(Collider::new(floor_shape).with_body(floor_h));
let radius = 0.25_f64;
let dyn_shape: Arc<dyn Shape> = Arc::new(Sphere::new(radius));
let mut box_handles = Vec::with_capacity(10);
for i in 0..10 {
let x = (i as f64 - 4.5) * 0.7;
let mut b = RigidBody::new(1.0);
b.transform = Transform::from_position(Vec3::new(x, 1.5, 0.0));
b.linear_damping = 0.02;
let h = bodies.insert(b);
colliders.insert(
Collider::new(Arc::clone(&dyn_shape))
.with_body(h)
.with_restitution(0.2),
);
box_handles.push(h);
}
let dt = 1.0 / 120.0;
let steps = (5.0 / dt) as usize;
for _ in 0..steps {
pipeline.step(dt, &mut bodies, &colliders);
}
println!("=== falling_boxes: final positions after 5 s ===");
let mut all_above = true;
for (idx, &h) in box_handles.iter().enumerate() {
if let Some(b) = bodies.get(h) {
let pos = b.transform.position;
println!(" box {:2}: y = {:.4}", idx, pos.y);
if pos.y < -2.0 {
all_above = false;
println!(" FAIL: box {} fell below y=-2.0 (y={:.4})", idx, pos.y);
}
}
}
if all_above {
println!("PASS: All boxes above floor");
}
}