main
Jordan Orelli 1 year ago
commit 212adc86e4

1
.gitignore vendored

@ -0,0 +1 @@
/target

3830
Cargo.lock generated

File diff suppressed because it is too large Load Diff

@ -0,0 +1,17 @@
[package]
name = "spinner"
version = "0.1.0"
edition = "2021"
[profile.dev]
opt-level = 1
[profile.dev.package."*"]
opt-level = 3
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
bevy = "0.12.1"
# bevy-inspector-egui = "0.21.0"
tracing = "0.1.40"

3
dev

@ -0,0 +1,3 @@
#!/usr/bin/env bash
cargo run --features bevy/dynamic_linking

@ -0,0 +1,22 @@
use bevy::ecs::system::Command;
use bevy::prelude::*;
pub struct SpawnCamera {
pub position: Vec3,
pub target: Vec3,
}
impl Command for SpawnCamera {
fn apply(self, world: &mut World) {
info!(
"Spawning camera at {pos} looking at {target}",
pos = self.position,
target = self.target
);
let bundle = Camera3dBundle {
transform: Transform::from_translation(self.position).looking_at(self.target, Vec3::Y),
..default()
};
world.spawn(bundle);
}
}

@ -0,0 +1,9 @@
mod commands;
mod spinner;
use bevy::prelude::*;
use spinner::Spinner;
fn main() {
App::new().add_plugins((DefaultPlugins, Spinner {})).run();
}

@ -0,0 +1,61 @@
use bevy::prelude::*;
use tracing::info;
use crate::commands::SpawnCamera;
pub struct Spinner {}
impl Plugin for Spinner {
fn build(&self, app: &mut App) {
app.add_systems(Startup, setup);
app.add_systems(Update, spin);
}
}
fn setup(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
info!("Running setup");
commands.add(SpawnCamera {
position: Vec3::new(-5.0, 5.0, 5.0),
target: Vec3::new(0.0, 0.0, 0.0),
});
let cube = meshes.add(Mesh::from(shape::Cube { size: 1.0 }));
let material = materials.add(Color::rgb_u8(124, 144, 255).into());
commands.spawn((
Spin {
by: Quat::from_euler(EulerRot::XYZ, 0.0, 0.01, 0.005),
},
PbrBundle {
mesh: cube,
material,
transform: Transform::from_xyz(0.0, 0.0, 0.0),
..default()
},
));
commands.spawn(PointLightBundle {
point_light: PointLight {
intensity: 1500.0,
shadows_enabled: true,
..default()
},
transform: Transform::from_xyz(4.0, 8.0, 4.0),
..default()
});
}
#[derive(Component)]
struct Spin {
by: Quat,
}
fn spin(mut objects: Query<(&mut Transform, &Spin)>, _time: Res<Time>) {
for (mut pos, spin) in &mut objects {
pos.rotate(spin.by);
}
}

@ -0,0 +1,4 @@
#!/usr/bin/env bash
cargo watch -c -q -x run --features bevy/dynamic_linking
Loading…
Cancel
Save