little CCam cleanup; fix in CWorld sphere test

This commit is contained in:
aap 2020-06-12 21:53:39 +02:00
parent 5a961d0284
commit 41dac0773f
3 changed files with 37 additions and 29 deletions

View file

@ -40,11 +40,11 @@ CCam::Init(void)
Mode = MODE_FOLLOWPED; Mode = MODE_FOLLOWPED;
Front = CVector(0.0f, 0.0f, -1.0f); Front = CVector(0.0f, 0.0f, -1.0f);
Up = CVector(0.0f, 0.0f, 1.0f); Up = CVector(0.0f, 0.0f, 1.0f);
Rotating = 0; Rotating = false;
m_iDoCollisionChecksOnFrameNum = 1; m_iDoCollisionChecksOnFrameNum = 1;
m_iDoCollisionCheckEveryNumOfFrames = 9; m_iDoCollisionCheckEveryNumOfFrames = 9;
m_iFrameNumWereAt = 0; m_iFrameNumWereAt = 0;
m_bCollisionChecksOn = 1; m_bCollisionChecksOn = false;
m_fRealGroundDist = 0.0f; m_fRealGroundDist = 0.0f;
BetaSpeed = 0.0f; BetaSpeed = 0.0f;
AlphaSpeed = 0.0f; AlphaSpeed = 0.0f;
@ -54,19 +54,19 @@ CCam::Init(void)
DistanceSpeed = 0.0f; DistanceSpeed = 0.0f;
m_pLastCarEntered = 0; m_pLastCarEntered = 0;
m_pLastPedLookedAt = 0; m_pLastPedLookedAt = 0;
ResetStatics = 1; ResetStatics = true;
Beta = 0.0f; Beta = 0.0f;
m_bFixingBeta = 0; m_bFixingBeta = false;
CA_MIN_DISTANCE = 0.0f; CA_MIN_DISTANCE = 0.0f;
CA_MAX_DISTANCE = 0.0f; CA_MAX_DISTANCE = 0.0f;
LookingBehind = 0; LookingBehind = false;
LookingLeft = 0; LookingLeft = false;
LookingRight = 0; LookingRight = false;
m_fPlayerInFrontSyphonAngleOffSet = DEGTORAD(20.0f); m_fPlayerInFrontSyphonAngleOffSet = DEGTORAD(20.0f);
m_fSyphonModeTargetZOffSet = 0.5f; m_fSyphonModeTargetZOffSet = 0.5f;
m_fRadiusForDead = 1.5f; m_fRadiusForDead = 1.5f;
DirectionWasLooking = LOOKING_FORWARD; DirectionWasLooking = LOOKING_FORWARD;
LookBehindCamWasInFront = 0; LookBehindCamWasInFront = false;
f_Roll = 0.0f; f_Roll = 0.0f;
f_rollSpeed = 0.0f; f_rollSpeed = 0.0f;
m_fCloseInPedHeightOffset = 0.0f; m_fCloseInPedHeightOffset = 0.0f;
@ -1007,6 +1007,9 @@ static float DefaultMaxStep = 0.15f;
void void
CCam::Process_FollowPed(const CVector &CameraTarget, float TargetOrientation, float, float) CCam::Process_FollowPed(const CVector &CameraTarget, float TargetOrientation, float, float)
{ {
if(!CamTargetEntity->IsPed())
return;
const float GroundDist = 1.85f; const float GroundDist = 1.85f;
CVector TargetCoors, Dist, IdealSource; CVector TargetCoors, Dist, IdealSource;
@ -1023,7 +1026,7 @@ CCam::Process_FollowPed(const CVector &CameraTarget, float TargetOrientation, fl
bool GoingBehind = false; bool GoingBehind = false;
bool Obscured = false; bool Obscured = false;
bool BuildingCheckObscured = false; bool BuildingCheckObscured = false;
bool HackPlayerOnStoppingTrain = false; bool StandingInTrain = false;
static int TimeIndicatedWantedToGoDown = 0; static int TimeIndicatedWantedToGoDown = 0;
static bool StartedCountingForGoDown = false; static bool StartedCountingForGoDown = false;
float DeltaBeta; float DeltaBeta;
@ -1032,12 +1035,6 @@ CCam::Process_FollowPed(const CVector &CameraTarget, float TargetOrientation, fl
bBelowMinDist = false; bBelowMinDist = false;
bBehindPlayerDesired = false; bBehindPlayerDesired = false;
#ifdef FIX_BUGS
if(!CamTargetEntity->IsPed())
return;
#endif
assert(CamTargetEntity->IsPed());
// CenterDist should be > LateralDist because we don't have an angle for safety in this case // CenterDist should be > LateralDist because we don't have an angle for safety in this case
float CenterDist, LateralDist; float CenterDist, LateralDist;
float AngleToGoToSpeed; float AngleToGoToSpeed;
@ -1103,7 +1100,7 @@ CCam::Process_FollowPed(const CVector &CameraTarget, float TargetOrientation, fl
if(FindPlayerVehicle()) if(FindPlayerVehicle())
if(FindPlayerVehicle()->m_vehType == VEHICLE_TYPE_TRAIN) if(FindPlayerVehicle()->m_vehType == VEHICLE_TYPE_TRAIN)
HackPlayerOnStoppingTrain = true; StandingInTrain = true;
if(TheCamera.m_bCamDirectlyInFront){ if(TheCamera.m_bCamDirectlyInFront){
m_bCollisionChecksOn = true; m_bCollisionChecksOn = true;
@ -1356,7 +1353,7 @@ CCam::Process_FollowPed(const CVector &CameraTarget, float TargetOrientation, fl
if(TheCamera.m_bCamDirectlyBehind || TheCamera.m_bCamDirectlyInFront || if(TheCamera.m_bCamDirectlyBehind || TheCamera.m_bCamDirectlyInFront ||
HackPlayerOnStoppingTrain || Rotating){ StandingInTrain || Rotating){
if(TheCamera.m_bCamDirectlyBehind){ if(TheCamera.m_bCamDirectlyBehind){
Beta = TargetOrientation + PI; Beta = TargetOrientation + PI;
Source.x = TargetCoors.x + RotDistance * Cos(Beta); Source.x = TargetCoors.x + RotDistance * Cos(Beta);
@ -1367,7 +1364,7 @@ CCam::Process_FollowPed(const CVector &CameraTarget, float TargetOrientation, fl
Source.x = TargetCoors.x + RotDistance * Cos(Beta); Source.x = TargetCoors.x + RotDistance * Cos(Beta);
Source.y = TargetCoors.y + RotDistance * Sin(Beta); Source.y = TargetCoors.y + RotDistance * Sin(Beta);
} }
if(HackPlayerOnStoppingTrain){ if(StandingInTrain){
Beta = TargetOrientation + PI; Beta = TargetOrientation + PI;
Source.x = TargetCoors.x + RotDistance * Cos(Beta); Source.x = TargetCoors.x + RotDistance * Cos(Beta);
Source.y = TargetCoors.y + RotDistance * Sin(Beta); Source.y = TargetCoors.y + RotDistance * Sin(Beta);
@ -2477,8 +2474,8 @@ CCam::Process_Rocket(const CVector &CameraTarget, float, float, float)
}else{ }else{
float xdir = LookLeftRight < 0.0f ? -1.0f : 1.0f; float xdir = LookLeftRight < 0.0f ? -1.0f : 1.0f;
float ydir = LookUpDown < 0.0f ? -1.0f : 1.0f; float ydir = LookUpDown < 0.0f ? -1.0f : 1.0f;
Beta += SQR(LookLeftRight/100.0f)*xdir/17.5 * FOV/80.0f * CTimer::GetTimeStep(); Beta += SQR(LookLeftRight/100.0f)*xdir*0.8f/14.0f * FOV/80.0f * CTimer::GetTimeStep();
Alpha += SQR(LookUpDown/150.0f)*ydir/14.0f * FOV/80.0f * CTimer::GetTimeStep(); Alpha += SQR(LookUpDown/150.0f)*ydir*1.0f/14.0f * FOV/80.0f * CTimer::GetTimeStep();
} }
while(Beta >= PI) Beta -= 2*PI; while(Beta >= PI) Beta -= 2*PI;
while(Beta < -PI) Beta += 2*PI; while(Beta < -PI) Beta += 2*PI;
@ -2579,8 +2576,8 @@ CCam::Process_M16_1stPerson(const CVector &CameraTarget, float, float, float)
}else{ }else{
float xdir = LookLeftRight < 0.0f ? -1.0f : 1.0f; float xdir = LookLeftRight < 0.0f ? -1.0f : 1.0f;
float ydir = LookUpDown < 0.0f ? -1.0f : 1.0f; float ydir = LookUpDown < 0.0f ? -1.0f : 1.0f;
Beta += SQR(LookLeftRight/100.0f)*xdir/17.5 * FOV/80.0f * CTimer::GetTimeStep(); Beta += SQR(LookLeftRight/100.0f)*xdir*0.8f/14.0f * FOV/80.0f * CTimer::GetTimeStep();
Alpha += SQR(LookUpDown/150.0f)*ydir/14.0f * FOV/80.0f * CTimer::GetTimeStep(); Alpha += SQR(LookUpDown/150.0f)*ydir*1.0f/14.0f * FOV/80.0f * CTimer::GetTimeStep();
} }
while(Beta >= PI) Beta -= 2*PI; while(Beta >= PI) Beta -= 2*PI;
while(Beta < -PI) Beta += 2*PI; while(Beta < -PI) Beta += 2*PI;
@ -2691,8 +2688,8 @@ CCam::Process_1stPerson(const CVector &CameraTarget, float TargetOrientation, fl
LookUpDown = CPad::GetPad(0)->LookAroundUpDown(); LookUpDown = CPad::GetPad(0)->LookAroundUpDown();
float xdir = LookLeftRight < 0.0f ? -1.0f : 1.0f; float xdir = LookLeftRight < 0.0f ? -1.0f : 1.0f;
float ydir = LookUpDown < 0.0f ? -1.0f : 1.0f; float ydir = LookUpDown < 0.0f ? -1.0f : 1.0f;
Beta += SQR(LookLeftRight/100.0f)*xdir/17.5 * FOV/80.0f * CTimer::GetTimeStep(); Beta += SQR(LookLeftRight/100.0f)*xdir*0.8f/14.0f * FOV/80.0f * CTimer::GetTimeStep();
Alpha += SQR(LookUpDown/150.0f)*ydir/14.0f * FOV/80.0f * CTimer::GetTimeStep(); Alpha += SQR(LookUpDown/150.0f)*ydir*1.0f/14.0f * FOV/80.0f * CTimer::GetTimeStep();
while(Beta >= PI) Beta -= 2*PI; while(Beta >= PI) Beta -= 2*PI;
while(Beta < -PI) Beta += 2*PI; while(Beta < -PI) Beta += 2*PI;
if(Alpha > DEGTORAD(60.0f)) Alpha = DEGTORAD(60.0f); if(Alpha > DEGTORAD(60.0f)) Alpha = DEGTORAD(60.0f);
@ -2870,8 +2867,8 @@ CCam::Process_1rstPersonPedOnPC(const CVector&, float TargetOrientation, float,
}else{ }else{
float xdir = LookLeftRight < 0.0f ? -1.0f : 1.0f; float xdir = LookLeftRight < 0.0f ? -1.0f : 1.0f;
float ydir = LookUpDown < 0.0f ? -1.0f : 1.0f; float ydir = LookUpDown < 0.0f ? -1.0f : 1.0f;
Beta += SQR(LookLeftRight/100.0f)*xdir/17.5 * FOV/80.0f * CTimer::GetTimeStep(); Beta += SQR(LookLeftRight/100.0f)*xdir*0.8f/14.0f * FOV/80.0f * CTimer::GetTimeStep();
Alpha += SQR(LookUpDown/150.0f)*ydir/14.0f * FOV/80.0f * CTimer::GetTimeStep(); Alpha += SQR(LookUpDown/150.0f)*ydir*1.0f/14.0f * FOV/80.0f * CTimer::GetTimeStep();
} }
while(Beta >= PI) Beta -= 2*PI; while(Beta >= PI) Beta -= 2*PI;
while(Beta < -PI) Beta += 2*PI; while(Beta < -PI) Beta += 2*PI;
@ -2973,8 +2970,8 @@ CCam::Process_Sniper(const CVector &CameraTarget, float TargetOrientation, float
}else{ }else{
float xdir = LookLeftRight < 0.0f ? -1.0f : 1.0f; float xdir = LookLeftRight < 0.0f ? -1.0f : 1.0f;
float ydir = LookUpDown < 0.0f ? -1.0f : 1.0f; float ydir = LookUpDown < 0.0f ? -1.0f : 1.0f;
Beta += SQR(LookLeftRight/100.0f)*xdir/17.5 * FOV/80.0f * CTimer::GetTimeStep(); Beta += SQR(LookLeftRight/100.0f)*xdir*0.8f/14.0f * FOV/80.0f * CTimer::GetTimeStep();
Alpha += SQR(LookUpDown/150.0f)*ydir/14.0f * FOV/80.0f * CTimer::GetTimeStep(); Alpha += SQR(LookUpDown/150.0f)*ydir*1.0f/14.0f * FOV/80.0f * CTimer::GetTimeStep();
} }
while(Beta >= PI) Beta -= 2*PI; while(Beta >= PI) Beta -= 2*PI;
while(Beta < -PI) Beta += 2*PI; while(Beta < -PI) Beta += 2*PI;

View file

@ -111,7 +111,7 @@ CCamera::Init(void)
Cams[0].Mode = CCam::MODE_FOLLOWPED; Cams[0].Mode = CCam::MODE_FOLLOWPED;
Cams[1].Mode = CCam::MODE_FOLLOWPED; Cams[1].Mode = CCam::MODE_FOLLOWPED;
unknown = 0; unknown = 0;
m_bJustJumpedOutOf1stPersonBecauseOfTarget = 0; m_bJustJumpedOutOf1stPersonBecauseOfTarget = false;
ClearPlayerWeaponMode(); ClearPlayerWeaponMode();
m_bInATunnelAndABigVehicle = false; m_bInATunnelAndABigVehicle = false;
m_iModeObbeCamIsInForCar = OBBE_INVALID; m_iModeObbeCamIsInForCar = OBBE_INVALID;
@ -2869,6 +2869,13 @@ CCamera::Process_Train_Camera_Control(void)
if(node >= m_uiNumberOfTrainCamNodes) if(node >= m_uiNumberOfTrainCamNodes)
node = 0; node = 0;
} }
#ifdef FIX_BUGS
// Not really a bug but be nice and respect the debug mode
if(DebugCamMode){
TakeControl(target, DebugCamMode, JUMP_CUT, CAMCONTROL_SCRIPT);
return;
}
#endif
if(found){ if(found){
SetWideScreenOn(); SetWideScreenOn();

View file

@ -949,7 +949,11 @@ CWorld::TestSphereAgainstSectorList(CPtrList &list, CVector spherePos, float rad
if(e != entityToIgnore && e->bUsesCollision && if(e != entityToIgnore && e->bUsesCollision &&
!(ignoreSomeObjects && CameraToIgnoreThisObject(e))) { !(ignoreSomeObjects && CameraToIgnoreThisObject(e))) {
#ifdef FIX_BUGS
CVector diff = spherePos - e->GetBoundCentre();
#else
CVector diff = spherePos - e->GetPosition(); CVector diff = spherePos - e->GetPosition();
#endif
float distance = diff.Magnitude(); float distance = diff.Magnitude();
if(e->GetBoundRadius() + radius > distance) { if(e->GetBoundRadius() + radius > distance) {