mirror of
https://github.com/GTAmodding/re3.git
synced 2021-02-19 17:49:54 +01:00
Make free cam collision code readable by aap, fixes
This commit is contained in:
parent
6d3adf57e8
commit
64b509af52
108
src/core/Cam.cpp
108
src/core/Cam.cpp
@ -3003,8 +3003,7 @@ CCam::Process_Sniper(const CVector &CameraTarget, float TargetOrientation, float
|
|||||||
UseMouse = false;
|
UseMouse = false;
|
||||||
int ZoomInButton = ControlsManager.GetMouseButtonAssociatedWithAction(PED_SNIPER_ZOOM_IN);
|
int ZoomInButton = ControlsManager.GetMouseButtonAssociatedWithAction(PED_SNIPER_ZOOM_IN);
|
||||||
int ZoomOutButton = ControlsManager.GetMouseButtonAssociatedWithAction(PED_SNIPER_ZOOM_OUT);
|
int ZoomOutButton = ControlsManager.GetMouseButtonAssociatedWithAction(PED_SNIPER_ZOOM_OUT);
|
||||||
// TODO: enum? this should be mouse wheel up and down
|
if(ZoomInButton == rsMOUSEWHEELUPBUTTON || ZoomInButton == rsMOUSEWHEELDOWNBUTTON || ZoomOutButton == rsMOUSEWHEELUPBUTTON || ZoomOutButton == rsMOUSEWHEELDOWNBUTTON){
|
||||||
if(ZoomInButton == 4 || ZoomInButton == 5 || ZoomOutButton == 4 || ZoomOutButton == 5){
|
|
||||||
if(CPad::GetPad(0)->GetMouseWheelUp() || CPad::GetPad(0)->GetMouseWheelDown()){
|
if(CPad::GetPad(0)->GetMouseWheelUp() || CPad::GetPad(0)->GetMouseWheelDown()){
|
||||||
if(CPad::GetPad(0)->SniperZoomIn()){
|
if(CPad::GetPad(0)->SniperZoomIn()){
|
||||||
TargetFOV = FOV - 10.0f;
|
TargetFOV = FOV - 10.0f;
|
||||||
@ -4894,13 +4893,9 @@ CCam::Process_FollowCar_SA(const CVector& CameraTarget, float TargetOrientation,
|
|||||||
|
|
||||||
if (FOV > DefaultFOV)
|
if (FOV > DefaultFOV)
|
||||||
// 0.98f: CAR_FOV_FADE_MULT
|
// 0.98f: CAR_FOV_FADE_MULT
|
||||||
FOV = pow(0.98f, CTimer::GetTimeStep()) * (FOV - DefaultFOV) + DefaultFOV;
|
FOV = Pow(0.98f, CTimer::GetTimeStep()) * (FOV - DefaultFOV) + DefaultFOV;
|
||||||
|
|
||||||
if (FOV <= DefaultFOV + 30.0f) {
|
FOV = clamp(FOV, DefaultFOV, DefaultFOV + 30.0f);
|
||||||
if (FOV < DefaultFOV)
|
|
||||||
FOV = DefaultFOV;
|
|
||||||
} else
|
|
||||||
FOV = DefaultFOV + 30.0f;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// WORKAROUND: I still don't know how looking behind works (m_bCamDirectlyInFront is unused in III, they seem to use m_bUseTransitionBeta)
|
// WORKAROUND: I still don't know how looking behind works (m_bCamDirectlyInFront is unused in III, they seem to use m_bUseTransitionBeta)
|
||||||
@ -5030,7 +5025,7 @@ CCam::Process_FollowCar_SA(const CVector& CameraTarget, float TargetOrientation,
|
|||||||
targetAlpha = maxAlphaAllowed;
|
targetAlpha = maxAlphaAllowed;
|
||||||
}
|
}
|
||||||
float maxAlphaBlendAmount = CTimer::GetTimeStep() * CARCAM_SET[camSetArrPos][6];
|
float maxAlphaBlendAmount = CTimer::GetTimeStep() * CARCAM_SET[camSetArrPos][6];
|
||||||
float targetAlphaBlendAmount = (1.0f - pow(CARCAM_SET[camSetArrPos][5], CTimer::GetTimeStep())) * (targetAlpha - Alpha);
|
float targetAlphaBlendAmount = (1.0f - Pow(CARCAM_SET[camSetArrPos][5], CTimer::GetTimeStep())) * (targetAlpha - Alpha);
|
||||||
if (targetAlphaBlendAmount <= maxAlphaBlendAmount) {
|
if (targetAlphaBlendAmount <= maxAlphaBlendAmount) {
|
||||||
if (targetAlphaBlendAmount < -maxAlphaBlendAmount)
|
if (targetAlphaBlendAmount < -maxAlphaBlendAmount)
|
||||||
targetAlphaBlendAmount = -maxAlphaBlendAmount;
|
targetAlphaBlendAmount = -maxAlphaBlendAmount;
|
||||||
@ -5122,7 +5117,7 @@ CCam::Process_FollowCar_SA(const CVector& CameraTarget, float TargetOrientation,
|
|||||||
float betaSpeedFromStickX = xMovement * CARCAM_SET[camSetArrPos][12];
|
float betaSpeedFromStickX = xMovement * CARCAM_SET[camSetArrPos][12];
|
||||||
|
|
||||||
float newAngleSpeedMaxBlendAmount = CARCAM_SET[camSetArrPos][9];
|
float newAngleSpeedMaxBlendAmount = CARCAM_SET[camSetArrPos][9];
|
||||||
float angleChangeStep = pow(CARCAM_SET[camSetArrPos][8], CTimer::GetTimeStep());
|
float angleChangeStep = Pow(CARCAM_SET[camSetArrPos][8], CTimer::GetTimeStep());
|
||||||
float targetBetaWithStickBlendAmount = betaSpeedFromStickX + (targetBeta - Beta) / Max(CTimer::GetTimeStep(), 1.0f);
|
float targetBetaWithStickBlendAmount = betaSpeedFromStickX + (targetBeta - Beta) / Max(CTimer::GetTimeStep(), 1.0f);
|
||||||
|
|
||||||
if (targetBetaWithStickBlendAmount < -newAngleSpeedMaxBlendAmount)
|
if (targetBetaWithStickBlendAmount < -newAngleSpeedMaxBlendAmount)
|
||||||
@ -5234,75 +5229,76 @@ CCam::Process_FollowCar_SA(const CVector& CameraTarget, float TargetOrientation,
|
|||||||
// SA calls SetColVarsVehicle in here
|
// SA calls SetColVarsVehicle in here
|
||||||
if (nextDirectionIsForward) {
|
if (nextDirectionIsForward) {
|
||||||
|
|
||||||
// This is new in LCS!
|
// LCS uses exactly the same collision code as FollowPedWithMouse, so we will do so.
|
||||||
|
|
||||||
|
// This is only in LCS!
|
||||||
float timestepFactor = Pow(0.99f, CTimer::GetTimeStep());
|
float timestepFactor = Pow(0.99f, CTimer::GetTimeStep());
|
||||||
dontCollideWithCars = (timestepFactor * dontCollideWithCars) + ((1.0f - timestepFactor) * car->m_vecMoveSpeed.Magnitude());
|
dontCollideWithCars = (timestepFactor * dontCollideWithCars) + ((1.0f - timestepFactor) * car->m_vecMoveSpeed.Magnitude());
|
||||||
|
|
||||||
// Our addition
|
// Our addition
|
||||||
#define IS_TRAFFIC_LIGHT(ent) (ent->IsObject() && (IsStreetLight(ent->GetModelIndex())))
|
#define IS_TRAFFIC_LIGHT(ent) (ent->IsObject() && (IsStreetLight(ent->GetModelIndex())))
|
||||||
|
|
||||||
// Move cam if on collision
|
// Clip Source and fix near clip
|
||||||
CColPoint foundCol;
|
CColPoint colPoint;
|
||||||
CEntity* foundEnt;
|
CEntity* entity;
|
||||||
CWorld::pIgnoreEntity = CamTargetEntity;
|
CWorld::pIgnoreEntity = CamTargetEntity;
|
||||||
if (CWorld::ProcessLineOfSight(TargetCoors, Source, foundCol, foundEnt, true, dontCollideWithCars < 0.1f, false, true, false, true, false) && !IS_TRAFFIC_LIGHT(foundEnt)) {
|
if(CWorld::ProcessLineOfSight(TargetCoors, Source, colPoint, entity, true, dontCollideWithCars < 0.1f, false, true, false, true, true) && !IS_TRAFFIC_LIGHT(entity)){
|
||||||
float obstacleTargetDist = (TargetCoors - foundCol.point).Magnitude();
|
float PedColDist = (TargetCoors - colPoint.point).Magnitude();
|
||||||
float obstacleCamDist = newDistance - obstacleTargetDist;
|
float ColCamDist = newDistance - PedColDist;
|
||||||
if (!foundEnt->IsPed() || obstacleCamDist <= 1.0f) {
|
if(entity->IsPed() && ColCamDist > DEFAULT_NEAR + 0.1f){
|
||||||
Source = foundCol.point;
|
// Ped in the way but not clipping through
|
||||||
if (obstacleTargetDist < 1.2f) {
|
if(CWorld::ProcessLineOfSight(colPoint.point, Source, colPoint, entity, true, dontCollideWithCars < 0.1f, false, true, false, true, true) || IS_TRAFFIC_LIGHT(entity)){
|
||||||
RwCameraSetNearClipPlane(Scene.camera, Max(0.05f, obstacleTargetDist - 0.3f));
|
PedColDist = (TargetCoors - colPoint.point).Magnitude();
|
||||||
|
Source = colPoint.point;
|
||||||
|
if(PedColDist < DEFAULT_NEAR + 0.3f)
|
||||||
|
RwCameraSetNearClipPlane(Scene.camera, Max(PedColDist-0.3f, 0.05f));
|
||||||
|
}else{
|
||||||
|
RwCameraSetNearClipPlane(Scene.camera, Min(ColCamDist-0.35f, DEFAULT_NEAR));
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
if (!CWorld::ProcessLineOfSight(foundCol.point, Source, foundCol, foundEnt, true, dontCollideWithCars < 0.1f, false, true, false, true, false) || IS_TRAFFIC_LIGHT(foundEnt)) {
|
Source = colPoint.point;
|
||||||
float lessClip = obstacleCamDist - 0.35f;
|
if(PedColDist < DEFAULT_NEAR + 0.3f)
|
||||||
if (lessClip <= DEFAULT_NEAR)
|
RwCameraSetNearClipPlane(Scene.camera, Max(PedColDist-0.3f, 0.05f));
|
||||||
RwCameraSetNearClipPlane(Scene.camera, lessClip);
|
|
||||||
else
|
|
||||||
RwCameraSetNearClipPlane(Scene.camera, DEFAULT_NEAR);
|
|
||||||
} else {
|
|
||||||
obstacleTargetDist = (TargetCoors - foundCol.point).Magnitude();
|
|
||||||
Source = foundCol.point;
|
|
||||||
if (obstacleTargetDist < 1.2f) {
|
|
||||||
float lessClip = obstacleTargetDist - 0.3f;
|
|
||||||
if (lessClip >= 0.05f)
|
|
||||||
RwCameraSetNearClipPlane(Scene.camera, lessClip);
|
|
||||||
else
|
|
||||||
RwCameraSetNearClipPlane(Scene.camera, 0.05f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CWorld::pIgnoreEntity = nil;
|
CWorld::pIgnoreEntity = nil;
|
||||||
float nearClip = RwCameraGetNearClipPlane(Scene.camera);
|
|
||||||
float radius = Tan(DEGTORAD(FOV * 0.5f)) * CDraw::GetAspectRatio() * 1.1f;
|
|
||||||
|
|
||||||
// If we're seeing blue hell due to camera intersects some surface, fix it.
|
// If we're seeing blue hell due to camera intersects some surface, fix it.
|
||||||
// SA and LCS have this unrolled.
|
// SA and LCS have this unrolled.
|
||||||
for (int i = 0;
|
|
||||||
i <= 5 && (foundEnt = CWorld::TestSphereAgainstWorld((nearClip * Front) + Source, radius * nearClip, nil, true, true, false, true, false, false));
|
|
||||||
i++) {
|
|
||||||
|
|
||||||
if (IS_TRAFFIC_LIGHT(foundEnt))
|
float ViewPlaneHeight = Tan(DEGTORAD(FOV) / 2.0f);
|
||||||
|
float ViewPlaneWidth = ViewPlaneHeight * CDraw::FindAspectRatio() * fTweakFOV;
|
||||||
|
float Near = RwCameraGetNearClipPlane(Scene.camera);
|
||||||
|
float radius = ViewPlaneWidth*Near;
|
||||||
|
entity = CWorld::TestSphereAgainstWorld(Source + Front*Near, radius, nil, true, true, false, true, false, true);
|
||||||
|
int i = 0;
|
||||||
|
while(entity){
|
||||||
|
|
||||||
|
if (IS_TRAFFIC_LIGHT(entity))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
CVector surfaceCamDist = gaTempSphereColPoints->point - Source;
|
CVector CamToCol = gaTempSphereColPoints[0].point - Source;
|
||||||
CVector frontButInvertedIfTouchesSurface = DotProduct(surfaceCamDist, Front) * Front;
|
float frontDist = DotProduct(CamToCol, Front);
|
||||||
float newNearClip = (surfaceCamDist - frontButInvertedIfTouchesSurface).Magnitude() / radius;
|
float dist = (CamToCol - Front*frontDist).Magnitude() / ViewPlaneWidth;
|
||||||
|
|
||||||
if (newNearClip > nearClip)
|
// Try to decrease near clip
|
||||||
newNearClip = nearClip;
|
dist = Max(Min(Near, dist), 0.1f);
|
||||||
if (newNearClip < 0.1f)
|
if(dist < Near)
|
||||||
newNearClip = 0.1f;
|
RwCameraSetNearClipPlane(Scene.camera, dist);
|
||||||
if (nearClip > newNearClip)
|
|
||||||
RwCameraSetNearClipPlane(Scene.camera, newNearClip);
|
|
||||||
|
|
||||||
if (newNearClip == 0.1f)
|
// Move forward a bit
|
||||||
|
if(dist == 0.1f)
|
||||||
Source += (TargetCoors - Source)*0.3f;
|
Source += (TargetCoors - Source)*0.3f;
|
||||||
|
|
||||||
nearClip = RwCameraGetNearClipPlane(Scene.camera);
|
// Keep testing
|
||||||
radius = Tan(DEGTORAD(FOV * 0.5f)) * CDraw::GetAspectRatio() * 1.1f;
|
Near = RwCameraGetNearClipPlane(Scene.camera);
|
||||||
|
radius = ViewPlaneWidth*Near;
|
||||||
|
entity = CWorld::TestSphereAgainstWorld(Source + Front*Near, radius, nil, true, true, false, true, false, true);
|
||||||
|
|
||||||
|
i++;
|
||||||
|
if(i > 5)
|
||||||
|
entity = nil;
|
||||||
}
|
}
|
||||||
#undef IS_TRAFFIC_LIGHT
|
#undef IS_TRAFFIC_LIGHT
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user