Skip to main content

Camera

Struct Camera 

Source
pub struct Camera {
Show 14 fields pub position: Vec3, pub target: Vec3, pub up: Vec3, pub fov: f32, pub aspect_ratio: f32, pub near: f32, pub far: f32, pub navigation_style: NavigationStyle, pub projection_mode: ProjectionMode, pub up_direction: AxisDirection, pub front_direction: AxisDirection, pub move_speed: f32, pub ortho_scale: f32, pub flight: Option<CameraFlight>,
}
Expand description

A 3D camera for viewing the scene.

Fields§

§position: Vec3

Camera position in world space.

§target: Vec3

Point the camera is looking at.

§up: Vec3

Up vector.

§fov: f32

Field of view in radians.

§aspect_ratio: f32

Aspect ratio (width / height).

§near: f32

Near clipping plane.

§far: f32

Far clipping plane.

§navigation_style: NavigationStyle

Navigation style.

§projection_mode: ProjectionMode

Projection mode.

§up_direction: AxisDirection

Up direction.

§front_direction: AxisDirection

Front direction.

§move_speed: f32

Movement speed multiplier.

§ortho_scale: f32

Orthographic scale (used when projection_mode is Orthographic).

§flight: Option<CameraFlight>

Active camera flight animation (if any).

Implementations§

Source§

impl Camera

Source

pub fn new(aspect_ratio: f32) -> Self

Creates a new camera with default settings.

Source

pub fn set_aspect_ratio(&mut self, aspect_ratio: f32)

Sets the aspect ratio.

Source

pub fn view_matrix(&self) -> Mat4

Returns the view matrix.

Source

pub fn projection_matrix(&self) -> Mat4

Returns the projection matrix.

Source

pub fn view_projection_matrix(&self) -> Mat4

Returns the combined view-projection matrix.

Source

pub fn forward(&self) -> Vec3

Returns the camera’s forward direction.

Source

pub fn right(&self) -> Vec3

Returns the camera’s right direction.

Source

pub fn camera_up(&self) -> Vec3

Returns the camera’s local up direction (from the view matrix).

Source

pub fn orbit_turntable(&mut self, delta_x: f32, delta_y: f32)

Turntable orbit: yaw around world-space up, pitch around camera-space right, with gimbal-lock protection. Always looks at target.

Matches C++ Polyscope processRotate for NavigateStyle::Turntable: operates on the view matrix directly, then reconstructs position via lookAt. This avoids degenerate cross products at the poles that occur when transforming the camera position in world space.

Source

pub fn orbit_free(&mut self, delta_x: f32, delta_y: f32)

Free orbit: unconstrained rotation using camera-local axes. Both yaw and pitch use the camera’s own coordinate frame.

Matches C++ Polyscope processRotate for NavigateStyle::Free.

Source

pub fn orbit_arcball(&mut self, start: [f32; 2], end: [f32; 2])

Arcball orbit: maps 2D mouse positions to a virtual sphere for rotation. start and end are normalized screen coordinates in [-1, 1].

Matches C++ Polyscope processRotate for NavigateStyle::Arcball.

Source

pub fn mouse_look(&mut self, delta_x: f32, delta_y: f32)

First-person mouse look: yaw around world up, pitch around camera right. Unlike orbit modes, this moves the target (look direction) rather than orbiting around a fixed target.

Matches C++ Polyscope processRotate for NavigateStyle::FirstPerson.

Source

pub fn move_first_person(&mut self, delta: Vec3)

First-person WASD movement in camera-local coordinates. delta is (right, up, forward) movement in camera space, pre-scaled by move_speed and delta time by the caller.

Source

pub fn orbit(&mut self, delta_x: f32, delta_y: f32)

Legacy orbit method — delegates to orbit_turntable.

Source

pub fn pan(&mut self, delta_x: f32, delta_y: f32)

Pans the camera (translates position and target together). For Turntable mode, this moves the orbit center.

Source

pub fn zoom(&mut self, delta: f32)

Zooms the camera (moves toward/away from target for perspective, adjusts ortho_scale for orthographic).

Source

pub fn look_at_box(&mut self, min: Vec3, max: Vec3)

Resets the camera to look at the given bounding box.

Source

pub fn set_navigation_style(&mut self, style: NavigationStyle)

Sets the navigation style.

Source

pub fn set_projection_mode(&mut self, mode: ProjectionMode)

Sets the projection mode.

Source

pub fn set_up_direction(&mut self, direction: AxisDirection)

Sets the up direction and updates both the up vector and front direction. The front direction is automatically derived using right-hand coordinate conventions.

Source

pub fn set_move_speed(&mut self, speed: f32)

Sets the movement speed.

Source

pub fn set_ortho_scale(&mut self, scale: f32)

Sets the orthographic scale.

Source

pub fn set_fov(&mut self, fov: f32)

Sets the field of view in radians.

Source

pub fn set_near(&mut self, near: f32)

Sets the near clipping plane.

Source

pub fn set_far(&mut self, far: f32)

Sets the far clipping plane.

Source

pub fn start_flight_to( &mut self, target_view: Mat4, target_fov: f32, duration_secs: f32, )

Starts a smooth animated flight to the given view matrix and FOV.

The target_view is a 4x4 view matrix (world-to-eye). The target_fov is in radians. duration_secs controls the flight length (C++ Polyscope default is 0.4 seconds).

Source

pub fn update_flight(&mut self)

Updates the camera flight animation. Call once per frame.

When the flight completes, the camera is set exactly to the target position and self.flight is cleared.

Source

pub fn cancel_flight(&mut self)

Cancels any active camera flight animation.

Source

pub fn is_in_flight(&self) -> bool

Returns whether a camera flight animation is currently active.

Source

pub fn fov_degrees(&self) -> f32

Returns FOV in degrees.

Source

pub fn set_fov_degrees(&mut self, degrees: f32)

Sets FOV from degrees.

Trait Implementations§

Source§

impl Clone for Camera

Source§

fn clone(&self) -> Camera

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Camera

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Camera

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,