fix Vectoe3 clamp for real.

This commit is contained in:
Christoph Oelckers 2023-10-03 14:56:07 +02:00
parent a8f03ed10d
commit 77f61004c3
2 changed files with 3 additions and 4 deletions

View file

@ -44,6 +44,7 @@
#include <math.h>
#include <float.h>
#include <string.h>
#include <algorithm>
// this is needed to properly normalize angles. We cannot do that with compiler provided conversions because they differ too much
#include "xs_Float.h"
@ -1543,7 +1544,7 @@ inline TVector2<T> clamp(const TVector2<T> &vec, const TVector2<T> &min, const T
template<class T>
inline TVector3<T> clamp(const TVector3<T> &vec, const TVector3<T> &min, const TVector3<T> &max)
{
return TVector3<T>(clamp(vec.X, min.X, max.X), clamp(vec.Y, min.Y, max.Y), clamp(vec.Z, min.Z, max.Z));
return TVector3<T>(std::clamp<T>(vec.X, min.X, max.X), std::clamp<T>(vec.Y, min.Y, max.Y), std::clamp<T>(vec.Z, min.Z, max.Z));
}
template<class T>

View file

@ -169,9 +169,7 @@ void GameInput::processMovement(PlayerAngles* const plrAngles, const double scal
// add collected input to game's local input accumulation packet.
const DVector3 maxVel{ (double)keymove, (double)keymove, 1. };
const DRotator maxAng{ MAXANG, MAXANG, MAXANG };
inputBuffer.vel.X = clamp(inputBuffer.vel.X + thisInput.vel.X, -(double)keymove, (double)keymove);
inputBuffer.vel.Y = clamp(inputBuffer.vel.Y + thisInput.vel.Y, -(double)keymove, (double)keymove);
inputBuffer.vel.Z = clamp(inputBuffer.vel.Z + thisInput.vel.Z, -1., 1.);
inputBuffer.vel = clamp(inputBuffer.vel + thisInput.vel, -maxVel, maxVel);
inputBuffer.ang = clamp(inputBuffer.ang + thisInput.ang, -maxAng, maxAng);
// directly update player angles if we can.