From ef52694365c6ce350e610df7a7c2ee7470bce061 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Sun, 16 Oct 2022 18:33:42 +1100 Subject: [PATCH] - Improved crosshair drawing that factor's in look_ang better I've had stashed away for a little bit. --- source/core/gamecontrol.cpp | 4 ++-- source/core/gamecontrol.h | 2 +- source/core/gameinput.h | 7 +++++++ source/games/blood/src/view.cpp | 4 ++-- source/games/duke/src/game_misc.cpp | 3 ++- source/games/exhumed/src/gameloop.cpp | 3 ++- source/games/sw/src/draw.cpp | 5 +++-- 7 files changed, 19 insertions(+), 9 deletions(-) diff --git a/source/core/gamecontrol.cpp b/source/core/gamecontrol.cpp index fdb5f65d9..aacd51b24 100644 --- a/source/core/gamecontrol.cpp +++ b/source/core/gamecontrol.cpp @@ -1374,7 +1374,7 @@ void ST_LoadCrosshair(int num, bool alwaysload); CVAR(Int, crosshair, 0, CVAR_ARCHIVE) -void DrawCrosshair(int deftile, int health, double xdelta, double ydelta, double scale, PalEntry color) +void DrawCrosshair(int deftile, int health, double xdelta, double ydelta, double scale, DAngle angle, PalEntry color) { if (automapMode == am_off && cl_crosshair) { @@ -1384,7 +1384,7 @@ void DrawCrosshair(int deftile, int health, double xdelta, double ydelta, double if (tile) { double crosshair_scale = crosshairscale * scale; - DrawTexture(twod, tile, 160 + xdelta, 100 + ydelta, DTA_Color, color, + DrawTexture(twod, tile, 160 + xdelta, 100 + ydelta, DTA_Color, color, DTA_Rotate, angle.Degrees(), DTA_FullscreenScale, FSMode_Fit320x200, DTA_ScaleX, crosshair_scale, DTA_ScaleY, crosshair_scale, DTA_CenterOffsetRel, true, DTA_ViewportX, viewport3d.Left(), DTA_ViewportY, viewport3d.Top(), DTA_ViewportWidth, viewport3d.Width(), DTA_ViewportHeight, viewport3d.Height(), TAG_DONE); diff --git a/source/core/gamecontrol.h b/source/core/gamecontrol.h index fc05001ac..ffa9436dc 100644 --- a/source/core/gamecontrol.h +++ b/source/core/gamecontrol.h @@ -40,7 +40,7 @@ void CONFIG_ReadCombatMacros(); int GameMain(); int GetAutomapZoom(int gZoom); -void DrawCrosshair(int deftile, int health, double xdelta, double ydelta, double scale, PalEntry color = 0xffffffff); +void DrawCrosshair(int deftile, int health, double xdelta, double ydelta, double scale, DAngle angle, PalEntry color = 0xffffffff); void updatePauseStatus(); void DeferredStartGame(MapRecord* map, int skill, bool nostopsound = false); void ChangeLevel(MapRecord* map, int skill, bool bossexit = false); diff --git a/source/core/gameinput.h b/source/core/gameinput.h index 53eea0414..9c033e8b5 100644 --- a/source/core/gameinput.h +++ b/source/core/gameinput.h @@ -129,6 +129,7 @@ struct PlayerAngle DAngle interpolatedlookang(double const interpfrac) { return interpolatedvalue(olook_ang, look_ang, interpfrac); } DAngle interpolatedrotscrn(double const interpfrac) { return interpolatedvalue(orotscrnang, rotscrnang, interpfrac); } DAngle renderlookang(double const interpfrac) { return !SyncInput() ? look_ang : interpolatedlookang(interpfrac); } + DAngle renderrotscrn(double const interpfrac) { return !SyncInput() ? rotscrnang : interpolatedrotscrn(interpfrac); } // Ticrate playsim adjustment helpers. void resetadjustment() { adjustment = nullAngle; } @@ -143,6 +144,12 @@ struct PlayerAngle double look_anghalf(double const interpfrac) { return renderlookang(interpfrac).Normalized180().Degrees() * (128. / 45.); } double looking_arc(double const interpfrac) { return fabs(renderlookang(interpfrac).Normalized180().Degrees() * (1024. / 1620.)); } + // Crosshair x/y offsets based on look_ang's tangent. + DVector2 crosshairoffsets(const double interpfrac) + { + return DVector2(159.72, 145.5 * renderrotscrn(interpfrac).Sin()) * -renderlookang(interpfrac).Tan() * (1. / tan(r_fov * pi::pi() / 360.)); + } + // Ticrate playsim adjustment setters and processor. void addadjustment(const DAngle value) { diff --git a/source/games/blood/src/view.cpp b/source/games/blood/src/view.cpp index 3567fa2cb..5c960c539 100644 --- a/source/games/blood/src/view.cpp +++ b/source/games/blood/src/view.cpp @@ -743,8 +743,8 @@ void viewDrawScreen(bool sceneonly) bDeliriumOld = bDelirium && gDeliriumBlur; if (sceneonly) return; - double look_anghalf = pPlayer->angle.look_anghalf(interpfrac); - DrawCrosshair(kCrosshairTile, pPlayer->actor->xspr.health >> 4, -look_anghalf, 0, 2); + auto offsets = pPlayer->angle.crosshairoffsets(interpfrac); + DrawCrosshair(kCrosshairTile, pPlayer->actor->xspr.health >> 4, offsets.X, offsets.Y, 2, -pPlayer->angle.interpolatedrotscrn(interpfrac)); #if 0 // This currently does not work. May have to be redone as a hardware effect. if (v4 && gNetPlayers > 1) { diff --git a/source/games/duke/src/game_misc.cpp b/source/games/duke/src/game_misc.cpp index a00c9c141..9d8f0afac 100644 --- a/source/games/duke/src/game_misc.cpp +++ b/source/games/duke/src/game_misc.cpp @@ -289,7 +289,8 @@ void drawoverlays(double interpfrac) if (ps[myconnectindex].newOwner == nullptr && ud.cameraactor == nullptr) { - DrawCrosshair(TILE_CROSSHAIR, ps[screenpeek].last_extra, -pp->angle.look_anghalf(interpfrac), pp->over_shoulder_on ? 2.5 : 0, isRR() ? 0.5 : 1); + auto offsets = pp->angle.crosshairoffsets(interpfrac); + DrawCrosshair(TILE_CROSSHAIR, ps[screenpeek].last_extra, offsets.X, offsets.Y + (pp->over_shoulder_on ? 2.5 : 0), isRR() ? 0.5 : 1, -pp->angle.interpolatedrotscrn(interpfrac)); } if (paused == 2) diff --git a/source/games/exhumed/src/gameloop.cpp b/source/games/exhumed/src/gameloop.cpp index 2141a2ef8..2fb648c78 100644 --- a/source/games/exhumed/src/gameloop.cpp +++ b/source/games/exhumed/src/gameloop.cpp @@ -87,7 +87,8 @@ void GameInterface::Render() if (nFreeze != 2) // Hide when Ramses is talking. { DrawStatusBar(); - DrawCrosshair(kCrosshairTile, PlayerList[nLocalPlayer].nHealth >> 3, -PlayerList[nLocalPlayer].angle.look_anghalf(interpfrac), 0, 1); + auto offsets = PlayerList[nLocalPlayer].angle.crosshairoffsets(interpfrac); + DrawCrosshair(kCrosshairTile, PlayerList[nLocalPlayer].nHealth >> 3, offsets.X, offsets.Y, 1, -PlayerList[nLocalPlayer].angle.interpolatedrotscrn(interpfrac)); if (paused && !M_Active()) { diff --git a/source/games/sw/src/draw.cpp b/source/games/sw/src/draw.cpp index 17b0be742..d36cf11f2 100644 --- a/source/games/sw/src/draw.cpp +++ b/source/games/sw/src/draw.cpp @@ -1018,9 +1018,10 @@ void PrintSpriteInfo(PLAYER* pp) // //--------------------------------------------------------------------------- -static void DrawCrosshair(PLAYER* pp, const double inputfrac) +static void DrawCrosshair(PLAYER* pp, const double interpfrac) { - ::DrawCrosshair(2326, pp->actor->user.Health, -pp->angle.look_anghalf(inputfrac), (pp->Flags & PF_VIEW_FROM_OUTSIDE) ? 5 : 0, 2, shadeToLight(10)); + auto offsets = pp->angle.crosshairoffsets(interpfrac); + ::DrawCrosshair(2326, pp->actor->user.Health, offsets.X, offsets.Y + ((pp->Flags & PF_VIEW_FROM_OUTSIDE) ? 5 : 0), 2, -pp->angle.interpolatedrotscrn(interpfrac), shadeToLight(10)); } //---------------------------------------------------------------------------