ccamera cleanup

This commit is contained in:
aap 2020-06-19 09:15:23 +02:00
parent 5f3eb76cff
commit 4cd4f91e57
2 changed files with 118 additions and 119 deletions

View File

@ -234,7 +234,7 @@ CCamera::Process(void)
float oldBeta, newBeta; float oldBeta, newBeta;
float deltaBeta = 0.0f; float deltaBeta = 0.0f;
bool lookLRBVehicle = false; bool lookLRBVehicle = false;
CVector CamFront, CamUp, CamSource, Target; CVector CamFront, CamUp, CamRight, CamSource, Target;
m_bJust_Switched = false; m_bJust_Switched = false;
m_RealPreviousCameraPosition = GetPosition(); m_RealPreviousCameraPosition = GetPosition();
@ -378,15 +378,17 @@ CCamera::Process(void)
if(Cams[ActiveCam].Mode == CCam::MODE_TOPDOWN || Cams[ActiveCam].Mode == CCam::MODE_TOP_DOWN_PED){ if(Cams[ActiveCam].Mode == CCam::MODE_TOPDOWN || Cams[ActiveCam].Mode == CCam::MODE_TOP_DOWN_PED){
CamFront.Normalise(); CamFront.Normalise();
CamUp = CrossProduct(CamFront, CVector(-1.0f, 0.0f, 0.0f)); CamRight = CVector(-1.0f, 0.0f, 0.0f);
CamUp = CrossProduct(CamFront, CamRight);
CamUp.Normalise();
}else{ }else{
CamFront.Normalise(); CamFront.Normalise();
CamUp.Normalise(); CamUp.Normalise();
CVector right = CrossProduct(CamFront, CamUp); CamRight = CrossProduct(CamFront, CamUp);
right.Normalise(); CamRight.Normalise();
CamUp = CrossProduct(right, CamFront); CamUp = CrossProduct(CamRight, CamFront);
}
CamUp.Normalise(); CamUp.Normalise();
}
FOV = m_fFOVWhenInterPol; FOV = m_fFOVWhenInterPol;
}else if(fractionInter > m_fFractionInterToStopMoving && fractionInter <= 1.0f){ }else if(fractionInter > m_fFractionInterToStopMoving && fractionInter <= 1.0f){
float inter; float inter;
@ -433,15 +435,17 @@ CCamera::Process(void)
if(Cams[ActiveCam].Mode == CCam::MODE_TOPDOWN || Cams[ActiveCam].Mode == CCam::MODE_TOP_DOWN_PED){ if(Cams[ActiveCam].Mode == CCam::MODE_TOPDOWN || Cams[ActiveCam].Mode == CCam::MODE_TOP_DOWN_PED){
CamFront.Normalise(); CamFront.Normalise();
CamUp = CrossProduct(CamFront, CVector(-1.0f, 0.0f, 0.0f)); CamRight = CVector(-1.0f, 0.0f, 0.0f);
CamUp = CrossProduct(CamFront, CamRight);
CamUp.Normalise();
}else{ }else{
CamFront.Normalise(); CamFront.Normalise();
CamUp.Normalise(); CamUp.Normalise();
CVector right = CrossProduct(CamFront, CamUp); CamRight = CrossProduct(CamFront, CamUp);
right.Normalise(); CamRight.Normalise();
CamUp = CrossProduct(right, CamFront); CamUp = CrossProduct(CamRight, CamFront);
}
CamUp.Normalise(); CamUp.Normalise();
}
#ifndef FIX_BUGS #ifndef FIX_BUGS
// BUG: FOV was already interpolated but m_fFOVWhenInterPol was not // BUG: FOV was already interpolated but m_fFOVWhenInterPol was not
FOV = m_fFOVWhenInterPol; FOV = m_fFOVWhenInterPol;
@ -563,7 +567,7 @@ CCamera::Process(void)
} }
m_PreviousCameraPosition = GetPosition(); m_PreviousCameraPosition = GetPosition();
// PS2: something doing on with forward vector here // PS2: something going on with forward vector here
if(Cams[ActiveCam].DirectionWasLooking != LOOKING_FORWARD && Cams[ActiveCam].Mode != CCam::MODE_TOP_DOWN_PED){ if(Cams[ActiveCam].DirectionWasLooking != LOOKING_FORWARD && Cams[ActiveCam].Mode != CCam::MODE_TOP_DOWN_PED){
Cams[ActiveCam].Source = Cams[ActiveCam].SourceBeforeLookBehind; Cams[ActiveCam].Source = Cams[ActiveCam].SourceBeforeLookBehind;
@ -994,7 +998,7 @@ CCamera::CamControl(void)
garageCenter.y = (az->miny + az->maxy)/2.0f; garageCenter.y = (az->miny + az->maxy)/2.0f;
garageCenter.z = 0.0f; garageCenter.z = 0.0f;
}else }else
garageCenter = pTargetEntity->GetPosition(); garageCenter = CVector(pTargetEntity->GetPosition().x, pTargetEntity->GetPosition().y, 0.0f);
} }
if(whichDoor == 1) if(whichDoor == 1)
garageCenterToDoor = garageDoorPos1 - garageCenter; garageCenterToDoor = garageDoorPos1 - garageCenter;
@ -2243,25 +2247,22 @@ CCamera::IsItTimeForNewcam(int32 obbeMode, int32 time)
switch(obbeMode){ switch(obbeMode){
case OBBE_WHEEL: case OBBE_WHEEL:
veh = FindPlayerVehicle(); veh = FindPlayerVehicle();
if(veh == nil){ if(veh){
if(CTimer::GetTimeInMilliseconds() > t+5000)
return true;
SetNearClipScript(0.6f);
return false;
}
if(veh->IsBoat() || veh->GetModelIndex() == MI_RHINO) if(veh->IsBoat() || veh->GetModelIndex() == MI_RHINO)
return true; return true;
if(CWorld::GetIsLineOfSightClear(pTargetEntity->GetPosition(), Cams[ActiveCam].Source, true, false, false, false, false, false, false)){ if(!CWorld::GetIsLineOfSightClear(pTargetEntity->GetPosition(), Cams[ActiveCam].Source, true, false, false, false, false, false, false))
return true;
}
if(CTimer::GetTimeInMilliseconds() > t+5000) if(CTimer::GetTimeInMilliseconds() > t+5000)
return true; return true;
SetNearClipScript(0.6f); SetNearClipScript(0.6f);
return false; return false;
}
return true;
case OBBE_1: case OBBE_1:
if(FindPlayerVehicle() && FindPlayerVehicle()->IsBoat()) if(FindPlayerVehicle() && FindPlayerVehicle()->IsBoat())
return true; return true;
if(CWorld::GetIsLineOfSightClear(FindPlayerCoors(), m_vecFixedModeSource, true, false, false, false, false, false, false)){ if(!CWorld::GetIsLineOfSightClear(FindPlayerCoors(), m_vecFixedModeSource, true, false, false, false, false, false, false))
return true;
fwd = FindPlayerCoors() - m_vecFixedModeSource; fwd = FindPlayerCoors() - m_vecFixedModeSource;
fwd.z = 0.0f; fwd.z = 0.0f;
@ -2272,12 +2273,12 @@ CCamera::IsItTimeForNewcam(int32 obbeMode, int32 time)
if(fwd.Magnitude() < 1.6f) if(fwd.Magnitude() < 1.6f)
return true; return true;
return false; return false;
}
return true;
case OBBE_2: case OBBE_2:
if(FindPlayerVehicle() && FindPlayerVehicle()->IsBoat()) if(FindPlayerVehicle() && FindPlayerVehicle()->IsBoat())
return true; return true;
if(CWorld::GetIsLineOfSightClear(FindPlayerCoors(), m_vecFixedModeSource, true, false, false, false, false, false, false)){ if(!CWorld::GetIsLineOfSightClear(FindPlayerCoors(), m_vecFixedModeSource, true, false, false, false, false, false, false))
return true;
fwd = FindPlayerCoors() - m_vecFixedModeSource; fwd = FindPlayerCoors() - m_vecFixedModeSource;
fwd.z = 0.0f; fwd.z = 0.0f;
@ -2291,10 +2292,10 @@ CCamera::IsItTimeForNewcam(int32 obbeMode, int32 time)
if(fwd.Magnitude() < 1.6f) if(fwd.Magnitude() < 1.6f)
return true; return true;
return false; return false;
}
return true;
case OBBE_3: case OBBE_3:
if(CWorld::GetIsLineOfSightClear(FindPlayerCoors(), m_vecFixedModeSource, true, false, false, false, false, false, false)){ if(!CWorld::GetIsLineOfSightClear(FindPlayerCoors(), m_vecFixedModeSource, true, false, false, false, false, false, false))
return true;
fwd = FindPlayerCoors() - m_vecFixedModeSource; fwd = FindPlayerCoors() - m_vecFixedModeSource;
fwd.z = 0.0f; fwd.z = 0.0f;
@ -2302,14 +2303,14 @@ CCamera::IsItTimeForNewcam(int32 obbeMode, int32 time)
if(fwd.Magnitude() > 28.0f && DotProduct(FindPlayerSpeed(), fwd) > 0.0f) if(fwd.Magnitude() > 28.0f && DotProduct(FindPlayerSpeed(), fwd) > 0.0f)
return true; return true;
return false; return false;
}
return true;
case OBBE_1STPERSON: case OBBE_1STPERSON:
return CTimer::GetTimeInMilliseconds() > t+3000; return CTimer::GetTimeInMilliseconds() > t+3000;
case OBBE_5: case OBBE_5:
if(FindPlayerVehicle() && FindPlayerVehicle()->IsBoat()) if(FindPlayerVehicle() && FindPlayerVehicle()->IsBoat())
return true; return true;
if(CWorld::GetIsLineOfSightClear(FindPlayerCoors(), m_vecFixedModeSource, true, false, false, false, false, false, false)){ if(!CWorld::GetIsLineOfSightClear(FindPlayerCoors(), m_vecFixedModeSource, true, false, false, false, false, false, false))
return true;
fwd = FindPlayerCoors() - m_vecFixedModeSource; fwd = FindPlayerCoors() - m_vecFixedModeSource;
fwd.z = 0.0f; fwd.z = 0.0f;
@ -2317,8 +2318,6 @@ CCamera::IsItTimeForNewcam(int32 obbeMode, int32 time)
if(fwd.Magnitude() > 28.0f && DotProduct(FindPlayerSpeed(), fwd) > 0.0f) if(fwd.Magnitude() > 28.0f && DotProduct(FindPlayerSpeed(), fwd) > 0.0f)
return true; return true;
return false; return false;
}
return true;
case OBBE_ONSTRING: case OBBE_ONSTRING:
return CTimer::GetTimeInMilliseconds() > t+3000; return CTimer::GetTimeInMilliseconds() > t+3000;
case OBBE_COPCAR: case OBBE_COPCAR:
@ -2326,17 +2325,18 @@ CCamera::IsItTimeForNewcam(int32 obbeMode, int32 time)
case OBBE_COPCAR_WHEEL: case OBBE_COPCAR_WHEEL:
if(FindPlayerVehicle() && FindPlayerVehicle()->IsBoat()) if(FindPlayerVehicle() && FindPlayerVehicle()->IsBoat())
return true; return true;
if(CWorld::GetIsLineOfSightClear(pTargetEntity->GetPosition(), Cams[ActiveCam].Source, true, false, false, false, false, false, false)){ if(!CWorld::GetIsLineOfSightClear(pTargetEntity->GetPosition(), Cams[ActiveCam].Source, true, false, false, false, false, false, false))
return true;
if(CTimer::GetTimeInMilliseconds() > t+1000) if(CTimer::GetTimeInMilliseconds() > t+1000)
return true; return true;
SetNearClipScript(0.6f); SetNearClipScript(0.6f);
return false; return false;
}
return true;
// Ped modes // Ped modes
case OBBE_9: case OBBE_9:
if(CWorld::GetIsLineOfSightClear(FindPlayerCoors(), m_vecFixedModeSource, true, false, false, false, false, false, false)){ if(!CWorld::GetIsLineOfSightClear(FindPlayerCoors(), m_vecFixedModeSource, true, false, false, false, false, false, false))
return true;
fwd = FindPlayerCoors() - m_vecFixedModeSource; fwd = FindPlayerCoors() - m_vecFixedModeSource;
fwd.z = 0.0f; fwd.z = 0.0f;
@ -2344,10 +2344,10 @@ CCamera::IsItTimeForNewcam(int32 obbeMode, int32 time)
if(fwd.Magnitude() > 20.0f && DotProduct(FindPlayerSpeed(), fwd) > 0.0f) if(fwd.Magnitude() > 20.0f && DotProduct(FindPlayerSpeed(), fwd) > 0.0f)
return true; return true;
return false; return false;
}
return true;
case OBBE_10: case OBBE_10:
if(CWorld::GetIsLineOfSightClear(FindPlayerCoors(), m_vecFixedModeSource, true, false, false, false, false, false, false)){ if(!CWorld::GetIsLineOfSightClear(FindPlayerCoors(), m_vecFixedModeSource, true, false, false, false, false, false, false))
return true;
fwd = FindPlayerCoors() - m_vecFixedModeSource; fwd = FindPlayerCoors() - m_vecFixedModeSource;
fwd.z = 0.0f; fwd.z = 0.0f;
@ -2355,10 +2355,10 @@ CCamera::IsItTimeForNewcam(int32 obbeMode, int32 time)
if(fwd.Magnitude() > 8.0f && DotProduct(FindPlayerSpeed(), fwd) > 0.0f) if(fwd.Magnitude() > 8.0f && DotProduct(FindPlayerSpeed(), fwd) > 0.0f)
return true; return true;
return false; return false;
}
return true;
case OBBE_11: case OBBE_11:
if(CWorld::GetIsLineOfSightClear(FindPlayerCoors(), m_vecFixedModeSource, true, false, false, false, false, false, false)){ if(!CWorld::GetIsLineOfSightClear(FindPlayerCoors(), m_vecFixedModeSource, true, false, false, false, false, false, false))
return true;
fwd = FindPlayerCoors() - m_vecFixedModeSource; fwd = FindPlayerCoors() - m_vecFixedModeSource;
fwd.z = 0.0f; fwd.z = 0.0f;
@ -2366,10 +2366,10 @@ CCamera::IsItTimeForNewcam(int32 obbeMode, int32 time)
if(fwd.Magnitude() > 25.0f && DotProduct(FindPlayerSpeed(), fwd) > 0.0f) if(fwd.Magnitude() > 25.0f && DotProduct(FindPlayerSpeed(), fwd) > 0.0f)
return true; return true;
return false; return false;
}
return true;
case OBBE_12: case OBBE_12:
if(CWorld::GetIsLineOfSightClear(FindPlayerCoors(), m_vecFixedModeSource, true, false, false, false, false, false, false)){ if(!CWorld::GetIsLineOfSightClear(FindPlayerCoors(), m_vecFixedModeSource, true, false, false, false, false, false, false))
return true;
fwd = FindPlayerCoors() - m_vecFixedModeSource; fwd = FindPlayerCoors() - m_vecFixedModeSource;
fwd.z = 0.0f; fwd.z = 0.0f;
@ -2377,8 +2377,6 @@ CCamera::IsItTimeForNewcam(int32 obbeMode, int32 time)
if(fwd.Magnitude() > 8.0f && DotProduct(FindPlayerSpeed(), fwd) > 0.0f) if(fwd.Magnitude() > 8.0f && DotProduct(FindPlayerSpeed(), fwd) > 0.0f)
return true; return true;
return false; return false;
}
return true;
case OBBE_13: case OBBE_13:
return CTimer::GetTimeInMilliseconds() > t+5000; return CTimer::GetTimeInMilliseconds() > t+5000;
default: default:
@ -2653,7 +2651,7 @@ CCamera::TryToStartNewCamMode(int obbeMode)
} }
} }
static int32 SequenceOfCams[16] = { int32 SequenceOfCams[16] = {
OBBE_WHEEL, OBBE_COPCAR, OBBE_3, OBBE_1, OBBE_3, OBBE_COPCAR_WHEEL, OBBE_WHEEL, OBBE_COPCAR, OBBE_3, OBBE_1, OBBE_3, OBBE_COPCAR_WHEEL,
OBBE_2, OBBE_3, OBBE_COPCAR_WHEEL, OBBE_COPCAR, OBBE_2, OBBE_3, OBBE_2, OBBE_3, OBBE_COPCAR_WHEEL, OBBE_COPCAR, OBBE_2, OBBE_3,
OBBE_5, OBBE_3, OBBE_5, OBBE_3,
@ -2689,7 +2687,7 @@ CCamera::ProcessObbeCinemaCameraCar(void)
bDidWeProcessAnyCinemaCam = true; bDidWeProcessAnyCinemaCam = true;
} }
static int32 SequenceOfPedCams[5] = { OBBE_9, OBBE_10, OBBE_11, OBBE_12, OBBE_13 }; int32 SequenceOfPedCams[5] = { OBBE_9, OBBE_10, OBBE_11, OBBE_12, OBBE_13 };
void void
CCamera::ProcessObbeCinemaCameraPed(void) CCamera::ProcessObbeCinemaCameraPed(void)
@ -3282,12 +3280,13 @@ CCamera::UpdateAimingCoors(CVector const &coors)
m_cvecAimingTargetCoors = coors; m_cvecAimingTargetCoors = coors;
} }
void bool
CCamera::Find3rdPersonCamTargetVector(float dist, CVector pos, CVector &source, CVector &target) CCamera::Find3rdPersonCamTargetVector(float dist, CVector pos, CVector &source, CVector &target)
{ {
if(CPad::GetPad(0)->GetLookBehindForPed()){ if(CPad::GetPad(0)->GetLookBehindForPed()){
source = pos; source = pos;
target = dist*Cams[ActiveCam].CamTargetEntity->GetForward() + source; target = dist*Cams[ActiveCam].CamTargetEntity->GetForward() + source;
return false;
}else{ }else{
float angleX = DEGTORAD((m_f3rdPersonCHairMultX-0.5f) * 1.8f * 0.5f * Cams[ActiveCam].FOV * CDraw::GetAspectRatio()); float angleX = DEGTORAD((m_f3rdPersonCHairMultX-0.5f) * 1.8f * 0.5f * Cams[ActiveCam].FOV * CDraw::GetAspectRatio());
float angleY = DEGTORAD((0.5f-m_f3rdPersonCHairMultY) * 1.8f * 0.5f * Cams[ActiveCam].FOV); float angleY = DEGTORAD((0.5f-m_f3rdPersonCHairMultY) * 1.8f * 0.5f * Cams[ActiveCam].FOV);
@ -3296,9 +3295,9 @@ CCamera::Find3rdPersonCamTargetVector(float dist, CVector pos, CVector &source,
target += Cams[ActiveCam].Up * Tan(angleY); target += Cams[ActiveCam].Up * Tan(angleY);
target += CrossProduct(Cams[ActiveCam].Front, Cams[ActiveCam].Up) * Tan(angleX); target += CrossProduct(Cams[ActiveCam].Front, Cams[ActiveCam].Up) * Tan(angleX);
target.Normalise(); target.Normalise();
float dot = DotProduct(pos - source, target); source += DotProduct(pos - source, target)*target;
source += dot*target;
target = dist*target + source; target = dist*target + source;
return true;
} }
} }

View File

@ -624,7 +624,7 @@ public:
void SetNewPlayerWeaponMode(int16 mode, int16 minZoom, int16 maxZoom); void SetNewPlayerWeaponMode(int16 mode, int16 minZoom, int16 maxZoom);
void ClearPlayerWeaponMode(void); void ClearPlayerWeaponMode(void);
void UpdateAimingCoors(CVector const &coors); void UpdateAimingCoors(CVector const &coors);
void Find3rdPersonCamTargetVector(float dist, CVector pos, CVector &source, CVector &target); bool Find3rdPersonCamTargetVector(float dist, CVector pos, CVector &source, CVector &target);
float Find3rdPersonQuickAimPitch(void); float Find3rdPersonQuickAimPitch(void);
// Physical camera // Physical camera