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
pointernint
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
iint
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
vectorVector
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
upVectorDirection 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
leftandright.
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
leftdivided byright.
explicit operator Vector3(Vector)
public static explicit operator Vector3(Vector v)
Parameters
vVector
Returns
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
leftmultiplied 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
rightsubtracted fromleft.
operator -(Vector)
public static Vector operator -(Vector a)
Parameters
aVector