CameraFrame

Struct CameraFrame 

Source
pub struct CameraFrame {
    pub pos: DVec3,
    pub up: DVec3,
    pub facing: DVec3,
    pub near: f64,
    pub far: f64,
    pub perspective_blend: f64,
    pub frame_height: f64,
    pub scale: f64,
    pub fovy: f64,
}
Expand description

The data of a camera

The CameraFrame has a CameraFrame::perspective_blend property (default is 0.0), which is used to blend between orthographic and perspective projection.

Fields§

§pos: DVec3

The position

§up: DVec3

The up unit vec

§facing: DVec3

The facing unit vec

§near: f64

The near pane

§far: f64

The far pane

§perspective_blend: f64

The perspective blend value in [0.0, 1.0]

§frame_height: f64

Ortho: Top - Bottom

§scale: f64

Ortho: The scaling factor

§fovy: f64

Perspective: The field of view angle, used in perspective projection

Implementations§

Source§

impl CameraFrame

Source

pub fn new() -> Self

Create a new CameraFrame at the origin facing to the negative z-axis and use Y as up vector with default projection settings.

Source§

impl CameraFrame

Source

pub fn set_view_matrix(&mut self, view_matrix: DMat4)

Set the view matrix of the camera.

Source

pub fn with_view_matrix(self, view_matrix: DMat4) -> Self

Set the view matrix of the camera and return the modified Self.

Source

pub fn view_matrix(&self) -> DMat4

The view matrix of the camera

Source

pub fn orthographic_mat(&self, aspect_ratio: f64) -> DMat4

Use the given frame size as left, right, bottom, top to construct an orthographic matrix

Source

pub fn perspective_mat(&self, aspect_ratio: f64) -> DMat4

Use the given frame aspect ratio to construct a perspective matrix

Source

pub fn projection_matrix(&self, aspect_ratio: f64) -> DMat4

Use the given frame size to construct projection matrix

Source

pub fn view_projection_matrix(&self, aspect_ratio: f64) -> DMat4

Use the given frame size to construct view projection matrix

Source§

impl CameraFrame

Source

pub fn from_spherical(phi: f64, theta: f64, distance: f64) -> Self

Create a perspective camera positioned using spherical coordinates (Z-up), looking at the origin.

  • phi: polar angle from +Z axis in radians (0 = straight up along +Z, π/2 = XY plane)
  • theta: azimuth angle in radians (0 = +X direction, π/2 = +Y direction)
  • distance: distance from the origin
Source

pub fn set_spherical( &mut self, phi: f64, theta: f64, distance: f64, target: DVec3, ) -> &mut Self

Position the camera using spherical coordinates (Z-up) around a target point.

  • phi: polar angle from +Z axis in radians (0 = straight up along +Z, π/2 = XY plane)
  • theta: azimuth angle in radians (0 = +X direction, π/2 = +Y direction)
  • distance: distance from target
  • target: the point the camera looks at
Source

pub fn look_at(&mut self, target: DVec3) -> &mut Self

Set the camera to look at a target point.

Source

pub fn orbit(&mut self, target: DVec3, total_angle: f64) -> AnimationCell<Self>

Create an orbit animation that rotates the camera around target by total_angle radians in the XY plane (Z-up).

The camera’s current position is used to derive the spherical coordinates (distance, elevation) which are kept constant during the orbit.

§Example
use std::f64::consts::TAU;

let mut cam = CameraFrame::from_spherical(phi, theta, distance);
let r_cam = r.insert(cam.clone());
r.timeline_mut(r_cam).play(
    cam.orbit(DVec3::ZERO, TAU)
       .with_duration(8.0)
       .with_rate_func(linear),
);
Source§

impl CameraFrame

Source

pub fn center_canvas_in_frame( &mut self, center: DVec3, width: f64, height: f64, up: DVec3, normal: DVec3, aspect_ratio: f64, ) -> &mut Self

Center the canvas in the frame when CameraFrame::perspective_blend is 1.0

Trait Implementations§

Source§

impl Alignable for CameraFrame

Source§

fn is_aligned(&self, _other: &Self) -> bool

Checking if two items are aligned
Source§

fn align_with(&mut self, _other: &mut Self)

Aligning two items
Source§

impl Clone for CameraFrame

Source§

fn clone(&self) -> CameraFrame

Returns a duplicate of the value. Read more
1.0.0§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for CameraFrame

Source§

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

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

impl Default for CameraFrame

Source§

fn default() -> Self

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

impl Extract for CameraFrame

Source§

type Target = CoreItem

The extraction result
Source§

fn extract_into(&self, buf: &mut Vec<Self::Target>)

Extract a Extract::Target from reference.
Source§

fn extract(&self) -> Vec<Self::Target>

Extract a Extract::Target from reference.
Source§

impl Interpolatable for CameraFrame

Source§

fn lerp(&self, target: &Self, t: f64) -> Self

Lerping between values
Source§

impl PartialEq for CameraFrame

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for CameraFrame

Auto Trait Implementations§

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

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

§

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> Discard for T

Source§

fn discard(&self)

Simply returns ()
Source§

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

§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

fn in_current_span(self) -> Instrumented<Self>

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

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

§

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> StaticAnim for T
where T: StaticAnimRequirement + 'static,

Source§

fn show(&self) -> AnimationCell<T>

Show the item
Source§

fn hide(&self) -> AnimationCell<T>

Hide the item
§

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

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

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

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

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

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.
Source§

impl<T> With for T

Source§

fn with(self, f: impl Fn(&mut Self)) -> Self
where Self: Sized,

Mutating a value in place
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> AnyExtractCoreItem for T
where T: Extract<Target = CoreItem> + Any + DynClone,

Source§

impl<T> Component for T
where T: Debug + Default + Clone + PartialEq,

Source§

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