@@ -14,7 +14,7 @@ use bevy_egui::EguiPreUpdateSet;
1414
1515#[ cfg( feature = "bevy_egui" ) ]
1616pub use crate :: egui:: { EguiFocusIncludesHover , EguiWantsFocus } ;
17- use crate :: input:: { mouse_key_tracker, MouseKeyTracker } ;
17+ use crate :: input:: { button_zoom_just_pressed , mouse_key_tracker, MouseKeyTracker } ;
1818pub use crate :: touch:: TouchControls ;
1919use crate :: touch:: { touch_tracker, TouchGestures , TouchTracker } ;
2020use crate :: traits:: OptionalClamp ;
@@ -217,6 +217,12 @@ pub struct PanOrbitCamera {
217217 /// Button used to pan the camera.
218218 /// Defaults to `Button::Right`.
219219 pub button_pan : MouseButton ,
220+ /// Button used to zoom the camera, by holding it down and moving the mouse forward and back.
221+ /// Defaults to `None`.
222+ pub button_zoom : Option < MouseButton > ,
223+ /// Which axis should zoom the camera when using `button_zoom`.
224+ /// Defaults to `ButtonZoomAxis::Y`.
225+ pub button_zoom_axis : ButtonZoomAxis ,
220226 /// Key that must be pressed for `button_orbit` to work.
221227 /// Defaults to `None` (no modifier).
222228 pub modifier_orbit : Option < KeyCode > ,
@@ -293,6 +299,8 @@ impl Default for PanOrbitCamera {
293299 zoom_smoothness : 0.1 ,
294300 button_orbit : MouseButton :: Left ,
295301 button_pan : MouseButton :: Right ,
302+ button_zoom : None ,
303+ button_zoom_axis : ButtonZoomAxis :: Y ,
296304 modifier_orbit : None ,
297305 modifier_pan : None ,
298306 touch_enabled : true ,
@@ -357,6 +365,17 @@ pub enum FocusBoundsShape {
357365 Cuboid ( Cuboid ) ,
358366}
359367
368+ /// The shape to restrict the camera's focus inside.
369+ #[ derive( Clone , PartialEq , Debug , Reflect , Copy ) ]
370+ pub enum ButtonZoomAxis {
371+ /// Zoom by moving the mouse along the x-axis.
372+ X ,
373+ /// Zoom by moving the mouse along the y-axis.
374+ Y ,
375+ /// Zoom by moving the mouse along either the x-axis or the y-axis.
376+ XY ,
377+ }
378+
360379impl From < Sphere > for FocusBoundsShape {
361380 fn from ( value : Sphere ) -> Self {
362381 Self :: Sphere ( value)
@@ -420,6 +439,7 @@ fn active_viewport_data(
420439 || input:: pan_just_pressed ( pan_orbit, & mouse_input, & key_input)
421440 || !pinch_events. is_empty ( )
422441 || !scroll_events. is_empty ( )
442+ || button_zoom_just_pressed ( pan_orbit, & mouse_input)
423443 || ( touches. iter_just_pressed ( ) . count ( ) > 0
424444 && touches. iter_just_pressed ( ) . count ( ) == touches. iter ( ) . count ( ) ) ;
425445
0 commit comments