Skip to main content

Camera2D

Struct Camera2D 

Source
pub struct Camera2D {
    pub pan: Vec2,
    pub zoom: f32,
    pub rotation: f32,
}
Expand description

2D pan/zoom viewport camera with rotation support.

Fields§

§pan: Vec2§zoom: f32§rotation: f32

Implementations§

Source§

impl Camera2D

Source

pub fn new(pan: Vec2, zoom: f32) -> Self

Source

pub fn view_matrix(&self) -> Mat4

Computes the 2D view matrix (pan, rotation, and uniform zoom).

Source

pub fn proj_matrix(&self, width: f32, height: f32) -> Mat4

Computes the orthographic projection matrix for a given viewport size (center-origin, Y-up).

Source

pub fn view_proj_matrix(&self, width: f32, height: f32) -> Mat4

Combined view-projection matrix.

Source

pub fn screen_to_world(&self, screen_pt: Vec2, viewport: ViewportRect) -> Vec2

Converts a screen pixel coordinate within viewport to Y-up 2D world coordinates.

Source

pub fn world_to_screen(&self, world_pt: Vec2, viewport: ViewportRect) -> Vec2

Converts a Y-up 2D world point to screen pixel coordinates within viewport.

Source

pub fn zoom_at( &mut self, screen_pt: Vec2, viewport: ViewportRect, new_zoom: f32, )

Updates zoom to new_zoom while keeping the world point under screen_pt stationary.

Source

pub fn zoom_by_at( &mut self, screen_pt: Vec2, viewport: ViewportRect, factor: f32, )

Multiplies zoom by factor while keeping the world point under screen_pt stationary.

Source

pub fn visible_world_rect(&self, viewport: ViewportRect) -> ViewportRect

Returns the axis-aligned world-space bounding rectangle visible inside viewport.

Source

pub fn to_vello_affine_ortho(&self, width: f32, height: f32) -> [f64; 6]

Returns a 2D affine [a, b, c, d, e, f] (column-major 2x3, matching kurbo::Affine::new) mapping Y-up world coordinates to top-left Y-down canvas pixels of size (width, height).

Source

pub fn to_vello_affine_y_down(&self) -> [f64; 6]

Returns a 2D affine [a, b, c, d, e, f] (matching kurbo::Affine::new) for Y-down world space (p_screen = pan + zoom * R(rotation) * p_world).

Source

pub fn screen_to_world_y_down( &self, screen_pt: Vec2, viewport: ViewportRect, ) -> Vec2

Converts a screen pixel coordinate within viewport to Y-down 2D world coordinates.

Source

pub fn world_to_screen_y_down( &self, world_pt: Vec2, viewport: ViewportRect, ) -> Vec2

Converts a Y-down 2D world point to screen pixel coordinates within viewport.

Source

pub fn zoom_at_y_down(&mut self, screen_pt: Vec2, factor: f32)

Multiplies zoom by factor while keeping screen_pt stationary in Y-down canvas space.

Trait Implementations§

Source§

impl Clone for Camera2D

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 Copy for Camera2D

Source§

impl Debug for Camera2D

Source§

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

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

impl Default for Camera2D

Source§

fn default() -> Self

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

impl PartialEq for Camera2D

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 Camera2D

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

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

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

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

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

Source§

impl<T> WasmNotSendSync for T

Source§

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