diff --git a/README.md b/README.md deleted file mode 100644 index 44b1874..0000000 --- a/README.md +++ /dev/null @@ -1,17 +0,0 @@ -## Feuille de route -* Créer deuxième planète -* Gravité naïve - * Vitesse - * Poids -* Faire un système solaire (trouver valeurs) -* Quadtree -* Réutiliser les mêmes Mesh et Material (augmente FPS en dézoom) -* Générer un mesh avec noise -* Générer plusieurs meshes -* (?) Collision - * Détection - * Double boucle naïve - * Intégré au quadtree - * Fusion simple - * Fragmentation - * Cratère diff --git a/src/gen.rs b/src/gen.rs index 4de5e64..32243d7 100644 --- a/src/gen.rs +++ b/src/gen.rs @@ -17,7 +17,7 @@ pub fn planet() -> Mesh { let a = std::f32::consts::TAU * i as f32 / perimeter as f32; [r * a.cos(), r * a.sin(), 0.] }) - .chain([[0., 0., 0.]]) + .chain([[0., 0., 0.]].into_iter()) .collect::>(), ); let mut triangles = Vec::new(); diff --git a/src/main.rs b/src/main.rs index 2ee5d7e..097c611 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,11 +1,7 @@ mod gen; mod quadtree; -use bevy::{ - ecs::query::BatchingStrategy, - prelude::*, - sprite::{MaterialMesh2dBundle, Mesh2dHandle}, -}; +use bevy::{ecs::query::BatchingStrategy, prelude::*, sprite::MaterialMesh2dBundle}; #[global_allocator] static ALLOCATOR: cap::Cap = @@ -42,70 +38,47 @@ fn setup( .spawn(Camera2dBundle::default()) .insert(bevy_pancam::PanCam::default()); - let red = materials.add(ColorMaterial::from(Color::RED)); - let circle_5: Mesh2dHandle = meshes.add(shape::Circle::new(5.).into()).into(); - - commands - .spawn(Planet { - pos: TransformBundle::from(Transform::from_translation(Vec3::new(0., 0., 0.))), - mass: Mass(1.988e18), - speed: Speed(Vec2::new(0.0, 0.0)), - visibility: InheritedVisibility::VISIBLE, - }) - .with_children(|parent| { - parent.spawn(MaterialMesh2dBundle { - mesh: meshes.add(gen::planet()).into(), - material: materials.add(ColorMaterial::from(Color::YELLOW)), - ..default() - }); - }); - commands - .spawn(Planet { - pos: TransformBundle::from(Transform::from_translation(Vec3::new(400., 0., 0.))), - mass: Mass(5.9736e14), - speed: Speed(Vec2::new(0.0, 500.0)), - visibility: InheritedVisibility::VISIBLE, - }) - .with_children(|parent| { - parent.spawn(MaterialMesh2dBundle { - mesh: meshes.add(shape::Circle::new(10.).into()).into(), - material: materials.add(ColorMaterial::from(Color::BLUE)), - ..default() - }); - }); - commands - .spawn(Planet { - pos: TransformBundle::from(Transform::from_translation(Vec3::new(-400., 0., 0.))), - mass: Mass(5.9736e14), - speed: Speed(Vec2::new(0.0, -500.0)), - visibility: InheritedVisibility::VISIBLE, - }) - .with_children(|parent| { - parent.spawn(MaterialMesh2dBundle { - mesh: meshes.add(shape::Circle::new(10.).into()).into(), - material: materials.add(ColorMaterial::from(Color::BLUE)), - ..default() - }); - }); + commands.spawn(Planet { + mass: Mass(1.988e18), + speed: Speed(Vec2::new(0.0, 0.0)), + mesh: MaterialMesh2dBundle { + mesh: meshes.add(gen::planet()).into(), + material: materials.add(ColorMaterial::from(Color::YELLOW)), + transform: Transform::from_translation(Vec3::new(0., 0., 0.)), + ..default() + }, + }); + commands.spawn(Planet { + mass: Mass(5.9736e14), + speed: Speed(Vec2::new(0.0, 500.0)), + mesh: MaterialMesh2dBundle { + mesh: meshes.add(shape::Circle::new(10.).into()).into(), + material: materials.add(ColorMaterial::from(Color::BLUE)), + transform: Transform::from_translation(Vec3::new(400., 0., 0.)), + ..default() + }, + }); + commands.spawn(Planet { + mass: Mass(5.9736e14), + speed: Speed(Vec2::new(0.0, -500.0)), + mesh: MaterialMesh2dBundle { + mesh: meshes.add(shape::Circle::new(10.).into()).into(), + material: materials.add(ColorMaterial::from(Color::BLUE)), + transform: Transform::from_translation(Vec3::new(-400., 0., 0.)), + ..default() + }, + }); for i in 0..4000u32 { - commands - .spawn(Planet { - pos: TransformBundle::from(Transform::from_translation(Vec3::new( - -450. - i as f32 / 4., - 0., - 0., - ))), - mass: Mass(1.), - speed: Speed(Vec2::new(0.0, -500.0)), - visibility: InheritedVisibility::VISIBLE, - }) - .with_children(|parent| { - parent.spawn(MaterialMesh2dBundle { - mesh: circle_5.clone(), - material: red.clone(), - ..default() - }); - }); + commands.spawn(Planet { + mass: Mass(1.), + speed: Speed(Vec2::new(0.0, -500.0)), + mesh: MaterialMesh2dBundle { + mesh: meshes.add(shape::Circle::new(5.).into()).into(), + material: materials.add(ColorMaterial::from(Color::RED)), + transform: Transform::from_translation(Vec3::new(-450. - i as f32 / 4., 0., 0.)), + ..default() + }, + }); } } @@ -123,10 +96,9 @@ struct Mass(f32); #[derive(Bundle)] struct Planet { - pos: TransformBundle, mass: Mass, speed: Speed, - visibility: InheritedVisibility, + mesh: MaterialMesh2dBundle, } #[derive(Resource)]