Improve vertical mouse aim

This improves vertical mouse aim in two ways: the Y axis is normalized to match the sensitivity of the X axis, and horiz adjustment has been corrected so that the player's pitch is operated on as an angle instead of as the tangent of said angle. Based on a patch from Fox.

git-svn-id: https://svn.eduke32.com/eduke32@7342 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2019-02-20 21:33:00 +00:00
parent eef6667fbc
commit a3f49b4584
1 changed files with 13 additions and 6 deletions

View File

@ -2944,7 +2944,7 @@ void P_GetInput(int const playerNum)
else else
input.q16avel = fix16_div(fix16_from_int(info.dyaw), F16(32)); input.q16avel = fix16_div(fix16_from_int(info.dyaw), F16(32));
input.q16horz = fix16_div(fix16_from_int(info.dpitch), F16(256)); input.q16horz = fix16_div(fix16_from_int(info.dpitch), F16(128));
if (ud.mouseflip) input.q16horz = -input.q16horz; if (ud.mouseflip) input.q16horz = -input.q16horz;
@ -5362,12 +5362,17 @@ HORIZONLY:;
if (VM_OnEvent(EVENT_RETURNTOCENTER,pPlayer->i,playerNum) == 0) if (VM_OnEvent(EVENT_RETURNTOCENTER,pPlayer->i,playerNum) == 0)
pPlayer->return_to_center = 9; pPlayer->return_to_center = 9;
// A horiz diff of 128 equal 45 degrees,
// so we convert horiz to 1024 angle units
float horizAngle = atan2f(pPlayer->q16horiz - F16(100), F16(128)) * (512.f / PI) + fix16_to_float(g_player[playerNum].inputBits->q16horz);
if (TEST_SYNC_KEY(playerBits, SK_LOOK_UP)) if (TEST_SYNC_KEY(playerBits, SK_LOOK_UP))
{ {
if (VM_OnEvent(EVENT_LOOKUP,pPlayer->i,playerNum) == 0) if (VM_OnEvent(EVENT_LOOKUP,pPlayer->i,playerNum) == 0)
{ {
pPlayer->return_to_center = 9; pPlayer->return_to_center = 9;
pPlayer->q16horiz += fix16_from_int(12<<(int)(TEST_SYNC_KEY(playerBits, SK_RUN))); horizAngle += float(12<<(int)(TEST_SYNC_KEY(playerBits, SK_RUN)));
centerHoriz++; centerHoriz++;
} }
} }
@ -5377,7 +5382,7 @@ HORIZONLY:;
if (VM_OnEvent(EVENT_LOOKDOWN,pPlayer->i,playerNum) == 0) if (VM_OnEvent(EVENT_LOOKDOWN,pPlayer->i,playerNum) == 0)
{ {
pPlayer->return_to_center = 9; pPlayer->return_to_center = 9;
pPlayer->q16horiz -= fix16_from_int(12<<(int)(TEST_SYNC_KEY(playerBits, SK_RUN))); horizAngle -= float(12<<(int)(TEST_SYNC_KEY(playerBits, SK_RUN)));
centerHoriz++; centerHoriz++;
} }
} }
@ -5386,7 +5391,7 @@ HORIZONLY:;
{ {
if (VM_OnEvent(EVENT_AIMUP,pPlayer->i,playerNum) == 0) if (VM_OnEvent(EVENT_AIMUP,pPlayer->i,playerNum) == 0)
{ {
pPlayer->q16horiz += fix16_from_int(6<<(int)(TEST_SYNC_KEY(playerBits, SK_RUN))); horizAngle += float(6<<(int)(TEST_SYNC_KEY(playerBits, SK_RUN)));
centerHoriz++; centerHoriz++;
} }
} }
@ -5395,11 +5400,13 @@ HORIZONLY:;
{ {
if (VM_OnEvent(EVENT_AIMDOWN,pPlayer->i,playerNum) == 0) if (VM_OnEvent(EVENT_AIMDOWN,pPlayer->i,playerNum) == 0)
{ {
pPlayer->q16horiz -= fix16_from_int(6<<(int)(TEST_SYNC_KEY(playerBits, SK_RUN))); horizAngle -= float(6<<(int)(TEST_SYNC_KEY(playerBits, SK_RUN)));
centerHoriz++; centerHoriz++;
} }
} }
pPlayer->q16horiz = F16(100) + F16(128) * tanf(horizAngle * (PI / 512.f));
if (pPlayer->return_to_center > 0 && !TEST_SYNC_KEY(playerBits, SK_LOOK_UP) && !TEST_SYNC_KEY(playerBits, SK_LOOK_DOWN)) if (pPlayer->return_to_center > 0 && !TEST_SYNC_KEY(playerBits, SK_LOOK_UP) && !TEST_SYNC_KEY(playerBits, SK_LOOK_DOWN))
{ {
pPlayer->return_to_center--; pPlayer->return_to_center--;
@ -5419,7 +5426,7 @@ HORIZONLY:;
if (pPlayer->q16horizoff > F16(-5) && pPlayer->q16horizoff < F16(5)) pPlayer->q16horizoff = 0; if (pPlayer->q16horizoff > F16(-5) && pPlayer->q16horizoff < F16(5)) pPlayer->q16horizoff = 0;
} }
pPlayer->q16horiz = fix16_clamp(pPlayer->q16horiz + g_player[playerNum].inputBits->q16horz, F16(HORIZ_MIN), F16(HORIZ_MAX)); pPlayer->q16horiz = fix16_clamp(pPlayer->q16horiz, F16(HORIZ_MIN), F16(HORIZ_MAX));
//Shooting code/changes //Shooting code/changes