#![feature(get_many_mut)] use bevy::{prelude::*, sprite::MaterialMesh2dBundle}; use rox2d::rox2d::*; #[derive(Debug, Resource)] struct World { inner: rox2d::World, } #[derive(Debug, Component)] struct Body { body_id: usize, } impl Default for World { fn default() -> Self { let world = rox2d::World::new(rox2d::Vec2::new(0.0, -9.81), 5); Self { inner: world } } } fn main() { App::new() .init_resource::() .add_plugins(DefaultPlugins) .add_startup_system(setup) .add_system(update) .run(); } fn setup( mut commands: Commands, mut meshes: ResMut>, mut materials: ResMut>, mut world: ResMut, ) { commands.spawn(Camera2dBundle::default()); // Rectangle commands.spawn(SpriteBundle { sprite: Sprite { color: Color::rgb(0.25, 0.25, 0.75), custom_size: Some(bevy::prelude::Vec2::new(50.0, 100.0)), ..default() }, ..default() }); // Circle commands.spawn(MaterialMesh2dBundle { mesh: meshes.add(shape::Circle::new(50.).into()).into(), material: materials.add(ColorMaterial::from(Color::PURPLE)), transform: Transform::from_translation(Vec3::new(-100., 0., 0.)), ..default() }); let body_id = world .inner .add_body(rox2d::Body::new(rox2d::Vec2::new(20.0, 20.0), 100.0)); // Hexagon commands.spawn(( MaterialMesh2dBundle { mesh: meshes.add(shape::RegularPolygon::new(50., 6).into()).into(), material: materials.add(ColorMaterial::from(Color::TURQUOISE)), transform: Transform::from_translation(Vec3::new(100., 0., 0.)), ..default() }, Body { body_id }, )); } fn update( time: Res