use bevy::prelude::*; use bevy_inspector_egui::WorldInspectorPlugin; use cyber_rider::flycam::{MovementSettings, PlayerPlugin}; // stolen with neither shame nor pity from // git@github.com:sburris0/bevy_flycam.git, b90f6fc, which is copyright 2020 // Spencer Burris fn main() { App::build() .insert_resource(Msaa { samples: 4 }) .add_plugins(DefaultPlugins) .add_plugin(PlayerPlugin) .add_plugin(WorldInspectorPlugin::new()) .insert_resource(MovementSettings { sensitivity: 0.00015, // default: 0.00012 speed: 12.0, // default: 12.0 }) .add_startup_system(setup.system()) .add_system(animate_lights.system()) .run(); } /// set up a simple 3D scene fn setup( mut commands: Commands, mut meshes: ResMut>, mut materials: ResMut>, ) { let red_light = Light { intensity: 50_000.0, range: 1800.0, color: Color::RED, ..Default::default() }; let blue_light = Light { intensity: 50_000.0, range: 1800.0, color: Color::BLUE, ..Default::default() }; let purple_light = Light { intensity: 50_000.0, range: 1800.0, color: Color::PURPLE, ..Default::default() }; // world commands.spawn_bundle(PbrBundle { mesh: meshes.add(Mesh::from(shape::Icosphere { radius: 300.0, subdivisions: 5, })), material: materials.add(StandardMaterial { base_color: Color::GRAY, metallic: 0.7, roughness: 0.2, ..Default::default() }), ..Default::default() }); // east light commands.spawn_bundle(LightBundle { transform: Transform::from_xyz(750.0, 0.0, 0.0), light: purple_light.clone(), ..Default::default() }); // west light commands.spawn_bundle(LightBundle { transform: Transform::from_xyz(-750.0, 0.0, 0.0), light: purple_light.clone(), ..Default::default() }); // north light commands.spawn_bundle(LightBundle { transform: Transform::from_xyz(0.0, 0.0, 750.0), light: purple_light.clone(), ..Default::default() }); // south light commands.spawn_bundle(LightBundle { transform: Transform::from_xyz(0.0, 0.0, -750.0), light: purple_light, ..Default::default() }); // up light commands.spawn_bundle(LightBundle { transform: Transform::from_xyz(0.0, 750.0, 0.0), light: red_light, ..Default::default() }); // down light commands.spawn_bundle(LightBundle { transform: Transform::from_xyz(0.0, 750.0, 0.0), light: blue_light, ..Default::default() }); } fn animate_lights(mut query: Query<&mut Transform, With>) { for mut transform in query.iter_mut() { let translation = &transform.translation; let x = translation.x; let y = if translation.y.abs() < 0.1 { translation.y + 0.15 } else { translation.y }; let theta = y.atan2(x) + 0.174533; // 10 degrees == 0.174533 radians let x_new = 750.0 * theta.cos(); let y_new = 750.0 * theta.sin(); *transform = Transform::from_xyz(x_new, y_new, 0.0); } }