Transform3D
A 3×4 matrix representing a 3D transformation.
Transform3D.swift:19struct Transform3D
The Transform3D
built-in Variant
type is a 3×4 matrix representing a transformation in 3D space. It contains a Basis
, which on its own can represent rotation, scale, and shear. Additionally, combined with its own origin
, the transform can also represent a translation.
For a general introduction, see the Matrices and transforms tutorial.
Citizens in SwiftGodot
Conformances
protocol Copyable
A type whose values can be implicitly or explicitly copied.
protocol Equatable
A type that can be compared for value equality.
protocol Escapable
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
Transform3D
identical to theIDENTITY
.init(basis: Basis, origin: Vector3
) Constructs a
Transform3D
from aBasis
andVector3
.init(from: Transform3D
) Constructs a
Transform3D
as a copy of the givenTransform3D
.init(from: Projection
) Constructs a
Transform3D
from aProjection
. BecauseTransform3D
is a 3×4 matrix andProjection
is a 4×4 matrix, this operation trims the last row of the projection matrix (from.x.w
,from.y.w
,from.z.w
, andfrom.w.w
are not included in the new transform).init(xAxis: Vector3, yAxis: Vector3, zAxis: Vector3, origin: Vector3
) Constructs a
Transform3D
from fourVector3
values (also called matrix columns).static let flipX: Transform3D
Transform3D
with mirroring applied perpendicular to the YZ plane. Itsbasis
is equal toBasis.FLIP_X
.static let flipY: Transform3D
Transform3D
with mirroring applied perpendicular to the XZ plane. Itsbasis
is equal toBasis.FLIP_Y
.static let flipZ: Transform3D
Transform3D
with mirroring applied perpendicular to the XY plane. Itsbasis
is equal toBasis.FLIP_Z
.static var godotType: Variant.GType
static let identity: Transform3D
A transform with no translation, no rotation, and its scale being
1
. Itsbasis
is equal toBasis.IDENTITY
.static func != (lhs: Transform3D, rhs: Transform3D
) -> Bool Returns
true
if the components of both transforms are not equal.static func * (lhs: Transform3D, rhs: Transform3D
) -> Transform3D Transforms (multiplies) this transform by the
right
transform.static func * (lhs: Transform3D, rhs: Double
) -> Transform3D Multiplies all components of the
Transform3D
by the given float, including theorigin
. This affects the transform’s scale uniformly, scaling thebasis
.static func * (lhs: Transform3D, rhs: Int64
) -> Transform3D Multiplies all components of the
Transform3D
by the given integer, including theorigin
. This affects the transform’s scale uniformly, scaling thebasis
.static func * (lhs: Transform3D, rhs: PackedVector3Array
) -> PackedVector3Array Transforms (multiplies) every
Vector3
element of the givenPackedVector3Array
by this transformation matrix.static func * (lhs: Transform3D, rhs: AABB
) -> AABB Transforms (multiplies) the
AABB
by this transformation matrix.static func * (lhs: Transform3D, rhs: Plane
) -> Plane Transforms (multiplies) the
Plane
by this transformation matrix.static func * (lhs: Transform3D, rhs: Vector3
) -> Vector3 Transforms (multiplies) the
Vector3
by this transformation matrix.static func / (lhs: Transform3D, rhs: Double
) -> Transform3D Divides all components of the
Transform3D
by the given float, including theorigin
. This affects the transform’s scale uniformly, scaling thebasis
.static func / (lhs: Transform3D, rhs: Int64
) -> Transform3D Divides all components of the
Transform3D
by the given integer, including theorigin
. This affects the transform’s scale uniformly, scaling thebasis
.static func == (lhs: Transform3D, rhs: Transform3D
) -> Bool Returns
true
if the components of both transforms are exactly equal.
Instance members
var basis: Basis
The
Basis
of this transform. It is composed by 3 axes (x
,y
, andz
). Together, these represent the transform’s rotation, scale, and shear.var origin: Vector3
The translation offset of this transform. In 3D space, this can be seen as the position.
func affineInverse(
) -> Transform3D Returns the inverted version of this transform. Unlike
inverse
, this method works with almost anybasis
, including non-uniform ones, but is slower. See alsoinverse
.func interpolateWith(xform: Transform3D, weight: Double
) -> Transform3D Returns the result of the linear interpolation between this transform and
xform
by the givenweight
.func inverse(
) -> Transform3D Returns the inverted version of this transform. See also
inverse
.func isEqualApprox(xform: Transform3D
) -> Bool Returns
true
if this transform andxform
are approximately equal, by running@GlobalScope.is_equal_approx
on each component.func isFinite(
) -> Bool Returns
true
if this transform is finite, by calling@GlobalScope.is_finite
on each component.func lookingAt(target: Vector3, up: Vector3, useModelFront: Bool
) -> Transform3D Returns a copy of this transform rotated so that the forward axis (-Z) points towards the
target
position.func orthonormalized(
) -> Transform3D Returns a copy of this transform with its
basis
orthonormalized. An orthonormal basis is both orthogonal (the axes are perpendicular to each other) and normalized (the axes have a length of1
), which also means it can only represent rotation. See alsoorthonormalized
.func rotated(axis: Vector3, angle: Double
) -> Transform3D Returns a copy of this transform rotated around the given
axis
by the givenangle
(in radians).func rotatedLocal(axis: Vector3, angle: Double
) -> Transform3D Returns a copy of this transform rotated around the given
axis
by the givenangle
(in radians).func scaled(scale: Vector3
) -> Transform3D Returns a copy of this transform scaled by the given
scale
factor.func scaledLocal(scale: Vector3
) -> Transform3D Returns a copy of this transform scaled by the given
scale
factor.func translated(offset: Vector3
) -> Transform3D Returns a copy of this transform translated by the given
offset
.func translatedLocal(offset: Vector3
) -> Transform3D Returns a copy of this transform translated by the given
offset
.
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.