Class Vector
- Namespace
- CounterStrikeSharp.API.Modules.Utils
- Assembly
- CounterStrikeSharp.API.dll
A Vector
object represents a line with a direction and length.
Each vector contains three co-ordinates:
- X+forward/-backward
- Y+left/-right
- Z+up/-down
public class Vector : NativeObject, IAdditionOperators<Vector, Vector, Vector>, ISubtractionOperators<Vector, Vector, Vector>, IMultiplyOperators<Vector, float, Vector>, IDivisionOperators<Vector, float, Vector>
- Inheritance
-
objectVector
- Implements
- Inherited Members
Constructors
Vector(nint)
public Vector(nint pointer)
Parameters
pointer
nint
Vector(float?, float?, float?)
public Vector(float? x = null, float? y = null, float? z = null)
Parameters
Fields
Zero
public static readonly Vector Zero
Field Value
Properties
this[int]
public float this[int i] { get; set; }
Parameters
i
int
Property Value
X
public ref float X { get; }
Property Value
Y
public ref float Y { get; }
Property Value
Z
public ref float Z { get; }
Property Value
Methods
Add(Vector)
Adds values of argument vector to the original vector. Does not create a new vector object, skipping object construction.
public void Add(Vector vector)
Parameters
vector
Vector
Angle()
Returns an angle that represents the normal of the vector.
public Angle Angle()
Returns
Angle(Vector)
Returns the angle of the vector, but allows the use of a different 'up' direction.
public Angle Angle(Vector up)
Parameters
up
VectorDirection for up
Returns
IsZero()
Returns whether all fields on the Vector are 0.
public bool IsZero()
Returns
Length()
Returns the Euclidean length of the vector: √x² + y² + z²
public float Length()
Returns
- float
Euclidean length of vector
Length2D()
Returns length of Vector excluding Z axis.
public float Length2D()
Returns
- float
2D Length
Length2DSqr()
Returns the squared length of the vectors x and y value, x² + y². Faster than Length2D()
public float Length2DSqr()
Returns
LengthSqr()
Returns the squared length of the vector, x² + y² + z². Faster than Length()
public float LengthSqr()
Returns
ToString()
Returns a string that represents the current object.
public override string ToString()
Returns
- string
A string that represents the current object.
With(float?, float?, float?)
Returns a copy of the vector with values replaced.
public Vector With(float? x = null, float? y = null, float? z = null)
Parameters
Returns
- Vector
Copy of vector
Operators
operator +(Vector, Vector)
Adds two values together to compute their sum.
public static Vector operator +(Vector a, Vector b)
Parameters
Returns
- Vector
The sum of
left
andright
.
operator /(Vector, float)
Divides one value by another to compute their quotient.
public static Vector operator /(Vector a, float b)
Parameters
Returns
- Vector
The quotient of
left
divided byright
.
operator *(Vector, float)
Multiplies two values together to compute their product.
public static Vector operator *(Vector a, float b)
Parameters
Returns
- Vector
The product of
left
multiplied byright
.
operator -(Vector, Vector)
Subtracts two values to compute their difference.
public static Vector operator -(Vector a, Vector b)
Parameters
Returns
- Vector
The value of
right
subtracted fromleft
.
operator -(Vector)
public static Vector operator -(Vector a)
Parameters
a
Vector