#[macro_use]
extern crate log;
extern crate simple_logger;
use specs::world::{Builder, World};
use specs_physics::{
colliders::Shape,
events::ContactEvents,
nalgebra::Isometry3,
nphysics::{algebra::Velocity3, object::BodyStatus},
physics_dispatcher,
PhysicsBodyBuilder,
PhysicsColliderBuilder,
SimplePosition,
};
fn main() {
simple_logger::init().unwrap();
let mut world = World::new();
let mut dispatcher = physics_dispatcher::<f32, SimplePosition<f32>>();
dispatcher.setup(&mut world.res);
let mut contact_event_reader = world.res.fetch_mut::<ContactEvents>().register_reader();
world
.create_entity()
.with(SimplePosition::<f32>(Isometry3::<f32>::translation(
1.0, 1.0, 1.0,
)))
.with(
PhysicsBodyBuilder::<f32>::from(BodyStatus::Dynamic)
.velocity(Velocity3::linear(1.0, 0.0, 0.0))
.build(),
)
.with(PhysicsColliderBuilder::<f32>::from(Shape::Rectangle(2.0, 2.0, 1.0)).build())
.build();
world
.create_entity()
.with(SimplePosition::<f32>(Isometry3::<f32>::translation(
3.0, 1.0, 1.0,
)))
.with(PhysicsBodyBuilder::<f32>::from(BodyStatus::Static).build())
.with(PhysicsColliderBuilder::<f32>::from(Shape::Rectangle(2.0, 2.0, 1.0)).build())
.build();
dispatcher.dispatch(&world.res);
let contact_events = world.read_resource::<ContactEvents>();
for contact_event in contact_events.read(&mut contact_event_reader) {
info!("Read ContactEvent from channel: {:?}", contact_event);
}
}