Class Vector2GodotExtensions
- Namespace
- Elegy.Common.Extensions
- Assembly
- Elegy.Common.dll
Vector2 extensions from Godot's own Vector2 class. Lots of useful gamedev-specific stuff there.
public static class Vector2GodotExtensions
- Inheritance
-
Vector2GodotExtensions
- Inherited Members
Methods
Abs(Vector2)
Returns a new vector with all components in absolute values (i.e. positive).
public static Vector2 Abs(this Vector2 v)
Parameters
v
Vector2
Returns
Angle(Vector2)
Returns this vector's angle with respect to the X axis, or (1, 0) vector, in radians.
Equivalent to the result of Atan2(float, float) when
called with the vector's Y and X as parameters: Mathf.Atan2(v.Y, v.X)
.
public static float Angle(this Vector2 v)
Parameters
v
Vector2
Returns
- float
The angle of this vector, in radians.
AngleTo(Vector2, Vector2)
Returns the angle to the given vector, in radians.
public static float AngleTo(this Vector2 v, Vector2 to)
Parameters
Returns
- float
The angle between the two vectors, in radians.
AngleToPoint(Vector2, Vector2)
Returns the angle between the line connecting the two points and the X axis, in radians.
public static float AngleToPoint(this Vector2 v, Vector2 to)
Parameters
Returns
- float
The angle between the two vectors, in radians.
At(Vector2, int)
Returns the Nth component of the vector.
public static float At(this Vector2 v, int i)
Parameters
Returns
Exceptions
BezierDerivative(Vector2, Vector2, Vector2, Vector2, 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 Vector2 BezierDerivative(this Vector2 v, Vector2 control1, Vector2 control2, Vector2 end, float t)
Parameters
v
Vector2control1
Vector2Control point that defines the bezier curve.
control2
Vector2Control point that defines the bezier curve.
end
Vector2The destination value for the interpolation.
t
floatA value on the range of 0.0 to 1.0, representing the amount of interpolation.
Returns
- Vector2
The resulting value of the interpolation.
BezierInterpolate(Vector2, Vector2, Vector2, Vector2, 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 Vector2 BezierInterpolate(this Vector2 v, Vector2 control1, Vector2 control2, Vector2 end, float t)
Parameters
v
Vector2control1
Vector2Control point that defines the bezier curve.
control2
Vector2Control point that defines the bezier curve.
end
Vector2The destination vector.
t
floatA value on the range of 0.0 to 1.0, representing the amount of interpolation.
Returns
- Vector2
The interpolated vector.
Ceil(Vector2)
Returns a new vector with all components rounded up (towards positive infinity).
public static Vector2 Ceil(this Vector2 v)
Parameters
v
Vector2
Returns
Clamp(Vector2, Vector2, Vector2)
Returns a new vector with all components clamped between the
components of min
and max
.
public static Vector2 Clamp(this Vector2 v, Vector2 min, Vector2 max)
Parameters
v
Vector2min
Vector2The vector with minimum allowed values.
max
Vector2The vector with maximum allowed values.
Returns
Cross(Vector2, Vector2)
Returns the cross product of this vector and with
.
public static float Cross(this Vector2 v, Vector2 with)
Parameters
Returns
- float
The cross product value.
CubicInterpolate(Vector2, Vector2, Vector2, Vector2, float)
Performs a cubic interpolation between vectors preA
, this vector,
b
, and postB
, by the given amount weight
.
public static Vector2 CubicInterpolate(this Vector2 v, Vector2 b, Vector2 preA, Vector2 postB, float weight)
Parameters
v
Vector2b
Vector2The destination vector.
preA
Vector2A vector before this vector.
postB
Vector2A vector after
b
.weight
floatA value on the range of 0.0 to 1.0, representing the amount of interpolation.
Returns
- Vector2
The interpolated vector.
CubicInterpolateInTime(Vector2, Vector2, Vector2, Vector2, 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(Vector2, Vector2, Vector2, Vector2, float)
by the time values.
public static Vector2 CubicInterpolateInTime(this Vector2 v, Vector2 b, Vector2 preA, Vector2 postB, float weight, float t, float preAT, float postBT)
Parameters
v
Vector2b
Vector2The destination vector.
preA
Vector2A vector before this vector.
postB
Vector2A 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
- Vector2
The interpolated vector.
DirectionTo(Vector2, Vector2)
Returns the normalized vector pointing from this vector to to
.
public static Vector2 DirectionTo(this Vector2 v, Vector2 to)
Parameters
Returns
- Vector2
The direction from this vector to
to
.
DistanceSquaredTo(Vector2, Vector2)
Returns the squared distance between this vector and to
.
This method runs faster than DistanceTo(Vector2, Vector2), so prefer it if
you need to compare vectors or need the squared distance for some formula.
public static float DistanceSquaredTo(this Vector2 v, Vector2 to)
Parameters
Returns
- float
The squared distance between the two vectors.
DistanceTo(Vector2, Vector2)
Returns the distance between this vector and to
.
public static float DistanceTo(this Vector2 v, Vector2 to)
Parameters
Returns
- float
The distance between the two vectors.
- See Also
Dot(in Vector2, in Vector2)
Returns the dot product of this vector and with
.
public static float Dot(this in Vector2 v, in Vector2 with)
Parameters
Returns
- float
The dot product of the two vectors.
IsEqualApprox(Vector2, Vector2)
Returns true if this vector and other
are approximately equal,
by running IsEqualApprox(float, float) on each component.
public static bool IsEqualApprox(this Vector2 v, Vector2 other)
Parameters
Returns
- bool
Whether or not the vectors are approximately equal.
IsEqualApprox(Vector2, Vector2, float)
Returns true if this vector and other
are approximately equal,
by running IsEqualApprox(float, float) on each component.
public static bool IsEqualApprox(this Vector2 v, Vector2 other, float tolerance)
Parameters
v
Vector2other
Vector2The other vector to compare.
tolerance
floatThe approximate radius of comparison.
Returns
- bool
Whether or not the vectors are approximately equal.
IsFinite(Vector2)
Returns true if this vector is finite, by calling IsFinite(float) on each component.
public static bool IsFinite(this Vector2 v)
Parameters
v
Vector2
Returns
- bool
Whether this vector is finite or not.
IsNormalized(in Vector2)
public static bool IsNormalized(this in Vector2 v)
Parameters
v
Vector2
Returns
IsZeroApprox(Vector2)
Returns true if this vector's values are approximately zero, by running IsZeroApprox(float) on each component. This method is faster than using IsEqualApprox(Vector2, Vector2) with one value as a zero vector.
public static bool IsZeroApprox(this Vector2 v)
Parameters
v
Vector2
Returns
- bool
Whether or not the vector is approximately zero.
Lerp(in Vector2, Vector2, float)
Returns the result of the linear interpolation between
this vector and to
by amount weight
.
public static Vector2 Lerp(this in Vector2 v, Vector2 to, float weight)
Parameters
v
Vector2to
Vector2The destination vector for interpolation.
weight
floatA value on the range of 0.0 to 1.0, representing the amount of interpolation.
Returns
- Vector2
The resulting vector of the interpolation.
LimitLength(in Vector2, float)
Returns the vector with a maximum length by limiting its length to length
.
public static Vector2 LimitLength(this in Vector2 v, float length = 1)
Parameters
Returns
- Vector2
The vector with its length limited.
MaxAxisIndex(in Vector2)
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 Vector2 v)
Parameters
v
Vector2
Returns
- Axis
The index of the highest axis.
MinAxisIndex(in Vector2)
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 Vector2 v)
Parameters
v
Vector2
Returns
- Axis
The index of the lowest axis.
MoveToward(Vector2, Vector2, float)
Moves this vector toward to
by the fixed delta
amount.
public static Vector2 MoveToward(this Vector2 v, Vector2 to, float delta)
Parameters
Returns
- Vector2
The resulting vector.
Normalize(in Vector2)
Returns the vector scaled to unit length. Equivalent to v / v.Length()
.
public static Vector2 Normalize(this in Vector2 v)
Parameters
v
Vector2
Returns
- Vector2
A normalized version of the vector.
Reflect(Vector2, in Vector2)
Returns this vector reflected from a plane defined by the given normal
.
public static Vector2 Reflect(this Vector2 v, in Vector2 normal)
Parameters
Returns
- Vector2
The reflected vector.
Round(Vector2)
Returns this vector with all components rounded to the nearest integer, with halfway cases rounded towards the nearest multiple of two.
public static Vector2 Round(this Vector2 v)
Parameters
v
Vector2
Returns
- Vector2
The rounded vector.
Sign(Vector2)
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 Vector2 Sign(this Vector2 v)
Parameters
v
Vector2
Returns
- Vector2
A vector with all components as either
1
,-1
, or0
.