103 lines
2.9 KiB
Rust
103 lines
2.9 KiB
Rust
//use std::f32::consts::PI;
|
|
|
|
use bevy::prelude::*;
|
|
|
|
use audubon::*;
|
|
|
|
fn main() {
|
|
let config: audubon::Config = argh::from_env();
|
|
App::new()
|
|
.add_plugins(DefaultPlugins)
|
|
.insert_resource(config)
|
|
.add_systems(Startup, setup)
|
|
.add_systems(
|
|
Update,
|
|
(
|
|
add_gizmos,
|
|
rotate_camera,
|
|
update_config,
|
|
bevy::window::close_on_esc,
|
|
),
|
|
)
|
|
.run();
|
|
}
|
|
|
|
fn setup(
|
|
mut commands: Commands,
|
|
mut meshes: ResMut<Assets<Mesh>>,
|
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
|
config: Res<Config>,
|
|
models: Res<AssetServer>,
|
|
) {
|
|
commands.spawn(Camera3dBundle {
|
|
transform: Transform::from_xyz(0., 1.5, 6.).looking_at(Vec3::ZERO, Vec3::Y),
|
|
..default()
|
|
});
|
|
// plane
|
|
commands.spawn(PbrBundle {
|
|
mesh: meshes.add(Mesh::from(shape::Plane::from_size(5.0))),
|
|
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
|
|
..default()
|
|
});
|
|
|
|
let toid_model = models.load("models/boid.glb#Scene0");
|
|
|
|
for _ in 0..config.toids {
|
|
let _ = turkey_time(&mut commands, &toid_model);
|
|
}
|
|
|
|
// light
|
|
commands.spawn(PointLightBundle {
|
|
point_light: PointLight {
|
|
intensity: 1500.0,
|
|
shadows_enabled: true,
|
|
..default()
|
|
},
|
|
transform: Transform::from_xyz(4.0, 8.0, 4.0),
|
|
..default()
|
|
});
|
|
|
|
// example instructions
|
|
commands.spawn(
|
|
TextBundle::from_section(
|
|
"Press 'D' to toggle drawing gizmos on top of everything else in the scene\n\
|
|
Press 'P' to toggle perspective for line gizmos\n\
|
|
Hold 'Left' or 'Right' to change the line width",
|
|
TextStyle {
|
|
font_size: 20.,
|
|
..default()
|
|
},
|
|
)
|
|
.with_style(Style {
|
|
position_type: PositionType::Absolute,
|
|
top: Val::Px(12.0),
|
|
left: Val::Px(12.0),
|
|
..default()
|
|
}),
|
|
);
|
|
}
|
|
|
|
fn rotate_camera(mut query: Query<&mut Transform, With<Camera>>, time: Res<Time>) {
|
|
let mut transform = query.single_mut();
|
|
|
|
transform.rotate_around(Vec3::ZERO, Quat::from_rotation_y(time.delta_seconds() / 2.));
|
|
}
|
|
|
|
fn update_config(mut config: ResMut<GizmoConfig>, keyboard: Res<Input<KeyCode>>, time: Res<Time>) {
|
|
if keyboard.just_pressed(KeyCode::D) {
|
|
config.depth_bias = if config.depth_bias == 0. { -1. } else { 0. };
|
|
}
|
|
if keyboard.just_pressed(KeyCode::P) {
|
|
// Toggle line_perspective
|
|
config.line_perspective ^= true;
|
|
// Increase the line width when line_perspective is on
|
|
config.line_width *= if config.line_perspective { 5. } else { 1. / 5. };
|
|
}
|
|
|
|
if keyboard.pressed(KeyCode::Right) {
|
|
config.line_width += 5. * time.delta_seconds();
|
|
}
|
|
if keyboard.pressed(KeyCode::Left) {
|
|
config.line_width -= 5. * time.delta_seconds();
|
|
}
|
|
}
|