Struct Vector2
Implements
Inherited Members
Namespace: GTA.Math
Assembly: ScriptHookVDotNet3.dll
Syntax
[Serializable]
public struct Vector2 : IEquatable<Vector2>
Constructors
| Improve this Doc View SourceVector2(Single, Single)
Initializes a new instance of the Vector2 class.
Declaration
public Vector2(float x, float y)
Parameters
Type | Name | Description |
---|---|---|
Single | x | Initial value for the X component of the vector. |
Single | y | Initial value for the Y component of the vector. |
Fields
| Improve this Doc View SourceX
Gets or sets the X component of the vector.
Declaration
public float X
Field Value
Type | Description |
---|---|
Single | The X component of the vector. |
Y
Gets or sets the Y component of the vector.
Declaration
public float Y
Field Value
Type | Description |
---|---|
Single | The Y component of the vector. |
Properties
| Improve this Doc View SourceDown
Returns the down vector. (0,-1)
Declaration
public static readonly Vector2 Down { get; }
Property Value
Type | Description |
---|---|
Vector2 |
Item[Int32]
Gets or sets the component at the specified index.
Declaration
public float this[int index] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | The index of the component to access. Use 0 for the X component and 1 for the Y component. |
Property Value
Type | Description |
---|---|
Single | The value of the X or Y component, depending on the index. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | Thrown when the |
Left
Returns the left vector. (-1,0)
Declaration
public static readonly Vector2 Left { get; }
Property Value
Type | Description |
---|---|
Vector2 |
Normalized
Returns this vector with a magnitude of 1.
Declaration
public readonly Vector2 Normalized { get; }
Property Value
Type | Description |
---|---|
Vector2 |
Right
Returns the right vector. (1,0)
Declaration
public static readonly Vector2 Right { get; }
Property Value
Type | Description |
---|---|
Vector2 |
UnitX
The X unit Vector2 (1, 0).
Declaration
public static readonly Vector2 UnitX { get; }
Property Value
Type | Description |
---|---|
Vector2 |
UnitY
The Y unit Vector2 (0, 1).
Declaration
public static readonly Vector2 UnitY { get; }
Property Value
Type | Description |
---|---|
Vector2 |
Up
Returns the up vector. (0,1)
Declaration
public static readonly Vector2 Up { get; }
Property Value
Type | Description |
---|---|
Vector2 |
Zero
Returns a null vector. (0,0)
Declaration
public static readonly Vector2 Zero { get; }
Property Value
Type | Description |
---|---|
Vector2 |
Methods
| Improve this Doc View SourceAdd(Vector2, Vector2)
Adds two vectors.
Declaration
public static Vector2 Add(Vector2 left, Vector2 right)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | left | The first vector to add. |
Vector2 | right | The second vector to add. |
Returns
Type | Description |
---|---|
Vector2 | The sum of the two vectors. |
Angle(Vector2, Vector2)
Returns the angle in degrees between from and to. The angle returned is always the acute angle between the two vectors.
Declaration
public static float Angle(Vector2 from, Vector2 to)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | from | |
Vector2 | to |
Returns
Type | Description |
---|---|
Single |
Clamp(Vector2, Vector2, Vector2)
Restricts a value to be within a specified range.
Declaration
public static Vector2 Clamp(Vector2 value, Vector2 min, Vector2 max)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | value | The value to clamp. |
Vector2 | min | The minimum value. |
Vector2 | max | The maximum value. |
Returns
Type | Description |
---|---|
Vector2 | The clamped value. |
Distance(Vector2, Vector2)
Calculates the distance between two vectors.
Declaration
public static float Distance(Vector2 position1, Vector2 position2)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | position1 | The first vector to calculate the distance to the second vector. |
Vector2 | position2 | The second vector to calculate the distance to the first vector. |
Returns
Type | Description |
---|---|
Single | The distance between the two vectors. |
DistanceSquared(Vector2, Vector2)
Calculates the squared distance between two vectors.
Declaration
public static float DistanceSquared(Vector2 position1, Vector2 position2)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | position1 | The first vector to calculate the squared distance to the second vector. |
Vector2 | position2 | The second vector to calculate the squared distance to the first vector. |
Returns
Type | Description |
---|---|
Single | The squared distance between the two vectors. |
DistanceTo(Vector2)
Calculates the distance between two vectors.
Declaration
public float DistanceTo(Vector2 position)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | position | The second vector to calculate the distance to. |
Returns
Type | Description |
---|---|
Single | The distance to the other vector. |
DistanceToSquared(Vector2)
Calculates the squared distance between two vectors.
Declaration
public float DistanceToSquared(Vector2 position)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | position | The second vector to calculate the squared distance to. |
Returns
Type | Description |
---|---|
Single | The squared distance to the other vector. |
Divide(Vector2, Single)
Scales a vector by the given value.
Declaration
public static Vector2 Divide(Vector2 value, float scale)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | value | The vector to scale. |
Single | scale | The amount by which to scale the vector. |
Returns
Type | Description |
---|---|
Vector2 | The scaled vector. |
Dot(Vector2, Vector2)
Calculates the dot product of two vectors.
Declaration
public static float Dot(Vector2 left, Vector2 right)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | left | First source vector. |
Vector2 | right | Second source vector. |
Returns
Type | Description |
---|---|
Single | The dot product of the two vectors. |
Equals(Vector2)
Returns a value that indicates whether the current instance is equal to the specified object.
Declaration
public bool Equals(Vector2 other)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | other | Object to make the comparison with. |
Returns
Type | Description |
---|---|
Boolean | true if the current instance is equal to the specified object; false otherwise. |
Equals(Object)
Returns a value that indicates whether the current instance is equal to a specified object.
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
Object | obj | Object to make the comparison with. |
Returns
Type | Description |
---|---|
Boolean | true if the current instance is equal to the specified object; otherwise, false. |
Overrides
| Improve this Doc View SourceGetHashCode()
Returns the hash code for this instance.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
Int32 | A 32-bit signed integer hash code. |
Overrides
| Improve this Doc View SourceLength()
Calculates the length of the vector.
Declaration
public float Length()
Returns
Type | Description |
---|---|
Single | The length of the vector. |
LengthSquared()
Calculates the squared length of the vector.
Declaration
public float LengthSquared()
Returns
Type | Description |
---|---|
Single | The squared length of the vector. |
Lerp(Vector2, Vector2, Single)
Performs a linear interpolation between two vectors.
Declaration
public static Vector2 Lerp(Vector2 start, Vector2 end, float amount)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | start | Start vector. |
Vector2 | end | End vector. |
Single | amount | Value between 0 and 1 indicating the weight of |
Returns
Type | Description |
---|---|
Vector2 | The linear interpolation of the two vectors. |
Remarks
This method performs the linear interpolation based on the following formula.
start + (end - start) * amount
Passing amount
a value of 0 will cause start
to be returned; a value of 1 will cause end
to be returned.
Maximize(Vector2, Vector2)
Returns a vector containing the largest components of the specified vectors.
Declaration
public static Vector2 Maximize(Vector2 left, Vector2 right)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | left | The first source vector. |
Vector2 | right | The second source vector. |
Returns
Type | Description |
---|---|
Vector2 | A vector containing the largest components of the source vectors. |
Minimize(Vector2, Vector2)
Returns a vector containing the smallest components of the specified vectors.
Declaration
public static Vector2 Minimize(Vector2 left, Vector2 right)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | left | The first source vector. |
Vector2 | right | The second source vector. |
Returns
Type | Description |
---|---|
Vector2 | A vector containing the smallest components of the source vectors. |
Multiply(Vector2, Vector2)
Multiplies a vector with another by performing component-wise multiplication.
Declaration
public static Vector2 Multiply(Vector2 left, Vector2 right)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | left | The first vector to multiply. |
Vector2 | right | The second vector to multiply. |
Returns
Type | Description |
---|---|
Vector2 | The multiplied vector. |
Multiply(Vector2, Single)
Scales a vector by the given value.
Declaration
public static Vector2 Multiply(Vector2 value, float scale)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | value | The vector to scale. |
Single | scale | The amount by which to scale the vector. |
Returns
Type | Description |
---|---|
Vector2 | The scaled vector. |
Negate(Vector2)
Reverses the direction of a given vector.
Declaration
public static Vector2 Negate(Vector2 value)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | value | The vector to negate. |
Returns
Type | Description |
---|---|
Vector2 | A vector facing in the opposite direction. |
Normalize()
Converts the vector into a unit vector.
Declaration
public void Normalize()
Normalize(Vector2)
Converts the vector into a unit vector.
Declaration
public static Vector2 Normalize(Vector2 vector)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | vector | The vector to normalize. |
Returns
Type | Description |
---|---|
Vector2 | The normalized vector. |
RandomXY()
Returns a new normalized vector with random X and Y components.
Declaration
public static Vector2 RandomXY()
Returns
Type | Description |
---|---|
Vector2 |
Reflect(Vector2, Vector2)
Returns the reflection of a vector off a surface that has the specified normal.
Declaration
public static Vector2 Reflect(Vector2 vector, Vector2 normal)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | vector | The source vector. |
Vector2 | normal | Normal of the surface. |
Returns
Type | Description |
---|---|
Vector2 | The reflected vector. |
Remarks
Reflect only gives the direction of a reflection off a surface, it does not determine whether the original vector was close enough to the surface to hit it.
SignedAngle(Vector2, Vector2)
Returns the signed angle in degrees between from and to.
Declaration
public static float SignedAngle(Vector2 from, Vector2 to)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | from | |
Vector2 | to |
Returns
Type | Description |
---|---|
Single |
Subtract(Vector2, Vector2)
Subtracts two vectors.
Declaration
public static Vector2 Subtract(Vector2 left, Vector2 right)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | left | The first vector to subtract. |
Vector2 | right | The second vector to subtract. |
Returns
Type | Description |
---|---|
Vector2 | The difference of the two vectors. |
ToHeading()
Converts a vector to a heading.
Declaration
public float ToHeading()
Returns
Type | Description |
---|---|
Single |
ToString()
Converts the value of the object to its equivalent string representation.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String | The string representation of the value of this instance. |
Overrides
| Improve this Doc View SourceToString(String)
Converts the value of the object to its equivalent string representation.
Declaration
public string ToString(string format)
Parameters
Type | Name | Description |
---|---|---|
String | format | The format. |
Returns
Type | Description |
---|---|
String | The string representation of the value of this instance. |
Operators
| Improve this Doc View SourceAddition(Vector2, Vector2)
Adds two vectors.
Declaration
public static Vector2 operator +(Vector2 left, Vector2 right)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | left | The first vector to add. |
Vector2 | right | The second vector to add. |
Returns
Type | Description |
---|---|
Vector2 | The sum of the two vectors. |
Division(Vector2, Single)
Scales a vector by the given value.
Declaration
public static Vector2 operator /(Vector2 vector, float scale)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | vector | The vector to scale. |
Single | scale | The amount by which to scale the vector. |
Returns
Type | Description |
---|---|
Vector2 | The scaled vector. |
Equality(Vector2, Vector2)
Tests for equality between two objects.
Declaration
public static bool operator ==(Vector2 left, Vector2 right)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | left | The first value to compare. |
Vector2 | right | The second value to compare. |
Returns
Type | Description |
---|---|
Boolean | true if |
Implicit(Vector2 to Vector3)
Converts a Vector2 to a Vector3 implicitly.
Declaration
public static implicit operator Vector3(Vector2 vector)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | vector |
Returns
Type | Description |
---|---|
Vector3 |
Inequality(Vector2, Vector2)
Tests for inequality between two objects.
Declaration
public static bool operator !=(Vector2 left, Vector2 right)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | left | The first value to compare. |
Vector2 | right | The second value to compare. |
Returns
Type | Description |
---|---|
Boolean | true if |
Multiply(Vector2, Single)
Scales a vector by the given value.
Declaration
public static Vector2 operator *(Vector2 vector, float scale)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | vector | The vector to scale. |
Single | scale | The amount by which to scale the vector. |
Returns
Type | Description |
---|---|
Vector2 | The scaled vector. |
Multiply(Single, Vector2)
Scales a vector by the given value.
Declaration
public static Vector2 operator *(float scale, Vector2 vector)
Parameters
Type | Name | Description |
---|---|---|
Single | scale | The amount by which to scale the vector. |
Vector2 | vector | The vector to scale. |
Returns
Type | Description |
---|---|
Vector2 | The scaled vector. |
Subtraction(Vector2, Vector2)
Subtracts two vectors.
Declaration
public static Vector2 operator -(Vector2 left, Vector2 right)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | left | The first vector to subtract. |
Vector2 | right | The second vector to subtract. |
Returns
Type | Description |
---|---|
Vector2 | The difference of the two vectors. |
UnaryNegation(Vector2)
Reverses the direction of a given vector.
Declaration
public static Vector2 operator -(Vector2 value)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | value | The vector to negate. |
Returns
Type | Description |
---|---|
Vector2 | A vector facing in the opposite direction. |