Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/graphics/GameView.cpp
Show First 20 Lines • Show All 575 Lines • ▼ Show 20 Lines | static void FocusHeight(CGameViewImpl* m, bool smooth) | ||||
// horizontal view radius | // horizontal view radius | ||||
const float radius = sqrtf(forwards.X * forwards.X + forwards.Z * forwards.Z) * m->Zoom.GetSmoothedValue(); | const float radius = sqrtf(forwards.X * forwards.X + forwards.Z * forwards.Z) * m->Zoom.GetSmoothedValue(); | ||||
const float near_radius = radius * m->HeightSmoothness; | const float near_radius = radius * m->HeightSmoothness; | ||||
const float pivot_radius = radius * m->HeightSmoothness; | const float pivot_radius = radius * m->HeightSmoothness; | ||||
const CVector3D nearPoint = position + forwards * m->ViewNear; | const CVector3D nearPoint = position + forwards * m->ViewNear; | ||||
const CVector3D pivotPoint = position + forwards * m->Zoom.GetSmoothedValue(); | const CVector3D pivotPoint = position + forwards * m->Zoom.GetSmoothedValue(); | ||||
const float ground = m->Game->GetWorld()->GetTerrain()->GetExactGroundLevel(nearPoint.X, nearPoint.Z); | const float ground = std::max( | ||||
m->Game->GetWorld()->GetTerrain()->GetExactGroundLevel(nearPoint.X, nearPoint.Z), | |||||
g_Renderer.GetWaterManager()->m_WaterHeight); | |||||
// filter ground levels for smooth camera movement | // filter ground levels for smooth camera movement | ||||
const float filtered_near_ground = m->Game->GetWorld()->GetTerrain()->GetFilteredGroundLevel(nearPoint.X, nearPoint.Z, near_radius); | const float filtered_near_ground = m->Game->GetWorld()->GetTerrain()->GetFilteredGroundLevel(nearPoint.X, nearPoint.Z, near_radius); | ||||
const float filtered_pivot_ground = m->Game->GetWorld()->GetTerrain()->GetFilteredGroundLevel(pivotPoint.X, pivotPoint.Z, pivot_radius); | const float filtered_pivot_ground = m->Game->GetWorld()->GetTerrain()->GetFilteredGroundLevel(pivotPoint.X, pivotPoint.Z, pivot_radius); | ||||
// filtered maximum visible ground level in view | // filtered maximum visible ground level in view | ||||
const float filtered_ground = std::max(filtered_near_ground, filtered_pivot_ground); | const float filtered_ground = std::max( | ||||
std::max(filtered_near_ground, filtered_pivot_ground), | |||||
g_Renderer.GetWaterManager()->m_WaterHeight); | |||||
// target camera height above pivot point | // target camera height above pivot point | ||||
const float pivot_height = -forwards.Y * (m->Zoom.GetSmoothedValue() - m->ViewNear); | const float pivot_height = -forwards.Y * (m->Zoom.GetSmoothedValue() - m->ViewNear); | ||||
// minimum camera height above filtered ground level | // minimum camera height above filtered ground level | ||||
const float min_height = (m->HeightMin + ground - filtered_ground); | const float min_height = (m->HeightMin + ground - filtered_ground); | ||||
const float target_height = std::max(pivot_height, min_height); | const float target_height = std::max(pivot_height, min_height); | ||||
const float height = (nearPoint.Y - filtered_ground); | const float height = (nearPoint.Y - filtered_ground); | ||||
const float diff = target_height - height; | const float diff = target_height - height; | ||||
if (fabsf(diff) < 0.0001f) | if (fabsf(diff) < 0.0001f) | ||||
return; | return; | ||||
if (smooth) | if (smooth) | ||||
{ | |||||
m->PosY.AddSmoothly(diff); | m->PosY.AddSmoothly(diff); | ||||
} | |||||
else | else | ||||
{ | |||||
m->PosY.Add(diff); | m->PosY.Add(diff); | ||||
} | } | ||||
} | |||||
CVector3D CGameView::GetSmoothPivot(CCamera& camera) const | CVector3D CGameView::GetSmoothPivot(CCamera& camera) const | ||||
{ | { | ||||
return camera.m_Orientation.GetTranslation() + camera.m_Orientation.GetIn() * m->Zoom.GetSmoothedValue(); | return camera.m_Orientation.GetTranslation() + camera.m_Orientation.GetIn() * m->Zoom.GetSmoothedValue(); | ||||
} | } | ||||
void CGameView::Update(const float deltaRealTime) | void CGameView::Update(const float deltaRealTime) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 534 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator