Struct Vector3
Implements
Inherited Members
Namespace: GTA.Math
Assembly: ScriptHookVDotNet3.dll
Syntax
[Serializable]
public struct Vector3 : IEquatable<Vector3>
Constructors
| Improve this Doc View SourceVector3(Single, Single, Single)
Initializes a new instance of the Vector3 class.
Declaration
public Vector3(float x, float y, float z)
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. |
Single | z | Initial value for the Z 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. |
Z
Gets or sets the Z component of the vector.
Declaration
public float Z
Field Value
Type | Description |
---|---|
Single | The Z component of the vector. |
Properties
| Improve this Doc View SourceItem[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, 1 for the Y component and 2 for the Z component. |
Property Value
Type | Description |
---|---|
Single | The value of the X, Y or Z component, depending on the index. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | Thrown when the |
Normalized
Returns this vector with a magnitude of 1.
Declaration
public readonly Vector3 Normalized { get; }
Property Value
Type | Description |
---|---|
Vector3 |
RelativeBack
Returns the relative Back vector. (0,-1,0)
Declaration
public static readonly Vector3 RelativeBack { get; }
Property Value
Type | Description |
---|---|
Vector3 |
RelativeBottom
Returns the relative Bottom vector as used. (0,0,-1)
Declaration
public static readonly Vector3 RelativeBottom { get; }
Property Value
Type | Description |
---|---|
Vector3 |
RelativeFront
Returns the relative Front vector. (0,1,0)
Declaration
public static readonly Vector3 RelativeFront { get; }
Property Value
Type | Description |
---|---|
Vector3 |
RelativeLeft
Returns the relative Left vector. (-1,0,0)
Declaration
public static readonly Vector3 RelativeLeft { get; }
Property Value
Type | Description |
---|---|
Vector3 |
RelativeRight
Returns the relative Right vector. (1,0,0)
Declaration
public static readonly Vector3 RelativeRight { get; }
Property Value
Type | Description |
---|---|
Vector3 |
RelativeTop
Returns the relative Top vector. (0,0,1)
Declaration
public static readonly Vector3 RelativeTop { get; }
Property Value
Type | Description |
---|---|
Vector3 |
UnitX
The X unit Vector3 (1, 0, 0).
Declaration
public static readonly Vector3 UnitX { get; }
Property Value
Type | Description |
---|---|
Vector3 |
UnitY
The Y unit Vector3 (0, 1, 0).
Declaration
public static readonly Vector3 UnitY { get; }
Property Value
Type | Description |
---|---|
Vector3 |
UnitZ
The Z unit Vector3 (0, 0, 1).
Declaration
public static readonly Vector3 UnitZ { get; }
Property Value
Type | Description |
---|---|
Vector3 |
WorldDown
Returns the world Down vector. (0,0,-1)
Declaration
public static readonly Vector3 WorldDown { get; }
Property Value
Type | Description |
---|---|
Vector3 |
WorldEast
Returns the world East vector. (1,0,0)
Declaration
public static readonly Vector3 WorldEast { get; }
Property Value
Type | Description |
---|---|
Vector3 |
WorldNorth
Returns the world North vector. (0,1,0)
Declaration
public static readonly Vector3 WorldNorth { get; }
Property Value
Type | Description |
---|---|
Vector3 |
WorldSouth
Returns the world South vector. (0,-1,0)
Declaration
public static readonly Vector3 WorldSouth { get; }
Property Value
Type | Description |
---|---|
Vector3 |
WorldUp
Returns the world Up vector. (0,0,1)
Declaration
public static readonly Vector3 WorldUp { get; }
Property Value
Type | Description |
---|---|
Vector3 |
WorldWest
Returns the world West vector. (-1,0,0)
Declaration
public static readonly Vector3 WorldWest { get; }
Property Value
Type | Description |
---|---|
Vector3 |
Zero
Returns a null vector. (0,0,0)
Declaration
public static readonly Vector3 Zero { get; }
Property Value
Type | Description |
---|---|
Vector3 |
Methods
| Improve this Doc View SourceAdd(Vector3, Vector3)
Adds two vectors.
Declaration
public static Vector3 Add(Vector3 left, Vector3 right)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | left | The first vector to add. |
Vector3 | right | The second vector to add. |
Returns
Type | Description |
---|---|
Vector3 | The sum of the two vectors. |
Angle(Vector3, Vector3)
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(Vector3 from, Vector3 to)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | from | |
Vector3 | to |
Returns
Type | Description |
---|---|
Single |
Around(Single)
Creates a random vector inside the circle around this position.
Declaration
public Vector3 Around(float distance)
Parameters
Type | Name | Description |
---|---|---|
Single | distance |
Returns
Type | Description |
---|---|
Vector3 |
Clamp(Vector3, Vector3, Vector3)
Restricts a value to be within a specified range.
Declaration
public static Vector3 Clamp(Vector3 value, Vector3 min, Vector3 max)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | value | The value to clamp. |
Vector3 | min | The minimum value. |
Vector3 | max | The maximum value. |
Returns
Type | Description |
---|---|
Vector3 | The clamped value. |
Cross(Vector3, Vector3)
Calculates the cross product of two vectors.
Declaration
public static Vector3 Cross(Vector3 left, Vector3 right)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | left | First source vector. |
Vector3 | right | Second source vector. |
Returns
Type | Description |
---|---|
Vector3 | The cross product of the two vectors. |
Distance(Vector3, Vector3)
Calculates the distance between two vectors.
Declaration
public static float Distance(Vector3 position1, Vector3 position2)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | position1 | The first vector to calculate the distance to the second vector. |
Vector3 | position2 | The second vector to calculate the distance to the first vector. |
Returns
Type | Description |
---|---|
Single | The distance between the two vectors. |
Distance2D(Vector3, Vector3)
Calculates the distance between two vectors, ignoring the Z-component.
Declaration
public static float Distance2D(Vector3 position1, Vector3 position2)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | position1 | The first vector to calculate the distance to the second vector. |
Vector3 | position2 | The second vector to calculate the distance to the first vector. |
Returns
Type | Description |
---|---|
Single | The distance between the two vectors. |
DistanceSquared(Vector3, Vector3)
Calculates the squared distance between two vectors.
Declaration
public static float DistanceSquared(Vector3 position1, Vector3 position2)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | position1 | The first vector to calculate the squared distance to the second vector. |
Vector3 | position2 | The second vector to calculate the squared distance to the first vector. |
Returns
Type | Description |
---|---|
Single | The squared distance between the two vectors. |
DistanceSquared2D(Vector3, Vector3)
Calculates the squared distance between two vectors, ignoring the Z-component.
Declaration
public static float DistanceSquared2D(Vector3 position1, Vector3 position2)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | position1 | The first vector to calculate the squared distance to the second vector. |
Vector3 | 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(Vector3)
Calculates the distance between two vectors.
Declaration
public float DistanceTo(Vector3 position)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | position | The second vector to calculate the distance to. |
Returns
Type | Description |
---|---|
Single | The distance to the other vector. |
DistanceTo2D(Vector3)
Calculates the distance between two vectors, ignoring the Z-component.
Declaration
public float DistanceTo2D(Vector3 position)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | position | The second vector to calculate the distance to. |
Returns
Type | Description |
---|---|
Single | The distance to the other vector. |
DistanceToSquared(Vector3)
Calculates the squared distance between two vectors.
Declaration
public float DistanceToSquared(Vector3 position)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | position | The second vector to calculate the distance to. |
Returns
Type | Description |
---|---|
Single | The distance to the other vector. |
DistanceToSquared2D(Vector3)
Calculates the squared distance between two vectors, ignoring the Z-component.
Declaration
public float DistanceToSquared2D(Vector3 position)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | position | The second vector to calculate the squared distance to. |
Returns
Type | Description |
---|---|
Single | The distance to the other vector. |
Divide(Vector3, Single)
Scales a vector by the given value.
Declaration
public static Vector3 Divide(Vector3 value, float scale)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | value | The vector to scale. |
Single | scale | The amount by which to scale the vector. |
Returns
Type | Description |
---|---|
Vector3 | The scaled vector. |
Dot(Vector3, Vector3)
Calculates the dot product of two vectors.
Declaration
public static float Dot(Vector3 left, Vector3 right)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | left | First source vector. |
Vector3 | right | Second source vector. |
Returns
Type | Description |
---|---|
Single | The dot product of the two vectors. |
Equals(Vector3)
Returns a value that indicates whether the current instance is equal to the specified object.
Declaration
public bool Equals(Vector3 other)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | 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; false otherwise. |
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(Vector3, Vector3, Single)
Performs a linear interpolation between two vectors.
Declaration
public static Vector3 Lerp(Vector3 start, Vector3 end, float amount)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | start | Start vector. |
Vector3 | end | End vector. |
Single | amount | Value between 0 and 1 indicating the weight of |
Returns
Type | Description |
---|---|
Vector3 | 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(Vector3, Vector3)
Returns a vector containing the largest components of the specified vectors.
Declaration
public static Vector3 Maximize(Vector3 left, Vector3 right)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | left | The first source vector. |
Vector3 | right | The second source vector. |
Returns
Type | Description |
---|---|
Vector3 | A vector containing the largest components of the source vectors. |
Minimize(Vector3, Vector3)
Returns a vector containing the smallest components of the specified vectors.
Declaration
public static Vector3 Minimize(Vector3 left, Vector3 right)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | left | The first source vector. |
Vector3 | right | The second source vector. |
Returns
Type | Description |
---|---|
Vector3 | A vector containing the smallest components of the source vectors. |
Multiply(Vector3, Vector3)
Multiply a vector with another by performing component-wise multiplication.
Declaration
public static Vector3 Multiply(Vector3 left, Vector3 right)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | left | The first vector to multiply. |
Vector3 | right | The second vector to multiply. |
Returns
Type | Description |
---|---|
Vector3 | The multiplied vector. |
Multiply(Vector3, Single)
Scales a vector by the given value.
Declaration
public static Vector3 Multiply(Vector3 value, float scale)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | value | The vector to scale. |
Single | scale | The amount by which to scale the vector. |
Returns
Type | Description |
---|---|
Vector3 | The scaled vector. |
Negate(Vector3)
Reverses the direction of a given vector.
Declaration
public static Vector3 Negate(Vector3 value)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | value | The vector to negate. |
Returns
Type | Description |
---|---|
Vector3 | A vector facing in the opposite direction. |
Normalize()
Converts the vector into a unit vector.
Declaration
public void Normalize()
Normalize(Vector3)
Converts the vector into a unit vector.
Declaration
public static Vector3 Normalize(Vector3 vector)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vector | The vector to normalize. |
Returns
Type | Description |
---|---|
Vector3 | The normalized vector. |
Project(Vector3, Vector3)
Projects a vector onto another vector.
Declaration
public static Vector3 Project(Vector3 vector, Vector3 onNormal)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vector | The vector to project. |
Vector3 | onNormal | Vector to project onto, does not assume it is normalized. |
Returns
Type | Description |
---|---|
Vector3 | The projected vector. |
ProjectOnPlane(Vector3, Vector3)
Projects a vector onto a plane defined by a normal orthogonal to the plane.
Declaration
public static Vector3 ProjectOnPlane(Vector3 vector, Vector3 planeNormal)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vector | The vector to project. |
Vector3 | planeNormal | Normal of the plane, does not assume it is normalized. |
Returns
Type | Description |
---|---|
Vector3 | The Projection of vector onto plane. |
RandomXY()
Returns a new normalized vector with random X and Y components.
Declaration
public static Vector3 RandomXY()
Returns
Type | Description |
---|---|
Vector3 |
RandomXYZ()
Returns a new normalized vector with random X, Y and Z components.
Declaration
public static Vector3 RandomXYZ()
Returns
Type | Description |
---|---|
Vector3 |
Reflect(Vector3, Vector3)
Returns the reflection of a vector off a surface that has the specified normal.
Declaration
public static Vector3 Reflect(Vector3 vector, Vector3 normal)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vector | The vector to project onto the plane. |
Vector3 | normal | Normal of the surface. |
Returns
Type | Description |
---|---|
Vector3 | 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.
Round(Int32)
Rounds each float inside the vector to a select amount of decimal places (2 by default).
Declaration
public Vector3 Round(int decimalPlaces = 2)
Parameters
Type | Name | Description |
---|---|---|
Int32 | decimalPlaces | Number of decimal places to round to |
Returns
Type | Description |
---|---|
Vector3 | The vector containing rounded values |
SignedAngle(Vector3, Vector3, Vector3)
Returns the signed angle in degrees between from and to.
Declaration
public static float SignedAngle(Vector3 from, Vector3 to, Vector3 planeNormal)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | from | |
Vector3 | to | |
Vector3 | planeNormal |
Returns
Type | Description |
---|---|
Single |
Subtract(Vector3, Vector3)
Subtracts two vectors.
Declaration
public static Vector3 Subtract(Vector3 left, Vector3 right)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | left | The first vector to subtract. |
Vector3 | right | The second vector to subtract. |
Returns
Type | Description |
---|---|
Vector3 | The difference of the two vectors. |
ToArray()
Converts the matrix to an array of floats.
Declaration
public float[] ToArray()
Returns
Type | Description |
---|---|
Single[] |
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 number format. |
Returns
Type | Description |
---|---|
String | The string representation of the value of this instance. |
Operators
| Improve this Doc View SourceAddition(Vector3, Vector3)
Adds two vectors.
Declaration
public static Vector3 operator +(Vector3 left, Vector3 right)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | left | The first vector to add. |
Vector3 | right | The second vector to add. |
Returns
Type | Description |
---|---|
Vector3 | The sum of the two vectors. |
Division(Vector3, Single)
Scales a vector by the given value.
Declaration
public static Vector3 operator /(Vector3 vector, float scale)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vector | The vector to scale. |
Single | scale | The amount by which to scale the vector. |
Returns
Type | Description |
---|---|
Vector3 | The scaled vector. |
Equality(Vector3, Vector3)
Tests for equality between two objects.
Declaration
public static bool operator ==(Vector3 left, Vector3 right)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | left | The first value to compare. |
Vector3 | right | The second value to compare. |
Returns
Type | Description |
---|---|
Boolean | true if |
Implicit(Vector3 to Vector2)
Converts a Vector3 to a Vector2 implicitly.
Declaration
public static implicit operator Vector2(Vector3 vector)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vector |
Returns
Type | Description |
---|---|
Vector2 |
Inequality(Vector3, Vector3)
Tests for inequality between two objects.
Declaration
public static bool operator !=(Vector3 left, Vector3 right)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | left | The first value to compare. |
Vector3 | right | The second value to compare. |
Returns
Type | Description |
---|---|
Boolean | true if |
Multiply(Vector3, Single)
Scales a vector by the given value.
Declaration
public static Vector3 operator *(Vector3 vector, float scale)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vector | The vector to scale. |
Single | scale | The amount by which to scale the vector. |
Returns
Type | Description |
---|---|
Vector3 | The scaled vector. |
Multiply(Single, Vector3)
Scales a vector by the given value.
Declaration
public static Vector3 operator *(float scale, Vector3 vector)
Parameters
Type | Name | Description |
---|---|---|
Single | scale | The amount by which to scale the vector. |
Vector3 | vector | The vector to scale. |
Returns
Type | Description |
---|---|
Vector3 | The scaled vector. |
Subtraction(Vector3, Vector3)
Subtracts two vectors.
Declaration
public static Vector3 operator -(Vector3 left, Vector3 right)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | left | The first vector to subtract. |
Vector3 | right | The second vector to subtract. |
Returns
Type | Description |
---|---|
Vector3 | The difference of the two vectors. |
UnaryNegation(Vector3)
Reverses the direction of a given vector.
Declaration
public static Vector3 operator -(Vector3 vector)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vector | The vector to negate. |
Returns
Type | Description |
---|---|
Vector3 | A vector facing in the opposite direction. |