2021-11-06 05:32:55 +00:00
|
|
|
use bevy::prelude::*;
|
2021-11-08 07:58:43 +00:00
|
|
|
use bevy_inspector_egui::WorldInspectorPlugin;
|
|
|
|
use cyber_rider::flycam::{MovementSettings, PlayerPlugin};
|
2021-11-06 05:32:55 +00:00
|
|
|
|
2021-11-08 07:58:43 +00:00
|
|
|
// stolen with neither shame nor pity from
|
|
|
|
// git@github.com:sburris0/bevy_flycam.git, b90f6fc, which is copyright 2020
|
|
|
|
// Spencer Burris
|
2021-11-06 05:32:55 +00:00
|
|
|
|
|
|
|
fn main() {
|
2021-11-08 07:58:43 +00:00
|
|
|
App::build()
|
2021-11-06 05:32:55 +00:00
|
|
|
.insert_resource(Msaa { samples: 4 })
|
|
|
|
.add_plugins(DefaultPlugins)
|
|
|
|
.add_plugin(PlayerPlugin)
|
2021-11-08 07:58:43 +00:00
|
|
|
.add_plugin(WorldInspectorPlugin::new())
|
2021-11-06 05:32:55 +00:00
|
|
|
.insert_resource(MovementSettings {
|
|
|
|
sensitivity: 0.00015, // default: 0.00012
|
|
|
|
speed: 12.0, // default: 12.0
|
|
|
|
})
|
|
|
|
.add_startup_system(setup.system())
|
2021-11-08 07:58:43 +00:00
|
|
|
.add_system(animate_lights.system())
|
2021-11-06 05:32:55 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// set up a simple 3D scene
|
|
|
|
fn setup(
|
|
|
|
mut commands: Commands,
|
|
|
|
mut meshes: ResMut<Assets<Mesh>>,
|
|
|
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
|
|
|
) {
|
2021-11-08 07:58:43 +00:00
|
|
|
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
|
2021-11-06 05:32:55 +00:00
|
|
|
commands.spawn_bundle(PbrBundle {
|
2021-11-08 07:58:43 +00:00
|
|
|
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()
|
|
|
|
}),
|
|
|
|
|
2021-11-06 05:32:55 +00:00
|
|
|
..Default::default()
|
|
|
|
});
|
2021-11-08 07:58:43 +00:00
|
|
|
// 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(),
|
2021-11-06 05:32:55 +00:00
|
|
|
..Default::default()
|
|
|
|
});
|
2021-11-08 07:58:43 +00:00
|
|
|
// north light
|
|
|
|
commands.spawn_bundle(LightBundle {
|
|
|
|
transform: Transform::from_xyz(0.0, 0.0, 750.0),
|
|
|
|
light: purple_light.clone(),
|
2021-11-06 05:32:55 +00:00
|
|
|
..Default::default()
|
|
|
|
});
|
2021-11-08 07:58:43 +00:00
|
|
|
// 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<Light>>) {
|
|
|
|
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);
|
|
|
|
}
|
2021-11-06 05:32:55 +00:00
|
|
|
}
|