forked from Brickworks/yahs
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bevy: get working on bevy 0.15.0-rc.3
- Loading branch information
1 parent
e7a6f27
commit e08cf94
Showing
19 changed files
with
295 additions
and
319 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
mod scene; | ||
mod ui; | ||
pub mod controls; | ||
|
||
// Re-export the plugins so they can be added to the app with `app.add_plugins`. | ||
pub use scene::ScenePlugin; | ||
pub use ui::InterfacePlugins; | ||
pub use controls::ControlsPlugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,20 @@ | ||
use bevy::prelude::*; | ||
use bevy_panorbit_camera::{PanOrbitCamera, PanOrbitCameraPlugin}; | ||
use avian3d::math::TAU; | ||
|
||
use crate::controls::KeyBindingsConfig; | ||
// use crate::controls::CameraControls; | ||
|
||
pub struct CameraPlugin; | ||
|
||
impl Plugin for CameraPlugin { | ||
fn build(&self, app: &mut App) { | ||
app.add_plugins(PanOrbitCameraPlugin); | ||
app.add_systems(Startup, setup); | ||
app.add_systems(Update, toggle_camera_controls_system); | ||
} | ||
} | ||
|
||
fn setup(mut commands: Commands, key_bindings: Res<KeyBindingsConfig>) { | ||
fn setup(mut commands: Commands) { | ||
commands.spawn(( | ||
// Note we're setting the initial position below with yaw, pitch, and radius, hence | ||
// we don't set transform on the camera. | ||
Camera3dBundle::default(), | ||
PanOrbitCamera { | ||
// Set focal point (what the camera should look at) | ||
focus: Vec3::new(0.0, 1.0, 0.0), | ||
// Set the starting position, relative to focus (overrides camera's transform). | ||
yaw: Some(TAU / 8.0), | ||
pitch: Some(TAU / 8.0), | ||
radius: Some(5.0), | ||
// Set limits on rotation and zoom | ||
yaw_upper_limit: Some(TAU / 4.0), | ||
yaw_lower_limit: Some(-TAU / 4.0), | ||
pitch_upper_limit: Some(TAU / 3.0), | ||
pitch_lower_limit: Some(-TAU / 3.0), | ||
zoom_upper_limit: Some(100.0), | ||
zoom_lower_limit: 1.0, | ||
// Adjust sensitivity of controls | ||
orbit_sensitivity: 1.5, | ||
pan_sensitivity: 0.5, | ||
zoom_sensitivity: 0.5, | ||
// Allow the camera to go upside down | ||
allow_upside_down: true, | ||
// Change the controls (these match Blender) | ||
button_orbit: key_bindings.camera_controls.button_orbit, | ||
button_pan: key_bindings.camera_controls.button_pan, | ||
modifier_pan: key_bindings.camera_controls.modifier_pan, | ||
// Reverse the zoom direction | ||
reversed_zoom: false, | ||
..default() | ||
}, | ||
Camera3d::default(), | ||
Transform::from_xyz(0.0, 20., 14.0).looking_at(Vec3::new(0., 1., 0.), Vec3::Y), | ||
)); | ||
} | ||
|
||
// This is how you can change config at runtime. | ||
// Press 'T' to toggle the camera zoom direction. | ||
fn toggle_camera_controls_system( | ||
key_input: Res<ButtonInput<KeyCode>>, | ||
key_bindings: Res<KeyBindingsConfig>, | ||
mut pan_orbit_query: Query<&mut PanOrbitCamera>, | ||
) { | ||
if key_input.just_pressed(key_bindings.camera_controls.toggle_zoom_direction) { | ||
for mut pan_orbit in pan_orbit_query.iter_mut() { | ||
pan_orbit.reversed_zoom = !pan_orbit.reversed_zoom; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.