pub struct Matrix { /* private fields */ }
Expand description
A structure capable of holding a 4x4 matrix.
The contents of the Matrix
structure are private and
should never be accessed directly.
GLib type: Inline allocated boxed type with stack copy semantics.
Implementations§
source§impl Matrix
impl Matrix
pub fn as_ptr(&self) -> *mut graphene_matrix_t
sourcepub unsafe fn from_glib_ptr_borrow<'a>(
ptr: *const graphene_matrix_t,
) -> &'a Self
pub unsafe fn from_glib_ptr_borrow<'a>( ptr: *const graphene_matrix_t, ) -> &'a Self
Borrows the underlying C value.
sourcepub unsafe fn from_glib_ptr_borrow_mut<'a>(
ptr: *mut graphene_matrix_t,
) -> &'a mut Self
pub unsafe fn from_glib_ptr_borrow_mut<'a>( ptr: *mut graphene_matrix_t, ) -> &'a mut Self
Borrows the underlying C value mutably.
source§impl Matrix
impl Matrix
sourcepub fn decompose(&self) -> Option<(Vec3, Vec3, Quaternion, Vec3, Vec4)>
pub fn decompose(&self) -> Option<(Vec3, Vec3, Quaternion, Vec3, Vec4)>
Decomposes a transformation matrix into its component transformations.
The algorithm for decomposing a matrix is taken from the CSS3 Transforms specification; specifically, the decomposition code is based on the equivalent code published in “Graphics Gems II”, edited by Jim Arvo, and available online.
§Returns
true
if the matrix could be decomposed
§translate
the translation vector
§scale
the scale vector
§rotate
the rotation quaternion
§shear
the shear vector
§perspective
the perspective vector
sourcepub fn determinant(&self) -> f32
pub fn determinant(&self) -> f32
sourcepub fn equal_fast(&self, b: &Matrix) -> bool
pub fn equal_fast(&self, b: &Matrix) -> bool
Checks whether the two given Matrix
matrices are
byte-by-byte equal.
While this function is faster than graphene_matrix_equal()
, it
can also return false negatives, so it should be used in
conjuction with either graphene_matrix_equal()
or
near()
. For instance:
⚠️ The following code is in C ⚠️
if (graphene_matrix_equal_fast (a, b))
{
// matrices are definitely the same
}
else
{
if (graphene_matrix_equal (a, b))
// matrices contain the same values within an epsilon of FLT_EPSILON
else if (graphene_matrix_near (a, b, 0.0001))
// matrices contain the same values within an epsilon of 0.0001
else
// matrices are not equal
}
§b
a Matrix
§Returns
true
if the matrices are equal. and false
otherwise
sourcepub fn x_translation(&self) -> f32
pub fn x_translation(&self) -> f32
sourcepub fn y_translation(&self) -> f32
pub fn y_translation(&self) -> f32
sourcepub fn z_translation(&self) -> f32
pub fn z_translation(&self) -> f32
sourcepub fn interpolate(&self, b: &Matrix, factor: f64) -> Matrix
pub fn interpolate(&self, b: &Matrix, factor: f64) -> Matrix
Linearly interpolates the two given Matrix
by
interpolating the decomposed transformations separately.
If either matrix cannot be reduced to their transformations then the interpolation cannot be performed, and this function will return an identity matrix.
§b
a Matrix
§factor
the linear interpolation factor
§Returns
§res
return location for the interpolated matrix
sourcepub fn is_backface_visible(&self) -> bool
pub fn is_backface_visible(&self) -> bool
sourcepub fn is_identity(&self) -> bool
pub fn is_identity(&self) -> bool
sourcepub fn is_singular(&self) -> bool
pub fn is_singular(&self) -> bool
sourcepub fn perspective(&self, depth: f32) -> Matrix
pub fn perspective(&self, depth: f32) -> Matrix
sourcepub fn print(&self)
pub fn print(&self)
Prints the contents of a matrix to the standard error stream.
This function is only useful for debugging; there are no guarantees made on the format of the output.
sourcepub fn project_point(&self, p: &Point) -> Point
pub fn project_point(&self, p: &Point) -> Point
sourcepub fn project_rect(&self, r: &Rect) -> Quad
pub fn project_rect(&self, r: &Rect) -> Quad
sourcepub fn project_rect_bounds(&self, r: &Rect) -> Rect
pub fn project_rect_bounds(&self, r: &Rect) -> Rect
sourcepub fn rotate(&mut self, angle: f32, axis: &Vec3)
pub fn rotate(&mut self, angle: f32, axis: &Vec3)
Adds a rotation transformation to self
, using the given angle
and axis
vector.
This is the equivalent of calling new_rotate()
and
then multiplying the matrix self
with the rotation matrix.
§angle
the rotation angle, in degrees
§axis
the rotation axis, as a Vec3
sourcepub fn rotate_euler(&mut self, e: &Euler)
pub fn rotate_euler(&mut self, e: &Euler)
sourcepub fn rotate_quaternion(&mut self, q: &Quaternion)
pub fn rotate_quaternion(&mut self, q: &Quaternion)
Adds a rotation transformation to self
, using the given
Quaternion
.
This is the equivalent of calling Quaternion::to_matrix()
and
then multiplying self
with the rotation matrix.
§q
a rotation described by a Quaternion
sourcepub fn scale(&mut self, factor_x: f32, factor_y: f32, factor_z: f32)
pub fn scale(&mut self, factor_x: f32, factor_y: f32, factor_z: f32)
Adds a scaling transformation to self
, using the three
given factors.
This is the equivalent of calling new_scale()
and then
multiplying the matrix self
with the scale matrix.
§factor_x
scaling factor on the X axis
§factor_y
scaling factor on the Y axis
§factor_z
scaling factor on the Z axis
sourcepub fn to_2d(&self) -> Option<(f64, f64, f64, f64, f64, f64)>
pub fn to_2d(&self) -> Option<(f64, f64, f64, f64, f64, f64)>
Converts a Matrix
to an affine transformation
matrix, if the given matrix is compatible.
The returned values have the following layout:
⚠️ The following code is in plain ⚠️
⎛ xx yx ⎞ ⎛ a b 0 ⎞
⎜ xy yy ⎟ = ⎜ c d 0 ⎟
⎝ x0 y0 ⎠ ⎝ tx ty 1 ⎠
This function can be used to convert between a Matrix
and an affine matrix type from other libraries.
§Returns
true
if the matrix is compatible with an affine
transformation matrix
§xx
return location for the xx member
§yx
return location for the yx member
§xy
return location for the xy member
§yy
return location for the yy member
§x_0
return location for the x0 member
§y_0
return location for the y0 member
sourcepub fn transform_bounds(&self, r: &Rect) -> Rect
pub fn transform_bounds(&self, r: &Rect) -> Rect
sourcepub fn transform_box(&self, b: &Box) -> Box
pub fn transform_box(&self, b: &Box) -> Box
sourcepub fn transform_point(&self, p: &Point) -> Point
pub fn transform_point(&self, p: &Point) -> Point
Transforms the given Point
using the matrix self
.
Unlike transform_vec3()
, this function will take into
account the fourth row vector of the Matrix
when computing
the dot product of each row vector of the matrix.
See also: graphene_simd4x4f_point3_mul()
§p
a Point
§Returns
§res
return location for the
transformed Point
sourcepub fn transform_point3d(&self, p: &Point3D) -> Point3D
pub fn transform_point3d(&self, p: &Point3D) -> Point3D
Transforms the given Point3D
using the matrix self
.
Unlike transform_vec3()
, this function will take into
account the fourth row vector of the Matrix
when computing
the dot product of each row vector of the matrix.
See also: graphene_simd4x4f_point3_mul()
§p
a Point3D
§Returns
§res
return location for the result
sourcepub fn transform_ray(&self, r: &Ray) -> Ray
pub fn transform_ray(&self, r: &Ray) -> Ray
sourcepub fn transform_rect(&self, r: &Rect) -> Quad
pub fn transform_rect(&self, r: &Rect) -> Quad
sourcepub fn transform_sphere(&self, s: &Sphere) -> Sphere
pub fn transform_sphere(&self, s: &Sphere) -> Sphere
sourcepub fn transform_vec3(&self, v: &Vec3) -> Vec3
pub fn transform_vec3(&self, v: &Vec3) -> Vec3
sourcepub fn transform_vec4(&self, v: &Vec4) -> Vec4
pub fn transform_vec4(&self, v: &Vec4) -> Vec4
sourcepub fn translate(&mut self, pos: &Point3D)
pub fn translate(&mut self, pos: &Point3D)
Adds a translation transformation to self
using the coordinates
of the given Point3D
.
This is the equivalent of calling new_translate()
and
then multiplying self
with the translation matrix.
§pos
a Point3D
sourcepub fn unproject_point3d(&self, modelview: &Matrix, point: &Point3D) -> Point3D
pub fn unproject_point3d(&self, modelview: &Matrix, point: &Point3D) -> Point3D
sourcepub fn untransform_bounds(&self, r: &Rect, bounds: &Rect) -> Rect
pub fn untransform_bounds(&self, r: &Rect, bounds: &Rect) -> Rect
source§impl Matrix
impl Matrix
sourcepub fn from_2d(xx: f64, yx: f64, xy: f64, yy: f64, x_0: f64, y_0: f64) -> Self
pub fn from_2d(xx: f64, yx: f64, xy: f64, yy: f64, x_0: f64, y_0: f64) -> Self
Initializes a Matrix
from the values of an affine
transformation matrix.
The arguments map to the following matrix layout:
⚠️ The following code is in plain ⚠️
⎛ xx yx ⎞ ⎛ a b 0 ⎞
⎜ xy yy ⎟ = ⎜ c d 0 ⎟
⎝ x0 y0 ⎠ ⎝ tx ty 1 ⎠
This function can be used to convert between an affine matrix type
from other libraries and a Matrix
.
§xx
the xx member
§yx
the yx member
§xy
the xy member
§yy
the yy member
§x_0
the x0 member
§y_0
the y0 member
§Returns
the initialized matrix
sourcepub fn from_float(v: [f32; 16]) -> Self
pub fn from_float(v: [f32; 16]) -> Self
sourcepub fn new_frustum(
left: f32,
right: f32,
bottom: f32,
top: f32,
z_near: f32,
z_far: f32,
) -> Self
pub fn new_frustum( left: f32, right: f32, bottom: f32, top: f32, z_near: f32, z_far: f32, ) -> Self
Initializes a Matrix
compatible with Frustum
.
See also: Frustum::from_matrix()
§left
distance of the left clipping plane
§right
distance of the right clipping plane
§bottom
distance of the bottom clipping plane
§top
distance of the top clipping plane
§z_near
distance of the near clipping plane
§z_far
distance of the far clipping plane
§Returns
the initialized matrix
sourcepub fn new_identity() -> Self
pub fn new_identity() -> Self
sourcepub fn new_look_at(eye: &Vec3, center: &Vec3, up: &Vec3) -> Self
pub fn new_look_at(eye: &Vec3, center: &Vec3, up: &Vec3) -> Self
Initializes a Matrix
so that it positions the “camera”
at the given eye
coordinates towards an object at the center
coordinates. The top of the camera is aligned to the direction
of the up
vector.
Before the transform, the camera is assumed to be placed at the origin, looking towards the negative Z axis, with the top side of the camera facing in the direction of the Y axis and the right side in the direction of the X axis.
In theory, one could use self
to transform a model of such a camera
into world-space. However, it is more common to use the inverse of
self
to transform another object from world coordinates to the view
coordinates of the camera. Typically you would then apply the
camera projection transform to get from view to screen
coordinates.
§eye
the vector describing the position to look from
§center
the vector describing the position to look at
§up
the vector describing the world’s upward direction; usually,
this is the Vec3::y_axis()
vector
§Returns
the initialized matrix
sourcepub fn new_ortho(
left: f32,
right: f32,
top: f32,
bottom: f32,
z_near: f32,
z_far: f32,
) -> Self
pub fn new_ortho( left: f32, right: f32, top: f32, bottom: f32, z_near: f32, z_far: f32, ) -> Self
Initializes a Matrix
with an orthographic projection.
§left
the left edge of the clipping plane
§right
the right edge of the clipping plane
§top
the top edge of the clipping plane
§bottom
the bottom edge of the clipping plane
§z_near
the distance of the near clipping plane
§z_far
the distance of the far clipping plane
§Returns
the initialized matrix
sourcepub fn new_rotate(angle: f32, axis: &Vec3) -> Self
pub fn new_rotate(angle: f32, axis: &Vec3) -> Self
sourcepub fn new_translate(p: &Point3D) -> Self
pub fn new_translate(p: &Point3D) -> Self
pub fn values(&self) -> &[[f32; 4]; 4]
Trait Implementations§
source§impl HasParamSpec for Matrix
impl HasParamSpec for Matrix
source§impl StaticType for Matrix
impl StaticType for Matrix
source§fn static_type() -> Type
fn static_type() -> Type
Self
.impl Copy for Matrix
impl Eq for Matrix
Auto Trait Implementations§
impl Freeze for Matrix
impl RefUnwindSafe for Matrix
impl Send for Matrix
impl Sync for Matrix
impl Unpin for Matrix
impl UnwindSafe for Matrix
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
source§impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
source§impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
source§impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
source§impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
source§impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
source§impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
source§impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
source§impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
source§impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
source§impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
source§impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
source§impl<T> IntoClosureReturnValue for T
impl<T> IntoClosureReturnValue for T
fn into_closure_return_value(self) -> Option<Value>
source§impl<T> PropertyGet for Twhere
T: HasParamSpec,
impl<T> PropertyGet for Twhere
T: HasParamSpec,
source§impl<T> StaticTypeExt for Twhere
T: StaticType,
impl<T> StaticTypeExt for Twhere
T: StaticType,
source§fn ensure_type()
fn ensure_type()
source§impl<T> ToSendValue for T
impl<T> ToSendValue for T
source§fn to_send_value(&self) -> SendValue
fn to_send_value(&self) -> SendValue
SendValue
clone of self
.