vec3_t

vec3_t represents a three-dimensional vector commonly used in 3D space calculations, such as positions, directions, and velocities.

Declaration:

class vec3_t
{
    float x;
    float y;
    float z;
    
    // calculates the Euclidean distance between this vector and another.
    float distance(const vec3_t&in to);
    
    // calculates the dot product between this vector and another.
    float dot(const vec3_t&in to);
    
    // calculates the magnitude (length) of the vector.
    float length();
    
    // calculates the magnitude of the vector in 2D space (ignoring the z-component).
    float length_2d();
    
    // alias for length().
    float magnitude();
    
    // calculates the cross product between this vector and another.
    vec3_t cross(const vec3_t&in to);
    
    // all operators registered (with their respective operation)
    bool opEquals(const vec3_t& in) const; // ==
    bool opNotEquals(const vec3_t &in) const; // !=
    vec3_t opAdd(const vec3_t&in) const; // +
    vec3_t opSub(const vec3_t&in) const; // -
    vec3_t opMul(float) const; // *
    vec3_t& opDiv(float); // /
    vec3_t& opAddAssign(const vec3_t&in); // +=
    vec3_t& opSubAssign(const vec3_t&in); // -=
    vec3_t& opMulAssign(float); // *=
    vec3_t& opDivAssign(float); // /=
}

Constructors:

vec3_t(float x, float y, float z) // standard constructor
vec3_t{float x, float y, float z} // initializer list style

Examples:

Sample code to get the distance to an enemy target

auto player_position = vec3_t( 200.f, 200.f, 10.f );  // Player's position
auto enemy_position = vec3_t( 250.f, 210.f, 10.f );   // Enemy's position

// distance_to_enemy will be ~50.99 meters
auto distance_to_enemy = player_position.distance(enemy_position); 

Sample code to calculate player's movement speed

auto previous_position = vec3_t( 100.f, 100.f, 0.f ); // Player's position at previous frame
auto current_position = vec3_t( 110.f, 120.f, 0.f );  // Player's position at current frame

auto movement_vector = current_position - previous_position;
auto speed = movement_vector.length(); // speed will be ~22.36 meters per frame

Sample code to convert a 3D world position to a 2D screen position for ESP

auto enemy_world_position = vec3_t( 250.f, 210.f, 15.f ); // Enemy's world position

// enemy_screen_position can be used to draw ESP boxes on the screen
auto enemy_screen_position = render::to_screen(enemy_world_position);

Last updated