pub struct MapControls {
pub target: Vector3,
pub distance: f32,
pub bearing: f32,
pub pitch: f32,
pub min_distance: f32,
pub max_distance: f32,
pub max_pitch: f32,
pub ground: f32,
pub rotate_speed: f32,
pub zoom_speed: f32,
}Expand description
A camera that looks at a point on a horizontal ground plane, the way a map application’s does.
The state is the look-at point, the distance to it, a bearing and a pitch, and the camera is derived from those on every update — so a map can be put anywhere by setting four numbers, and the controls never drift.
- Pan (
ev.panning) grabs the ground: the point under the cursor stays under the cursor however far the camera is tilted. - Zoom (
ev.wheel) moves toward the point under the cursor, not the middle of the view. - Rotate (
ev.rotating) turns the bearing with horizontal motion and tilts with vertical motion.
Y is up. Bearing 0 looks toward −Z, and increases clockwise seen from above; pitch 0 looks straight down.
Unlike three.js’s MapControls, which is OrbitControls with the buttons
swapped, this needs the cursor position, because two of its three gestures
are about the point under it.
Fields§
§target: Vector3The look-at point. Kept on the ground plane.
distance: f32§bearing: f32Radians clockwise from looking toward −Z.
pitch: f32Radians from straight down.
min_distance: f32§max_distance: f32§max_pitch: f32§ground: f32Height of the ground plane.
rotate_speed: f32§zoom_speed: f32Implementations§
Source§impl MapControls
impl MapControls
Sourcepub fn new(target: Vector3, distance: f32) -> Self
pub fn new(target: Vector3, distance: f32) -> Self
Looking straight down at target from distance away.
Sourcepub fn apply(&self, camera: &mut PerspectiveCamera)
pub fn apply(&self, camera: &mut PerspectiveCamera)
Put camera where the state says.
Sourcepub fn fit_clip_planes(&self, camera: &mut PerspectiveCamera)
pub fn fit_clip_planes(&self, camera: &mut PerspectiveCamera)
Set camera’s near and far planes to what this view can see: near a
fraction of the distance, far growing as the view tilts towards the
horizon (capped at 1000 distances). Keeps the depth buffer’s far ÷
near — which sets its precision — near 10⁴. Call after
apply.
Sourcepub fn ground_point(
&self,
camera: &PerspectiveCamera,
x: f32,
y: f32,
viewport: (f32, f32),
) -> Option<Vector3>
pub fn ground_point( &self, camera: &PerspectiveCamera, x: f32, y: f32, viewport: (f32, f32), ) -> Option<Vector3>
Where the ray through pixel (x, y) (top-left origin) meets the
ground, or None when it points at the sky.
Sourcepub fn update(
&mut self,
ev: PointerEvent,
cursor: (f32, f32),
camera: &mut PerspectiveCamera,
viewport: (f32, f32),
)
pub fn update( &mut self, ev: PointerEvent, cursor: (f32, f32), camera: &mut PerspectiveCamera, viewport: (f32, f32), )
Apply one frame of input. cursor is where the pointer is now; the
event’s dx, dy are how far it moved to get there.
Trait Implementations§
Source§impl Clone for MapControls
impl Clone for MapControls
impl Copy for MapControls
Auto Trait Implementations§
impl Forget for MapControls
impl Freeze for MapControls
impl Move for MapControls
impl RefUnwindSafe for MapControls
impl Send for MapControls
impl Sync for MapControls
impl Unpin for MapControls
impl UnsafeUnpin for MapControls
impl UnwindSafe for MapControls
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more