Struct MatrixStack

Source
pub struct MatrixStack(/* private fields */);

Implementations§

Source§

impl MatrixStack

Source

pub fn new(ctx: &Context) -> MatrixStack

Allocates a new MatrixStack that can be used to build up transformations relating to objects in a scenegraph like hierarchy. (See the description of MatrixStack and MatrixEntry for more details of what a matrix stack is best suited for)

When a MatrixStack is first allocated it is conceptually positioned at the root of your scenegraph hierarchy. As you traverse your scenegraph then you should call MatrixStack::push whenever you move down a level and MatrixStack::pop whenever you move back up a level towards the root.

Once you have allocated a MatrixStack you can get a reference to the current transformation for the current position in the hierarchy by calling MatrixStack::get_entry.

Once you have allocated a MatrixStack you can apply operations such as rotate, scale and translate to modify the current transform for the current position in the hierarchy by calling MatrixStack::rotate, MatrixStack::scale and MatrixStack::translate.

§ctx

A Context

§Returns

A newly allocated MatrixStack

Source

pub fn frustum( &self, left: f32, right: f32, bottom: f32, top: f32, z_near: f32, z_far: f32, )

Replaces the current matrix with a perspective matrix for a given viewing frustum defined by 4 side clip planes that all cross through the origin and 2 near and far clip planes.

§left

X position of the left clipping plane where it intersects the near clipping plane

X position of the right clipping plane where it intersects the near clipping plane

§bottom

Y position of the bottom clipping plane where it intersects the near clipping plane

§top

Y position of the top clipping plane where it intersects the near clipping plane

§z_near

The distance to the near clipping plane (Must be positive)

§z_far

The distance to the far clipping plane (Must be positive)

Source

pub fn get(&self) -> (Matrix, Matrix)

Resolves the current self transform into a Matrix by combining the operations that have been applied to build up the current transform.

There are two possible ways that this function may return its result depending on whether the stack is able to directly point to an internal Matrix or whether the result needs to be composed of multiple operations.

If an internal matrix contains the required result then this function will directly return a pointer to that matrix, otherwise if the function returns None then matrix will be initialized to match the current transform of self.

<note>``matrix will be left untouched if a direct pointer is returned.</note>

§matrix

The potential destination for the current matrix

§Returns

A direct pointer to the current transform or None and in that case matrix will be initialized with the value of the current transform.

Source

pub fn get_entry(&self) -> Option<MatrixEntry>

Gets a reference to the current transform represented by a MatrixEntry pointer.

<note>The transform represented by a MatrixEntry is immutable.</note>

<note>``MatrixEntrys are reference counted using MatrixEntry::ref and MatrixEntry::unref and you should call MatrixEntry::unref when you are finished with and entry you get via MatrixStack::get_entry.</note>

§Returns

A pointer to the MatrixEntry representing the current matrix stack transform.

Source

pub fn get_inverse(&self) -> (bool, Matrix)

Gets the inverse transform of the current matrix and uses it to initialize a new Matrix.

§inverse

The destination for a 4x4 inverse transformation matrix

§Returns

true if the inverse was successfully calculated or false for degenerate transformations that can’t be inverted (in this case the inverse matrix will simply be initialized with the identity matrix)

Source

pub fn load_identity(&self)

Resets the current matrix to the identity matrix.

Source

pub fn multiply(&self, matrix: &Matrix)

Multiplies the current matrix by the given matrix.

§matrix

the matrix to multiply with the current model-view

Source

pub fn orthographic( &self, x_1: f32, y_1: f32, x_2: f32, y_2: f32, near: f32, far: f32, )

Replaces the current matrix with an orthographic projection matrix.

§x_1

The x coordinate for the first vertical clipping plane

§y_1

The y coordinate for the first horizontal clipping plane

§x_2

The x coordinate for the second vertical clipping plane

§y_2

The y coordinate for the second horizontal clipping plane

§near

The <emphasis>distance</emphasis> to the near clipping plane (will be <emphasis>negative</emphasis> if the plane is behind the viewer)

§far

The <emphasis>distance</emphasis> to the far clipping plane (will be <emphasis>negative</emphasis> if the plane is behind the viewer)

Source

pub fn perspective(&self, fov_y: f32, aspect: f32, z_near: f32, z_far: f32)

Replaces the current matrix with a perspective matrix based on the provided values.

<note>You should be careful not to have too great a z_far / z_near ratio since that will reduce the effectiveness of depth testing since there wont be enough precision to identify the depth of objects near to each other.</note>

§fov_y

Vertical field of view angle in degrees.

§aspect

The (width over height) aspect ratio for display

§z_near

The distance to the near clipping plane (Must be positive, and must not be 0)

§z_far

The distance to the far clipping plane (Must be positive)

Source

pub fn pop(&self)

Restores the previous transform that was last saved by calling MatrixStack::push.

This is usually called while traversing a scenegraph whenever you return up one level in the graph towards the root node.

Source

pub fn push(&self)

Saves the current transform and starts a new transform that derives from the current transform.

This is usually called while traversing a scenegraph whenever you traverse one level deeper. MatrixStack::pop can then be called when going back up one layer to restore the previous transform of an ancestor.

Source

pub fn rotate(&self, angle: f32, x: f32, y: f32, z: f32)

Multiplies the current matrix by one that rotates the around the axis-vector specified by x, y and z. The rotation follows the right-hand thumb rule so for example rotating by 10 degrees about the axis-vector (0, 0, 1) causes a small counter-clockwise rotation.

§angle

Angle in degrees to rotate.

§x

X-component of vertex to rotate around.

§y

Y-component of vertex to rotate around.

§z

Z-component of vertex to rotate around.

Source

pub fn rotate_euler(&self, euler: &Euler)

Multiplies the current matrix by one that rotates according to the rotation described by euler.

§euler

A Euler

Source

pub fn rotate_quaternion(&self, quaternion: &Quaternion)

Multiplies the current matrix by one that rotates according to the rotation described by quaternion.

§quaternion

A Quaternion

Source

pub fn scale(&self, x: f32, y: f32, z: f32)

Multiplies the current matrix by one that scales the x, y and z axes by the given values.

§x

Amount to scale along the x-axis

§y

Amount to scale along the y-axis

§z

Amount to scale along the z-axis

Source

pub fn set(&self, matrix: &Matrix)

Replaces the current self matrix value with the value of matrix. This effectively discards any other operations that were applied since the last time MatrixStack::push was called or since the stack was initialized.

§matrix

A Matrix replace the current matrix value with

Source

pub fn translate(&self, x: f32, y: f32, z: f32)

Multiplies the current matrix by one that translates along all three axes according to the given values.

§x

Distance to translate along the x-axis

§y

Distance to translate along the y-axis

§z

Distance to translate along the z-axis

Trait Implementations§

Source§

impl Clone for MatrixStack

Source§

fn clone(&self) -> MatrixStack

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 MatrixStack

Source§

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

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

impl Display for MatrixStack

Source§

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

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

impl Hash for MatrixStack

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for MatrixStack

Source§

fn cmp(&self, other: &MatrixStack) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T: ObjectType> PartialEq<T> for MatrixStack

Source§

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

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

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<T: ObjectType> PartialOrd<T> for MatrixStack

Source§

fn partial_cmp(&self, other: &T) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StaticType for MatrixStack

Source§

fn static_type() -> Type

Returns the type identifier of Self.
Source§

impl Eq for MatrixStack

Source§

impl IsA<Object> for MatrixStack

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> Cast for T
where T: ObjectType,

Source§

fn upcast<T>(self) -> T
where T: ObjectType, Self: IsA<T>,

Upcasts an object to a superclass or interface T. Read more
Source§

fn upcast_ref<T>(&self) -> &T
where T: ObjectType, Self: IsA<T>,

Upcasts an object to a reference of its superclass or interface T. Read more
Source§

fn downcast<T>(self) -> Result<T, Self>
where T: ObjectType, Self: CanDowncast<T>,

Tries to downcast to a subclass or interface implementor T. Read more
Source§

fn downcast_ref<T>(&self) -> Option<&T>
where T: ObjectType, Self: CanDowncast<T>,

Tries to downcast to a reference of its subclass or interface implementor T. Read more
Source§

fn dynamic_cast<T>(self) -> Result<T, Self>
where T: ObjectType,

Tries to cast to an object of type T. This handles upcasting, downcasting and casting between interface and interface implementors. All checks are performed at runtime, while downcast and upcast will do many checks at compile-time already. Read more
Source§

fn dynamic_cast_ref<T>(&self) -> Option<&T>
where T: ObjectType,

Tries to cast to reference to an object of type T. This handles upcasting, downcasting and casting between interface and interface implementors. All checks are performed at runtime, while downcast and upcast will do many checks at compile-time already. Read more
Source§

unsafe fn unsafe_cast<T>(self) -> T
where T: ObjectType,

Casts to T unconditionally. Read more
Source§

unsafe fn unsafe_cast_ref<T>(&self) -> &T
where T: ObjectType,

Casts to &T unconditionally. 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> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for T

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for T

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for T

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for T

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for T

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for T

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for T

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for T

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for T

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for T

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for T

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for T

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> ObjectExt for T
where T: ObjectType,

Source§

fn is<U>(&self) -> bool
where U: StaticType,

Returns true if the object is an instance of (can be cast to) T.
Source§

fn get_type(&self) -> Type

Source§

fn get_object_class(&self) -> &ObjectClass

Source§

fn set_properties( &self, property_values: &[(&str, &dyn ToValue)], ) -> Result<(), BoolError>

Source§

fn set_property<'a, N>( &self, property_name: N, value: &dyn ToValue, ) -> Result<(), BoolError>
where N: Into<&'a str>,

Source§

fn get_property<'a, N>(&self, property_name: N) -> Result<Value, BoolError>
where N: Into<&'a str>,

Source§

unsafe fn set_qdata<QD>(&self, key: Quark, value: QD)
where QD: 'static,

Safety Read more
Source§

unsafe fn get_qdata<QD>(&self, key: Quark) -> Option<&QD>
where QD: 'static,

Safety Read more
Source§

unsafe fn steal_qdata<QD>(&self, key: Quark) -> Option<QD>
where QD: 'static,

Safety Read more
Source§

unsafe fn set_data<QD>(&self, key: &str, value: QD)
where QD: 'static,

Safety Read more
Source§

unsafe fn get_data<QD>(&self, key: &str) -> Option<&QD>
where QD: 'static,

Safety Read more
Source§

unsafe fn steal_data<QD>(&self, key: &str) -> Option<QD>
where QD: 'static,

Safety Read more
Source§

fn block_signal(&self, handler_id: &SignalHandlerId)

Source§

fn unblock_signal(&self, handler_id: &SignalHandlerId)

Source§

fn stop_signal_emission(&self, signal_name: &str)

Source§

fn disconnect(&self, handler_id: SignalHandlerId)

Source§

fn connect_notify<F>(&self, name: Option<&str>, f: F) -> SignalHandlerId
where F: Fn(&T, &ParamSpec) + Send + Sync + 'static,

Source§

unsafe fn connect_notify_unsafe<F>( &self, name: Option<&str>, f: F, ) -> SignalHandlerId
where F: Fn(&T, &ParamSpec),

Source§

fn notify<'a, N>(&self, property_name: N)
where N: Into<&'a str>,

Source§

fn notify_by_pspec(&self, pspec: &ParamSpec)

Source§

fn has_property<'a, N>(&self, property_name: N, type_: Option<Type>) -> bool
where N: Into<&'a str>,

Source§

fn get_property_type<'a, N>(&self, property_name: N) -> Option<Type>
where N: Into<&'a str>,

Source§

fn find_property<'a, N>(&self, property_name: N) -> Option<ParamSpec>
where N: Into<&'a str>,

Source§

fn list_properties(&self) -> Vec<ParamSpec>

Source§

fn connect<'a, N, F>( &self, signal_name: N, after: bool, callback: F, ) -> Result<SignalHandlerId, BoolError>
where N: Into<&'a str>, F: Fn(&[Value]) -> Option<Value> + Send + Sync + 'static,

Source§

fn connect_local<'a, N, F>( &self, signal_name: N, after: bool, callback: F, ) -> Result<SignalHandlerId, BoolError>
where N: Into<&'a str>, F: Fn(&[Value]) -> Option<Value> + 'static,

Source§

unsafe fn connect_unsafe<'a, N, F>( &self, signal_name: N, after: bool, callback: F, ) -> Result<SignalHandlerId, BoolError>
where N: Into<&'a str>, F: Fn(&[Value]) -> Option<Value>,

Source§

fn emit<'a, N>( &self, signal_name: N, args: &[&dyn ToValue], ) -> Result<Option<Value>, BoolError>
where N: Into<&'a str>,

Source§

fn downgrade(&self) -> WeakRef<T>

Source§

fn bind_property<'a, O, N, M>( &'a self, source_property: N, target: &'a O, target_property: M, ) -> BindingBuilder<'a>
where O: ObjectType, N: Into<&'a str>, M: Into<&'a str>,

Source§

fn ref_count(&self) -> u32

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> ToValue for T
where T: SetValue + ?Sized,

Source§

fn to_value(&self) -> Value

Returns a Value clone of self.
Source§

fn to_value_type(&self) -> Type

Returns the type identifer of self. 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<Super, Sub> CanDowncast<Sub> for Super
where Super: IsA<Super>, Sub: IsA<Super>,

Source§

impl<O> ObjectExt for O
where O: IsA<Object>,