2020-10-11 16:33:43 +02:00
|
|
|
#pragma once
|
|
|
|
|
2023-03-13 21:33:37 +11:00
|
|
|
#include "serializer.h"
|
2022-08-28 14:19:04 +10:00
|
|
|
#include "gamefuncs.h"
|
2020-10-11 16:33:43 +02:00
|
|
|
|
2022-11-25 17:09:11 +11:00
|
|
|
struct PlayerAngles
|
2020-10-11 16:33:43 +02:00
|
|
|
{
|
2022-11-27 14:48:37 +11:00
|
|
|
// Player viewing angles, separate from the camera.
|
|
|
|
DRotator PrevViewAngles, ViewAngles;
|
|
|
|
|
|
|
|
// Holder of current yaw spin state for the 180 degree turn.
|
|
|
|
DAngle YawSpin;
|
|
|
|
|
2022-11-25 17:09:11 +11:00
|
|
|
friend FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerAngles& w, PlayerAngles* def);
|
2023-03-18 19:48:18 +11:00
|
|
|
friend void getInput(const double scaleAdjust, PlayerAngles* const plrAngles, InputPacket* packet);
|
2021-07-18 19:25:41 +10:00
|
|
|
|
2022-12-09 18:09:59 +11:00
|
|
|
// Prototypes.
|
2023-03-13 21:17:53 +11:00
|
|
|
void doPitchKeys(InputPacket* const input);
|
2023-03-13 21:33:37 +11:00
|
|
|
void doYawKeys(InputPacket* const input);
|
2023-03-13 21:17:33 +11:00
|
|
|
void doViewPitch(const bool canslopetilt, const bool climbing = false);
|
2023-03-13 21:33:37 +11:00
|
|
|
void doViewYaw(InputPacket* const input);
|
2021-07-18 19:25:41 +10:00
|
|
|
|
2022-11-27 13:36:55 +11:00
|
|
|
// General methods.
|
2022-12-09 17:55:13 +11:00
|
|
|
void initialize(DCoreActor* const actor, const DAngle viewyaw = nullAngle)
|
|
|
|
{
|
2023-03-17 14:20:36 +11:00
|
|
|
if (pActor = actor) CameraAngles = PrevLerpAngles = pActor->spr.Angles;
|
2022-12-09 17:55:13 +11:00
|
|
|
PrevViewAngles.Yaw = ViewAngles.Yaw = viewyaw;
|
|
|
|
}
|
2022-11-25 22:24:32 +11:00
|
|
|
DAngle getPitchWithView()
|
|
|
|
{
|
2022-12-09 17:55:13 +11:00
|
|
|
return ClampViewPitch(pActor->spr.Angles.Pitch + ViewAngles.Pitch);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Render angle functions.
|
2023-03-18 20:14:01 +11:00
|
|
|
const DRotator& getCameraAngles() const
|
2023-03-18 19:48:18 +11:00
|
|
|
{
|
|
|
|
return CameraAngles;
|
|
|
|
}
|
2022-12-05 16:09:43 +11:00
|
|
|
DRotator getRenderAngles(const double interpfrac)
|
|
|
|
{
|
2022-12-09 17:55:13 +11:00
|
|
|
// Get angles and return with clamped off pitch.
|
2023-03-17 14:20:36 +11:00
|
|
|
auto angles = CameraAngles + interpolatedvalue(PrevViewAngles, ViewAngles, interpfrac);
|
2022-12-09 17:55:13 +11:00
|
|
|
angles.Pitch = ClampViewPitch(angles.Pitch);
|
|
|
|
return angles;
|
|
|
|
}
|
2023-03-17 14:20:36 +11:00
|
|
|
void updateCameraAngles(const double interpfrac)
|
2022-12-09 17:55:13 +11:00
|
|
|
{
|
|
|
|
// Apply the current interpolated angle state to the render angles.
|
2023-02-04 17:05:18 +11:00
|
|
|
const auto lerpAngles = interpolatedvalue(pActor->PrevAngles, pActor->spr.Angles, interpfrac);
|
2023-03-17 14:20:36 +11:00
|
|
|
CameraAngles += lerpAngles - PrevLerpAngles;
|
2022-12-09 17:55:13 +11:00
|
|
|
PrevLerpAngles = lerpAngles;
|
|
|
|
}
|
2023-03-17 14:20:36 +11:00
|
|
|
void resetCameraAngles()
|
2022-12-09 17:55:13 +11:00
|
|
|
{
|
|
|
|
// Apply any last remaining ticrate angle updates and reset variables.
|
2023-03-17 14:20:36 +11:00
|
|
|
CameraAngles += pActor->spr.Angles - PrevLerpAngles;
|
|
|
|
PrevLerpAngles = pActor->spr.Angles = CameraAngles;
|
2022-12-09 17:55:13 +11:00
|
|
|
PrevViewAngles = ViewAngles;
|
2022-12-05 16:09:43 +11:00
|
|
|
}
|
|
|
|
|
2022-12-02 18:16:04 +11:00
|
|
|
// Draw code helpers.
|
|
|
|
auto getCrosshairOffsets(const double interpfrac)
|
|
|
|
{
|
2023-02-04 17:05:18 +11:00
|
|
|
// Set up angles and return as pair with roll as the 2nd object since all callers inevitably need it.
|
|
|
|
const auto viewAngles = interpolatedvalue(PrevViewAngles, ViewAngles, interpfrac);
|
|
|
|
return std::make_pair(DVector2(160, 120 * -viewAngles.Roll.Tan()) * -viewAngles.Yaw.Tan() / tan(r_fov * pi::pi() / 360.), viewAngles.Roll);
|
2022-12-02 18:16:04 +11:00
|
|
|
}
|
|
|
|
auto getWeaponOffsets(const double interpfrac)
|
|
|
|
{
|
2023-03-16 16:34:31 +11:00
|
|
|
// Push the Y down a bit since the weapon is at the edge of the screen. Also null roll for now.
|
|
|
|
auto offsets = getCrosshairOffsets(interpfrac); offsets.first.Y *= 4.; offsets.second = nullAngle;
|
2022-12-02 18:16:04 +11:00
|
|
|
return offsets;
|
|
|
|
}
|
|
|
|
|
2021-04-02 22:46:43 +11:00
|
|
|
private:
|
2023-03-18 19:48:18 +11:00
|
|
|
// Private data which should never be accessed publicly.
|
|
|
|
DRotator PrevLerpAngles, CameraAngles;
|
2022-11-27 13:36:55 +11:00
|
|
|
DCoreActor* pActor;
|
2020-10-11 16:33:43 +02:00
|
|
|
};
|
|
|
|
|
2020-10-11 16:55:12 +02:00
|
|
|
class FSerializer;
|
2022-11-25 17:09:11 +11:00
|
|
|
FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerAngles& w, PlayerAngles* def);
|
2020-10-11 16:55:12 +02:00
|
|
|
|
2021-01-02 09:53:03 +11:00
|
|
|
|
2023-03-13 21:33:37 +11:00
|
|
|
void updateTurnHeldAmt(const double scaleAdjust);
|
2021-10-08 19:06:41 +02:00
|
|
|
bool isTurboTurnTime();
|
2021-01-02 09:53:03 +11:00
|
|
|
void resetTurnHeldAmt();
|
2023-03-18 19:48:18 +11:00
|
|
|
void clearLocalInputBuffer();
|
|
|
|
void getInput(const double scaleAdjust, PlayerAngles* const plrAngles, InputPacket* packet = nullptr);
|