Vector
Revision as of 05:30, 20 February 2025 by Outerbeast (talk | contribs)
Vectors are essentially float arrays of size 3 which are used to represent various quanties like spatial co-ordinates, angles, velocities and colours, and so will come up very often.
A Vector can be instanced like so:
Vector vec(1, 2, 3);
Each vector component can be accessed via the fields x, y and z, which are of type float
vec.x // 1.0 vec.y // 2.0 vec.z // 3.0
These components are also accessible via the index operator:
vec[0] // vec.x vec[1] // vec.y vec[2] // vec.z
Operations such as dot product and cross product can be performed on vectors using these global functions:
| Function | Description | 
|---|---|
float DotProduct(const Vector2D& in lhs, const Vector2D& in rhs)
 | 
Returns a dot product of the given 2D vectors | 
float DotProduct(const Vector& in lhs, const Vector& in rhs)
 | 
Returns the dot product of the given vectors | 
Vector CrossProduct(const Vector& in, const Vector& in)
 | 
Returns the cross product of the given vectors | 
1 Methods
| Method | Description | 
|---|---|
void Vector()
 | 
Default constructs a 3D vector (0, 0, 0) | 
void Vector(const Vector& in vec)
 | 
Copy constructs a 3D vector | 
void Vector(float x, float y, float z)
 | 
Constructs a 3D vector from 3 floats | 
Vector& opAssign(const Vector& in other)
 | 
Assign vector | 
Vector opNeg() const
 | 
Negate vector | 
Vector opAdd(const Vector& in other) const
 | 
Add vectors | 
Vector opSub(const Vector& in other) const
 | 
Subtract vectors | 
Vector opMul(float fl) const
 | 
Multiply vector by value | 
Vector opMul_r(float fl) const
 | 
Multiply vector by value | 
Vector opDiv(float fl) const
 | 
Divide vector by value | 
Vector opDiv_r(float fl) const
 | 
Divide vector by value | 
float& opIndex(size_t uiIndex)
 | 
Index operator | 
float opIndex(size_t uiIndex) const
 | 
Index operator | 
bool opEquals(const Vector& in other) const
 | 
Compare vectors | 
Vector opMul(const Vector& in other) const
 | 
Multiply vectors | 
Vector opDiv(const Vector& in other) const
 | 
Divide vectors | 
float Length() const
 | 
Gets the length of this vector | 
float Length2D() const
 | 
Gets the length of this vector in 2D | 
Vector Normalize() const
 | 
Returns the normalized form of this vector | 
Vector2D Make2D() const
 | 
Returns the 2D form of this vector | 
string ToString() const
 | 
Returns a string representation of this vector in the format "x, y, z" | 
2 Constants
| Constant | Value | 
|---|---|
| const Vector g_vecZero | Zero vector (0, 0, 0) | 
| const Vector VEC_HULL_MIN | Default hull minimum. Used with CEntityFuncs::SetSize Value: (-16.0, -16.0, -36.0)  | 
| const Vector VEC_HULL_MAX | Default hull maximum. Used with CEntityFuncs::SetSize Value: (16.0, 16.0, 36.0)  | 
| const Vector VEC_HUMAN_HULL_MIN | Default human hull maximum. Used with CEntityFuncs::SetSize Value: (-16.0, -16.0, 0.0)  | 
| const Vector VEC_HUMAN_HULL_MAX | |
| const Vector VEC_HUMAN_HULL_DUCK | Default human hull maximum while ducking. Used with CEntityFuncs::SetSize Value: (16.0, 16.0, 36.0)  | 
| const Vector VEC_VIEW | View offset. Value: (0.0, 0.0, 28.0)  | 
| const Vector VEC_DUCK_HULL_MIN | Hull minimum while ducking. Used with CEntityFuncs::SetSize Value: (-16.0, -16.0, -18.0)  | 
| Hull maximum while ducking. Used with CEntityFuncs::SetSize Value: (16.0, 16.0, 18.0)  | |
| const Vector VEC_DUCK_VIEW | Hull view offset while ducking. Value: (0.0, 0.0, 12.0)  | 
| const Vector VECTOR_CONE_9DEGREES | (0.078460, 0.078460, 0.078460) | 
| const Vector VECTOR_CONE_10DEGREES | (0.087160, 0.087160, 0.087160) | 
| const Vector VECTOR_CONE_15DEGREES | (0.130530, 0.130530, 0.130530) | 
| const Vector VECTOR_CONE_20DEGREES | (0.173650, 0.173650, 0.173650) |