From 2a57c694443aba841184917d31e429876b5ff466 Mon Sep 17 00:00:00 2001 From: 8dcc <8dcc.git@gmail.com> Date: Fri, 28 Jul 2023 21:56:35 +0200 Subject: [PATCH] Replace vector indexing with members Use .x instead of [0] Also add vec_add() to util.c --- src/features/esp.c | 22 +++++++++++----------- src/features/movement.c | 8 ++++---- src/include/util.h | 1 + src/util.c | 18 +++++++++++------- 4 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/features/esp.c b/src/features/esp.c index 1e4e21c..83aca1b 100644 --- a/src/features/esp.c +++ b/src/features/esp.c @@ -36,14 +36,14 @@ bool gl_draw3dbox(vec3_t o, int bh, int bw, int lw) { * |/ O|/ z(-) * 7---8 */ - vec3_t p1 = vec3(o[0] - bw / 2, o[1] + bw / 2, o[2] + bh / 2); - vec3_t p2 = vec3(o[0] + bw / 2, o[1] + bw / 2, o[2] + bh / 2); - vec3_t p3 = vec3(o[0] - bw / 2, o[1] - bw / 2, o[2] + bh / 2); - vec3_t p4 = vec3(o[0] + bw / 2, o[1] - bw / 2, o[2] + bh / 2); - vec3_t p5 = vec3(o[0] - bw / 2, o[1] + bw / 2, o[2] - bh / 2); - vec3_t p6 = vec3(o[0] + bw / 2, o[1] + bw / 2, o[2] - bh / 2); - vec3_t p7 = vec3(o[0] - bw / 2, o[1] - bw / 2, o[2] - bh / 2); - vec3_t p8 = vec3(o[0] + bw / 2, o[1] - bw / 2, o[2] - bh / 2); + vec3_t p1 = vec3(o.x - bw / 2, o.y + bw / 2, o.z + bh / 2); + vec3_t p2 = vec3(o.x + bw / 2, o.y + bw / 2, o.z + bh / 2); + vec3_t p3 = vec3(o.x - bw / 2, o.y - bw / 2, o.z + bh / 2); + vec3_t p4 = vec3(o.x + bw / 2, o.y - bw / 2, o.z + bh / 2); + vec3_t p5 = vec3(o.x - bw / 2, o.y + bw / 2, o.z - bh / 2); + vec3_t p6 = vec3(o.x + bw / 2, o.y + bw / 2, o.z - bh / 2); + vec3_t p7 = vec3(o.x - bw / 2, o.y - bw / 2, o.z - bh / 2); + vec3_t p8 = vec3(o.x + bw / 2, o.y - bw / 2, o.z - bh / 2); vec2_t s1, s2, s3, s4, s5, s6, s7, s8; if (!world_to_screen(p1, s1) || !world_to_screen(p2, s2) || @@ -78,8 +78,8 @@ static bool gl_draw2dbox(vec3_t o, int bh) { const rgb_t out_col = { 0, 0, 0 }; /* Outline */ /* Get top and bottom of player from origin with box height */ - const vec3_t bot = vec3(o[0], o[1], o[2] - bh / 2); - const vec3_t top = vec3(o[0], o[1], o[2] + bh / 2); + const vec3_t bot = vec3(o.x, o.y, o.z - bh / 2); + const vec3_t top = vec3(o.x, o.y, o.z + bh / 2); vec2_t s_bot, s_top; if (!world_to_screen(bot, s_bot) || !world_to_screen(top, s_top)) @@ -121,7 +121,7 @@ void esp(void) { continue; /* Draw name on top of the player. */ - vec3_t top = vec3(ent->origin[0], ent->origin[1], ent->origin[2] + bh); + vec3_t top = vec3(ent->origin.x, ent->origin.y, ent->origin.z + bh); vec2_t s_top; if (!world_to_screen(top, s_top)) diff --git a/src/features/movement.c b/src/features/movement.c index e32efad..d4dd780 100644 --- a/src/features/movement.c +++ b/src/features/movement.c @@ -53,8 +53,8 @@ static void autostrafe_rage(usercmd_t* cmd) { i_engine->GetViewAngles(viewangles); /* Get our desired angles and delta */ - float yaw = DEG2RAD(viewangles[1]); - float vel_dir = atan2f(i_pmove->velocity[1], i_pmove->velocity[0]) - yaw; + float yaw = DEG2RAD(viewangles.y); + float vel_dir = atan2f(i_pmove->velocity.y, i_pmove->velocity.x) - yaw; float target_ang = atan2f(-cmd->sidemove, cmd->forwardmove); float delta = angle_delta_rad(vel_dir, target_ang); @@ -101,8 +101,8 @@ void bhop(usercmd_t* cmd) { * https://github.com/deboogerxyz/ahc/blob/0492646e28dd7234a8cd431d37b152dc18a21b04/ahc.c#L377 */ void correct_movement(usercmd_t* cmd, vec3_t old_angles) { - float old_y = old_angles[1] + (old_angles[1] < 0 ? 360 : 0); - float new_y = cmd->viewangles[1] + (cmd->viewangles[1] < 0 ? 360 : 0); + float old_y = old_angles.y + (old_angles.y < 0 ? 360 : 0); + float new_y = cmd->viewangles.y + (cmd->viewangles.y < 0 ? 360 : 0); float delta = (new_y < old_y) ? fabsf(new_y - old_y) : 360 - fabsf(new_y - old_y); diff --git a/src/include/util.h b/src/include/util.h index ac48129..1e8c1f2 100644 --- a/src/include/util.h +++ b/src/include/util.h @@ -30,6 +30,7 @@ bool is_friend(cl_entity_t* ent); char* get_name(int ent_idx); game_id get_cur_game(void); vec3_t vec3(float x, float y, float z); +vec3_t vec_add(vec3_t a, vec3_t b); bool vec_is_zero(vec3_t v); float vec_len2d(vec3_t v); void vec_clamp(vec3_t v); diff --git a/src/util.c b/src/util.c index afcd2cf..6aa7a47 100644 --- a/src/util.c +++ b/src/util.c @@ -93,15 +93,19 @@ game_id get_cur_game(void) { vec3_t vec3(float x, float y, float z) { vec3_t ret; - ret[0] = x; - ret[1] = y; - ret[2] = z; + ret.x = x; + ret.y = y; + ret.z = z; return ret; } +vec3_t vec_add(vec3_t a, vec3_t b) { + return vec3(a.x + b.x, a.y + b.y, a.z + b.z); +} + bool vec_is_zero(vec3_t v) { - return v[0] == 0.0f && v[1] == 0.0f && v[2] == 0.0f; + return v.x == 0.0f && v.y == 0.0f && v.z == 0.0f; } float vec_len2d(vec3_t v) { @@ -109,9 +113,9 @@ float vec_len2d(vec3_t v) { } void vec_clamp(vec3_t v) { - v[0] = CLAMP(v[0], -89.0f, 89.0f); - v[1] = CLAMP(remainderf(v[1], 360.0f), -180.0f, 180.0f); /* v.y % 360 */ - v[2] = CLAMP(v[2], -50.0f, 50.0f); + v.x = CLAMP(v.x, -89.0f, 89.0f); + v.y = CLAMP(remainderf(v.y, 360.0f), -180.0f, 180.0f); /* v.y % 360 */ + v.z = CLAMP(v.z, -50.0f, 50.0f); } float angle_delta_rad(float a, float b) {