forked from 0ad/0ad
Fix #554 (camera should be always inside the terrain), based on patch from markelov
This was SVN commit r8070.
This commit is contained in:
parent
6ceee8a5ec
commit
0fa0181f0c
@ -60,6 +60,7 @@ const float CGameView::defaultFOV = DEGTORAD(20.f);
|
||||
const float CGameView::defaultNear = 4.f;
|
||||
const float CGameView::defaultFar = 4096.f;
|
||||
const float CGameView::defaultCullFOV = CGameView::defaultFOV + DEGTORAD(6.0f); //add 6 degrees to the default FOV for use with the culling frustum
|
||||
const float CGameView::cameraPivotMargin = 20.0f;
|
||||
|
||||
/**
|
||||
* A value with exponential decay towards the target value.
|
||||
@ -667,6 +668,25 @@ void CGameView::Update(float DeltaTime)
|
||||
|
||||
ClampDistance(m, true);
|
||||
|
||||
// Ensure the ViewCamera focus is inside the map with the chosen margins
|
||||
// if not so - apply margins to the camera
|
||||
if (m->ConstrainCamera)
|
||||
{
|
||||
CCamera targetCam = m->ViewCamera;
|
||||
SetupCameraMatrix(m, &targetCam.m_Orientation);
|
||||
|
||||
CTerrain* pTerrain = m->Game->GetWorld()->GetTerrain();
|
||||
float min_x = pTerrain->GetMinX() + cameraPivotMargin;
|
||||
float max_x = pTerrain->GetMaxX() - cameraPivotMargin;
|
||||
float min_z = pTerrain->GetMinZ() + cameraPivotMargin;
|
||||
float max_z = pTerrain->GetMaxZ() - cameraPivotMargin;
|
||||
|
||||
// Clamp so that pos+in is within the margin
|
||||
CVector3D in = targetCam.m_Orientation.GetIn() * m->ViewZoomDefault;
|
||||
m->PosX.ClampSmoothly(min_x - in.X, max_x - in.X);
|
||||
m->PosZ.ClampSmoothly(min_z - in.Z, max_z - in.Z);
|
||||
}
|
||||
|
||||
m->PosX.Update(DeltaTime);
|
||||
m->PosY.Update(DeltaTime);
|
||||
m->PosZ.Update(DeltaTime);
|
||||
|
@ -44,6 +44,7 @@ public:
|
||||
static const float defaultFOV, defaultCullFOV, defaultNear, defaultFar;
|
||||
|
||||
private:
|
||||
static const float cameraPivotMargin;
|
||||
CGameViewImpl* m;
|
||||
|
||||
// Check whether lighting environment has changed and update vertex data if necessary
|
||||
|
@ -66,10 +66,15 @@ public:
|
||||
// return number of patches along edge of the terrain
|
||||
ssize_t GetPatchesPerSide() const { return m_MapSizePatches; }
|
||||
|
||||
float GetMinX() const { return 0.0f; }
|
||||
float GetMinZ() const { return 0.0f; }
|
||||
float GetMaxX() const { return (float)((m_MapSize-1) * CELL_SIZE); }
|
||||
float GetMaxZ() const { return (float)((m_MapSize-1) * CELL_SIZE); }
|
||||
|
||||
bool IsOnMap(float x, float z) const
|
||||
{
|
||||
return ((x >= 0.0f) && (x < (float)((m_MapSize-1) * CELL_SIZE))
|
||||
&& (z >= 0.0f) && (z < (float)((m_MapSize-1) * CELL_SIZE)));
|
||||
return ((x >= GetMinX()) && (x < GetMaxX())
|
||||
&& (z >= GetMinZ()) && (z < GetMaxZ()));
|
||||
}
|
||||
|
||||
CStr8 GetMovementClass(ssize_t i, ssize_t j) const;
|
||||
|
Loading…
Reference in New Issue
Block a user