Changeset View
Changeset View
Standalone View
Standalone View
source/graphics/Camera.cpp
Show First 20 Lines • Show All 218 Lines • ▼ Show 20 Lines | CVector3D CCamera::GetWorldCoordinates(int px, int py, bool aboveWater) const | ||||
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) | ||||
{ | { | ||||
waterPoint.X = clamp(waterPoint.X, 0.f, (float)((mapSize-1)*TERRAIN_TILE_SIZE)); | waterPoint.X = Clamp(waterPoint.X, 0.f, static_cast<float>((mapSize-1)*TERRAIN_TILE_SIZE)); | ||||
waterPoint.Z = clamp(waterPoint.Z, 0.f, (float)((mapSize-1)*TERRAIN_TILE_SIZE)); | waterPoint.Z = Clamp(waterPoint.Z, 0.f, static_cast<float>((mapSize-1)*TERRAIN_TILE_SIZE)); | ||||
Stan: static_cast | |||||
Done Inline ActionsMissing spaces between operators. Stan: Missing spaces between operators. | |||||
} | } | ||||
if (gotTerrain) | if (gotTerrain) | ||||
{ | { | ||||
if (gotWater) | if (gotWater) | ||||
{ | { | ||||
// Intersecting both heightmap and water plane; choose the closest of those | // Intersecting both heightmap and water plane; choose the closest of those | ||||
if ((origin - terrainPoint).LengthSquared() < (origin - waterPoint).LengthSquared()) | if ((origin - terrainPoint).LengthSquared() < (origin - waterPoint).LengthSquared()) | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | CVector3D CCamera::GetFocus() const | ||||
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) | ||||
{ | { | ||||
waterPoint.X = clamp(waterPoint.X, 0.f, (float)((mapSize-1)*TERRAIN_TILE_SIZE)); | waterPoint.X = Clamp(waterPoint.X, 0.f, static_cast<float>((mapSize-1)*TERRAIN_TILE_SIZE)); | ||||
waterPoint.Z = clamp(waterPoint.Z, 0.f, (float)((mapSize-1)*TERRAIN_TILE_SIZE)); | waterPoint.Z = Clamp(waterPoint.Z, 0.f, static_cast<float>((mapSize-1)*TERRAIN_TILE_SIZE)); | ||||
Not Done Inline Actionsstatic_cast Stan: static_cast | |||||
Done Inline ActionsMissing spaces between operators. Stan: Missing spaces between operators. | |||||
Not Done Inline ActionsIs the compiler smart enough to optimize (mapSize - 1) * TERRAIN_TILE_SIZE) ? as it's also used below ? could be inlined in a variable. Here it's a multiplication while others are mostly substractions Stan: Is the compiler smart enough to optimize (mapSize - 1) * TERRAIN_TILE_SIZE) ? as it's also used… | |||||
Done Inline ActionsYeah, most compilers calculate this expression once. vladislavbelov: Yeah, most compilers calculate this expression once. | |||||
} | } | ||||
if (gotTerrain) | if (gotTerrain) | ||||
{ | { | ||||
if (gotWater) | if (gotWater) | ||||
{ | { | ||||
// Intersecting both heightmap and water plane; choose the closest of those | // Intersecting both heightmap and water plane; choose the closest of those | ||||
if ((origin - terrainPoint).LengthSquared() < (origin - waterPoint).LengthSquared()) | if ((origin - terrainPoint).LengthSquared() < (origin - waterPoint).LengthSquared()) | ||||
▲ Show 20 Lines • Show All 110 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
static_cast