Changeset View
Changeset View
Standalone View
Standalone View
source/graphics/CameraController.cpp
Show All 13 Lines | |||||
* You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | ||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | ||||
*/ | */ | ||||
#include "precompiled.h" | #include "precompiled.h" | ||||
#include "CameraController.h" | #include "CameraController.h" | ||||
#include "graphics/GameView.h" | |||||
#include "graphics/HFTracer.h" | #include "graphics/HFTracer.h" | ||||
#include "graphics/Terrain.h" | #include "graphics/Terrain.h" | ||||
#include "graphics/WaterManager.h" | |||||
#include "graphics/scripting/JSInterface_GameView.h" | #include "graphics/scripting/JSInterface_GameView.h" | ||||
#include "lib/input.h" | #include "lib/input.h" | ||||
#include "lib/timer.h" | #include "lib/timer.h" | ||||
#include "maths/MathUtil.h" | #include "maths/MathUtil.h" | ||||
#include "maths/Matrix3D.h" | #include "maths/Matrix3D.h" | ||||
#include "maths/Quaternion.h" | #include "maths/Quaternion.h" | ||||
#include "ps/ConfigDB.h" | #include "ps/ConfigDB.h" | ||||
#include "ps/Game.h" | #include "ps/Game.h" | ||||
#include "ps/Globals.h" | #include "ps/Globals.h" | ||||
#include "ps/Hotkey.h" | #include "ps/Hotkey.h" | ||||
#include "ps/Joystick.h" | #include "ps/Joystick.h" | ||||
#include "ps/Pyrogenesis.h" | #include "ps/Pyrogenesis.h" | ||||
#include "ps/TouchInput.h" | #include "ps/TouchInput.h" | ||||
#include "ps/World.h" | #include "ps/World.h" | ||||
#include "renderer/Renderer.h" | #include "renderer/Renderer.h" | ||||
#include "renderer/WaterManager.h" | |||||
#include "simulation2/Simulation2.h" | #include "simulation2/Simulation2.h" | ||||
phosit: Not required anymore | |||||
#include "simulation2/components/ICmpPosition.h" | #include "simulation2/components/ICmpPosition.h" | ||||
#include "simulation2/components/ICmpRangeManager.h" | #include "simulation2/components/ICmpRangeManager.h" | ||||
#include "simulation2/helpers/Los.h" | #include "simulation2/helpers/Los.h" | ||||
extern int g_xres, g_yres; | extern int g_xres, g_yres; | ||||
// Maximum distance outside the edge of the map that the camera's | // Maximum distance outside the edge of the map that the camera's | ||||
// focus point can be moved | // focus point can be moved | ||||
▲ Show 20 Lines • Show All 553 Lines • ▼ Show 20 Lines | void CCameraController::FocusHeight(bool smooth) | ||||
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 = std::max( | const float ground = std::max( | ||||
g_Game->GetWorld()->GetTerrain()->GetExactGroundLevel(nearPoint.X, nearPoint.Z), | g_Game->GetWorld()->GetTerrain()->GetExactGroundLevel(nearPoint.X, nearPoint.Z), | ||||
g_Renderer.GetWaterManager()->m_WaterHeight); | g_Game->GetView()->GetWaterManager().GetWaterHeight()); | ||||
// filter ground levels for smooth camera movement | // filter ground levels for smooth camera movement | ||||
const float filtered_near_ground = g_Game->GetWorld()->GetTerrain()->GetFilteredGroundLevel(nearPoint.X, nearPoint.Z, near_radius); | const float filtered_near_ground = g_Game->GetWorld()->GetTerrain()->GetFilteredGroundLevel(nearPoint.X, nearPoint.Z, near_radius); | ||||
const float filtered_pivot_ground = g_Game->GetWorld()->GetTerrain()->GetFilteredGroundLevel(pivotPoint.X, pivotPoint.Z, pivot_radius); | const float filtered_pivot_ground = g_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( | const float filtered_ground = std::max( | ||||
std::max(filtered_near_ground, filtered_pivot_ground), | std::max(filtered_near_ground, filtered_pivot_ground), | ||||
g_Renderer.GetWaterManager()->m_WaterHeight); | g_Game->GetView()->GetWaterManager().GetWaterHeight()); | ||||
// 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); | ||||
▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Not required anymore