add debug cam orbit controls

This commit is contained in:
Joe Ardent 2023-01-23 20:12:15 -08:00
parent 9d2e41a971
commit bf35c963b2
6 changed files with 42 additions and 7 deletions

View file

@ -16,6 +16,7 @@ enum CyberCameras {
pub struct DebugCamOffset {
pub rot: f32,
pub dist: f32,
pub alt: f32,
}
impl Default for DebugCamOffset {
@ -23,6 +24,7 @@ impl Default for DebugCamOffset {
DebugCamOffset {
rot: 60.0,
dist: 10.0,
alt: 4.0,
}
}
}
@ -84,6 +86,7 @@ fn follow_cyberbike(
let mut ncx = bike_xform.to_owned();
ncx.rotate(Quat::from_axis_angle(up, offset.rot.to_radians()));
ncx.translation += ncx.forward() * offset.dist;
ncx.translation += ncx.up() * offset.alt;
*cam_xform = ncx;
cam_xform.look_at(bike_xform.translation, up);
}

View file

@ -74,7 +74,8 @@ fn wireframify_lights(mut lights: Query<&mut AnimateCyberLightWireframe>) {
pub struct CyberGlamorPlugin;
impl Plugin for CyberGlamorPlugin {
fn build(&self, app: &mut App) {
app.add_startup_system_to_stage(StartupStage::PostStartup, wireframe_planet)
app.insert_resource(ClearColor(Color::rgb(0.408, 0.6236, 0.925)))
.add_startup_system_to_stage(StartupStage::PostStartup, wireframe_planet)
.add_system(wireframify_lights)
.add_plugin(PolylinePlugin);
}

View file

@ -1,4 +1,7 @@
use bevy::prelude::*;
use bevy::{prelude::*, utils::HashSet};
use crate::camera::DebugCamOffset;
#[derive(Default, Debug, Resource)]
pub(crate) struct InputState {
pub yaw: f32,
@ -7,6 +10,33 @@ pub(crate) struct InputState {
pub pitch: f32,
}
fn update_debug_cam(mut offset: ResMut<DebugCamOffset>, mut keys: ResMut<Input<KeyCode>>) {
let keyset: HashSet<_> = keys.get_pressed().collect();
let shifted = keyset.contains(&KeyCode::LShift) || keyset.contains(&KeyCode::RShift);
for key in keyset {
match key {
KeyCode::Left => offset.rot += 5.0,
KeyCode::Right => offset.rot -= 5.0,
KeyCode::Up => {
if shifted {
offset.alt += 0.5;
} else {
offset.dist -= 0.5;
}
}
KeyCode::Down => {
if shifted {
offset.alt -= 0.5;
} else {
offset.dist += 0.5;
}
}
_ => continue,
}
}
}
fn update_input(mut events: EventReader<GamepadEvent>, mut istate: ResMut<InputState>) {
for GamepadEvent {
gamepad: _,
@ -46,6 +76,8 @@ fn update_input(mut events: EventReader<GamepadEvent>, mut istate: ResMut<InputS
pub struct CyberInputPlugin;
impl Plugin for CyberInputPlugin {
fn build(&self, app: &mut App) {
app.init_resource::<InputState>().add_system(update_input);
app.init_resource::<InputState>()
.add_system(update_input)
.add_system(update_debug_cam);
}
}

View file

@ -122,7 +122,7 @@ fn spawn_static_lights(
// up light
commands
.spawn(PointLightBundle {
transform: Transform::from_xyz(0.0, PLANET_RADIUS + 30.0, 0.0),
transform: Transform::from_xyz(20.0, 100.0, 20.0),
point_light: pink_light,
..Default::default()
})
@ -143,7 +143,7 @@ fn spawn_static_lights(
// down light
commands
.spawn(PointLightBundle {
transform: Transform::from_xyz(0.0, -PLANET_RADIUS - 30.0, 0.0),
transform: Transform::from_xyz(-20.0, 100.0, -20.0),
point_light: blue_light,
..Default::default()
})

View file

@ -20,7 +20,6 @@ const MOVEMENT_SETTINGS: MovementSettings = MovementSettings {
fn main() {
let mut app = App::new();
app.insert_resource(Msaa { samples: 4 })
.insert_resource(ClearColor(Color::rgb(0.07, 0.001, 0.02)))
.add_plugins(DefaultPlugins.set(WindowPlugin {
window: WindowDescriptor {
width: 2560.0,

View file

@ -17,7 +17,7 @@ fn spawn_planet(
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
let color = Color::rgb(0.2, 0.1, 0.2);
let color = Color::rgba(0.7, 0.7, 0.8, 0.3);
let plane = Plane {
size: PLANET_RADIUS,
};