Add correct_movement, call from CL_CreateMove

This commit is contained in:
8dcc
2023-07-23 15:50:01 +02:00
parent dcd38dc950
commit 611182e394
3 changed files with 28 additions and 0 deletions

View File

@@ -1,10 +1,12 @@
#include <stdio.h>
#include <math.h>
#include "features.h"
#include "../include/sdk.h"
#include "../include/globals.h"
#include "../include/cvars.h"
#include "../include/util.h"
static void autostrafe_legit(usercmd_t* cmd) {
/* Get mouse delta */
@@ -41,3 +43,24 @@ void bhop(usercmd_t* cmd) {
}
}
}
/*
* Unfortunately I don't know shit about math, so this is pasted from:
* 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 delta = (new_y < old_y) ? fabsf(new_y - old_y)
: 360 - fabsf(new_y - old_y);
delta = 360 - delta;
float forward = cmd->forwardmove;
float side = cmd->sidemove;
cmd->forwardmove =
cos(DEG2RAD(delta)) * forward + cos(DEG2RAD(delta + 90)) * side;
cmd->sidemove =
sin(DEG2RAD(delta)) * forward + sin(DEG2RAD(delta + 90)) * side;
}