Enumerationmigueldeicaza.swiftgodot 0.46.0SwiftGodot
Axis
Vector3.swift:28enum Axis
Cases
case x
Enumerated value for the X axis. Returned by
maxAxisIndex
andminAxisIndex
.case y
Enumerated value for the Y axis. Returned by
maxAxisIndex
andminAxisIndex
.case z
Enumerated value for the Z axis. Returned by
maxAxisIndex
andminAxisIndex
.
Other members in extension
View members
Hide members
This section is hidden by default because it contains too many (97) members.
Type members
init(
) Constructs a default-initialized
Vector3
with all components set to0
.init(from: Vector3
) init(from: Vector3i
) Constructs a new
Vector3
fromVector3i
.init(x: Float, y: Float, z: Float
) Returns a
Vector3
with the given components.static let axisX: Int
Enumerated value for the X axis. Returned by
maxAxisIndex
andminAxisIndex
.static let axisY: Int
Enumerated value for the Y axis. Returned by
maxAxisIndex
andminAxisIndex
.static let axisZ: Int
Enumerated value for the Z axis. Returned by
maxAxisIndex
andminAxisIndex
.static let back: Vector3
Back unit vector. Represents the local direction of back, and the global direction of south.
static let down: Vector3
Down unit vector.
static let forward: Vector3
Forward unit vector. Represents the local direction of forward, and the global direction of north. Keep in mind that the forward direction for lights, cameras, etc is different from 3D assets like characters, which face towards the camera by convention. Use
Vector3.MODEL_FRONT
and similar constants when working in 3D asset space.static var godotType: Variant.GType
static let inf: Vector3
Infinity vector, a vector with all components set to
@GDScript.INF
.static let left: Vector3
Left unit vector. Represents the local direction of left, and the global direction of west.
static let modelBottom: Vector3
Unit vector pointing towards the bottom side (down) of imported 3D assets.
static let modelFront: Vector3
Unit vector pointing towards the front side (facing forward) of imported 3D assets.
static let modelLeft: Vector3
Unit vector pointing towards the left side of imported 3D assets.
static let modelRear: Vector3
Unit vector pointing towards the rear side (back) of imported 3D assets.
static let modelRight: Vector3
Unit vector pointing towards the right side of imported 3D assets.
static let modelTop: Vector3
Unit vector pointing towards the top side (up) of imported 3D assets.
static let one: Vector3
One vector, a vector with all components set to
1
.static let right: Vector3
Right unit vector. Represents the local direction of right, and the global direction of east.
static let up: Vector3
Up unit vector.
static let zero: Vector3
Zero vector, a vector with all components set to
0
.static func octahedronDecode(uv: Vector2
) -> Vector3 Returns the
Vector3
from an octahedral-compressed form created usingoctahedronEncode
(stored as aVector2
).static func != (lhs: Vector3, rhs: Vector3
) -> Bool Returns
true
if the vectors are not equal.static func * (lhs: Vector3, rhs: Quaternion
) -> Vector3 Inversely transforms (multiplies) the
Vector3
by the givenQuaternion
.static func * (lhs: Vector3, rhs: Transform3D
) -> Vector3 Inversely transforms (multiplies) the
Vector3
by the givenTransform3D
transformation matrix, under the assumption that the transformation basis is orthonormal (i.e. rotation/reflection is fine, scaling/skew is not).static func * (lhs: Vector3, rhs: Basis
) -> Vector3 Inversely transforms (multiplies) the
Vector3
by the givenBasis
matrix, under the assumption that the basis is orthonormal (i.e. rotation/reflection is fine, scaling/skew is not).static func * (lhs: Vector3, rhs: Vector3
) -> Vector3 Multiplies each component of the
Vector3
by the components of the givenVector3
.static func * (lhs: Vector3, rhs: Double
) -> Vector3 Multiplies each component of the
Vector3
by the given float.static func * (lhs: Vector3, rhs: Int64
) -> Vector3 Multiplies each component of the
Vector3
by the given integer.static func *= (left: inout `Self`, right: `Self`
) static func + (lhs: Vector3, rhs: Vector3
) -> Vector3 Adds each component of the
Vector3
by the components of the givenVector3
.static func += (left: inout `Self`, right: `Self`
) static func - (v: `Self`
) -> Vector3 Returns the negative value of the Vector3. This is the same as writing Vector3(-v.x, -v.y, -v.z). This operation flips the direction of the vector while keeping the same magnitude. With floats, the number zero can be either positive or negative.
static func - (lhs: Vector3, rhs: Vector3
) -> Vector3 Subtracts each component of the
Vector3
by the components of the givenVector3
.static func -= (left: inout `Self`, right: `Self`
) static func / (lhs: Vector3, rhs: Vector3
) -> Vector3 Divides each component of the
Vector3
by the components of the givenVector3
.static func / (lhs: Vector3, rhs: Double
) -> Vector3 Divides each component of the
Vector3
by the given float.static func / (lhs: Vector3, rhs: Int64
) -> Vector3 Divides each component of the
Vector3
by the given integer.static func /= (left: inout `Self`, right: `Self`
) static func < (lhs: Vector3, rhs: Vector3
) -> Bool Compares two
Vector3
vectors by first checking if the X value of the left vector is less than the X value of theright
vector. If the X values are exactly equal, then it repeats this check with the Y values of the two vectors, and then with the Z values. This operator is useful for sorting vectors.static func <= (lhs: Vector3, rhs: Vector3
) -> Bool Compares two
Vector3
vectors by first checking if the X value of the left vector is less than or equal to the X value of theright
vector. If the X values are exactly equal, then it repeats this check with the Y values of the two vectors, and then with the Z values. This operator is useful for sorting vectors.static func == (lhs: Vector3, rhs: Vector3
) -> Bool Returns
true
if the vectors are exactly equal.static func > (lhs: Vector3, rhs: Vector3
) -> Bool Compares two
Vector3
vectors by first checking if the X value of the left vector is greater than the X value of theright
vector. If the X values are exactly equal, then it repeats this check with the Y values of the two vectors, and then with the Z values. This operator is useful for sorting vectors.static func >= (lhs: Vector3, rhs: Vector3
) -> Bool Compares two
Vector3
vectors by first checking if the X value of the left vector is greater than or equal to the X value of theright
vector. If the X values are exactly equal, then it repeats this check with the Y values of the two vectors, and then with the Z values. This operator is useful for sorting vectors.
Instance members
var x: Float
The vector’s X component. Also accessible by using the index position
[0]
.var y: Float
The vector’s Y component. Also accessible by using the index position
[1]
.var z: Float
The vector’s Z component. Also accessible by using the index position
[2]
.subscript(Int64
) -> Double func abs(
) -> Vector3 Returns a new vector with all components in absolute values (i.e. positive).
func angleTo(Vector3
) -> Double Returns the unsigned minimum angle to the given vector, in radians.
func bezierDerivative(control1: Vector3, control2: Vector3, end: Vector3, t: Double
) -> Vector3 Returns the derivative at the given
t
on the Bézier curve defined by this vector and the givencontrol1
,control2
, andend
points.func bezierInterpolate(control1: Vector3, control2: Vector3, end: Vector3, t: Double
) -> Vector3 Returns the point at the given
t
on the Bézier curve defined by this vector and the givencontrol1
,control2
, andend
points.func bounce(n: Vector3
) -> Vector3 Returns the vector “bounced off” from a plane defined by the given normal
n
.func ceil(
) -> Vector3 Returns a new vector with all components rounded up (towards positive infinity).
func clamp(min: Vector3, max: Vector3
) -> Vector3 Returns a new vector with all components clamped between the components of
min
andmax
, by running@GlobalScope.clamp
on each component.func clampf(min: Double, max: Double
) -> Vector3 Returns a new vector with all components clamped between
min
andmax
, by running@GlobalScope.clamp
on each component.func cross(with: Vector3
) -> Vector3 Returns the cross product of this vector and
with
.func cubicInterpolate(b: Vector3, preA: Vector3, postB: Vector3, weight: Double
) -> Vector3 Performs a cubic interpolation between this vector and
b
usingpreA
andpostB
as handles, and returns the result at positionweight
.weight
is on the range of 0.0 to 1.0, representing the amount of interpolation.func cubicInterpolateInTime(b: Vector3, preA: Vector3, postB: Vector3, weight: Double, bT: Double, preAT: Double, postBT: Double
) -> Vector3 Performs a cubic interpolation between this vector and
b
usingpreA
andpostB
as handles, and returns the result at positionweight
.weight
is on the range of 0.0 to 1.0, representing the amount of interpolation.func directionTo(Vector3
) -> Vector3 Returns the normalized vector pointing from this vector to
to
. This is equivalent to using(b - a).normalized()
.func distanceSquaredTo(Vector3
) -> Double Returns the squared distance between this vector and
to
.func distanceTo(Vector3
) -> Double Returns the distance between this vector and
to
.func dot(with: Vector3
) -> Double Returns the dot product of this vector and
with
. This can be used to compare the angle between two vectors. For example, this can be used to determine whether an enemy is facing the player.func floor(
) -> Vector3 Returns a new vector with all components rounded down (towards negative infinity).
func inverse(
) -> Vector3 Returns the inverse of the vector. This is the same as
Vector3(1.0 / v.x, 1.0 / v.y, 1.0 / v.z)
.func isEqualApprox(to: Vector3
) -> Bool Returns
true
if this vector andto
are approximately equal, by running@GlobalScope.is_equal_approx
on each component.func isFinite(
) -> Bool Returns
true
if this vector is finite, by calling@GlobalScope.is_finite
on each component.func isNormalized(
) -> Bool Returns
true
if the vector is normalized, i.e. its length is approximately equal to 1.func isZeroApprox(
) -> Bool Returns
true
if this vector’s values are approximately zero, by running@GlobalScope.is_zero_approx
on each component.func length(
) -> Double Returns the length (magnitude) of this vector.
func lengthSquared(
) -> Double Returns the squared length (squared magnitude) of this vector.
func lerp(to: `Self`, weight: any BinaryFloatingPoint
) -> Vector3 func limitLength(Double
) -> Vector3 Returns the vector with a maximum length by limiting its length to
length
.func max(with: Vector3
) -> Vector3 Returns the component-wise maximum of this and
with
, equivalent toVector3(maxf(x, with.x), maxf(y, with.y), maxf(z, with.z))
.func maxAxisIndex(
) -> Int64 Returns the axis of the vector’s highest value. See
AXIS_*
constants. If all components are equal, this method returns .x.func maxf(with: Double
) -> Vector3 Returns the component-wise maximum of this and
with
, equivalent toVector3(maxf(x, with), maxf(y, with), maxf(z, with))
.func min(with: Vector3
) -> Vector3 Returns the component-wise minimum of this and
with
, equivalent toVector3(minf(x, with.x), minf(y, with.y), minf(z, with.z))
.func minAxisIndex(
) -> Int64 Returns the axis of the vector’s lowest value. See
AXIS_*
constants. If all components are equal, this method returns .z.func minf(with: Double
) -> Vector3 Returns the component-wise minimum of this and
with
, equivalent toVector3(minf(x, with), minf(y, with), minf(z, with))
.func moveToward(to: Vector3, delta: Double
) -> Vector3 Returns a new vector moved toward
to
by the fixeddelta
amount. Will not go past the final value.func normalized(
) -> Vector3 Returns the result of scaling the vector to unit length. Equivalent to
v / v.length()
. Returns(0, 0, 0)
ifv.length() == 0
. See alsoisNormalized
.func octahedronEncode(
) -> Vector2 Returns the octahedral-encoded (oct32) form of this
Vector3
as aVector2
. Since aVector2
occupies 1/3 less memory compared toVector3
, this form of compression can be used to pass greater amounts ofnormalized
Vector3
s without increasing storage or memory requirements. See alsooctahedronDecode(uv:)
.func outer(with: Vector3
) -> Basis Returns the outer product with
with
.func posmod(mod: Double
) -> Vector3 Returns a vector composed of the
@GlobalScope.fposmod
of this vector’s components andmod
.func posmodv(modv: Vector3
) -> Vector3 Returns a vector composed of the
@GlobalScope.fposmod
of this vector’s components andmodv
’s components.func project(b: Vector3
) -> Vector3 Returns a new vector resulting from projecting this vector onto the given vector
b
. The resulting new vector is parallel tob
. See alsoslide(n:)
.func reflect(n: Vector3
) -> Vector3 Returns the result of reflecting the vector through a plane defined by the given normal vector
n
.func rotated(axis: Vector3, angle: Double
) -> Vector3 Returns the result of rotating this vector around a given axis by
angle
(in radians). The axis must be a normalized vector. See also@GlobalScope.deg_to_rad
.func round(
) -> Vector3 Returns a new vector with all components rounded to the nearest integer, with halfway cases rounded away from zero.
func sign(
) -> Vector3 Returns a new vector with each component set to
1.0
if it’s positive,-1.0
if it’s negative, and0.0
if it’s zero. The result is identical to calling@GlobalScope.sign
on each component.func signedAngleTo(Vector3, axis: Vector3
) -> Double Returns the signed angle to the given vector, in radians. The sign of the angle is positive in a counter-clockwise direction and negative in a clockwise direction when viewed from the side specified by the
axis
.func slerp(to: Vector3, weight: Double
) -> Vector3 Returns the result of spherical linear interpolation between this vector and
to
, by amountweight
.weight
is on the range of 0.0 to 1.0, representing the amount of interpolation.func slide(n: Vector3
) -> Vector3 Returns a new vector resulting from sliding this vector along a plane with normal
n
. The resulting new vector is perpendicular ton
, and is equivalent to this vector minus its projection onn
. See alsoproject(b:)
.func snapped(step: `Self`
) -> Vector3 func snappedf(step: Double
) -> Vector3 Returns a new vector with each component snapped to the nearest multiple of
step
. This can also be used to round the components to an arbitrary number of decimals.
Citizens in SwiftGodot
Conformances
protocol CaseIterable
A type that provides a collection of all of its values.
protocol CustomDebugStringConvertible
A type with a customized textual representation suitable for debugging purposes.
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 RawRepresentable<RawValue>
A type that can be converted to and from an associated raw value.
Type members
Instance members
var debugDescription: String
A textual representation of this instance, suitable for debugging
Type features
static func != (lhs: Self, rhs: Self
) -> Bool Returns a Boolean value indicating whether two values are not equal.