vec2_t

vec2_t represents a two-dimensional vector commonly used in 2D space calculations, such as screen positions and UI element placements.

Declaration:

class vec2_t
{
    float x;
    float y;
    
    // calculates the euclidean distance between this vector and another.
    float distance(const vec2_t& to);
    
    // calculates the magnitude (length) of the vector.
    float length();
    
    // all operators registered (with respective operation)
    vec2_t opAdd(const vec2_t&in) const; // +
    vec2_t opSub(const vec2_t&in) const; // -
    vec2_t opMul(const vec2_t&in) const; // *
    vec2_t opDiv(const vec2_t&in) const; // "/"
    vec2_t opMul(float) const; // *
    vec2_t opDiv(float) const; // "/"
    vec2_t& opAddAssign(const vec2_t&in); // +=
    vec2_t& opSubAssign(const vec2_t&in); // -=
    vec2_t& opMulAssign(const vec2_t&in); // *=
    vec2_t& opDivAssign(const vec2_t&in); // "/="
    vec2_t& opMulAssign(float); // *=
    vec2_t& opDivAssign(float); // "/="
}

Constructors:

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

Examples:

Sample code to move the cursor to a specific screen position

// target position on screen
auto target_position = vec2_t( 640.f, 360.f );

// cursor will be moved to the target position (640, 360)
render::move_mouse(target_position);

Calculating the Distance Between Two Points on the Screen

// crosshair pos (center of the screen)
// * 0.5f is the same as / 2f
auto crosshair_position = render::get_display_size() * 0.5f;

// enemy's position on screen
auto enemy_position_screen = vec2_t(550.f, 320.f);

// distance between crosshair and enemy's position (~53.85 pixels)
// use this for circle FOV based applications!
auto distance_to_enemy_screen = crosshair_position.distance(enemy_position_screen);

Checking if a Point is Inside a Bounding Box

// top-left corner of the esp box
auto box_top_left = vec2_t(300.f, 200.f);

// size of the esp box (width, height)
auto box_size = vec2_t(150.f, 200.f);

// enemy's position on screen
auto enemy_position_screen = vec2_t(350.f, 250.f);

// check if the enemy is inside the esp box (true if inside)
// use this for rectangle based FOV applications!
bool is_enemy_in_box = render::area_contains(box_top_left, box_size, enemy_position_screen);

Last updated