Struct gdnative::core_types::Basis
source · [−]Expand description
Fields
elements: [Vector3; 3]
Matrix rows. These are not the basis vectors!
This is a transposed view for performance.
To read basis vectors, see a()
, b()
, c()
.
To write them, see set_a()
, set_b()
, set_c()
.
Implementations
sourceimpl Basis
impl Basis
sourcepub const IDENTITY: Basis = Self{
elements:
[Vector3::new(1.0, 0.0, 0.0), Vector3::new(0.0, 1.0, 0.0),
Vector3::new(0.0, 0.0, 1.0)],}
pub const IDENTITY: Basis = Self{ elements: [Vector3::new(1.0, 0.0, 0.0), Vector3::new(0.0, 1.0, 0.0), Vector3::new(0.0, 0.0, 1.0)],}
The identity basis. Basis vectors are unit vectors along each axis X, Y and Z.
Equivalent to calling Basis::default()
.
sourcepub const FLIP_X: Basis = Self::from_diagonal(Vector3::new(-1.0, 1.0, 1.0))
pub const FLIP_X: Basis = Self::from_diagonal(Vector3::new(-1.0, 1.0, 1.0))
The basis that will flip something along the X axis when used in a transformation.
sourcepub const FLIP_Y: Basis = Self::from_diagonal(Vector3::new(1.0, -1.0, 1.0))
pub const FLIP_Y: Basis = Self::from_diagonal(Vector3::new(1.0, -1.0, 1.0))
The basis that will flip something along the Y axis when used in a transformation.
sourcepub const FLIP_Z: Basis = Self::from_diagonal(Vector3::new(1.0, 1.0, -1.0))
pub const FLIP_Z: Basis = Self::from_diagonal(Vector3::new(1.0, 1.0, -1.0))
The basis that will flip something along the Z axis when used in a transformation.
sourcepub const fn from_basis_vectors(a: Vector3, b: Vector3, c: Vector3) -> Basis
pub const fn from_basis_vectors(a: Vector3, b: Vector3, c: Vector3) -> Basis
Constructs a basis matrix from 3 linearly independent basis vectors (matrix columns).
This is the typical way to construct a basis. If you want to fill in the elements one-by-one,
consider using Self::from_rows()
.
sourcepub const fn from_rows(
x_components: Vector3,
y_components: Vector3,
z_components: Vector3
) -> Basis
pub const fn from_rows(
x_components: Vector3,
y_components: Vector3,
z_components: Vector3
) -> Basis
Creates a basis from 3 row vectors. These are not basis vectors.
This constructor is mostly useful if you want to write matrix elements in matrix syntax:
let basis = Basis::from_rows(
Vector3::new(a.x, b.x, c.x),
Vector3::new(a.y, b.y, c.y),
Vector3::new(a.z, b.z, c.z),
);
The vectors a
, b
and c
are the basis vectors.
In this particular case, you could also use Self::from_basis_vectors(a, b, c)
instead.
sourcepub const fn from_diagonal(scale: Vector3) -> Basis
pub const fn from_diagonal(scale: Vector3) -> Basis
Creates a diagonal matrix from the given vector.
Can be used as a basis for a scaling transform.
Each component of scale
represents the scale factor in the corresponding direction.
sourcepub fn from_euler(euler_angles: Vector3) -> Basis
pub fn from_euler(euler_angles: Vector3) -> Basis
Creates a rotation matrix from Euler angles.
The angle vector has XYZ components. However, the angles are applied in YXZ convention: first Z, then X, and Y last.
sourcepub fn from_quat(quat: Quat) -> Basis
pub fn from_quat(quat: Quat) -> Basis
Constructs a pure rotation basis matrix from the given quaternion.
sourcepub fn from_axis_angle(axis: Vector3, phi: f32) -> Basis
pub fn from_axis_angle(axis: Vector3, phi: f32) -> Basis
Rotation matrix from axis and angle.
See https://en.wikipedia.org/wiki/Rotation_matrix#Rotation_matrix_from_axis_and_angle
Panics
If axis
is not normalized.
sourcepub fn transposed(&self) -> Basis
pub fn transposed(&self) -> Basis
Returns the transposed version of the matrix.
sourcepub fn determinant(&self) -> f32
pub fn determinant(&self) -> f32
Returns the determinant of the matrix.
sourcepub fn orthonormalized(&self) -> Basis
pub fn orthonormalized(&self) -> Basis
Returns an orthonormalized version of the matrix: 3 orthogonal basis vectors of unit length.
sourcepub fn is_equal_approx(&self, other: &Basis) -> bool
pub fn is_equal_approx(&self, other: &Basis) -> bool
Returns true
if self
and other
are approximately equal.
sourcepub fn rotated(&self, axis: Vector3, phi: f32) -> Basis
pub fn rotated(&self, axis: Vector3, phi: f32) -> Basis
Multiplies the matrix from left with the rotation matrix: M -> R·M
The main use of Basis
is as a Transform.basis
, which is used as the transformation matrix
of the 3D object. rotated()
here refers to rotation of the object (which is R * self
), not the matrix itself.
sourcepub fn scaled(&self, scale: Vector3) -> Basis
pub fn scaled(&self, scale: Vector3) -> Basis
Introduce an additional scaling specified by the given 3D scaling factor.
sourcepub fn to_quat(&self) -> Quat
pub fn to_quat(&self) -> Quat
Converts matrix into a quaternion.
Quaternions are frequently used in 3D graphics, because they enable easy and cheap interpolation.
However, they are less human-readable. For Euler angles, see Basis::to_euler()
.
Panics
If self
is not normalized.
sourcepub fn to_euler(&self) -> Vector3
pub fn to_euler(&self) -> Vector3
Returns the Basis
’s rotation in the form of Euler angles.
In the YXZ convention: first Z, then X, and Y last.
The returned Vector3
contains the rotation angles in the format (X angle, Y angle, Z angle).
See Basis::to_quat
if you need a quaternion instead.
sourcepub fn xform(&self, v: Vector3) -> Vector3
pub fn xform(&self, v: Vector3) -> Vector3
Returns a vector transformed (multiplied) by the matrix.
sourcepub fn xform_inv(&self, v: Vector3) -> Vector3
pub fn xform_inv(&self, v: Vector3) -> Vector3
Returns a vector transformed (multiplied) by the transposed matrix.
Note: This results in a multiplication by the inverse of the matrix only if it represents a rotation-reflection.
sourcepub fn set_a(&mut self, v: Vector3)
pub fn set_a(&mut self, v: Vector3)
Set the 1st basis vector (first column vector of the matrix).
Trait Implementations
sourceimpl CoerceFromVariant for Basis
impl CoerceFromVariant for Basis
fn coerce_from_variant(v: &Variant) -> Basis
sourceimpl<'de> Deserialize<'de> for Basis
impl<'de> Deserialize<'de> for Basis
sourcefn deserialize<__D>(
__deserializer: __D
) -> Result<Basis, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D
) -> Result<Basis, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
sourceimpl Export for Basis
impl Export for Basis
sourcefn export_info(_hint: Option<<Basis as Export>::Hint>) -> ExportInfo
fn export_info(_hint: Option<<Basis as Export>::Hint>) -> ExportInfo
ExportInfo
given an optional typed hint.