vec2_t represents a two-dimensional vector commonly used in 2D space calculations, such as screen positions and UI element placements.
Declaration:
classvec2_t{float x;float y; // calculates the euclidean distance between this vector and another.floatdistance(constvec2_t& to); // calculates the magnitude (length) of the vector.floatlength(); // all operators registered (with respective operation)vec2_topAdd(constvec2_t&in) const; // +vec2_topSub(constvec2_t&in) const; // -vec2_topMul(constvec2_t&in) const; // *vec2_topDiv(constvec2_t&in) const; // "/"vec2_topMul(float) const; // *vec2_topDiv(float) const; // "/"vec2_t&opAddAssign(constvec2_t&in); // +=vec2_t&opSubAssign(constvec2_t&in); // -=vec2_t&opMulAssign(constvec2_t&in); // *=vec2_t&opDivAssign(constvec2_t&in); // "/="vec2_t&opMulAssign(float); // *=vec2_t&opDivAssign(float); // "/="}
Constructors:
vec2_t(float x,float y) // standard constructorvec2_t{float x,float y} // initializer list style
Examples:
Sample code to move the cursor to a specific screen position
// target position on screenauto 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 / 2fauto crosshair_position = render::get_display_size() *0.5f;// enemy's position on screenauto 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 boxauto 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 screenauto 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);