[]
Represents a four dimensional mathematical vector.
public struct Vector4 : IEquatable<Vector4>, IFormattable
Initializes a new instance of the Vector4 struct.
public Vector4(Vector2 value, float z, float w)
value
Vector2A vector containing the values with which to initialize the X and Y components.
z
floatInitial value for the Z component of the vector.
w
floatInitial value for the W component of the vector.
Initializes a new instance of the Vector4 struct.
public Vector4(Vector3 value, float w)
value
Vector3A vector containing the values with which to initialize the X, Y, and Z components.
w
floatInitial value for the W component of the vector.
Initializes a new instance of the Vector4 struct.
public Vector4(float x, float y, float z, float w)
x
floatInitial value for the X component of the vector.
y
floatInitial value for the Y component of the vector.
z
floatInitial value for the Z component of the vector.
w
floatInitial value for the W component of the vector.
Initializes a new instance of the Vector4 struct.
public Vector4(float value)
value
floatThe value that will be assigned to all components.
Initializes a new instance of the Vector4 struct.
public Vector4(float[] values)
values
float[]The values to assign to the X, Y, Z, and W components of the vector. This must be an array with four elements.
Thrown when values
is null
.
Thrown when values
contains more or less than four elements.
A Vector4 with all of its components set to one.
public static readonly Vector4 One
The size of the Vector4 type, in bytes.
public const int SizeInBytes = 16
The W unit Vector4 (0, 0, 0, 1).
public static readonly Vector4 UnitW
The X unit Vector4 (1, 0, 0, 0).
public static readonly Vector4 UnitX
The Y unit Vector4 (0, 1, 0, 0).
public static readonly Vector4 UnitY
The Z unit Vector4 (0, 0, 1, 0).
public static readonly Vector4 UnitZ
The W component of the vector.
public float W
The X component of the vector.
public float X
The Y component of the vector.
public float Y
The Z component of the vector.
public float Z
A Vector4 with all of its components set to zero.
public static readonly Vector4 Zero
Gets a value indicting whether this instance is normalized.
public bool IsNormalized { get; }
Gets or sets the component at the specified index.
public float this[int index] { get; set; }
index
intThe index of the component to access. Use 0 for the X component, 1 for the Y component, 2 for the Z component, and 3 for the W component.
The value of the X, Y, Z, or W component, depending on the index.
Thrown when the index
is out of the range [0, 3].
Gets the length of the vector.
public float Length { get; }
Gets the squared length of the vector.
public float LengthSquared { get; }
Returns a vector whose elements are the absolute values of each of the specified vector's elements.
public static Vector4 Abs(Vector4 value)
value
Vector4A vector.
The absolute value vector.
Calculates the absolute value vector.
public static void AbsRef(ref Vector4 value)
value
Vector4A vector.
Adds two vectors.
public static Vector4 Add(Vector4 left, Vector4 right)
The sum of the two vectors.
Restricts a vector between a minimum and a maximum value.
public static Vector4 Clamp(Vector4 value, Vector4 min, Vector4 max)
The restricted vector.
Divides the first vector by the second.
public static Vector4 Divide(Vector4 left, Vector4 right)
The vector resulting from the division.
Divides the specified vector by a specified scalar value.
public static Vector4 Divide(Vector4 left, float divisor)
left
Vector4The vector.
divisor
floatThe scalar value.
The vector that results from the division.
Calculates the dot product of two vectors.
public static float Dot(Vector4 left, Vector4 right)
The dot product of the two vectors.
Determines whether the specified Vector4 is equal to this instance.
public bool Equals(Vector4 other)
other
Vector4Determines whether the specified object is equal to this instance.
public override bool Equals(object value)
value
objectReturns a hash code for this instance.
public override int GetHashCode()
A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
Performs a linear interpolation between two vectors based on the given weighting.
public static Vector4 Lerp(Vector4 value1, Vector4 value2, float amount)
value1
Vector4The first vector.
value2
Vector4The second vector.
amount
floatA value between 0 and 1 that indicates the weight of value2.
The interpolated vector.
Returns a vector containing the largest components of the specified vectors.
public static Vector4 Max(Vector4 left, Vector4 right)
A vector containing the largest components of the source vectors.
Returns a vector containing the smallest components of the specified vectors.
public static Vector4 Min(Vector4 left, Vector4 right)
A vector containing the smallest components of the source vectors.
Modulates a vector with another by performing component-wise multiplication.
public static Vector4 Multiply(Vector4 left, Vector4 right)
The modulated vector.
Scales a vector by the given value.
public static Vector4 Multiply(Vector4 value, float scale)
value
Vector4The vector to scale.
scale
floatThe amount by which to scale the vector.
The scaled vector.
Reverses the direction of a given vector.
public static Vector4 Negate(Vector4 value)
value
Vector4The vector to negate.
A vector facing in the opposite direction.
Reverses the direction of the vector.
public static void NegateRef(ref Vector4 value)
value
Vector4The vector to negate.
Converts the vector into a unit vector.
public static Vector4 Normalize(Vector4 value)
value
Vector4The vector to normalize.
The normalized vector.
Converts the vector into a unit vector.
public static void NormalizeRef(ref Vector4 value)
value
Vector4The vector to normalize.
Subtracts two vectors.
public static Vector4 Subtract(Vector4 left, Vector4 right)
The difference of the two vectors.
Creates an array containing the elements of the vector.
public float[] ToArray()
A four-element array containing the components of the vector.
Returns a string that represents this instance.
public override string ToString()
A string that represents this instance.
Returns a string that represents this instance.
public string ToString(IFormatProvider formatProvider)
formatProvider
System.IFormatProviderThe format provider.
A string that represents this instance.
Returns a string that represents this instance.
public string ToString(string format, IFormatProvider formatProvider)
format
stringThe format.
formatProvider
System.IFormatProviderThe format provider.
A string that represents this instance.
Returns a string that represents this instance.
public string ToString(string format)
format
stringThe format.
A string that represents this instance.
Adds two vectors.
public static Vector4 operator +(Vector4 left, Vector4 right)
The sum of the two vectors.
Divides the first vector by the second.
public static Vector4 operator /(Vector4 left, Vector4 right)
The vector resulting from the division.
Divides the specified vector by a specified scalar value.
public static Vector4 operator /(Vector4 value, float divisor)
value
Vector4The vector.
divisor
floatThe scalar value.
The vector that results from the division.
Tests for equality between two objects.
public static bool operator ==(Vector4 left, Vector4 right)
public static explicit operator Vector2(Vector4 value)
value
Vector4The value.
The result of the conversion.
public static explicit operator Vector3(Vector4 value)
value
Vector4The value.
The result of the conversion.
Tests for inequality between two objects.
public static bool operator !=(Vector4 left, Vector4 right)
Modulates a vector with another by performing component-wise multiplication.
public static Vector4 operator *(Vector4 left, Vector4 right)
The multiplication of the two vectors.
Scales a vector by the given value.
public static Vector4 operator *(Vector4 value, float scale)
value
Vector4The vector to scale.
scale
floatThe amount by which to scale the vector.
The scaled vector.
Scales a vector by the given value.
public static Vector4 operator *(float scale, Vector4 value)
scale
floatThe amount by which to scale the vector.
value
Vector4The vector to scale.
The scaled vector.
Subtracts two vectors.
public static Vector4 operator -(Vector4 left, Vector4 right)
The difference of the two vectors.
Reverses the direction of a given vector.
public static Vector4 operator -(Vector4 value)
value
Vector4The vector to negate.
A vector facing in the opposite direction.