Initial commit, working, but w/ transparency issue
This commit is contained in:
commit
e33cdb55a2
15
.cargo/config
Normal file
15
.cargo/config
Normal file
@ -0,0 +1,15 @@
|
||||
# NOTE: For maximum performance, build using a nightly compiler
|
||||
# If you are using rust stable, remove the "-Zshare-generics=y" below.
|
||||
|
||||
[target.x86_64-unknown-linux-gnu]
|
||||
linker = "/usr/bin/clang"
|
||||
rustflags = ["-Clink-arg=-fuse-ld=lld", "-Zshare-generics=y"]
|
||||
|
||||
[target.x86_64-apple-darwin]
|
||||
rustflags = ["-Zshare-generics=y"]
|
||||
|
||||
# NOTE: you must manually install lld on windows. you can easily do this with the "scoop" package manager:
|
||||
# `scoop install llvm`
|
||||
[target.x86_64-pc-windows-msvc]
|
||||
linker = "lld-link.exe"
|
||||
rustflags = ["-Clinker=lld", "-Zshare-generics=y"]
|
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/target
|
2615
Cargo.lock
generated
Normal file
2615
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
12
Cargo.toml
Normal file
12
Cargo.toml
Normal file
@ -0,0 +1,12 @@
|
||||
[package]
|
||||
name = "bevy-nbody"
|
||||
version = "0.1.0"
|
||||
authors = ["Tyler Hallada <tyler@hallada.net>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
bevy = "0.1"
|
||||
bigbang = "0.0.9"
|
||||
rand = "0.7"
|
BIN
assets/circle.png
Normal file
BIN
assets/circle.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
83
src/main.rs
Normal file
83
src/main.rs
Normal file
@ -0,0 +1,83 @@
|
||||
use bevy::{prelude::*, render::pass::ClearColor};
|
||||
use bigbang::{Entity, GravTree};
|
||||
use rand::Rng;
|
||||
|
||||
struct Simulation(GravTree<Entity>);
|
||||
|
||||
fn main() {
|
||||
let mut rng = rand::thread_rng();
|
||||
let mut bodies = vec![];
|
||||
for _ in 0..100 {
|
||||
bodies.push(Entity {
|
||||
x: rng.gen_range(-400., 400.),
|
||||
y: rng.gen_range(-400., 400.),
|
||||
z: 0.,
|
||||
vx: rng.gen_range(-20., 20.),
|
||||
vy: rng.gen_range(-20., 20.),
|
||||
vz: 0.,
|
||||
mass: rng.gen_range(1., 20.),
|
||||
radius: rng.gen_range(1., 10.),
|
||||
});
|
||||
}
|
||||
App::build()
|
||||
.add_resource(Msaa { samples: 4 })
|
||||
.add_default_plugins()
|
||||
.add_resource(ClearColor(Color::rgb(0.1, 0.1, 0.1)))
|
||||
.add_resource(Simulation(GravTree::new(&bodies, 0.02)))
|
||||
.add_startup_system(add_bodies.system())
|
||||
.add_system(time_step.system())
|
||||
.add_system(update_bodies.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
fn add_bodies(
|
||||
mut commands: Commands,
|
||||
mut materials: ResMut<Assets<ColorMaterial>>,
|
||||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
asset_server: Res<AssetServer>,
|
||||
grav_tree: Res<Simulation>,
|
||||
) {
|
||||
let texture = asset_server.load("assets/circle.png").unwrap();
|
||||
// TODO: texture transparency not working
|
||||
commands
|
||||
.spawn(Camera2dComponents::default())
|
||||
.spawn(UiCameraComponents::default());
|
||||
|
||||
for body in grav_tree.0.as_vec() {
|
||||
commands
|
||||
.spawn(SpriteComponents {
|
||||
mesh: meshes.add(Mesh::from(shape::Quad::new(Vec2::new(
|
||||
(body.radius / 100.) as f32,
|
||||
(body.radius / 100.) as f32,
|
||||
)))),
|
||||
material: materials.add(texture.into()),
|
||||
translation: Translation(Vec3::new(body.x as f32, body.y as f32, body.z as f32)),
|
||||
draw: Draw {
|
||||
is_transparent: true,
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
})
|
||||
.with(body);
|
||||
}
|
||||
}
|
||||
|
||||
fn time_step(mut grav_tree: ResMut<Simulation>) {
|
||||
grav_tree.0 = grav_tree.0.time_step();
|
||||
}
|
||||
|
||||
fn update_bodies(grav_tree: Res<Simulation>, mut body_query: Query<(&Entity, &mut Translation)>) {
|
||||
let updated_bodies = grav_tree.0.as_vec();
|
||||
// for body in updated_bodies.iter() {
|
||||
// println!("body: {}", body.as_string());
|
||||
// }
|
||||
|
||||
let mut index = 0;
|
||||
for (_, mut translation) in &mut body_query.iter() {
|
||||
let updated_body = &updated_bodies[index];
|
||||
translation.0.set_x(updated_body.x as f32);
|
||||
translation.0.set_y(updated_body.y as f32);
|
||||
translation.0.set_z(updated_body.z as f32);
|
||||
index += 1;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user