Class Vector3GodotExtensions
- Namespace
- Elegy.Common.Extensions
- Assembly
- Elegy.Common.dll
Vector3 extensions from Godot's own Vector3 class. Lots of useful gamedev-specific stuff there.
public static class Vector3GodotExtensions
- Inheritance
-
Vector3GodotExtensions
- Inherited Members
Methods
Abs(Vector3)
Returns a new vector with all components in absolute values (i.e. positive).
public static Vector3 Abs(this Vector3 v)
Parameters
v
Vector3
Returns
AngleTo(Vector3, Vector3)
Returns the unsigned minimum angle to the given vector, in radians.
public static float AngleTo(this Vector3 v, Vector3 to)
Parameters
Returns
- float
The unsigned angle between the two vectors, in radians.
At(Vector3, int)
Returns the Nth component of the vector.
public static float At(this Vector3 v, int i)
Parameters
Returns
Exceptions
BezierDerivative(Vector3, Vector3, Vector3, Vector3, float)
Returns the derivative at the given t
on the Bezier curve defined by this vector
and the given control1
, control2
, and end
points.
public static Vector3 BezierDerivative(this Vector3 v, Vector3 control1, Vector3 control2, Vector3 end, float t)
Parameters
v
Vector3control1
Vector3Control point that defines the bezier curve.
control2
Vector3Control point that defines the bezier curve.
end
Vector3The destination value for the interpolation.
t
floatA value on the range of 0.0 to 1.0, representing the amount of interpolation.
Returns
- Vector3
The resulting value of the interpolation.
BezierInterpolate(Vector3, Vector3, Vector3, Vector3, float)
Returns the point at the given t
on a one-dimensional Bezier curve defined by this vector
and the given control1
, control2
, and end
points.
public static Vector3 BezierInterpolate(this Vector3 v, Vector3 control1, Vector3 control2, Vector3 end, float t)
Parameters
v
Vector3control1
Vector3Control point that defines the bezier curve.
control2
Vector3Control point that defines the bezier curve.
end
Vector3The destination vector.
t
floatA value on the range of 0.0 to 1.0, representing the amount of interpolation.
Returns
- Vector3
The interpolated vector.
Ceil(Vector3)
Returns a new vector with all components rounded up (towards positive infinity).
public static Vector3 Ceil(this Vector3 v)
Parameters
v
Vector3
Returns
Clamp(Vector3, Vector3, Vector3)
Returns a new vector with all components clamped between the
components of min
and max
.
public static Vector3 Clamp(this Vector3 v, Vector3 min, Vector3 max)
Parameters
v
Vector3min
Vector3The vector with minimum allowed values.
max
Vector3The vector with maximum allowed values.
Returns
Cross(in Vector3, in Vector3)
Returns the cross product of this vector and with
.
public static Vector3 Cross(this in Vector3 v, in Vector3 with)
Parameters
Returns
- Vector3
The cross product vector.
CubicInterpolate(Vector3, Vector3, Vector3, Vector3, float)
Performs a cubic interpolation between vectors preA
, this vector,
b
, and postB
, by the given amount weight
.
public static Vector3 CubicInterpolate(this Vector3 v, Vector3 b, Vector3 preA, Vector3 postB, float weight)
Parameters
v
Vector3b
Vector3The destination vector.
preA
Vector3A vector before this vector.
postB
Vector3A vector after
b
.weight
floatA value on the range of 0.0 to 1.0, representing the amount of interpolation.
Returns
- Vector3
The interpolated vector.
CubicInterpolateInTime(Vector3, Vector3, Vector3, Vector3, float, float, float, float)
Performs a cubic interpolation between vectors preA
, this vector,
b
, and postB
, by the given amount weight
.
It can perform smoother interpolation than CubicInterpolate(Vector3, Vector3, Vector3, Vector3, float)
by the time values.
public static Vector3 CubicInterpolateInTime(this Vector3 v, Vector3 b, Vector3 preA, Vector3 postB, float weight, float t, float preAT, float postBT)
Parameters
v
Vector3b
Vector3The destination vector.
preA
Vector3A vector before this vector.
postB
Vector3A vector after
b
.weight
floatA value on the range of 0.0 to 1.0, representing the amount of interpolation.
t
floatpreAT
floatpostBT
float
Returns
- Vector3
The interpolated vector.
DirectionTo(Vector3, Vector3)
Returns the normalized vector pointing from this vector to to
.
public static Vector3 DirectionTo(this Vector3 v, Vector3 to)
Parameters
Returns
- Vector3
The direction from this vector to
to
.
DistanceSquaredTo(Vector3, Vector3)
Returns the squared distance between this vector and to
.
This method runs faster than DistanceTo(Vector3, Vector3), so prefer it if
you need to compare vectors or need the squared distance for some formula.
public static float DistanceSquaredTo(this Vector3 v, Vector3 to)
Parameters
Returns
- float
The squared distance between the two vectors.
DistanceTo(Vector3, Vector3)
Returns the distance between this vector and to
.
public static float DistanceTo(this Vector3 v, Vector3 to)
Parameters
Returns
- float
The distance between the two vectors.
- See Also
Dot(in Vector3, in Vector3)
Returns the dot product of this vector and with
.
public static float Dot(this in Vector3 v, in Vector3 with)
Parameters
Returns
- float
The dot product of the two vectors.
IsEqualApprox(Vector3, Vector3)
Returns true if this vector and other
are approximately equal,
by running IsEqualApprox(float, float) on each component.
public static bool IsEqualApprox(this Vector3 v, Vector3 other)
Parameters
Returns
- bool
Whether or not the vectors are approximately equal.
IsEqualApprox(Vector3, Vector3, float)
Returns true if this vector and other
are approximately equal,
by running IsEqualApprox(float, float, float) on each component.
public static bool IsEqualApprox(this Vector3 v, Vector3 other, float tolerance)
Parameters
v
Vector3other
Vector3The other vector to compare.
tolerance
floatThe approximate radius of comparison.
Returns
- bool
Whether or not the vectors are approximately equal.
IsFinite(Vector3)
Returns true if this vector is finite, by calling IsFinite(float) on each component.
public static bool IsFinite(this Vector3 v)
Parameters
v
Vector3
Returns
- bool
Whether this vector is finite or not.
IsNormalized(in Vector3)
public static bool IsNormalized(this in Vector3 v)
Parameters
v
Vector3
Returns
IsZeroApprox(Vector3)
Returns true if this vector's values are approximately zero, by running IsZeroApprox(float) on each component. This method is faster than using IsEqualApprox(Vector3, Vector3) with one value as a zero vector.
public static bool IsZeroApprox(this Vector3 v)
Parameters
v
Vector3
Returns
- bool
Whether or not the vector is approximately zero.
Lerp(in Vector3, Vector3, float)
Returns the result of the linear interpolation between
this vector and to
by amount weight
.
public static Vector3 Lerp(this in Vector3 v, Vector3 to, float weight)
Parameters
v
Vector3to
Vector3The destination vector for interpolation.
weight
floatA value on the range of 0.0 to 1.0, representing the amount of interpolation.
Returns
- Vector3
The resulting vector of the interpolation.
LimitLength(in Vector3, float)
Returns the vector with a maximum length by limiting its length to length
.
public static Vector3 LimitLength(this in Vector3 v, float length = 1)
Parameters
Returns
- Vector3
The vector with its length limited.
MaxAxisIndex(in Vector3)
Returns the axis of the vector's highest value. See Axis. If all components are equal, this method returns X.
public static Axis MaxAxisIndex(this in Vector3 v)
Parameters
v
Vector3
Returns
- Axis
The index of the highest axis.
MinAxisIndex(in Vector3)
Returns the axis of the vector's lowest value. See Axis. If all components are equal, this method returns Z.
public static Axis MinAxisIndex(this in Vector3 v)
Parameters
v
Vector3
Returns
- Axis
The index of the lowest axis.
MoveToward(Vector3, Vector3, float)
Moves this vector toward to
by the fixed delta
amount.
public static Vector3 MoveToward(this Vector3 v, Vector3 to, float delta)
Parameters
Returns
- Vector3
The resulting vector.
Normalized(in Vector3)
Returns the vector scaled to unit length. Equivalent to v / v.Length()
.
public static Vector3 Normalized(this in Vector3 v)
Parameters
v
Vector3
Returns
- Vector3
A normalized version of the vector.
Reflect(Vector3, in Vector3)
Returns this vector reflected from a plane defined by the given normal
.
public static Vector3 Reflect(this Vector3 v, in Vector3 normal)
Parameters
Returns
- Vector3
The reflected vector.
Rotated(in Vector3, Vector3, float)
Rotates this vector around a given axis
vector by angle
(in radians).
The axis
vector must be a normalized vector.
public static Vector3 Rotated(this in Vector3 v, Vector3 axis, float angle)
Parameters
v
Vector3axis
Vector3The vector to rotate around. Must be normalized.
angle
floatThe angle to rotate by, in radians.
Returns
- Vector3
The rotated vector.
Round(Vector3)
Returns this vector with all components rounded to the nearest integer, with halfway cases rounded towards the nearest multiple of two.
public static Vector3 Round(this Vector3 v)
Parameters
v
Vector3
Returns
- Vector3
The rounded vector.
Sign(Vector3)
Returns a vector with each component set to one or negative one, depending on the signs of this vector's components, or zero if the component is zero, by calling Sign(float) on each component.
public static Vector3 Sign(this Vector3 v)
Parameters
v
Vector3
Returns
- Vector3
A vector with all components as either
1
,-1
, or0
.
SignedAngleTo(Vector3, Vector3, Vector3)
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
.
public static float SignedAngleTo(this Vector3 v, Vector3 to, Vector3 axis)
Parameters
v
Vector3to
Vector3The other vector to compare this vector to.
axis
Vector3The reference axis to use for the angle sign.
Returns
- float
The signed angle between the two vectors, in radians.
Slerp(in Vector3, Vector3, float)
Returns the result of the spherical linear interpolation between
this vector and to
by amount weight
.
This method also handles interpolating the lengths if the input vectors have different lengths. For the special case of one or both input vectors having zero length, this method behaves like Lerp(in Vector3, Vector3, float).
public static Vector3 Slerp(this in Vector3 v, Vector3 to, float weight)
Parameters
v
Vector3to
Vector3The destination vector for interpolation.
weight
floatA value on the range of 0.0 to 1.0, representing the amount of interpolation.
Returns
- Vector3
The resulting vector of the interpolation.
Slide(in Vector3, Vector3)
Returns this vector slid along a plane defined by the given normal
.
public static Vector3 Slide(this in Vector3 v, Vector3 normal)
Parameters
Returns
- Vector3
The slid vector.
Snapped(in Vector3, Vector3)
Returns this vector with each component snapped to the nearest multiple of step
.
This can also be used to round to an arbitrary number of decimals.
public static Vector3 Snapped(this in Vector3 v, Vector3 step)
Parameters
Returns
- Vector3
The snapped vector.