#[repr(C)]pub struct Mat3<T> {
pub cols: CVec3<Vec3<T>>,
}
Expand description
3x3 matrix.
Fields§
§cols: CVec3<Vec3<T>>
Implementations§
source§impl<T> Mat3<T>
impl<T> Mat3<T>
sourcepub fn identity() -> Selfwhere
T: Zero + One,
pub fn identity() -> Selfwhere T: Zero + One,
The identity matrix, which is also the default value for square matrices.
assert_eq!(Mat4::<f32>::default(), Mat4::<f32>::identity());
sourcepub fn apply<F>(&mut self, f: F)where
T: Copy,
F: FnMut(T) -> T,
pub fn apply<F>(&mut self, f: F)where T: Copy, F: FnMut(T) -> T,
Applies the function f to each element of this matrix, in-place.
For an example, see the map()
method.
sourcepub fn apply2<F, S>(&mut self, other: Mat3<S>, f: F)where
T: Copy,
F: FnMut(T, S) -> T,
pub fn apply2<F, S>(&mut self, other: Mat3<S>, f: F)where T: Copy, F: FnMut(T, S) -> T,
Applies the function f to each element of this matrix, in-place.
For an example, see the map2()
method.
sourcepub fn numcast<D>(self) -> Option<Mat3<D>>where
T: NumCast,
D: NumCast,
pub fn numcast<D>(self) -> Option<Mat3<D>>where T: NumCast, D: NumCast,
Returns a memberwise-converted copy of this matrix, using NumCast
.
let m = Mat4::<f32>::identity();
let m: Mat4<i32> = m.numcast().unwrap();
assert_eq!(m, Mat4::identity());
sourcepub fn broadcast_diagonal(val: T) -> Selfwhere
T: Zero + Copy,
pub fn broadcast_diagonal(val: T) -> Selfwhere T: Zero + Copy,
Initializes a new matrix with elements of the diagonal set to val
and the other to zero.
In a way, this is the same as single-argument matrix constructors in GLSL and GLM.
assert_eq!(Mat4::broadcast_diagonal(0), Mat4::zero());
assert_eq!(Mat4::broadcast_diagonal(1), Mat4::identity());
assert_eq!(Mat4::broadcast_diagonal(2), Mat4::new(
2,0,0,0,
0,2,0,0,
0,0,2,0,
0,0,0,2,
));
sourcepub fn with_diagonal(d: Vec3<T>) -> Selfwhere
T: Zero + Copy,
pub fn with_diagonal(d: Vec3<T>) -> Selfwhere T: Zero + Copy,
Initializes a matrix by its diagonal, setting other elements to zero.
sourcepub fn diagonal(self) -> Vec3<T>
pub fn diagonal(self) -> Vec3<T>
Gets the matrix’s diagonal into a vector.
assert_eq!(Mat4::<u32>::zero().diagonal(), Vec4::zero());
assert_eq!(Mat4::<u32>::identity().diagonal(), Vec4::one());
let mut m = Mat4::zero();
m[(0, 0)] = 1;
m[(1, 1)] = 2;
m[(2, 2)] = 3;
m[(3, 3)] = 4;
assert_eq!(m.diagonal(), Vec4::new(1, 2, 3, 4));
assert_eq!(m.diagonal(), Vec4::iota() + 1);
sourcepub fn trace(self) -> Twhere
T: Add<T, Output = T>,
pub fn trace(self) -> Twhere T: Add<T, Output = T>,
The sum of the diagonal’s elements.
assert_eq!(Mat4::<u32>::zero().trace(), 0);
assert_eq!(Mat4::<u32>::identity().trace(), 4);
sourcepub fn mul_memberwise(self, m: Self) -> Selfwhere
T: Mul<Output = T>,
pub fn mul_memberwise(self, m: Self) -> Selfwhere T: Mul<Output = T>,
Multiply elements of this matrix with another’s.
let m = Mat4::new(
0, 1, 2, 3,
1, 2, 3, 4,
2, 3, 4, 5,
3, 4, 5, 6,
);
let r = Mat4::new(
0, 1, 4, 9,
1, 4, 9, 16,
4, 9, 16, 25,
9, 16, 25, 36,
);
assert_eq!(m.mul_memberwise(m), r);
sourcepub const ROW_COUNT: usize = 3usize
pub const ROW_COUNT: usize = 3usize
Convenience constant representing the number of rows for matrices of this type.
source§impl<T> Mat3<T>
impl<T> Mat3<T>
sourcepub fn map_cols<D, F>(self, f: F) -> Mat3<D>where
F: FnMut(Vec3<T>) -> Vec3<D>,
pub fn map_cols<D, F>(self, f: F) -> Mat3<D>where F: FnMut(Vec3<T>) -> Vec3<D>,
Returns a column-wise-converted copy of this matrix, using the given conversion closure.
use vek::mat::repr_c::column_major::Mat4;
let m = Mat4::<f32>::new(
0.25, 1.25, 5.56, 8.66,
8.53, 2.92, 3.86, 9.36,
1.02, 0.28, 5.52, 6.06,
6.20, 7.01, 4.90, 5.26
);
let m = m.map_cols(|col| col.map(|x| x.round() as i32));
assert_eq!(m, Mat4::new(
0, 1, 6, 9,
9, 3, 4, 9,
1, 0, 6, 6,
6, 7, 5, 5
));
sourcepub fn into_col_array(self) -> [T; 9]
pub fn into_col_array(self) -> [T; 9]
Converts this matrix into a fixed-size array of elements.
use vek::mat::repr_c::column_major::Mat4;
let m = Mat4::<u32>::new(
0, 1, 2, 3,
4, 5, 6, 7,
8, 9, 10, 11,
12, 13, 14, 15
);
let array = [
0, 4, 8, 12,
1, 5, 9, 13,
2, 6, 10, 14,
3, 7, 11, 15
];
assert_eq!(m.into_col_array(), array);
sourcepub fn into_col_arrays(self) -> [[T; 3]; 3]
pub fn into_col_arrays(self) -> [[T; 3]; 3]
Converts this matrix into a fixed-size array of fixed-size arrays of elements.
use vek::mat::repr_c::column_major::Mat4;
let m = Mat4::<u32>::new(
0, 1, 2, 3,
4, 5, 6, 7,
8, 9, 10, 11,
12, 13, 14, 15
);
let array = [
[ 0, 4, 8, 12, ],
[ 1, 5, 9, 13, ],
[ 2, 6, 10, 14, ],
[ 3, 7, 11, 15, ],
];
assert_eq!(m.into_col_arrays(), array);
sourcepub fn from_col_array(array: [T; 9]) -> Self
pub fn from_col_array(array: [T; 9]) -> Self
Converts a fixed-size array of elements into a matrix.
use vek::mat::repr_c::column_major::Mat4;
let m = Mat4::<u32>::new(
0, 1, 2, 3,
4, 5, 6, 7,
8, 9, 10, 11,
12, 13, 14, 15
);
let array = [
0, 4, 8, 12,
1, 5, 9, 13,
2, 6, 10, 14,
3, 7, 11, 15
];
assert_eq!(m, Mat4::from_col_array(array));
sourcepub fn from_col_arrays(array: [[T; 3]; 3]) -> Self
pub fn from_col_arrays(array: [[T; 3]; 3]) -> Self
Converts a fixed-size array of fixed-size arrays of elements into a matrix.
use vek::mat::repr_c::column_major::Mat4;
let m = Mat4::<u32>::new(
0, 1, 2, 3,
4, 5, 6, 7,
8, 9, 10, 11,
12, 13, 14, 15
);
let array = [
[ 0, 4, 8, 12, ],
[ 1, 5, 9, 13, ],
[ 2, 6, 10, 14, ],
[ 3, 7, 11, 15, ],
];
assert_eq!(m, Mat4::from_col_arrays(array));
sourcepub fn into_row_array(self) -> [T; 9]
pub fn into_row_array(self) -> [T; 9]
Converts this matrix into a fixed-size array of elements.
use vek::mat::repr_c::column_major::Mat4;
let m = Mat4::<u32>::new(
0, 1, 2, 3,
4, 5, 6, 7,
8, 9, 10, 11,
12, 13, 14, 15
);
let array = [
0, 1, 2, 3,
4, 5, 6, 7,
8, 9, 10, 11,
12, 13, 14, 15
];
assert_eq!(m.into_row_array(), array);
sourcepub fn into_row_arrays(self) -> [[T; 3]; 3]
pub fn into_row_arrays(self) -> [[T; 3]; 3]
Converts this matrix into a fixed-size array of fixed-size arrays of elements.
use vek::mat::repr_c::column_major::Mat4;
let m = Mat4::<u32>::new(
0, 1, 2, 3,
4, 5, 6, 7,
8, 9, 10, 11,
12, 13, 14, 15
);
let array = [
[ 0, 1, 2, 3, ],
[ 4, 5, 6, 7, ],
[ 8, 9, 10, 11, ],
[ 12, 13, 14, 15, ],
];
assert_eq!(m.into_row_arrays(), array);
sourcepub fn from_row_array(array: [T; 9]) -> Self
pub fn from_row_array(array: [T; 9]) -> Self
Converts a fixed-size array of elements into a matrix.
use vek::mat::repr_c::column_major::Mat4;
let m = Mat4::<u32>::new(
0, 1, 2, 3,
4, 5, 6, 7,
8, 9, 10, 11,
12, 13, 14, 15
);
let array = [
0, 1, 2, 3,
4, 5, 6, 7,
8, 9, 10, 11,
12, 13, 14, 15
];
assert_eq!(m, Mat4::from_row_array(array));
sourcepub fn from_row_arrays(array: [[T; 3]; 3]) -> Self
pub fn from_row_arrays(array: [[T; 3]; 3]) -> Self
Converts a fixed-size array of fixed-size array of elements into a matrix.
use vek::mat::repr_c::column_major::Mat4;
let m = Mat4::<u32>::new(
0, 1, 2, 3,
4, 5, 6, 7,
8, 9, 10, 11,
12, 13, 14, 15
);
let array = [
[ 0, 1, 2, 3, ],
[ 4, 5, 6, 7, ],
[ 8, 9, 10, 11, ],
[ 12, 13, 14, 15, ],
];
assert_eq!(m, Mat4::from_row_arrays(array));
sourcepub fn as_col_ptr(&self) -> *const T
pub fn as_col_ptr(&self) -> *const T
Gets a const pointer to this matrix’s elements.
Panics
Panics if the matrix’s elements are not tightly packed in memory,
which may be the case for matrices in the repr_simd
module.
You may check this with the is_packed()
method.
sourcepub fn as_mut_col_ptr(&mut self) -> *mut T
pub fn as_mut_col_ptr(&mut self) -> *mut T
Gets a mut pointer to this matrix’s elements.
Panics
Panics if the matrix’s elements are not tightly packed in memory,
which may be the case for matrices in the repr_simd
module.
You may check this with the is_packed()
method.
sourcepub fn as_col_slice(&self) -> &[T]
pub fn as_col_slice(&self) -> &[T]
View this matrix as an immutable slice.
Panics
Panics if the matrix’s elements are not tightly packed in memory,
which may be the case for matrices in the repr_simd
module.
You may check this with the is_packed()
method.
sourcepub fn as_mut_col_slice(&mut self) -> &mut [T]
pub fn as_mut_col_slice(&mut self) -> &mut [T]
View this matrix as a mutable slice.
Panics
Panics if the matrix’s elements are not tightly packed in memory,
which may be the case for matrices in the repr_simd
module.
You may check this with the is_packed()
method.
source§impl<T> Mat3<T>
impl<T> Mat3<T>
sourcepub fn gl_should_transpose(&self) -> bool
pub fn gl_should_transpose(&self) -> bool
Gets the transpose
parameter to pass to OpenGL glUniformMatrix*()
functions.
The return value is a plain bool
which you may directly cast
to a GLboolean
.
This takes &self
to prevent surprises when changing the type
of matrix you plan to send.
sourcepub const GL_SHOULD_TRANSPOSE: bool = false
pub const GL_SHOULD_TRANSPOSE: bool = false
The transpose
parameter to pass to OpenGL glUniformMatrix*()
functions.
source§impl<T> Mat3<T>
impl<T> Mat3<T>
sourcepub fn map<D, F>(self, f: F) -> Mat3<D>where
F: FnMut(T) -> D,
pub fn map<D, F>(self, f: F) -> Mat3<D>where F: FnMut(T) -> D,
Returns an element-wise-converted copy of this matrix, using the given conversion closure.
use vek::mat::repr_c::row_major::Mat4;
let m = Mat4::<f32>::new(
0.25, 1.25, 5.56, 8.66,
8.53, 2.92, 3.86, 9.36,
1.02, 0.28, 5.52, 6.06,
6.20, 7.01, 4.90, 5.26
);
let m = m.map(|x| x.round() as i32);
assert_eq!(m, Mat4::new(
0, 1, 6, 9,
9, 3, 4, 9,
1, 0, 6, 6,
6, 7, 5, 5
));
sourcepub fn as_<D>(self) -> Mat3<D>where
T: AsPrimitive<D>,
D: 'static + Copy,
pub fn as_<D>(self) -> Mat3<D>where T: AsPrimitive<D>, D: 'static + Copy,
Returns a memberwise-converted copy of this matrix, using AsPrimitive
.
Examples
let v = Vec4::new(0_f32, 1., 2., 3.);
let i: Vec4<i32> = v.as_();
assert_eq!(i, Vec4::new(0, 1, 2, 3));
Safety
In Rust versions before 1.45.0, some uses of the as
operator were not entirely safe.
In particular, it was undefined behavior if
a truncated floating point value could not fit in the target integer
type (#10184);
let x: u8 = (1.04E+17).as_(); // UB
sourcepub fn map2<D, F, S>(self, other: Mat3<S>, f: F) -> Mat3<D>where
F: FnMut(T, S) -> D,
pub fn map2<D, F, S>(self, other: Mat3<S>, f: F) -> Mat3<D>where F: FnMut(T, S) -> D,
Applies the function f to each element of two matrices, pairwise, and returns the result.
use vek::mat::repr_c::row_major::Mat4;
let a = Mat4::<f32>::new(
0.25, 1.25, 2.52, 2.99,
0.25, 1.25, 2.52, 2.99,
0.25, 1.25, 2.52, 2.99,
0.25, 1.25, 2.52, 2.99
);
let b = Mat4::<i32>::new(
0, 1, 0, 0,
1, 0, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
);
let m = a.map2(b, |a, b| a.round() as i32 + b);
assert_eq!(m, Mat4::new(
0, 2, 3, 3,
1, 1, 3, 3,
0, 1, 4, 3,
0, 1, 3, 4
));
sourcepub fn transposed(self) -> Self
pub fn transposed(self) -> Self
The matrix’s transpose.
For orthogonal matrices, the transpose is the same as the inverse. All pure rotation matrices are orthogonal, and therefore can be inverted faster by simply computing their transpose.
use std::f32::consts::PI;
let m = Mat3::new(
0, 1, 2,
4, 5, 6,
8, 9, 0
);
let t = Mat3::new(
0, 4, 8,
1, 5, 9,
2, 6, 0
);
assert_eq!(m.transposed(), t);
assert_eq!(m, m.transposed().transposed());
let m = Mat3::rotation_x(PI/7.);
assert_relative_eq!(m * m.transposed(), Mat3::identity());
assert_relative_eq!(m.transposed() * m, Mat3::identity());
sourcepub fn transpose(&mut self)
pub fn transpose(&mut self)
Transpose this matrix.
let mut m = Mat3::new(
0, 1, 2,
4, 5, 6,
8, 9, 0
);
let t = Mat3::new(
0, 4, 8,
1, 5, 9,
2, 6, 0
);
m.transpose();
assert_eq!(m, t);
sourcepub fn determinant(self) -> Twhere
T: Copy + Mul<T, Output = T> + Sub<T, Output = T> + Add<T, Output = T>,
pub fn determinant(self) -> Twhere T: Copy + Mul<T, Output = T> + Sub<T, Output = T> + Add<T, Output = T>,
Get this matrix’s determinant.
A matrix is invertible if its determinant is non-zero.
sourcepub fn mul_point_2d<V: Into<Vec2<T>> + From<Vec3<T>>>(self, rhs: V) -> Vwhere
T: Real + MulAdd<T, T, Output = T>,
pub fn mul_point_2d<V: Into<Vec2<T>> + From<Vec3<T>>>(self, rhs: V) -> Vwhere T: Real + MulAdd<T, T, Output = T>,
Shortcut for self * Vec3::from_point_2d(rhs)
.
sourcepub fn mul_direction_2d<V: Into<Vec2<T>> + From<Vec3<T>>>(self, rhs: V) -> Vwhere
T: Real + MulAdd<T, T, Output = T>,
pub fn mul_direction_2d<V: Into<Vec2<T>> + From<Vec3<T>>>(self, rhs: V) -> Vwhere T: Real + MulAdd<T, T, Output = T>,
Shortcut for self * Vec3::from_direction_2d(rhs)
.
sourcepub fn translate_2d<V: Into<Vec2<T>>>(&mut self, v: V)where
T: Real + MulAdd<T, T, Output = T>,
pub fn translate_2d<V: Into<Vec2<T>>>(&mut self, v: V)where T: Real + MulAdd<T, T, Output = T>,
Translates this matrix in 2D.
sourcepub fn translated_2d<V: Into<Vec2<T>>>(self, v: V) -> Selfwhere
T: Real + MulAdd<T, T, Output = T>,
pub fn translated_2d<V: Into<Vec2<T>>>(self, v: V) -> Selfwhere T: Real + MulAdd<T, T, Output = T>,
Returns this matrix translated in 2D.
sourcepub fn translation_2d<V: Into<Vec2<T>>>(v: V) -> Selfwhere
T: Zero + One,
pub fn translation_2d<V: Into<Vec2<T>>>(v: V) -> Selfwhere T: Zero + One,
Creates a 2D translation matrix.
sourcepub fn scale_3d<V: Into<Vec3<T>>>(&mut self, v: V)where
T: Real + MulAdd<T, T, Output = T>,
pub fn scale_3d<V: Into<Vec3<T>>>(&mut self, v: V)where T: Real + MulAdd<T, T, Output = T>,
Scales this matrix in 3D.
sourcepub fn scaled_3d<V: Into<Vec3<T>>>(self, v: V) -> Selfwhere
T: Real + MulAdd<T, T, Output = T>,
pub fn scaled_3d<V: Into<Vec3<T>>>(self, v: V) -> Selfwhere T: Real + MulAdd<T, T, Output = T>,
Returns this matrix scaled in 3D.
sourcepub fn scaling_3d<V: Into<Vec3<T>>>(v: V) -> Selfwhere
T: Zero,
pub fn scaling_3d<V: Into<Vec3<T>>>(v: V) -> Selfwhere T: Zero,
Creates a 3D scaling matrix.
sourcepub fn rotate_x(&mut self, angle_radians: T)where
T: Real + MulAdd<T, T, Output = T>,
pub fn rotate_x(&mut self, angle_radians: T)where T: Real + MulAdd<T, T, Output = T>,
Rotates this matrix around the X axis.
sourcepub fn rotated_x(self, angle_radians: T) -> Selfwhere
T: Real + MulAdd<T, T, Output = T>,
pub fn rotated_x(self, angle_radians: T) -> Selfwhere T: Real + MulAdd<T, T, Output = T>,
Returns this matrix rotated around the X axis.
sourcepub fn rotation_x(angle_radians: T) -> Selfwhere
T: Real,
pub fn rotation_x(angle_radians: T) -> Selfwhere T: Real,
Creates a matrix that rotates around the X axis.
sourcepub fn rotate_y(&mut self, angle_radians: T)where
T: Real + MulAdd<T, T, Output = T>,
pub fn rotate_y(&mut self, angle_radians: T)where T: Real + MulAdd<T, T, Output = T>,
Rotates this matrix around the Y axis.
sourcepub fn rotated_y(self, angle_radians: T) -> Selfwhere
T: Real + MulAdd<T, T, Output = T>,
pub fn rotated_y(self, angle_radians: T) -> Selfwhere T: Real + MulAdd<T, T, Output = T>,
Returns this matrix rotated around the Y axis.
sourcepub fn rotation_y(angle_radians: T) -> Selfwhere
T: Real,
pub fn rotation_y(angle_radians: T) -> Selfwhere T: Real,
Creates a matrix that rotates around the Y axis.
sourcepub fn rotate_z(&mut self, angle_radians: T)where
T: Real + MulAdd<T, T, Output = T>,
pub fn rotate_z(&mut self, angle_radians: T)where T: Real + MulAdd<T, T, Output = T>,
Rotates this matrix around the Z axis.
sourcepub fn rotated_z(self, angle_radians: T) -> Selfwhere
T: Real + MulAdd<T, T, Output = T>,
pub fn rotated_z(self, angle_radians: T) -> Selfwhere T: Real + MulAdd<T, T, Output = T>,
Returns this matrix rotated around the Z axis.
sourcepub fn rotation_z(angle_radians: T) -> Selfwhere
T: Real,
pub fn rotation_z(angle_radians: T) -> Selfwhere T: Real,
Creates a matrix that rotates around the Z axis.
sourcepub fn rotate_3d<V: Into<Vec3<T>>>(&mut self, angle_radians: T, axis: V)where
T: Real + MulAdd<T, T, Output = T> + Add<T, Output = T>,
pub fn rotate_3d<V: Into<Vec3<T>>>(&mut self, angle_radians: T, axis: V)where T: Real + MulAdd<T, T, Output = T> + Add<T, Output = T>,
Rotates this matrix around a 3D axis. The axis is not required to be normalized.
sourcepub fn rotated_3d<V: Into<Vec3<T>>>(self, angle_radians: T, axis: V) -> Selfwhere
T: Real + MulAdd<T, T, Output = T> + Add<T, Output = T>,
pub fn rotated_3d<V: Into<Vec3<T>>>(self, angle_radians: T, axis: V) -> Selfwhere T: Real + MulAdd<T, T, Output = T> + Add<T, Output = T>,
Returns this matrix rotated around a 3D axis. The axis is not required to be normalized.
sourcepub fn rotation_3d<V: Into<Vec3<T>>>(angle_radians: T, axis: V) -> Selfwhere
T: Real + Add<T, Output = T>,
pub fn rotation_3d<V: Into<Vec3<T>>>(angle_radians: T, axis: V) -> Selfwhere T: Real + Add<T, Output = T>,
Creates a matrix that rotates around a 3D axis. The axis is not required to be normalized.
use std::f32::consts::PI;
let angles = 32;
for i in 0..angles {
let theta = PI * 2. * (i as f32) / (angles as f32);
assert_relative_eq!(Mat3::rotation_x(theta), Mat3::from(Quaternion::rotation_x(theta)), epsilon = 0.000001);
assert_relative_eq!(Mat3::rotation_y(theta), Mat3::from(Quaternion::rotation_y(theta)), epsilon = 0.000001);
assert_relative_eq!(Mat3::rotation_z(theta), Mat3::from(Quaternion::rotation_z(theta)), epsilon = 0.000001);
assert_relative_eq!(Mat3::rotation_x(theta), Mat3::rotation_3d(theta, Vec3::unit_x()));
assert_relative_eq!(Mat3::rotation_y(theta), Mat3::rotation_3d(theta, Vec3::unit_y()));
assert_relative_eq!(Mat3::rotation_z(theta), Mat3::rotation_3d(theta, Vec3::unit_z()));
assert_relative_eq!(Mat3::rotation_x(theta), Mat3::from(Mat4::rotation_3d(theta, Vec3::unit_x())));
assert_relative_eq!(Mat3::rotation_y(theta), Mat3::from(Mat4::rotation_3d(theta, Vec3::unit_y())));
assert_relative_eq!(Mat3::rotation_z(theta), Mat3::from(Mat4::rotation_3d(theta, Vec3::unit_z())));
assert_relative_eq!(Mat4::rotation_x(theta), Mat4::from(Mat3::rotation_3d(theta, Vec3::unit_x())));
assert_relative_eq!(Mat4::rotation_y(theta), Mat4::from(Mat3::rotation_3d(theta, Vec3::unit_y())));
assert_relative_eq!(Mat4::rotation_z(theta), Mat4::from(Mat3::rotation_3d(theta, Vec3::unit_z())));
// See what rotating unit vectors do for most angles between 0 and 2*PI.
// It's helpful to picture this as a right-handed coordinate system.
let v = Vec3::unit_y();
let m = Mat3::rotation_x(theta);
assert_relative_eq!(m * v, Vec3::new(0., theta.cos(), theta.sin()));
let v = Vec3::unit_z();
let m = Mat3::rotation_y(theta);
assert_relative_eq!(m * v, Vec3::new(theta.sin(), 0., theta.cos()));
let v = Vec3::unit_x();
let m = Mat3::rotation_z(theta);
assert_relative_eq!(m * v, Vec3::new(theta.cos(), theta.sin(), 0.));
}
sourcepub fn rotation_from_to_3d<V: Into<Vec3<T>>>(from: V, to: V) -> Selfwhere
T: Real + Add<T, Output = T>,
pub fn rotation_from_to_3d<V: Into<Vec3<T>>>(from: V, to: V) -> Selfwhere T: Real + Add<T, Output = T>,
Creates a matrix that would rotate a from
direction to to
.
let (from, to) = (Vec3::<f32>::unit_x(), Vec3::<f32>::unit_z());
let m = Mat3::<f32>::rotation_from_to_3d(from, to);
assert_relative_eq!(m * from, to);
let (from, to) = (Vec3::<f32>::unit_x(), -Vec3::<f32>::unit_x());
let m = Mat3::<f32>::rotation_from_to_3d(from, to);
assert_relative_eq!(m * from, to);
source§impl<T> Mat3<T>
impl<T> Mat3<T>
sourcepub fn new(
m00: T,
m01: T,
m02: T,
m10: T,
m11: T,
m12: T,
m20: T,
m21: T,
m22: T
) -> Self
pub fn new( m00: T, m01: T, m02: T, m10: T, m11: T, m12: T, m20: T, m21: T, m22: T ) -> Self
Creates a new 3x3 matrix from elements in a layout-agnostic way.
The parameters are named mij
where i
is the row index and
j
the column index. Their order is always the same regardless
of the matrix’s layout.
Trait Implementations§
source§impl<T: AbsDiffEq> AbsDiffEq<Mat3<T>> for Mat3<T>where
T::Epsilon: Copy,
impl<T: AbsDiffEq> AbsDiffEq<Mat3<T>> for Mat3<T>where T::Epsilon: Copy,
source§fn default_epsilon() -> T::Epsilon
fn default_epsilon() -> T::Epsilon
source§fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool
fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool
source§fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
AbsDiffEq::abs_diff_eq
.source§impl<T: Add<Output = T> + Copy> AddAssign<Mat3<T>> for Mat3<T>
impl<T: Add<Output = T> + Copy> AddAssign<Mat3<T>> for Mat3<T>
source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+=
operation. Read moresource§impl<T: Add<Output = T> + Copy> AddAssign<T> for Mat3<T>
impl<T: Add<Output = T> + Copy> AddAssign<T> for Mat3<T>
source§fn add_assign(&mut self, rhs: T)
fn add_assign(&mut self, rhs: T)
+=
operation. Read moresource§impl<T: Zero + One> Default for Mat3<T>
impl<T: Zero + One> Default for Mat3<T>
The default value for a square matrix is the identity.
assert_eq!(Mat4::<f32>::default(), Mat4::<f32>::identity());
source§impl<'de, T> Deserialize<'de> for Mat3<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for Mat3<T>where T: Deserialize<'de>,
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,
source§impl<T: Display> Display for Mat3<T>
impl<T: Display> Display for Mat3<T>
Displays this matrix using the following format:
(i
being the number of rows and j
the number of columns)
( m00 ... m0j
... ... ...
mi0 ... mij )
Note that elements are not comma-separated. This format doesn’t depend on the matrix’s storage layout.
source§impl<T: Div<Output = T> + Copy> DivAssign<Mat3<T>> for Mat3<T>
impl<T: Div<Output = T> + Copy> DivAssign<Mat3<T>> for Mat3<T>
source§fn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
/=
operation. Read moresource§impl<T: Div<Output = T> + Copy> DivAssign<T> for Mat3<T>
impl<T: Div<Output = T> + Copy> DivAssign<T> for Mat3<T>
source§fn div_assign(&mut self, rhs: T)
fn div_assign(&mut self, rhs: T)
/=
operation. Read moresource§impl<T> From<Quaternion<T>> for Mat3<T>where
T: Copy + Zero + One + Mul<Output = T> + Add<Output = T> + Sub<Output = T>,
impl<T> From<Quaternion<T>> for Mat3<T>where T: Copy + Zero + One + Mul<Output = T> + Add<Output = T> + Sub<Output = T>,
source§fn from(q: Quaternion<T>) -> Self
fn from(q: Quaternion<T>) -> Self
source§impl<T> Index<(usize, usize)> for Mat3<T>
impl<T> Index<(usize, usize)> for Mat3<T>
Index this matrix in a layout-agnostic way with an (i, j)
(row index, column index) tuple.
Matrices cannot be indexed by Vec2
s because that would be likely to cause confusion:
should x
be the row index (because it’s the first element) or the column index
(because it’s a horizontal position) ?
source§impl<T> Mul<CubicBezier2<T>> for Cols3<T>where
T: Real + MulAdd<T, T, Output = T>,
impl<T> Mul<CubicBezier2<T>> for Cols3<T>where T: Real + MulAdd<T, T, Output = T>,
§type Output = CubicBezier2<T>
type Output = CubicBezier2<T>
*
operator.source§fn mul(self, rhs: CubicBezier2<T>) -> CubicBezier2<T>
fn mul(self, rhs: CubicBezier2<T>) -> CubicBezier2<T>
*
operation. Read moresource§impl<T> Mul<CubicBezier3<T>> for Cols3<T>where
T: Real + MulAdd<T, T, Output = T>,
impl<T> Mul<CubicBezier3<T>> for Cols3<T>where T: Real + MulAdd<T, T, Output = T>,
§type Output = CubicBezier3<T>
type Output = CubicBezier3<T>
*
operator.source§fn mul(self, rhs: CubicBezier3<T>) -> CubicBezier3<T>
fn mul(self, rhs: CubicBezier3<T>) -> CubicBezier3<T>
*
operation. Read moresource§impl<T: MulAdd<T, T, Output = T> + Mul<Output = T> + Copy> Mul<Mat3<T>> for Mat3<T>
impl<T: MulAdd<T, T, Output = T> + Mul<Output = T> + Copy> Mul<Mat3<T>> for Mat3<T>
Multiplies a column-major matrix with a row-major matrix.
use vek::mat::row_major::Mat4 as Rows4;
use vek::mat::column_major::Mat4 as Cols4;
let m = Cols4::<u32>::new(
0, 1, 2, 3,
4, 5, 6, 7,
8, 9, 0, 1,
2, 3, 4, 5
);
let b = Rows4::from(m);
let r = Rows4::<u32>::new(
26, 32, 18, 24,
82, 104, 66, 88,
38, 56, 74, 92,
54, 68, 42, 56
);
assert_eq!(m * b, r);
assert_eq!(m * Rows4::<u32>::identity(), m.into());
assert_eq!(Cols4::<u32>::identity() * b, m.into());
source§impl<T: MulAdd<T, T, Output = T> + Mul<Output = T> + Copy> Mul<Mat3<T>> for Mat3<T>
impl<T: MulAdd<T, T, Output = T> + Mul<Output = T> + Copy> Mul<Mat3<T>> for Mat3<T>
Multiplies a row-major matrix with a column-major matrix, producing a column-major matrix.
use vek::mat::row_major::Mat4 as Rows4;
use vek::mat::column_major::Mat4 as Cols4;
let m = Rows4::<u32>::new(
0, 1, 2, 3,
4, 5, 6, 7,
8, 9, 0, 1,
2, 3, 4, 5
);
let b = Cols4::from(m);
let r = Cols4::<u32>::new(
26, 32, 18, 24,
82, 104, 66, 88,
38, 56, 74, 92,
54, 68, 42, 56
);
assert_eq!(m * b, r);
assert_eq!(m * Cols4::<u32>::identity(), m.into());
assert_eq!(Rows4::<u32>::identity() * b, m.into());
source§impl<T: MulAdd<T, T, Output = T> + Mul<Output = T> + Copy> Mul<Mat3<T>> for Mat3<T>
impl<T: MulAdd<T, T, Output = T> + Mul<Output = T> + Copy> Mul<Mat3<T>> for Mat3<T>
Multiplies a column-major matrix with another.
use vek::mat::column_major::Mat4;
let m = Mat4::<u32>::new(
0, 1, 2, 3,
4, 5, 6, 7,
8, 9, 0, 1,
2, 3, 4, 5
);
let r = Mat4::<u32>::new(
26, 32, 18, 24,
82, 104, 66, 88,
38, 56, 74, 92,
54, 68, 42, 56
);
assert_eq!(m * m, r);
assert_eq!(m, m * Mat4::<u32>::identity());
assert_eq!(m, Mat4::<u32>::identity() * m);
source§impl<T: MulAdd<T, T, Output = T> + Mul<Output = T> + Copy> Mul<Mat3<T>> for Vec3<T>
impl<T: MulAdd<T, T, Output = T> + Mul<Output = T> + Copy> Mul<Mat3<T>> for Vec3<T>
Multiplies a row vector with a column-major matrix, giving a row vector.
use vek::mat::column_major::Mat4;
use vek::vec::Vec4;
let m = Mat4::new(
0, 1, 2, 3,
4, 5, 6, 7,
8, 9, 0, 1,
2, 3, 4, 5
);
let v = Vec4::new(0, 1, 2, 3);
let r = Vec4::new(26, 32, 18, 24);
assert_eq!(v * m, r);
source§impl<T> Mul<QuadraticBezier2<T>> for Cols3<T>where
T: Real + MulAdd<T, T, Output = T>,
impl<T> Mul<QuadraticBezier2<T>> for Cols3<T>where T: Real + MulAdd<T, T, Output = T>,
§type Output = QuadraticBezier2<T>
type Output = QuadraticBezier2<T>
*
operator.source§fn mul(self, rhs: QuadraticBezier2<T>) -> QuadraticBezier2<T>
fn mul(self, rhs: QuadraticBezier2<T>) -> QuadraticBezier2<T>
*
operation. Read moresource§impl<T> Mul<QuadraticBezier3<T>> for Cols3<T>where
T: Real + MulAdd<T, T, Output = T>,
impl<T> Mul<QuadraticBezier3<T>> for Cols3<T>where T: Real + MulAdd<T, T, Output = T>,
§type Output = QuadraticBezier3<T>
type Output = QuadraticBezier3<T>
*
operator.source§fn mul(self, rhs: QuadraticBezier3<T>) -> QuadraticBezier3<T>
fn mul(self, rhs: QuadraticBezier3<T>) -> QuadraticBezier3<T>
*
operation. Read moresource§impl<T: MulAdd<T, T, Output = T> + Mul<Output = T> + Copy> Mul<Vec3<T>> for Mat3<T>
impl<T: MulAdd<T, T, Output = T> + Mul<Output = T> + Copy> Mul<Vec3<T>> for Mat3<T>
Multiplies a column-major matrix with a column vector, giving a column vector.
With SIMD vectors, this is the most efficient way.
use vek::mat::column_major::Mat4;
use vek::vec::Vec4;
let m = Mat4::new(
0, 1, 2, 3,
4, 5, 6, 7,
8, 9, 0, 1,
2, 3, 4, 5
);
let v = Vec4::new(0, 1, 2, 3);
let r = Vec4::new(14, 38, 12, 26);
assert_eq!(m * v, r);
source§impl<T> MulAssign<Mat3<T>> for Mat3<T>where
T: Copy + Zero + Add<Output = T> + Mul<Output = T> + MulAdd<T, T, Output = T>,
impl<T> MulAssign<Mat3<T>> for Mat3<T>where T: Copy + Zero + Add<Output = T> + Mul<Output = T> + MulAdd<T, T, Output = T>,
source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*=
operation. Read moresource§impl<T> MulAssign<T> for Mat3<T>where
T: Copy + Zero + Add<Output = T> + Mul<Output = T>,
impl<T> MulAssign<T> for Mat3<T>where T: Copy + Zero + Add<Output = T> + Mul<Output = T>,
source§fn mul_assign(&mut self, rhs: T)
fn mul_assign(&mut self, rhs: T)
*=
operation. Read moresource§impl<T: PartialEq> PartialEq<Mat3<T>> for Mat3<T>
impl<T: PartialEq> PartialEq<Mat3<T>> for Mat3<T>
source§impl<T: RelativeEq> RelativeEq<Mat3<T>> for Mat3<T>where
T::Epsilon: Copy,
impl<T: RelativeEq> RelativeEq<Mat3<T>> for Mat3<T>where T::Epsilon: Copy,
source§fn default_max_relative() -> T::Epsilon
fn default_max_relative() -> T::Epsilon
source§fn relative_eq(
&self,
other: &Self,
epsilon: T::Epsilon,
max_relative: T::Epsilon
) -> bool
fn relative_eq( &self, other: &Self, epsilon: T::Epsilon, max_relative: T::Epsilon ) -> bool
source§fn relative_ne(
&self,
other: &Rhs,
epsilon: Self::Epsilon,
max_relative: Self::Epsilon
) -> bool
fn relative_ne( &self, other: &Rhs, epsilon: Self::Epsilon, max_relative: Self::Epsilon ) -> bool
RelativeEq::relative_eq
.source§impl<T: Rem<Output = T> + Copy> RemAssign<Mat3<T>> for Mat3<T>
impl<T: Rem<Output = T> + Copy> RemAssign<Mat3<T>> for Mat3<T>
source§fn rem_assign(&mut self, rhs: Self)
fn rem_assign(&mut self, rhs: Self)
%=
operation. Read moresource§impl<T: Rem<Output = T> + Copy> RemAssign<T> for Mat3<T>
impl<T: Rem<Output = T> + Copy> RemAssign<T> for Mat3<T>
source§fn rem_assign(&mut self, rhs: T)
fn rem_assign(&mut self, rhs: T)
%=
operation. Read moresource§impl<T: Sub<Output = T> + Copy> SubAssign<Mat3<T>> for Mat3<T>
impl<T: Sub<Output = T> + Copy> SubAssign<Mat3<T>> for Mat3<T>
source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-=
operation. Read moresource§impl<T: Sub<Output = T> + Copy> SubAssign<T> for Mat3<T>
impl<T: Sub<Output = T> + Copy> SubAssign<T> for Mat3<T>
source§fn sub_assign(&mut self, rhs: T)
fn sub_assign(&mut self, rhs: T)
-=
operation. Read more