pub struct FirstPersonCameraController {
pub yaw: f32,
pub pitch: f32,
pub sensitivity: f32,
pub pitch_clamp: f32,
}Expand description
Body-attached first-person camera controller.
Call apply once per frame with the resolved
ActionFrame and the world-space eye position. The host owns the
Camera; this controller writes its center / distance / orientation
each frame. Read forward_dir /
right_dir to drive character movement.
Fields§
§yaw: f32Horizontal look angle in radians (rotation around world Z).
pitch: f32Vertical look angle in radians above the horizontal plane: positive looks up.
sensitivity: f32Look sensitivity, in radians per unit of navigation.orbit delta.
pitch_clamp: f32Maximum absolute pitch in radians before clamping (e.g. 1.4 is roughly
80 degrees).
Implementations§
Source§impl FirstPersonCameraController
impl FirstPersonCameraController
Sourcepub const DEFAULT_SENSITIVITY: f32 = 0.005
pub const DEFAULT_SENSITIVITY: f32 = 0.005
Default look sensitivity applied to the resolved orbit delta.
Sourcepub const DEFAULT_PITCH_CLAMP: f32 = 1.4
pub const DEFAULT_PITCH_CLAMP: f32 = 1.4
Default pitch clamp, roughly 80 degrees.
Sourcepub fn new(sensitivity: f32, pitch_clamp: f32) -> Self
pub fn new(sensitivity: f32, pitch_clamp: f32) -> Self
Create a controller with the given sensitivity and pitch clamp, looking along +Y.
Sourcepub fn apply(
&mut self,
camera: &mut Camera,
frame: &ActionFrame,
eye_position: Vec3,
)
pub fn apply( &mut self, camera: &mut Camera, frame: &ActionFrame, eye_position: Vec3, )
Apply the frame’s look delta, then attach the camera eye to
eye_position.
eye_position is the world-space eye point, typically the player body
origin offset by eye height.
Sourcepub fn sync_from_camera(&mut self, camera: &Camera)
pub fn sync_from_camera(&mut self, camera: &Camera)
Adopt the current view of camera as this controller’s yaw / pitch,
so switching into first-person continues from the existing view instead
of snapping. Call this when entering first-person mode.
Sourcepub fn set_look(&mut self, yaw: f32, pitch: f32)
pub fn set_look(&mut self, yaw: f32, pitch: f32)
Jump to an explicit look direction. pitch is clamped.
Sourcepub fn forward_dir(&self) -> Vec3
pub fn forward_dir(&self) -> Vec3
Horizontal forward vector (yaw only, z = 0) for movement. At yaw 0:
+Y; at yaw PI/2: +X.
Sourcepub fn right_dir(&self) -> Vec3
pub fn right_dir(&self) -> Vec3
Horizontal right vector perpendicular to forward_dir,
for strafing.
Auto Trait Implementations§
impl Freeze for FirstPersonCameraController
impl RefUnwindSafe for FirstPersonCameraController
impl Send for FirstPersonCameraController
impl Sync for FirstPersonCameraController
impl Unpin for FirstPersonCameraController
impl UnsafeUnpin for FirstPersonCameraController
impl UnwindSafe for FirstPersonCameraController
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> 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>, which can then be
downcast into Box<dyn 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>, which 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> DowncastSend for T
impl<T> DowncastSend for T
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.