pub struct OrbitControls {Show 13 fields
pub enable_damping: bool,
pub damping_factor: f32,
pub zoom_damping_factor: f32,
pub enable_zoom: bool,
pub zoom_speed: f32,
pub enable_rotate: bool,
pub rotate_speed: f32,
pub enable_pan: bool,
pub pan_speed: f32,
pub min_distance: f32,
pub max_distance: f32,
pub min_polar_angle: f32,
pub max_polar_angle: f32,
/* private fields */
}Expand description
Mouse-based orbit camera controller.
Allows users to rotate, zoom, and pan the camera around a target point using mouse input.
§Controls
| Input | Action |
|---|---|
| Left Mouse + Drag | Rotate camera around target |
| Right Mouse + Drag | Pan camera and target |
| Scroll Wheel | Zoom in/out |
§Features
- Smooth damping for natural feel
- Configurable rotation/zoom/pan speeds
- Distance and angle constraints
§Example
let mut orbit = OrbitControls::new(
Vec3::new(0.0, 5.0, 10.0), // camera position
Vec3::ZERO, // look-at target
);
// Customize settings
orbit.enable_damping = true;
orbit.rotate_speed = 0.5;
orbit.min_distance = 2.0;
orbit.max_distance = 50.0;
// In update loop
orbit.update(&mut camera_transform, &input, fov, dt);Fields§
§enable_damping: boolEnable smooth damping for rotation and zoom.
damping_factor: f32Damping factor for rotation (0.0 = instant, 1.0 = no movement).
zoom_damping_factor: f32Damping factor for zoom (0.0 = instant, 1.0 = no movement).
enable_zoom: boolEnable mouse wheel zoom.
zoom_speed: f32Zoom speed multiplier.
enable_rotate: boolEnable left-click rotation.
rotate_speed: f32Rotation speed multiplier.
enable_pan: boolEnable right-click panning.
pan_speed: f32Pan speed multiplier.
min_distance: f32Minimum distance from target (zoom limit).
max_distance: f32Maximum distance from target (zoom limit).
min_polar_angle: f32Minimum polar angle in radians (0 = top-down view).
max_polar_angle: f32Maximum polar angle in radians (π = bottom-up view).
Implementations§
Source§impl OrbitControls
impl OrbitControls
Sourcepub fn new(camera_pos: Vec3, target: Vec3) -> OrbitControls
pub fn new(camera_pos: Vec3, target: Vec3) -> OrbitControls
Creates a new orbit controller.
§Arguments
camera_pos- Initial camera world positiontarget- Point to orbit around (look-at target)
Sourcepub fn update(
&mut self,
transform: &mut Transform,
input: &Input,
fov: f32,
dt: f32,
)
pub fn update( &mut self, transform: &mut Transform, input: &Input, fov: f32, dt: f32, )
Updates the camera transform based on input.
Call this once per frame in your update loop.
§Arguments
transform- Camera’s transform component to modifyinput- Current input statefov- Camera field of view in radians (for pan scaling)dt- Delta time in seconds
Sourcepub fn set_target(&mut self, target: Vec3)
pub fn set_target(&mut self, target: Vec3)
Sets the orbit target point.
The camera will orbit around this point.
Sourcepub fn set_position(&mut self, position: Vec3)
pub fn set_position(&mut self, position: Vec3)
Sets the camera position directly.
Updates internal spherical coordinates to match the new position while keeping the current target.
Sourcepub fn fit(&mut self, bbox: &BoundingBox)
pub fn fit(&mut self, bbox: &BoundingBox)
Frames the camera to fit a pre-computed bounding box.
Positions the camera so the entire bounding box is visible, looking at its center from an appropriate distance.
Auto Trait Implementations§
impl Freeze for OrbitControls
impl RefUnwindSafe for OrbitControls
impl Send for OrbitControls
impl Sync for OrbitControls
impl Unpin for OrbitControls
impl UnsafeUnpin for OrbitControls
impl UnwindSafe for OrbitControls
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.