pub trait Matrix {
Show 23 methods
// Required methods
fn m00(&self) -> f32;
fn m01(&self) -> f32;
fn m02(&self) -> f32;
fn m03(&self) -> f32;
fn m10(&self) -> f32;
fn m11(&self) -> f32;
fn m12(&self) -> f32;
fn m13(&self) -> f32;
fn m20(&self) -> f32;
fn m21(&self) -> f32;
fn m22(&self) -> f32;
fn m23(&self) -> f32;
fn m30(&self) -> f32;
fn m31(&self) -> f32;
fn m32(&self) -> f32;
fn m33(&self) -> f32;
fn identity() -> Self;
// Provided methods
fn rotation_matrix(&self) -> Matrix3<f64> { ... }
fn extract_scales(matrix: Matrix3<f64>) -> (f64, f64, f64) { ... }
fn apply_scales(
matrix: Matrix3<f64>,
scales: (f64, f64, f64),
) -> Matrix3<f64> { ... }
fn normalize_rotation_matrix(
matrix: Matrix3<f64>,
scales: (f64, f64, f64),
) -> Matrix3<f64> { ... }
fn rotation_matrix_to_euler_angles(
matrix: Matrix3<f64>,
degrees: bool,
) -> (f64, f64, f64) { ... }
fn euler_angles_to_rotation_matrix(
angles: (f64, f64, f64),
degrees: bool,
) -> Matrix3<f64> { ... }
}Expand description
Common operations for transformation matrices.
This trait abstracts behavior shared between Transform3x4 and Transform4x4,
providing matrix element access and transformation utilities.
§Provided Methods
- Element Access: m00() through m33() - Access individual matrix elements
- Rotation:
rotation_matrix()- Extract 3x3 rotation submatrix - Scaling:
extract_scales(),apply_scales(),normalize_rotation_matrix() - Euler Angles:
rotation_matrix_to_euler_angles(),euler_angles_to_rotation_matrix() - Identity:
identity()- Create identity transform
§Rotation Order
Euler angle conversions use ‘xyz’ extrinsic rotation order (roll-pitch-yaw).
§Example
use rpfm_lib::files::bmd::common::{Transform4x4, Matrix};
let transform = Transform4x4::identity();
// Extract rotation
let rotation = transform.rotation_matrix();
let scales = Transform4x4::extract_scales(rotation);
// Convert to Euler angles (in degrees)
let (x, y, z) = Transform4x4::rotation_matrix_to_euler_angles(rotation, true);
println!("Rotation: X={}, Y={}, Z={}", x, y, z);Required Methods§
Provided Methods§
Sourcefn rotation_matrix(&self) -> Matrix3<f64>
fn rotation_matrix(&self) -> Matrix3<f64>
Sourcefn extract_scales(matrix: Matrix3<f64>) -> (f64, f64, f64)
fn extract_scales(matrix: Matrix3<f64>) -> (f64, f64, f64)
Extracts scale factors from a rotation matrix.
Computes the scale of each axis by taking the norm of each column vector.
§Parameters
matrix: 3x3 rotation/scale matrix
§Returns
Tuple of (scale_x, scale_y, scale_z)
§Note
Does not support negative scales. Negative scales will be treated as positive.
§Reference
Sourcefn normalize_rotation_matrix(
matrix: Matrix3<f64>,
scales: (f64, f64, f64),
) -> Matrix3<f64>
fn normalize_rotation_matrix( matrix: Matrix3<f64>, scales: (f64, f64, f64), ) -> Matrix3<f64>
Sourcefn rotation_matrix_to_euler_angles(
matrix: Matrix3<f64>,
degrees: bool,
) -> (f64, f64, f64)
fn rotation_matrix_to_euler_angles( matrix: Matrix3<f64>, degrees: bool, ) -> (f64, f64, f64)
Converts a rotation matrix to Euler angles.
Uses ‘xyz’ extrinsic rotation order (roll-pitch-yaw).
§Parameters
matrix: 3x3 rotation matrixdegrees: If true, return angles in degrees; if false, in radians
§Returns
Tuple of (x_rotation, y_rotation, z_rotation) in specified units
§Example (Python equivalent using scipy)
from scipy.spatial.transform import Rotation as R
r = R.from_euler("xyz", [-130.0, 80.0, -30.0], degrees=True)
m = r.as_matrix()
r = R.from_matrix(m)
angles = r.as_euler("xyz", degrees=True)Sourcefn euler_angles_to_rotation_matrix(
angles: (f64, f64, f64),
degrees: bool,
) -> Matrix3<f64>
fn euler_angles_to_rotation_matrix( angles: (f64, f64, f64), degrees: bool, ) -> Matrix3<f64>
Converts Euler angles to a rotation matrix.
Uses ‘xyz’ extrinsic rotation order (roll-pitch-yaw).
§Parameters
angles: Tuple of (x_rotation, y_rotation, z_rotation)degrees: If true, angles are in degrees; if false, in radians
§Returns
3x3 rotation matrix with values near zero cleaned up (< 1e-5 set to 0.0)
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.