Replace vector indexing with members
Use .x instead of [0] Also add vec_add() to util.c
This commit is contained in:
parent
8cfead04f9
commit
2a57c69444
|
@ -36,14 +36,14 @@ bool gl_draw3dbox(vec3_t o, int bh, int bw, int lw) {
|
||||||
* |/ O|/ z(-)
|
* |/ O|/ z(-)
|
||||||
* 7---8
|
* 7---8
|
||||||
*/
|
*/
|
||||||
vec3_t p1 = 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[0] + bw / 2, o[1] + bw / 2, o[2] + bh / 2);
|
vec3_t p2 = vec3(o.x + bw / 2, o.y + bw / 2, o.z + bh / 2);
|
||||||
vec3_t p3 = vec3(o[0] - bw / 2, o[1] - bw / 2, o[2] + bh / 2);
|
vec3_t p3 = vec3(o.x - bw / 2, o.y - bw / 2, o.z + bh / 2);
|
||||||
vec3_t p4 = vec3(o[0] + bw / 2, o[1] - bw / 2, o[2] + bh / 2);
|
vec3_t p4 = vec3(o.x + bw / 2, o.y - bw / 2, o.z + bh / 2);
|
||||||
vec3_t p5 = vec3(o[0] - bw / 2, o[1] + bw / 2, o[2] - bh / 2);
|
vec3_t p5 = vec3(o.x - bw / 2, o.y + bw / 2, o.z - bh / 2);
|
||||||
vec3_t p6 = vec3(o[0] + bw / 2, o[1] + bw / 2, o[2] - bh / 2);
|
vec3_t p6 = vec3(o.x + bw / 2, o.y + bw / 2, o.z - bh / 2);
|
||||||
vec3_t p7 = vec3(o[0] - bw / 2, o[1] - bw / 2, o[2] - bh / 2);
|
vec3_t p7 = vec3(o.x - bw / 2, o.y - bw / 2, o.z - bh / 2);
|
||||||
vec3_t p8 = vec3(o[0] + bw / 2, o[1] - bw / 2, o[2] - 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;
|
vec2_t s1, s2, s3, s4, s5, s6, s7, s8;
|
||||||
if (!world_to_screen(p1, s1) || !world_to_screen(p2, s2) ||
|
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 */
|
const rgb_t out_col = { 0, 0, 0 }; /* Outline */
|
||||||
|
|
||||||
/* Get top and bottom of player from origin with box height */
|
/* 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 bot = vec3(o.x, o.y, o.z - bh / 2);
|
||||||
const vec3_t top = vec3(o[0], o[1], o[2] + bh / 2);
|
const vec3_t top = vec3(o.x, o.y, o.z + bh / 2);
|
||||||
|
|
||||||
vec2_t s_bot, s_top;
|
vec2_t s_bot, s_top;
|
||||||
if (!world_to_screen(bot, s_bot) || !world_to_screen(top, s_top))
|
if (!world_to_screen(bot, s_bot) || !world_to_screen(top, s_top))
|
||||||
|
@ -121,7 +121,7 @@ void esp(void) {
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* Draw name on top of the player. */
|
/* 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;
|
vec2_t s_top;
|
||||||
|
|
||||||
if (!world_to_screen(top, s_top))
|
if (!world_to_screen(top, s_top))
|
||||||
|
|
|
@ -53,8 +53,8 @@ static void autostrafe_rage(usercmd_t* cmd) {
|
||||||
i_engine->GetViewAngles(viewangles);
|
i_engine->GetViewAngles(viewangles);
|
||||||
|
|
||||||
/* Get our desired angles and delta */
|
/* Get our desired angles and delta */
|
||||||
float yaw = DEG2RAD(viewangles[1]);
|
float yaw = DEG2RAD(viewangles.y);
|
||||||
float vel_dir = atan2f(i_pmove->velocity[1], i_pmove->velocity[0]) - yaw;
|
float vel_dir = atan2f(i_pmove->velocity.y, i_pmove->velocity.x) - yaw;
|
||||||
float target_ang = atan2f(-cmd->sidemove, cmd->forwardmove);
|
float target_ang = atan2f(-cmd->sidemove, cmd->forwardmove);
|
||||||
float delta = angle_delta_rad(vel_dir, target_ang);
|
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
|
* https://github.com/deboogerxyz/ahc/blob/0492646e28dd7234a8cd431d37b152dc18a21b04/ahc.c#L377
|
||||||
*/
|
*/
|
||||||
void correct_movement(usercmd_t* cmd, vec3_t old_angles) {
|
void correct_movement(usercmd_t* cmd, vec3_t old_angles) {
|
||||||
float old_y = old_angles[1] + (old_angles[1] < 0 ? 360 : 0);
|
float old_y = old_angles.y + (old_angles.y < 0 ? 360 : 0);
|
||||||
float new_y = cmd->viewangles[1] + (cmd->viewangles[1] < 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)
|
float delta = (new_y < old_y) ? fabsf(new_y - old_y)
|
||||||
: 360 - fabsf(new_y - old_y);
|
: 360 - fabsf(new_y - old_y);
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ bool is_friend(cl_entity_t* ent);
|
||||||
char* get_name(int ent_idx);
|
char* get_name(int ent_idx);
|
||||||
game_id get_cur_game(void);
|
game_id get_cur_game(void);
|
||||||
vec3_t vec3(float x, float y, float z);
|
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);
|
bool vec_is_zero(vec3_t v);
|
||||||
float vec_len2d(vec3_t v);
|
float vec_len2d(vec3_t v);
|
||||||
void vec_clamp(vec3_t v);
|
void vec_clamp(vec3_t v);
|
||||||
|
|
18
src/util.c
18
src/util.c
|
@ -93,15 +93,19 @@ game_id get_cur_game(void) {
|
||||||
vec3_t vec3(float x, float y, float z) {
|
vec3_t vec3(float x, float y, float z) {
|
||||||
vec3_t ret;
|
vec3_t ret;
|
||||||
|
|
||||||
ret[0] = x;
|
ret.x = x;
|
||||||
ret[1] = y;
|
ret.y = y;
|
||||||
ret[2] = z;
|
ret.z = z;
|
||||||
|
|
||||||
return ret;
|
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) {
|
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) {
|
float vec_len2d(vec3_t v) {
|
||||||
|
@ -109,9 +113,9 @@ float vec_len2d(vec3_t v) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void vec_clamp(vec3_t v) {
|
void vec_clamp(vec3_t v) {
|
||||||
v[0] = CLAMP(v[0], -89.0f, 89.0f);
|
v.x = CLAMP(v.x, -89.0f, 89.0f);
|
||||||
v[1] = CLAMP(remainderf(v[1], 360.0f), -180.0f, 180.0f); /* v.y % 360 */
|
v.y = CLAMP(remainderf(v.y, 360.0f), -180.0f, 180.0f); /* v.y % 360 */
|
||||||
v[2] = CLAMP(v[2], -50.0f, 50.0f);
|
v.z = CLAMP(v.z, -50.0f, 50.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
float angle_delta_rad(float a, float b) {
|
float angle_delta_rad(float a, float b) {
|
||||||
|
|
Loading…
Reference in New Issue