pub struct ThirdPersonCameraController {
pub yaw: f32,
pub pitch: f32,
pub yaw_sensitivity: f32,
pub pitch_sensitivity: f32,
pub pitch_clamp: (f32, f32),
pub distance: f32,
pub height: f32,
pub shoulder_offset: Vec2,
}Expand description
Body-attached third-person orbit-and-boom camera controller.
Call apply once per frame with the resolved
ActionFrame and the world-space target position. The host owns the
Camera; this controller writes its center / distance / orientation
each frame.
Fields§
§yaw: f32Horizontal look angle in radians (rotation around world Z).
pitch: f32Vertical look angle in radians above the horizontal plane: positive looks up.
yaw_sensitivity: f32Horizontal look sensitivity, in radians per unit of navigation.orbit.x.
pitch_sensitivity: f32Vertical look sensitivity, in radians per unit of navigation.orbit.y.
pitch_clamp: (f32, f32)(min, max) allowed pitch in radians. Defaults to roughly
(-PI/4, +PI/4) so the camera neither dives into the ground nor flips
overhead.
distance: f32Distance from the orbit pivot to the camera eye. Larger values pull the eye further back behind the target.
height: f32Height offset above the target used as the orbit pivot (roughly chest height for a character).
shoulder_offset: Vec2(right, up) offset of the orbit pivot for over-the-shoulder framing.
Vec2::ZERO is centred.
Implementations§
Source§impl ThirdPersonCameraController
impl ThirdPersonCameraController
Sourcepub const DEFAULT_DISTANCE: f32 = 6.0
pub const DEFAULT_DISTANCE: f32 = 6.0
Default boom distance.
Sourcepub const DEFAULT_HEIGHT: f32 = 1.2
pub const DEFAULT_HEIGHT: f32 = 1.2
Default pivot height above the target.
Sourcepub fn new(yaw_sensitivity: f32, pitch_sensitivity: f32) -> Self
pub fn new(yaw_sensitivity: f32, pitch_sensitivity: f32) -> Self
Create a controller with the given look sensitivities and third-person
defaults (distance = 6.0, height = 1.2, pitch clamped to
+/- PI/4).
Sourcepub fn with_distance(self, distance: f32) -> Self
pub fn with_distance(self, distance: f32) -> Self
Builder: set the boom distance.
Sourcepub fn with_height(self, height: f32) -> Self
pub fn with_height(self, height: f32) -> Self
Builder: set the pivot height above the target.
Sourcepub fn with_shoulder_offset(self, offset: Vec2) -> Self
pub fn with_shoulder_offset(self, offset: Vec2) -> Self
Builder: set the (right, up) shoulder offset.
Sourcepub fn with_pitch_clamp(self, min: f32, max: f32) -> Self
pub fn with_pitch_clamp(self, min: f32, max: f32) -> Self
Builder: set the (min, max) pitch clamp in radians.
Sourcepub fn apply(&mut self, camera: &mut Camera, frame: &ActionFrame, target: Vec3)
pub fn apply(&mut self, camera: &mut Camera, frame: &ActionFrame, target: Vec3)
Apply the frame’s look delta, then orbit the camera around target.
The orbit pivot lands height above the target, shifted by
shoulder_offset in the camera-local right / up axes.
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 third-person continues from the existing view instead
of snapping. Call this when entering third-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.
Auto Trait Implementations§
impl Freeze for ThirdPersonCameraController
impl RefUnwindSafe for ThirdPersonCameraController
impl Send for ThirdPersonCameraController
impl Sync for ThirdPersonCameraController
impl Unpin for ThirdPersonCameraController
impl UnsafeUnpin for ThirdPersonCameraController
impl UnwindSafe for ThirdPersonCameraController
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.