Basis
A 3×3 matrix for representing 3D rotation and scale.
Basis.swift:15struct Basis
A 3×3 matrix used for representing 3D rotation and scale. Usually used as an orthogonal basis for a Transform3D
.
Contains 3 vector fields X, Y and Z as its columns, which are typically interpreted as the local basis vectors of a transformation. For such use, it is composed of a scaling and a rotation matrix, in that order (M = R.S).
Basis can also be accessed as an array of 3D vectors. These vectors are usually orthogonal to each other, but are not necessarily normalized (due to scaling).
For more information, read the “Matrices and transforms” documentation article.
Citizens in SwiftGodot
Conformances
protocol Equatable
A type that can be compared for value equality.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol SelfVariantRepresentable
Structs and scalar types use their own layout for storage.
protocol VariantRepresentable
Types that conform to VariantRepresentable can be stored directly in
Variant
with no conversion. These include all of the Variant types from Godot (for exampleGString
,Rect
,Plane
), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.protocol VariantStorable
Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.
Type members
init(
) Constructs a default-initialized
Basis
set toIDENTITY
.init(axis: Vector3, angle: Float
) Constructs a pure rotation basis matrix, rotated around the given
axis
byangle
(in radians). The axis must be a normalized vector.init(from: Basis
) init(from: Quaternion
) Constructs a pure rotation basis matrix from the given quaternion.
init(xAxis: Vector3, yAxis: Vector3, zAxis: Vector3
) Constructs a basis matrix from 3 axis vectors (matrix columns).
static let flipX: Basis
The basis that will flip something along the X axis when used in a transformation.
static let flipY: Basis
The basis that will flip something along the Y axis when used in a transformation.
static let flipZ: Basis
The basis that will flip something along the Z axis when used in a transformation.
static var godotType: Variant.GType
static let identity: Basis
The identity basis, with no rotation or scaling applied.
static func fromEuler(Vector3, order: Int64
) -> Basis Constructs a pure rotation Basis matrix from Euler angles in the specified Euler rotation order. By default, use YXZ order (most common). See the
EulerOrder
enum for possible values.static func fromScale(Vector3
) -> Basis Constructs a pure scale basis matrix with no rotation or shearing. The scale values are set as the diagonal of the matrix, and the other parts of the matrix are zero.
static func lookingAt(target: Vector3, up: Vector3, useModelFront: Bool
) -> Basis Creates a Basis with a rotation such that the forward axis (-Z) points towards the
target
position.static func != (lhs: Basis, rhs: Basis
) -> Bool Returns
true
if theBasis
matrices are not equal.static func * (lhs: Basis, rhs: Basis
) -> Basis This operator multiplies all components of the
Basis
, which scales it uniformly.static func * (lhs: Basis, rhs: Double
) -> Basis This operator multiplies all components of the
Basis
, which scales it uniformly.static func * (lhs: Basis, rhs: Int64
) -> Basis This operator multiplies all components of the
Basis
, which scales it uniformly.static func * (lhs: Basis, rhs: Vector3
) -> Vector3 This operator multiplies all components of the
Basis
, which scales it uniformly.static func == (lhs: Basis, rhs: Basis
) -> Bool Returns
true
if theBasis
matrices are exactly equal.
Instance members
var x: Vector3
The basis matrix’s X vector (column 0). Equivalent to array index
0
.var y: Vector3
The basis matrix’s Y vector (column 1). Equivalent to array index
1
.var z: Vector3
The basis matrix’s Z vector (column 2). Equivalent to array index
2
.subscript(Int64
) -> Vector3 func determinant(
) -> Double Returns the determinant of the basis matrix. If the basis is uniformly scaled, its determinant is the square of the scale.
func getEuler(order: Int64
) -> Vector3 Returns the basis’s rotation in the form of Euler angles. The Euler order depends on the
order
parameter, by default it uses the YXZ convention: when decomposing, first Z, then X, and Y last. The returned vector contains the rotation angles in the format (X angle, Y angle, Z angle).func getRotationQuaternion(
) -> Quaternion Returns the basis’s rotation in the form of a quaternion. See
getEuler(order:)
if you need Euler angles, but keep in mind quaternions should generally be preferred to Euler angles.func getScale(
) -> Vector3 Assuming that the matrix is the combination of a rotation and scaling, return the absolute value of scaling factors along each axis.
func inverse(
) -> Basis Returns the inverse of the matrix.
func isConformal(
) -> Bool Returns
true
if the basis is conformal, meaning it preserves angles and distance ratios, and may only be composed of rotation and uniform scale. Returnsfalse
if the basis has non-uniform scale or shear/skew. This can be used to validate if the basis is non-distorted, which is important for physics and other use cases.func isEqualApprox(b: Basis
) -> Bool Returns
true
if this basis andb
are approximately equal, by calling@GlobalScope.is_equal_approx
on all vector components.func isFinite(
) -> Bool Returns
true
if this basis is finite, by calling@GlobalScope.is_finite
on all vector components.func orthonormalized(
) -> Basis Returns the orthonormalized version of the matrix (useful to call from time to time to avoid rounding error for orthogonal matrices). This performs a Gram-Schmidt orthonormalization on the basis of the matrix.
func rotated(axis: Vector3, angle: Double
) -> Basis Introduce an additional rotation around the given axis by
angle
(in radians). The axis must be a normalized vector.func scaled(scale: Vector3
) -> Basis Introduce an additional scaling specified by the given 3D scaling factor.
func slerp(to: Basis, weight: Double
) -> Basis Assuming that the matrix is a proper rotation matrix, slerp performs a spherical-linear interpolation with another rotation matrix.
func tdotx(with: Vector3
) -> Double Transposed dot product with the X axis of the matrix.
func tdoty(with: Vector3
) -> Double Transposed dot product with the Y axis of the matrix.
func tdotz(with: Vector3
) -> Double Transposed dot product with the Z axis of the matrix.
func transposed(
) -> Basis Returns the transposed version of the matrix.
Type features
init?(Variant
) static func makeOrUnwrap(Variant
) -> Self? Unwraps an object from a variant.
static func makeOrUnwrap(Variant
) -> Self? Unwraps an object from a variant. This is useful when you want one method to call that will return the unwrapped Variant, regardless of whether it is a SwiftGodot.Object or not.
static func != (lhs: Self, rhs: Self
) -> Bool Returns a Boolean value indicating whether two values are not equal.