Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
[sea_cameras] Better ship camera parameters calculation
Browse files Browse the repository at this point in the history
- Immersion considered
- Base camera centration clamped by hull height proportion
- Bottom view uses real height and applied after clamping
  • Loading branch information
espkk committed Mar 28, 2022
1 parent 900a9a0 commit f5840a0
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/libs/sea_cameras/src/ship_camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,16 @@ void SHIP_CAMERA::Move(float fDeltaTime)
if (vAng.x > fMaxAngleX)
vAng.x = fMaxAngleX;

// Current distance
auto boxSize =
GetAIObj()->GetBoxsize() * CVECTOR(SCMR_BOXSCALE_X * 0.5f, SCMR_BOXSCALE_Y * 0.5f, SCMR_BOXSCALE_Z * 0.5f);
boxSize.x += boxSize.y;
boxSize.z += boxSize.y;
auto *modelMtx = GetAIObj()->GetMatrix();
auto boxSize = GetAIObj()->GetBoxsize();
// Recalculate box size: (box size + immersion) * hand-fitted scale
boxSize.y += modelMtx->pos.y;
boxSize *= CVECTOR(SCMR_BOXSCALE_X * 0.5f, SCMR_BOXSCALE_Y * 0.5f, SCMR_BOXSCALE_Z * 0.5f);
// Project real height (with masts)
const auto realBoxSize = GetAIObj()->GetRealBoxsize();
boxSize.x += realBoxSize.y;
boxSize.z += realBoxSize.y;

const auto maxRad = boxSize.z * 2.0f;
// Semi-axes of the ellipsoid along which the camera moves
a = boxSize.x * 1.2f + fDistance * (maxRad - boxSize.x * 1.2f); // x
Expand All @@ -170,8 +175,10 @@ void SHIP_CAMERA::Move(float fDeltaTime)
vPos.z = c * cosf(vAng.y);
}
vPos = CMatrix(CVECTOR(0.0f, fModelAy, 0.0f), vCenter) * vPos;
vCenter.y += fDistance * 2.0f * boxSize.y;
vCenter.y = std::min(vCenter.y, boxSize.y);
if (vAng.x > 0.0f)
vCenter.y += boxSize.z * vAng.x * 6.0f;
vCenter.y += realBoxSize.y * vAng.x * 6.0f;
// Limit the height from the bottom
const auto fWaveY = pSea->WaveXZ(vPos.x, vPos.z);
if (vPos.y - fWaveY < fMinHeightOnSea)
Expand All @@ -188,7 +195,6 @@ void SHIP_CAMERA::Move(float fDeltaTime)
if (vPos.y > oldPosY)
vCenter.y += vPos.y - oldPosY;
// Set new camera
vCenter.y += fDistance * 2.0f * boxSize.y;
pRS->SetCamera(vPos, vCenter, CVECTOR(0.0f, 1.0f, 0.0f));
pRS->SetPerspective(GetPerspective());
}
Expand Down

0 comments on commit f5840a0

Please sign in to comment.