reckfellENGINE

Vector4

Four float components: X, Y, Z and W.

On this page
struct Vector4ReckfellSharpInherits ValueType

A struct with X, Y, Z and W components, represented as float in the installed C# SDK. Stores four numeric values. The receiving API determines W semantics; the type itself does not make W an alpha channel or the value a ready-made rotation. Assignment copies the value.

For projective calculations, check whether an operation expects homogeneous coordinates and performs division by W. Do not treat every Vector4 as a ready-to-use Vector3 point without that context.

Vector4 has no C# conversion to bool. Exact comparison with Vector4.Zero and tolerance-based comparison answer different questions; also validate finiteness for floating-point data.

Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.

Constructors1

Vector4Constructor
# Vector4
C#
public Vector4(float x, float y, float z, float w);

Returns a Vector4 with the given components.

Parameters
NameTypeDefault
xfloat—
yfloat—
zfloat—
wfloat—
x

The vector's X component.

y

The vector's Y component.

z

The vector's Z component.

w

The vector's W component.

Properties4

InfProperty
# Inf
C#
public static Vector4 Inf { get; }

Infinity vector, a vector with all components set to @C#.INF.

ItemProperty
# Item
C#
public float this[int index] { get; set; }

Access vector components using their index.

OneProperty
# One
C#
public static Vector4 One { get; }

One vector, a vector with all components set to 1.

ZeroProperty
# Zero
C#
public static Vector4 Zero { get; }

Zero vector, a vector with all components set to 0.

Methods55

AbsVector4
# Abs
C#
public Vector4 Abs();

Returns a new vector with all components in absolute values (i.e. positive).

Returns Vector4

A vector with Mathf.Abs called on each component.

CeilVector4
# Ceil
C#
public Vector4 Ceil();

Returns a new vector with all components rounded up (towards positive infinity).

Returns Vector4

A vector with Mathf.Ceil called on each component.

Clamp2 overloads
# Clamp · 1/2
C#
public Vector4 Clamp(Vector4 min, Vector4 max);

Returns a new vector with all components clamped between the components of Vector4.Min and Vector4.Max, by running @GlobalScope.clamp on each component.

Parameters
NameTypeDefault
minVector4—
maxVector4—
min

The vector with minimum allowed values.

max

The vector with maximum allowed values.

Returns Vector4

The vector with all components clamped.

# Clamp · 2/2
C#
public Vector4 Clamp(float min, float max);

Returns a new vector with all components clamped between the components of Vector4.Min and Vector4.Max, by running @GlobalScope.clamp on each component.

Parameters
NameTypeDefault
minfloat—
maxfloat—
min

The minimum allowed value.

max

The maximum allowed value.

Returns Vector4

The vector with all components clamped.

CubicInterpolateVector4
# CubicInterpolate
C#
public Vector4 CubicInterpolate(Vector4 b, Vector4 preA, Vector4 postB, float weight);

Performs a cubic interpolation between this vector and b using pre_a and post_b as handles, and returns the result at position weight. weight is on the range of 0.0 to 1.0, representing the amount of interpolation.

Parameters
NameTypeDefault
bVector4—
preAVector4—
postBVector4—
weightfloat—
b

The destination vector.

preA

A vector before this vector.

postB

A vector after b.

weight

A value on the range of 0.0 to 1.0, representing the amount of interpolation.

Returns Vector4

The interpolated vector.

CubicInterpolateInTimeVector4
# CubicInterpolateInTime
C#
public Vector4 CubicInterpolateInTime(Vector4 b, Vector4 preA, Vector4 postB, float weight, float t, float preAT, float postBT);

Performs a cubic interpolation between this vector and b using pre_a and post_b as handles, and returns the result at position weight. weight is on the range of 0.0 to 1.0, representing the amount of interpolation. It can perform smoother interpolation than Vector4.CubicInterpolate by the time values.

Parameters
NameTypeDefault
bVector4—
preAVector4—
postBVector4—
weightfloat—
tfloat—
preATfloat—
postBTfloat—
b

The destination vector.

preA

A vector before this vector.

postB

A vector after b.

weight

A value on the range of 0.0 to 1.0, representing the amount of interpolation.

Returns Vector4

The interpolated vector.

Deconstructvoid
# Deconstruct
C#
public void Deconstruct(out float x, out float y, out float z, out float w);

Helper method for deconstruction into a tuple.

Parameters
NameTypeDefault
xfloat—
yfloat—
zfloat—
wfloat—
DirectionToVector4
# DirectionTo
C#
public Vector4 DirectionTo(Vector4 to);

Returns the normalized vector pointing from this vector to to. a.direction_to(b) is equivalent to (b - a).normalized(). See also Vector4.Normalized.

Parameters
NameTypeDefault
toVector4—
to

The other vector to point towards.

Returns Vector4

The direction from this vector to to.

DistanceSquaredTofloat
# DistanceSquaredTo
C#
public float DistanceSquaredTo(Vector4 to);

Returns the squared Euclidean distance between this vector and to. This method runs faster than Vector4.DistanceTo, so prefer it if you need to compare vectors or need the squared distance for some formula.

Parameters
NameTypeDefault
toVector4—
to

The other vector to use.

Returns float

The squared distance between the two vectors.

DistanceTofloat
# DistanceTo
C#
public float DistanceTo(Vector4 to);

Returns the Euclidean distance between this vector and to.

Parameters
NameTypeDefault
toVector4—
to

The other vector to use.

Returns float

The distance between the two vectors.

Dotfloat
# Dot
C#
public float Dot(Vector4 with);

Returns the dot product of this vector and with.

Parameters
NameTypeDefault
withVector4—
with

The other vector to use.

Returns float

The dot product of the two vectors.

Equals2 overloads
# Equals · 1/2
C#
public bool Equals(Vector4 other);

Returns true if the vectors are exactly equal. Note: Due to floating-point precision errors, consider using Vector4.IsEqualApprox instead, which is more reliable.

Parameters
NameTypeDefault
otherVector4—
other

The other vector.

Returns bool

Whether or not the vectors are exactly equal.

# Equals · 2/2
C#
public override bool Equals(object? obj);

Returns true if the vector is exactly equal to the given object (obj). Note: Due to floating-point precision errors, consider using Vector4.IsEqualApprox instead, which is more reliable.

Parameters
NameTypeDefault
objobject—
obj

The object to compare with.

Returns bool

Whether or not the vector and the object are equal.

FloorVector4
# Floor
C#
public Vector4 Floor();

Returns a new vector with all components rounded down (towards negative infinity).

Returns Vector4

A vector with Mathf.Floor called on each component.

GetHashCodeint
# GetHashCode
C#
public override int GetHashCode();

Serves as the hash function for Vector4.

Returns int

A hash code for this vector.

InverseVector4
# Inverse
C#
public Vector4 Inverse();

Returns the inverse of the vector. This is the same as Vector4(1.0 / v.x, 1.0 / v.y, 1.0 / v.z, 1.0 / v.w).

Returns Vector4

The inverse of this vector.

IsEqualApproxbool
# IsEqualApprox
C#
public bool IsEqualApprox(Vector4 other);

Returns true if this vector and to are approximately equal, by running @GlobalScope.is_equal_approx on each component.

Parameters
NameTypeDefault
otherVector4—
other

The other vector to compare.

Returns bool

Whether or not the vectors are approximately equal.

IsFinitebool
# IsFinite
C#
public bool IsFinite();

Returns true if this vector is finite, by calling @GlobalScope.is_finite on each component.

Returns bool

Whether this vector is finite or not.

IsNormalizedbool
# IsNormalized
C#
public bool IsNormalized();

Returns true if the vector is normalized, i.e. its length is approximately equal to 1.

Returns bool

A bool indicating whether or not the vector is normalized.

IsZeroApproxbool
# IsZeroApprox
C#
public bool IsZeroApprox();

Returns true if this vector's values are approximately zero, by running @GlobalScope.is_zero_approx on each component. This method is faster than using Vector4.IsEqualApprox with one value as a zero vector.

Returns bool

Whether or not the vector is approximately zero.

Lengthfloat
# Length
C#
public float Length();

Returns the length (magnitude) of this vector.

Returns float

The length of this vector.

LengthSquaredfloat
# LengthSquared
C#
public float LengthSquared();

Returns the squared length (squared magnitude) of this vector. This method runs faster than Vector4.Length, so prefer it if you need to compare vectors or need the squared distance for some formula.

Returns float

The squared length of this vector.

LerpVector4
# Lerp
C#
public Vector4 Lerp(Vector4 to, float weight);

Returns the result of the linear interpolation between this vector and to by amount weight. weight is on the range of 0.0 to 1.0, representing the amount of interpolation.

Parameters
NameTypeDefault
toVector4—
weightfloat—
to

The destination vector for interpolation.

weight

A value on the range of 0.0 to 1.0, representing the amount of interpolation.

Returns Vector4

The resulting vector of the interpolation.

Max2 overloads
# Max · 1/2
C#
public Vector4 Max(Vector4 with);

Returns the component-wise maximum of this and with, equivalent to Vector4(maxf(x, with.x), maxf(y, with.y), maxf(z, with.z), maxf(w, with.w)).

Parameters
NameTypeDefault
withVector4—
with

The other vector to use.

Returns Vector4

The resulting maximum vector.

# Max · 2/2
C#
public Vector4 Max(float with);

Returns the component-wise maximum of this and with, equivalent to Vector4(maxf(x, with.x), maxf(y, with.y), maxf(z, with.z), maxf(w, with.w)).

Parameters
NameTypeDefault
withfloat—
with

The other value to use.

Returns Vector4

The resulting maximum vector.

MaxAxisIndexVector4.Axis
# MaxAxisIndex
C#
public Vector4.Axis MaxAxisIndex();

Returns the axis of the vector's highest value. See AXIS_* constants. If all components are equal, this method returns Vector4.Axis.X.

Returns Vector4.Axis

The index of the highest axis.

Min2 overloads
# Min · 1/2
C#
public Vector4 Min(Vector4 with);

Returns the component-wise minimum of this and with, equivalent to Vector4(minf(x, with.x), minf(y, with.y), minf(z, with.z), minf(w, with.w)).

Parameters
NameTypeDefault
withVector4—
with

The other vector to use.

Returns Vector4

The resulting minimum vector.

# Min · 2/2
C#
public Vector4 Min(float with);

Returns the component-wise minimum of this and with, equivalent to Vector4(minf(x, with.x), minf(y, with.y), minf(z, with.z), minf(w, with.w)).

Parameters
NameTypeDefault
withfloat—
with

The other value to use.

Returns Vector4

The resulting minimum vector.

MinAxisIndexVector4.Axis
# MinAxisIndex
C#
public Vector4.Axis MinAxisIndex();

Returns the axis of the vector's lowest value. See AXIS_* constants. If all components are equal, this method returns Vector4.Axis.W.

Returns Vector4.Axis

The index of the lowest axis.

NormalizedVector4
# Normalized
C#
public Vector4 Normalized();

Returns the result of scaling the vector to unit length. Equivalent to v / v.length(). Returns (0, 0, 0, 0) if v.length() == 0. See also Vector4.IsNormalized. Note: This function may return incorrect values if the input vector length is near zero.

Returns Vector4

A normalized version of the vector.

PosMod2 overloads
# PosMod · 1/2
C#
public Vector4 PosMod(Vector4 modv);

Returns a vector composed of the @GlobalScope.fposmod of this vector's components and mod.

Parameters
NameTypeDefault
modvVector4—
modv

A vector representing the divisors of the operation.

Returns Vector4

A vector with each component Mathf.PosMod by modv's components.

# PosMod · 2/2
C#
public Vector4 PosMod(float mod);

Returns a vector composed of the @GlobalScope.fposmod of this vector's components and mod.

Parameters
NameTypeDefault
modfloat—
mod

A value representing the divisor of the operation.

Returns Vector4

A vector with each component Mathf.PosMod by mod.

RoundVector4
# Round
C#
public Vector4 Round();

Returns a new vector with all components rounded to the nearest integer, with halfway cases rounded away from zero.

Returns Vector4

The rounded vector.

SignVector4
# Sign
C#
public Vector4 Sign();

Returns a new vector with each component set to 1.0 if it's positive, -1.0 if it's negative, and 0.0 if it's zero. The result is identical to calling @GlobalScope.sign on each component.

Returns Vector4

A vector with all components as either 1, -1, or 0.

Snapped2 overloads
# Snapped · 1/2
C#
public Vector4 Snapped(Vector4 step);

Returns a new vector with each component snapped to the nearest multiple of the corresponding component in step. This can also be used to round the components to an arbitrary number of decimals.

Parameters
NameTypeDefault
stepVector4—
step

A vector value representing the step size to snap to.

Returns Vector4

The snapped vector.

# Snapped · 2/2
C#
public Vector4 Snapped(float step);

Returns a new vector with each component snapped to the nearest multiple of the corresponding component in step. This can also be used to round the components to an arbitrary number of decimals.

Parameters
NameTypeDefault
stepfloat—
step

The step size to snap to.

Returns Vector4

The snapped vector.

ToString2 overloads
# ToString · 1/2
C#
public override string ToString();

Converts this Vector4 to a string.

Returns string

A string representation of this vector.

# ToString · 2/2
C#
public string ToString(string? format);

Converts this Vector4 to a string with the given format.

Parameters
NameTypeDefault
formatstring—
Returns string

A string representation of this vector.

op_AdditionVector4
# op_Addition
C#
public static Vector4 operator +(Vector4 left, Vector4 right);

Adds each component of the Vector4 with the components of the given Vector4.

Parameters
NameTypeDefault
leftVector4—
rightVector4—
left

The left vector.

right

The right vector.

Returns Vector4

The added vector.

op_Division2 overloads
# op_Division · 1/2
C#
public static Vector4 operator /(Vector4 vec, Vector4 divisorv);

Divides each component of the Vector4 by the components of the given Vector4.

Parameters
NameTypeDefault
vecVector4—
divisorvVector4—
vec

The dividend vector.

divisorv

The divisor vector.

Returns Vector4

The divided vector.

# op_Division · 2/2
C#
public static Vector4 operator /(Vector4 vec, float divisor);

Divides each component of the Vector4 by the given System.Single.

Parameters
NameTypeDefault
vecVector4—
divisorfloat—
vec

The dividend vector.

divisor

The divisor value.

Returns Vector4

The divided vector.

op_Equalitybool
# op_Equality
C#
public static bool operator ==(Vector4 left, Vector4 right);

Returns true if the vectors are exactly equal. Note: Due to floating-point precision errors, consider using Vector4.IsEqualApprox instead, which is more reliable.

Parameters
NameTypeDefault
leftVector4—
rightVector4—
left

The left vector.

right

The right vector.

Returns bool

Whether or not the vectors are exactly equal.

op_GreaterThanbool
# op_GreaterThan
C#
public static bool operator >(Vector4 left, Vector4 right);

Compares two Vector4 vectors by first checking if the X value of the left vector is greater than the X value of the right vector. If the X values are exactly equal, then it repeats this check with the Y, Z and finally W values of the two vectors. This operator is useful for sorting vectors.

Parameters
NameTypeDefault
leftVector4—
rightVector4—
left

The left vector.

right

The right vector.

Returns bool

Whether or not the left is greater than the right.

op_GreaterThanOrEqualbool
# op_GreaterThanOrEqual
C#
public static bool operator >=(Vector4 left, Vector4 right);

Compares two Vector4 vectors by first checking if the X value of the left vector is greater than or equal to the X value of the right vector. If the X values are exactly equal, then it repeats this check with the Y, Z and finally W values of the two vectors. This operator is useful for sorting vectors.

Parameters
NameTypeDefault
leftVector4—
rightVector4—
left

The left vector.

right

The right vector.

Returns bool

Whether or not the left is greater than or equal to the right.

op_Inequalitybool
# op_Inequality
C#
public static bool operator !=(Vector4 left, Vector4 right);

Returns true if the vectors are not equal. Note: Due to floating-point precision errors, consider using Vector4.IsEqualApprox instead, which is more reliable.

Parameters
NameTypeDefault
leftVector4—
rightVector4—
left

The left vector.

right

The right vector.

Returns bool

Whether or not the vectors are not equal.

op_LessThanbool
# op_LessThan
C#
public static bool operator <(Vector4 left, Vector4 right);

Compares two Vector4 vectors by first checking if the X value of the left vector is less than the X value of the right vector. If the X values are exactly equal, then it repeats this check with the Y, Z and finally W values of the two vectors. This operator is useful for sorting vectors.

Parameters
NameTypeDefault
leftVector4—
rightVector4—
left

The left vector.

right

The right vector.

Returns bool

Whether or not the left is less than the right.

op_LessThanOrEqualbool
# op_LessThanOrEqual
C#
public static bool operator <=(Vector4 left, Vector4 right);

Compares two Vector4 vectors by first checking if the X value of the left vector is less than or equal to the X value of the right vector. If the X values are exactly equal, then it repeats this check with the Y, Z and finally W values of the two vectors. This operator is useful for sorting vectors.

Parameters
NameTypeDefault
leftVector4—
rightVector4—
left

The left vector.

right

The right vector.

Returns bool

Whether or not the left is less than or equal to the right.

op_Modulus2 overloads
# op_Modulus · 1/2
C#
public static Vector4 operator %(Vector4 vec, Vector4 divisorv);

Gets the remainder of each component of the Vector4 with the components of the given Vector4. This operation uses truncated division, which is often not desired as it does not work well with negative numbers. Consider using Vector4.PosMod instead if you want to handle negative numbers.

Parameters
NameTypeDefault
vecVector4—
divisorvVector4—
vec

The dividend vector.

divisorv

The divisor vector.

Returns Vector4

The remainder vector.

# op_Modulus · 2/2
C#
public static Vector4 operator %(Vector4 vec, float divisor);

Gets the remainder of each component of the Vector4 with the components of the given System.Single. This operation uses truncated division, which is often not desired as it does not work well with negative numbers. Consider using Vector4.PosMod instead if you want to handle negative numbers.

Parameters
NameTypeDefault
vecVector4—
divisorfloat—
vec

The dividend vector.

divisor

The divisor value.

Returns Vector4

The remainder vector.

op_Multiply3 overloads
# op_Multiply · 1/3
C#
public static Vector4 operator *(Vector4 left, Vector4 right);

Multiplies each component of the Vector4 by the components of the given Vector4.

Parameters
NameTypeDefault
leftVector4—
rightVector4—
left

The left vector.

right

The right vector.

Returns Vector4

The multiplied vector.

# op_Multiply · 2/3
C#
public static Vector4 operator *(Vector4 vec, float scale);

Multiplies each component of the Vector4 by the given System.Single.

Parameters
NameTypeDefault
vecVector4—
scalefloat—
vec

The vector to multiply.

scale

The scale to multiply by.

Returns Vector4

The multiplied vector.

# op_Multiply · 3/3
C#
public static Vector4 operator *(float scale, Vector4 vec);

Multiplies each component of the Vector4 by the given System.Single.

Parameters
NameTypeDefault
scalefloat—
vecVector4—
scale

The scale to multiply by.

vec

The vector to multiply.

Returns Vector4

The multiplied vector.

op_SubtractionVector4
# op_Subtraction
C#
public static Vector4 operator -(Vector4 left, Vector4 right);

Subtracts each component of the Vector4 by the components of the given Vector4.

Parameters
NameTypeDefault
leftVector4—
rightVector4—
left

The left vector.

right

The right vector.

Returns Vector4

The subtracted vector.

op_UnaryNegationVector4
# op_UnaryNegation
C#
public static Vector4 operator -(Vector4 vec);

Returns the negative value of the Vector4. This is the same as writing new Vector4(-v.X, -v.Y, -v.Z, -v.W). This operation flips the direction of the vector while keeping the same magnitude. With floats, the number zero can be either positive or negative.

Parameters
NameTypeDefault
vecVector4—
vec

The vector to negate/flip.

Returns Vector4

The negated/flipped vector.

op_UnaryPlusVector4
# op_UnaryPlus
C#
public static Vector4 operator +(Vector4 vec);

Returns the same value as if the + was not there. Unary + does nothing, but sometimes it can make your code more readable.

Parameters
NameTypeDefault
vecVector4—
vec

The vector to do nothing to.

Returns Vector4

The original vector.

Fields and constants4

WField
# W
C#
public float W;

The vector's W component. Also accessible by using the index position [3].

XField
# X
C#
public float X;

The vector's X component. Also accessible by using the index position [0].

YField
# Y
C#
public float Y;

The vector's Y component. Also accessible by using the index position [1].

ZField
# Z
C#
public float Z;

The vector's Z component. Also accessible by using the index position [2].

Vector4.Axis

ValueDescription
W = 3

Enumerated value for the W axis. Returned by Vector4.MaxAxisIndex and Vector4.MinAxisIndex.

X = 0

Enumerated value for the X axis. Returned by Vector4.MaxAxisIndex and Vector4.MinAxisIndex.

Y = 1

Enumerated value for the Y axis. Returned by Vector4.MaxAxisIndex and Vector4.MinAxisIndex.

Z = 2

Enumerated value for the Z axis. Returned by Vector4.MaxAxisIndex and Vector4.MinAxisIndex.

Reckfell Engine documentationBack to top ↑
QUICK LINKSGetting startedEntity hierarchyC# & .NET 10Scenes and prefabs
Reckfell guides and full API K
reckfellENGINE
RECKFELL ACCOUNT

Sign in

Sign in to your Reckfell account.

One account for the entire Reckfell platform.