Skip to main content

Camera

Struct Camera 

Source
pub struct Camera { /* private fields */ }
Expand description

Semantic camera value.

Composes a Transform (placement) with lens parameters (projection shape). get_view_matrix derives from the transform’s position and forward direction. get_projection_matrix uses the lens parameters with Vulkan clip-space conventions (reversed-Y, depth [0, 1]).

Donor: oa::Camera / oa::FnCamera.

Implementations§

Source§

impl Camera

Source

pub fn new_perspective( position: Vec3, target: Vec3, fov_y: f32, aspect: f32, near: f32, far: f32, ) -> Self

Create a perspective camera.

fov_y is in degrees. near and far must be finite, positive, and near < far. aspect must be finite and positive.

Source

pub fn new_orthographic(width: f32, height: f32, near: f32, far: f32) -> Self

Create an orthographic camera.

Source

pub const fn transform(&self) -> &Transform

Return a reference to the placement transform.

Source

pub fn transform_mut(&mut self) -> &mut Transform

Return a mutable reference to the placement transform.

Source

pub fn position(&self) -> Vec3

Return the camera position (from the placement transform).

Source

pub fn set_position(&mut self, position: Vec3)

Set the camera position.

Source

pub fn look_at(&mut self, target: Vec3)

Orient the camera to look at target (world up = +Y).

Source

pub const fn projection(&self) -> CameraProjection

Return the current projection kind.

Source

pub const fn fov_y(&self) -> f32

Return the vertical field of view in degrees.

Source

pub fn effective_fov_y(&self) -> f32

Return the effective vertical field of view in degrees, applying zoom.

Matches donor getEffectiveFovY: fov_y / zoom clamped to (0°, 180°).

Source

pub const fn aspect(&self) -> f32

Return the aspect ratio.

Source

pub const fn near(&self) -> f32

Return the near plane distance.

Source

pub const fn far(&self) -> f32

Return the far plane distance.

Source

pub fn set_perspective(&mut self, fov_y: f32, aspect: f32, near: f32, far: f32)

Set perspective projection parameters.

Source

pub fn set_orthographic(&mut self, width: f32, height: f32, near: f32, far: f32)

Set orthographic projection parameters.

Source

pub fn set_aspect(&mut self, aspect: f32)

Set aspect ratio without changing other perspective parameters.

Source

pub fn fit_to_window(&mut self, window_width: f32, window_height: f32)

Adjust aspect ratio and orthographic extent to match a window size.

Source

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

Set zoom factor (must be > 0).

Source

pub const fn zoom(&self) -> f32

Return zoom factor.

Source

pub fn get_view_matrix(&self) -> Mat4

Compute the row-vector view matrix from the placement transform.

The camera faces its local -Z axis (OA convention). Returns an identity view when the forward vector is degenerate.

Source

pub fn get_projection_matrix(&self) -> Mat4

Compute the row-vector projection matrix in Vulkan clip space.

Perspective: reversed-Y (NDC Y points down) and Vulkan depth [0, 1]. Orthographic: likewise.

Source

pub fn get_view_projection_matrix(&self) -> Mat4

Compute the combined view-projection matrix.

Source

pub fn set_orbit_target(&mut self, target: Vec3)

Set the orbit pivot.

Source

pub fn set_orbit_distance(&mut self, distance: f32)

Set the orbit radius without changing the pivot or angles.

Source

pub fn orbit_yaw_pitch(&mut self, yaw_delta: f32, pitch_delta: f32)

Apply incremental yaw (around world Y) and pitch (around local right) deltas.

Source

pub fn orbit_set_yaw_pitch(&mut self, yaw: f32, pitch: f32)

Set absolute yaw and pitch around the orbit pivot.

Source

pub fn validate(&self) -> Result<()>

Validate camera parameters for use in a frame.

§Errors

Returns an error for non-finite parameters, zero/negative near/far, near >= far, or a non-finite view-projection matrix.

Trait Implementations§

Source§

impl Clone for Camera

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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

Perspective camera at (0, 0, 5), looking toward the origin.

Source§

impl PartialEq for Camera

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Camera

Auto Trait Implementations§

§

impl Forget for Camera

§

impl Freeze for Camera

§

impl Move for Camera

§

impl RefUnwindSafe for Camera

§

impl Send for Camera

§

impl Sync for Camera

§

impl Unpin for Camera

§

impl UnsafeUnpin for Camera

§

impl UnwindSafe for Camera

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

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<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.