2020-10-11 14:33:43 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "m_fixed.h"
|
|
|
|
#include "gamecvars.h"
|
2021-04-02 11:46:43 +00:00
|
|
|
#include "gamestruct.h"
|
2022-08-28 04:19:04 +00:00
|
|
|
#include "gamefuncs.h"
|
2020-10-11 14:33:43 +00:00
|
|
|
#include "packet.h"
|
|
|
|
|
2022-11-25 06:09:11 +00:00
|
|
|
struct PlayerAngles
|
2020-10-11 14:33:43 +00:00
|
|
|
{
|
2022-11-27 03:48:37 +00:00
|
|
|
// Player viewing angles, separate from the camera.
|
|
|
|
DRotator PrevViewAngles, ViewAngles;
|
|
|
|
|
2022-12-09 06:55:13 +00:00
|
|
|
// Player camera angles, not for direct manipulation within the playsim.
|
|
|
|
DRotator RenderAngles;
|
|
|
|
|
2022-11-27 03:48:37 +00:00
|
|
|
// Holder of current yaw spin state for the 180 degree turn.
|
|
|
|
DAngle YawSpin;
|
|
|
|
|
2022-11-25 06:09:11 +00:00
|
|
|
friend FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerAngles& w, PlayerAngles* def);
|
2021-07-18 09:25:41 +00:00
|
|
|
|
2022-12-09 07:09:59 +00:00
|
|
|
// Prototypes.
|
|
|
|
void doPitchKeys(ESyncBits* actions, const bool stopcentering);
|
|
|
|
void doYawKeys(ESyncBits* actions);
|
2022-11-25 10:18:36 +00:00
|
|
|
void doViewPitch(const DVector2& pos, DAngle const ang, bool const aimmode, bool const canslopetilt, sectortype* const cursectnum, bool const climbing = false);
|
2022-12-09 06:52:52 +00:00
|
|
|
void doViewYaw(const ESyncBits actions);
|
2021-07-18 09:25:41 +00:00
|
|
|
|
2022-11-27 02:36:55 +00:00
|
|
|
// General methods.
|
2022-12-09 06:55:13 +00:00
|
|
|
void initialize(DCoreActor* const actor, const DAngle viewyaw = nullAngle)
|
|
|
|
{
|
|
|
|
if ((pActor = actor)) RenderAngles = PrevLerpAngles = pActor->spr.Angles;
|
|
|
|
PrevViewAngles.Yaw = ViewAngles.Yaw = viewyaw;
|
|
|
|
}
|
2022-11-25 11:24:32 +00:00
|
|
|
DAngle getPitchWithView()
|
|
|
|
{
|
2022-12-09 06:55:13 +00:00
|
|
|
return ClampViewPitch(pActor->spr.Angles.Pitch + ViewAngles.Pitch);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Render angle functions.
|
2022-12-05 05:09:43 +00:00
|
|
|
DRotator lerpViewAngles(const double interpfrac)
|
|
|
|
{
|
|
|
|
return interpolatedvalue(PrevViewAngles, ViewAngles, interpfrac);
|
|
|
|
}
|
|
|
|
DRotator getRenderAngles(const double interpfrac)
|
|
|
|
{
|
2022-12-09 06:55:13 +00:00
|
|
|
// Get angles and return with clamped off pitch.
|
|
|
|
auto angles = RenderAngles + lerpViewAngles(interpfrac);
|
|
|
|
angles.Pitch = ClampViewPitch(angles.Pitch);
|
|
|
|
return angles;
|
|
|
|
}
|
|
|
|
void updateRenderAngles(const double interpfrac)
|
|
|
|
{
|
|
|
|
// Apply the current interpolated angle state to the render angles.
|
|
|
|
const auto lerpAngles = pActor->interpolatedangles(interpfrac);
|
|
|
|
RenderAngles += lerpAngles - PrevLerpAngles;
|
|
|
|
PrevLerpAngles = lerpAngles;
|
|
|
|
}
|
|
|
|
void resetRenderAngles()
|
|
|
|
{
|
|
|
|
// Apply any last remaining ticrate angle updates and reset variables.
|
|
|
|
RenderAngles += pActor->spr.Angles - PrevLerpAngles;
|
|
|
|
PrevLerpAngles = pActor->spr.Angles = RenderAngles;
|
|
|
|
PrevViewAngles = ViewAngles;
|
2022-12-05 05:09:43 +00:00
|
|
|
}
|
|
|
|
|
2022-12-02 07:16:04 +00:00
|
|
|
// Draw code helpers.
|
|
|
|
auto getCrosshairOffsets(const double interpfrac)
|
|
|
|
{
|
|
|
|
// Set up angles.
|
|
|
|
const auto viewAngles = lerpViewAngles(interpfrac);
|
|
|
|
const auto rotTangent = viewAngles.Roll.Tan();
|
|
|
|
const auto yawTangent = clamp(viewAngles.Yaw, -DAngle90, DAngle90).Tan();
|
|
|
|
const auto fovTangent = tan(r_fov * pi::pi() / 360.);
|
|
|
|
|
|
|
|
// Return as pair with roll as the 2nd object since all callers inevitably need it.
|
|
|
|
return std::make_pair(DVector2(160, 120 * -rotTangent) * -yawTangent / fovTangent, viewAngles.Roll);
|
|
|
|
}
|
|
|
|
auto getWeaponOffsets(const double interpfrac)
|
|
|
|
{
|
|
|
|
// Push the Y down a bit since the weapon is at the edge of the screen.
|
|
|
|
auto offsets = getCrosshairOffsets(interpfrac); offsets.first.Y *= 4.;
|
|
|
|
return offsets;
|
|
|
|
}
|
|
|
|
|
2021-04-02 11:46:43 +00:00
|
|
|
private:
|
2022-11-27 02:36:55 +00:00
|
|
|
// Private data which should never be accessed publically.
|
2022-12-09 06:55:13 +00:00
|
|
|
DRotator PrevLerpAngles;
|
2022-11-27 02:36:55 +00:00
|
|
|
DCoreActor* pActor;
|
2020-10-11 14:33:43 +00:00
|
|
|
};
|
|
|
|
|
2020-10-11 14:55:12 +00:00
|
|
|
class FSerializer;
|
2022-11-25 06:09:11 +00:00
|
|
|
FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerAngles& w, PlayerAngles* def);
|
2020-10-11 14:55:12 +00:00
|
|
|
|
2021-01-01 22:53:03 +00:00
|
|
|
|
|
|
|
void updateTurnHeldAmt(double const scaleAdjust);
|
2021-10-08 17:06:41 +00:00
|
|
|
bool isTurboTurnTime();
|
2021-01-01 22:53:03 +00:00
|
|
|
void resetTurnHeldAmt();
|
2021-11-05 22:28:39 +00:00
|
|
|
void processMovement(InputPacket* const currInput, InputPacket* const inputBuffer, ControlInfo* const hidInput, double const scaleAdjust, int const drink_amt = 0, bool const allowstrafe = true, double const turnscale = 1);
|