Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/graphics/Camera.cpp
/* Copyright (C) 2022 Wildfire Games. | /* Copyright (C) 2023 Wildfire Games. | ||||
* This file is part of 0!A.D. | * This file is part of 0!A.D. | ||||
* | * | ||||
* 0!A.D. is free software: you can redistribute it and/or modify | * 0!A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0!A.D. is distributed in the hope that it will be useful, | * 0!A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 262 Lines • ▼ Show 20 Lines | CVector3D CCamera::GetWorldCoordinates(int px, int py, bool aboveWater) const | ||||
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.GetSceneRenderer().GetWaterManager().m_WaterHeight, 0.f)); // passes through water plane | CVector3D(0.f, g_Renderer.GetSceneRenderer().GetWaterManager().m_WaterHeight, 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(); | const ssize_t mapSize = g_Game->GetWorld()->GetTerrain().GetVerticesPerSide(); | ||||
if (gotWater) | if (gotWater) | ||||
{ | { | ||||
waterPoint.X = Clamp<float>(waterPoint.X, 0.f, (mapSize - 1) * TERRAIN_TILE_SIZE); | waterPoint.X = Clamp<float>(waterPoint.X, 0.f, (mapSize - 1) * TERRAIN_TILE_SIZE); | ||||
waterPoint.Z = Clamp<float>(waterPoint.Z, 0.f, (mapSize - 1) * TERRAIN_TILE_SIZE); | waterPoint.Z = Clamp<float>(waterPoint.Z, 0.f, (mapSize - 1) * TERRAIN_TILE_SIZE); | ||||
} | } | ||||
if (gotTerrain) | if (gotTerrain) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | CVector3D CCamera::GetFocus() const | ||||
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.GetSceneRenderer().GetWaterManager().m_WaterHeight, 0.f)); // passes through water plane | CVector3D(0.f, g_Renderer.GetSceneRenderer().GetWaterManager().m_WaterHeight, 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(); | const ssize_t mapSize = g_Game->GetWorld()->GetTerrain().GetVerticesPerSide(); | ||||
if (gotWater) | if (gotWater) | ||||
{ | { | ||||
waterPoint.X = Clamp<float>(waterPoint.X, 0.f, (mapSize - 1) * TERRAIN_TILE_SIZE); | waterPoint.X = Clamp<float>(waterPoint.X, 0.f, (mapSize - 1) * TERRAIN_TILE_SIZE); | ||||
waterPoint.Z = Clamp<float>(waterPoint.Z, 0.f, (mapSize - 1) * TERRAIN_TILE_SIZE); | waterPoint.Z = Clamp<float>(waterPoint.Z, 0.f, (mapSize - 1) * TERRAIN_TILE_SIZE); | ||||
} | } | ||||
if (gotTerrain) | if (gotTerrain) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 90 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator