Skip to main content

M44

Struct M44 

pub struct M44 { /* private fields */ }
Expand description

4x4 matrix used by crate::Canvas and other parts of Skia.

Skia assumes a right-handed coordinate system: +X goes to the right +Y goes down +Z goes into the screen (away from the viewer)

Implementations§

§

impl M44

pub const fn new_identity() -> M44

pub fn concat(a: &M44, b: &M44) -> M44

pub const fn nan() -> M44

pub const fn new( m0: f32, m4: f32, m8: f32, m12: f32, m1: f32, m5: f32, m9: f32, m13: f32, m2: f32, m6: f32, m10: f32, m14: f32, m3: f32, m7: f32, m11: f32, m15: f32, ) -> M44

The constructor parameters are in row-major order.

pub fn rows(r0: &V4, r1: &V4, r2: &V4, r3: &V4) -> M44

pub fn cols(c0: &V4, c1: &V4, c2: &V4, c3: &V4) -> M44

pub fn row_major(r: &[f32; 16]) -> M44

pub fn col_major(c: &[f32; 16]) -> M44

pub fn translate(x: f32, y: f32, z: f32) -> M44

pub fn scale(x: f32, y: f32, z: f32) -> M44

pub fn rotate(axis: V3, radians: f32) -> M44

pub fn rect_to_rect(src: impl AsRef<Rect>, dst: impl AsRef<Rect>) -> M44

Scales and translates src to fill dst exactly.

  • src source rectangle
  • dst destination rectangle

pub fn look_at(eye: &V3, center: &V3, up: &V3) -> M44

pub fn perspective(near: f32, far: f32, angle: f32) -> M44

pub fn get_col_major(&self, v: &mut [f32; 16])

pub fn get_row_major(&self, v: &mut [f32; 16])

pub fn set_col_major(&mut self, v: &[f32; 16]) -> &mut M44

👎Deprecated since 0.30.0:

use M44::col_major() instead

pub fn set_row_major(&mut self, v: &[f32; 16]) -> &mut M44

👎Deprecated since 0.30.0:

use M44::row_major() instead

pub fn set_44( &mut self, m0: f32, m1: f32, m2: f32, m3: f32, m4: f32, m5: f32, m6: f32, m7: f32, m8: f32, m9: f32, m10: f32, m11: f32, m12: f32, m13: f32, m14: f32, m15: f32, ) -> &mut M44

👎Deprecated since 0.30.0:

use Self::new() instead

pub fn rc(&self, r: usize, c: usize) -> f32

pub fn set_rc(&mut self, r: usize, c: usize, value: f32)

pub fn row(&self, i: usize) -> V4

pub fn col(&self, i: usize) -> V4

pub fn set_row(&mut self, i: usize, v: &V4)

pub fn set_col(&mut self, i: usize, v: &V4)

pub fn set_identity(&mut self) -> &mut M44

pub fn set_translate(&mut self, x: f32, y: f32, z: f32) -> &mut M44

pub fn set_scale(&mut self, x: f32, y: f32, z: f32) -> &mut M44

pub fn set_rotate_unit_sin_cos( &mut self, axis: V3, sin_angle: f32, cos_angle: f32, ) -> &mut M44

Sets this matrix to rotate about the specified unit-length axis vector, by an angle specified by its sin and cos.

This does not attempt to verify that axis.length() == 1 or that the sin, cos values are correct.

  • axis unit-length axis vector
  • sin_angle sine of the rotation angle
  • cos_angle cosine of the rotation angle

pub fn set_rotate_unit(&mut self, axis: V3, radians: f32) -> &mut M44

Sets this matrix to rotate about the specified unit-length axis vector, by an angle specified in radians.

This does not attempt to verify that axis.length() == 1.

  • axis unit-length axis vector
  • radians rotation angle in radians

pub fn set_rotate(&mut self, axis: V3, radians: f32) -> &mut M44

Sets this matrix to rotate about the specified axis vector, by an angle specified in radians.

Note: axis is not assumed to be unit-length, so it will be normalized internally. If axis is already unit-length, call Self::set_rotate_unit() instead.

  • axis axis vector
  • radians rotation angle in radians

pub fn set_concat_16(&mut self, a: &M44, col_major: &[f32; 16]) -> &mut M44

👎Deprecated since 0.30.0:

use M44::col_major() and M44::set_concat()

pub fn set_concat(&mut self, a: &M44, b: &M44) -> &mut M44

pub fn pre_concat_16(&mut self, col_major: &[f32; 16]) -> &mut M44

👎Deprecated since 0.30.0:

use M44::col_major() and M44::pre_concat()

pub fn pre_concat(&mut self, m: &M44) -> &mut M44

pub fn post_concat(&mut self, m: &M44) -> &mut M44

pub fn normalize_perspective(&mut self)

A matrix is categorized as ‘perspective’ if the bottom row is not [0, 0, 0, 1]. For most uses, a bottom row of [0, 0, 0, X] behaves like a non-perspective matrix, though it will be categorized as perspective. Calling this will change the matrix such that, if its bottom row was [0, 0, 0, X], it will be changed to [0, 0, 0, 1] by scaling the rest of the matrix by 1/X.

| A B C D |    | A/X B/X C/X D/X |
| E F G H | -> | E/X F/X G/X H/X |   for X != 0
| I J K L |    | I/X J/X K/X L/X |
| 0 0 0 X |    |  0   0   0   1  |

pub fn is_finite(&self) -> bool

Returns true if all elements of the matrix are finite. Returns false if any element is infinity, or NaN.

pub fn invert(&self) -> Option<M44>

If this is invertible, returns Some(inverse). If it is not invertible, returns None.

pub fn transpose(&self) -> M44

pub fn dump(&self)

pub fn map(&self, x: f32, y: f32, z: f32, w: f32) -> V4

pub fn to_m33(&self) -> Matrix

When converting from M44 to Matrix, the third row and column is dropped. When converting from Matrix to M44 the third row and column remain as identity:

[ a b c ]      [ a b 0 c ]
[ d e f ]  ->  [ d e 0 f ]
[ g h i ]      [ 0 0 1 0 ]
               [ g h 0 i ]

pub fn pre_translate( &mut self, x: f32, y: f32, z: impl Into<Option<f32>>, ) -> &mut M44

pub fn post_translate( &mut self, x: f32, y: f32, z: impl Into<Option<f32>>, ) -> &mut M44

pub fn pre_scale(&mut self, x: f32, y: f32) -> &mut M44

pub fn pre_scale_xyz(&mut self, x: f32, y: f32, z: f32) -> &mut M44

Trait Implementations§

§

impl Clone for M44

§

fn clone(&self) -> M44

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
§

impl Debug for M44

§

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

Formats the value using the given formatter. Read more
§

impl Default for M44

§

fn default() -> M44

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

impl From<&Matrix> for M44

§

fn from(src: &Matrix) -> M44

Converts to this type from the input type.
§

impl From<Matrix> for M44

§

fn from(m: Matrix) -> M44

Converts to this type from the input type.
§

impl Mul for &M44

§

type Output = M44

The resulting type after applying the * operator.
§

fn mul(self, m: &M44) -> <&M44 as Mul>::Output

Performs the * operation. Read more
§

impl Mul<V3> for &M44

§

type Output = V3

The resulting type after applying the * operator.
§

fn mul(self, v: V3) -> <&M44 as Mul<V3>>::Output

Performs the * operation. Read more
§

impl Mul<V4> for &M44

§

type Output = V4

The resulting type after applying the * operator.
§

fn mul(self, v: V4) -> <&M44 as Mul<V4>>::Output

Performs the * operation. Read more
§

impl PartialEq for M44

§

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

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

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

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl Freeze for M44

§

impl RefUnwindSafe for M44

§

impl Send for M44

§

impl Sync for M44

§

impl Unpin for M44

§

impl UnsafeUnpin for M44

§

impl UnwindSafe for M44

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
§

impl<T> AnyEq for T
where T: Any + PartialEq,

§

fn equals(&self, other: &(dyn Any + 'static)) -> bool

§

fn as_any(&self) -> &(dyn Any + 'static)

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
§

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

§

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
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

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

§

impl<N, T> NativeTransmutableWrapper<N> for T
where T: NativeTransmutable<N>,

§

fn wrap(native: N) -> T

§

fn unwrap(self) -> N

§

fn inner(&self) -> &N

§

fn inner_mut(&mut self) -> &mut N

§

impl<T> NoneValue for T
where T: Default,

§

type NoneType = T

§

fn null_value() -> T

The none-equivalent value.
§

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

§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

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

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