Compare commits
No commits in common. "572dfb67880bf22232524b3795f63fe9599501cb" and "8fc0c391ca2e5ebe1b5b797964c9c3cef47cabf2" have entirely different histories.
572dfb6788
...
8fc0c391ca
3 changed files with 43 additions and 88 deletions
17
README.md
17
README.md
|
@ -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
|
|
|
@ -17,7 +17,7 @@ pub fn planet() -> Mesh {
|
||||||
let a = std::f32::consts::TAU * i as f32 / perimeter as f32;
|
let a = std::f32::consts::TAU * i as f32 / perimeter as f32;
|
||||||
[r * a.cos(), r * a.sin(), 0.]
|
[r * a.cos(), r * a.sin(), 0.]
|
||||||
})
|
})
|
||||||
.chain([[0., 0., 0.]])
|
.chain([[0., 0., 0.]].into_iter())
|
||||||
.collect::<Vec<_>>(),
|
.collect::<Vec<_>>(),
|
||||||
);
|
);
|
||||||
let mut triangles = Vec::new();
|
let mut triangles = Vec::new();
|
||||||
|
|
112
src/main.rs
112
src/main.rs
|
@ -1,11 +1,7 @@
|
||||||
mod gen;
|
mod gen;
|
||||||
mod quadtree;
|
mod quadtree;
|
||||||
|
|
||||||
use bevy::{
|
use bevy::{ecs::query::BatchingStrategy, prelude::*, sprite::MaterialMesh2dBundle};
|
||||||
ecs::query::BatchingStrategy,
|
|
||||||
prelude::*,
|
|
||||||
sprite::{MaterialMesh2dBundle, Mesh2dHandle},
|
|
||||||
};
|
|
||||||
|
|
||||||
#[global_allocator]
|
#[global_allocator]
|
||||||
static ALLOCATOR: cap::Cap<std::alloc::System> =
|
static ALLOCATOR: cap::Cap<std::alloc::System> =
|
||||||
|
@ -42,70 +38,47 @@ fn setup(
|
||||||
.spawn(Camera2dBundle::default())
|
.spawn(Camera2dBundle::default())
|
||||||
.insert(bevy_pancam::PanCam::default());
|
.insert(bevy_pancam::PanCam::default());
|
||||||
|
|
||||||
let red = materials.add(ColorMaterial::from(Color::RED));
|
commands.spawn(Planet {
|
||||||
let circle_5: Mesh2dHandle = meshes.add(shape::Circle::new(5.).into()).into();
|
mass: Mass(1.988e18),
|
||||||
|
speed: Speed(Vec2::new(0.0, 0.0)),
|
||||||
commands
|
mesh: MaterialMesh2dBundle {
|
||||||
.spawn(Planet {
|
mesh: meshes.add(gen::planet()).into(),
|
||||||
pos: TransformBundle::from(Transform::from_translation(Vec3::new(0., 0., 0.))),
|
material: materials.add(ColorMaterial::from(Color::YELLOW)),
|
||||||
mass: Mass(1.988e18),
|
transform: Transform::from_translation(Vec3::new(0., 0., 0.)),
|
||||||
speed: Speed(Vec2::new(0.0, 0.0)),
|
..default()
|
||||||
visibility: InheritedVisibility::VISIBLE,
|
},
|
||||||
})
|
});
|
||||||
.with_children(|parent| {
|
commands.spawn(Planet {
|
||||||
parent.spawn(MaterialMesh2dBundle {
|
mass: Mass(5.9736e14),
|
||||||
mesh: meshes.add(gen::planet()).into(),
|
speed: Speed(Vec2::new(0.0, 500.0)),
|
||||||
material: materials.add(ColorMaterial::from(Color::YELLOW)),
|
mesh: MaterialMesh2dBundle {
|
||||||
..default()
|
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.)),
|
||||||
commands
|
..default()
|
||||||
.spawn(Planet {
|
},
|
||||||
pos: TransformBundle::from(Transform::from_translation(Vec3::new(400., 0., 0.))),
|
});
|
||||||
mass: Mass(5.9736e14),
|
commands.spawn(Planet {
|
||||||
speed: Speed(Vec2::new(0.0, 500.0)),
|
mass: Mass(5.9736e14),
|
||||||
visibility: InheritedVisibility::VISIBLE,
|
speed: Speed(Vec2::new(0.0, -500.0)),
|
||||||
})
|
mesh: MaterialMesh2dBundle {
|
||||||
.with_children(|parent| {
|
mesh: meshes.add(shape::Circle::new(10.).into()).into(),
|
||||||
parent.spawn(MaterialMesh2dBundle {
|
material: materials.add(ColorMaterial::from(Color::BLUE)),
|
||||||
mesh: meshes.add(shape::Circle::new(10.).into()).into(),
|
transform: Transform::from_translation(Vec3::new(-400., 0., 0.)),
|
||||||
material: materials.add(ColorMaterial::from(Color::BLUE)),
|
..default()
|
||||||
..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()
|
|
||||||
});
|
|
||||||
});
|
|
||||||
for i in 0..4000u32 {
|
for i in 0..4000u32 {
|
||||||
commands
|
commands.spawn(Planet {
|
||||||
.spawn(Planet {
|
mass: Mass(1.),
|
||||||
pos: TransformBundle::from(Transform::from_translation(Vec3::new(
|
speed: Speed(Vec2::new(0.0, -500.0)),
|
||||||
-450. - i as f32 / 4.,
|
mesh: MaterialMesh2dBundle {
|
||||||
0.,
|
mesh: meshes.add(shape::Circle::new(5.).into()).into(),
|
||||||
0.,
|
material: materials.add(ColorMaterial::from(Color::RED)),
|
||||||
))),
|
transform: Transform::from_translation(Vec3::new(-450. - i as f32 / 4., 0., 0.)),
|
||||||
mass: Mass(1.),
|
..default()
|
||||||
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()
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,10 +96,9 @@ struct Mass(f32);
|
||||||
|
|
||||||
#[derive(Bundle)]
|
#[derive(Bundle)]
|
||||||
struct Planet {
|
struct Planet {
|
||||||
pos: TransformBundle,
|
|
||||||
mass: Mass,
|
mass: Mass,
|
||||||
speed: Speed,
|
speed: Speed,
|
||||||
visibility: InheritedVisibility,
|
mesh: MaterialMesh2dBundle<ColorMaterial>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Resource)]
|
#[derive(Resource)]
|
||||||
|
|
Loading…
Reference in a new issue