diff --git a/src/camera.rs b/src/camera.rs new file mode 100644 index 0000000..2701589 --- /dev/null +++ b/src/camera.rs @@ -0,0 +1,64 @@ +use bevy::{input::mouse::MouseWheel, prelude::*}; + +use crate::constants::{BASE_ZOOM_SPEED, DISTANCE_SCALE_FACTOR, MAX_ZOOM, MIN_ZOOM}; + +pub(super) fn plugin(app: &mut App) { + app.add_systems(Update, camera_zoom); +} + +#[derive(Debug, Reflect, Component)] +#[reflect(Component)] +pub struct MainCamera; + +pub fn spawn_camera(mut commands: Commands) { + commands.spawn(( + Name::new("Camera"), + MainCamera, + Camera3d::default(), + Transform::from_xyz(200., 200., 0.).looking_at(Vec3::ZERO, Vec3::Y), + // Render all UI to this camera. + // Not strictly necessary since we only use one camera, + // but if we don't use this component, our UI will disappear as soon + // as we add another camera. This includes indirect ways of adding cameras like using + // [ui node outlines](https://bevyengine.org/news/bevy-0-14/#ui-node-outline-gizmos) + // for debugging. So it's good to have this here for future-proofing. + IsDefaultUiCamera, + )); +} + +fn camera_zoom( + mut query: Query<&mut Transform, With>, + mut scrool_evr: EventReader, + keyboard: Res>, + time: Res