Changeset View
Changeset View
Standalone View
Standalone View
source/graphics/Camera.cpp
Show All 18 Lines | |||||
* CCamera holds a view and a projection matrix. It also has a frustum | * CCamera holds a view and a projection matrix. It also has a frustum | ||||
* which can be used to cull objects for rendering. | * which can be used to cull objects for rendering. | ||||
*/ | */ | ||||
#include "precompiled.h" | #include "precompiled.h" | ||||
#include "Camera.h" | #include "Camera.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 "lib/ogl.h" | #include "lib/ogl.h" | ||||
#include "maths/MathUtil.h" | #include "maths/MathUtil.h" | ||||
#include "maths/Vector4D.h" | #include "maths/Vector4D.h" | ||||
#include "ps/Game.h" | #include "ps/Game.h" | ||||
#include "ps/World.h" | #include "ps/World.h" | ||||
#include "renderer/Renderer.h" | #include "renderer/Renderer.h" | ||||
#include "renderer/WaterManager.h" | |||||
phosit: Not required anymore | |||||
CCamera::CCamera() | CCamera::CCamera() | ||||
: m_NearPlane(0.0f), m_FarPlane(0.0f), m_FOV(0.0f), m_ProjType(CUSTOM) | : m_NearPlane(0.0f), m_FarPlane(0.0f), m_FOV(0.0f), m_ProjType(CUSTOM) | ||||
{ | { | ||||
// Set viewport to something anything should handle, but should be initialised | // Set viewport to something anything should handle, but should be initialised | ||||
// to window size before use. | // to window size before use. | ||||
m_ViewPort.m_X = 0; | m_ViewPort.m_X = 0; | ||||
m_ViewPort.m_Y = 0; | m_ViewPort.m_Y = 0; | ||||
m_ViewPort.m_Width = 800; | m_ViewPort.m_Width = 800; | ||||
▲ Show 20 Lines • Show All 179 Lines • ▼ Show 20 Lines | if (!aboveWater) | ||||
// Off the edge of the world? | // Off the edge of the world? | ||||
// Work out where it /would/ hit, if the map were extended out to infinity with average height. | // Work out where it /would/ hit, if the map were extended out to infinity with average height. | ||||
return GetWorldCoordinates(px, py, 50.0f); | return GetWorldCoordinates(px, py, 50.0f); | ||||
} | } | ||||
CPlane plane; | CPlane plane; | ||||
plane.Set(CVector3D(0.f, 1.f, 0.f), // upwards normal | plane.Set(CVector3D(0.f, 1.f, 0.f), // upwards normal | ||||
CVector3D(0.f, g_Renderer.GetWaterManager()->m_WaterHeight, 0.f)); // passes through water plane | CVector3D(0.f, g_Game->GetView()->GetWaterManager().GetWaterHeight(), 0.f)); // passes through water plane | ||||
bool gotWater = plane.FindRayIntersection( origin, dir, &waterPoint ); | bool gotWater = plane.FindRayIntersection( origin, dir, &waterPoint ); | ||||
// Clamp the water intersection to within the map's bounds, so that | // Clamp the water intersection to within the map's bounds, so that | ||||
// we'll always return a valid position on the map | // we'll always return a valid position on the map | ||||
ssize_t mapSize = g_Game->GetWorld()->GetTerrain()->GetVerticesPerSide(); | ssize_t mapSize = g_Game->GetWorld()->GetTerrain()->GetVerticesPerSide(); | ||||
if (gotWater) | if (gotWater) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | CVector3D CCamera::GetFocus() const | ||||
origin = m_Orientation.GetTranslation(); | origin = m_Orientation.GetTranslation(); | ||||
dir = m_Orientation.GetIn(); | dir = m_Orientation.GetIn(); | ||||
bool gotTerrain = tracer.RayIntersect(origin, dir, x, z, terrainPoint); | bool gotTerrain = tracer.RayIntersect(origin, dir, x, z, terrainPoint); | ||||
CPlane plane; | CPlane plane; | ||||
plane.Set(CVector3D(0.f, 1.f, 0.f), // upwards normal | plane.Set(CVector3D(0.f, 1.f, 0.f), // upwards normal | ||||
CVector3D(0.f, g_Renderer.GetWaterManager()->m_WaterHeight, 0.f)); // passes through water plane | CVector3D(0.f, g_Game->GetView()->GetWaterManager().GetWaterHeight(), 0.f)); // passes through water plane | ||||
bool gotWater = plane.FindRayIntersection( origin, dir, &waterPoint ); | bool gotWater = plane.FindRayIntersection( origin, dir, &waterPoint ); | ||||
// Clamp the water intersection to within the map's bounds, so that | // Clamp the water intersection to within the map's bounds, so that | ||||
// we'll always return a valid position on the map | // we'll always return a valid position on the map | ||||
ssize_t mapSize = g_Game->GetWorld()->GetTerrain()->GetVerticesPerSide(); | ssize_t mapSize = g_Game->GetWorld()->GetTerrain()->GetVerticesPerSide(); | ||||
if (gotWater) | if (gotWater) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 118 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Not required anymore