Changeset View
Changeset View
Standalone View
Standalone View
source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp
Show First 20 Lines • Show All 371 Lines • ▼ Show 20 Lines | |||||
static CVector3D GetUnitPos(const Position& pos, bool floating) | static CVector3D GetUnitPos(const Position& pos, bool floating) | ||||
{ | { | ||||
static CVector3D vec; | static CVector3D vec; | ||||
vec = pos.GetWorldSpace(vec, floating); // if msg->pos is 'Unchanged', use the previous pos | vec = pos.GetWorldSpace(vec, floating); // if msg->pos is 'Unchanged', use the previous pos | ||||
// Clamp the position to the edges of the world: | // Clamp the position to the edges of the world: | ||||
// Use 'clamp' with a value slightly less than the width, so that converting | // Use 'Clamp' with a value slightly less than the width, so that converting | ||||
// to integer (rounding towards zero) will put it on the tile inside the edge | // to integer (rounding towards zero) will put it on the tile inside the edge | ||||
// instead of just outside | // instead of just outside | ||||
float mapWidth = (g_Game->GetWorld()->GetTerrain()->GetVerticesPerSide()-1)*TERRAIN_TILE_SIZE; | float mapWidth = (g_Game->GetWorld()->GetTerrain()->GetVerticesPerSide()-1)*TERRAIN_TILE_SIZE; | ||||
float delta = 1e-6f; // fraction of map width - must be > FLT_EPSILON | float delta = 1e-6f; // fraction of map width - must be > FLT_EPSILON | ||||
float xOnMap = clamp(vec.X, 0.f, mapWidth * (1.f - delta)); | float xOnMap = Clamp(vec.X, 0.f, mapWidth * (1.f - delta)); | ||||
float zOnMap = clamp(vec.Z, 0.f, mapWidth * (1.f - delta)); | float zOnMap = Clamp(vec.Z, 0.f, mapWidth * (1.f - delta)); | ||||
// Don't waste time with GetExactGroundLevel unless we've changed | // Don't waste time with GetExactGroundLevel unless we've changed | ||||
if (xOnMap != vec.X || zOnMap != vec.Z) | if (xOnMap != vec.X || zOnMap != vec.Z) | ||||
{ | { | ||||
vec.X = xOnMap; | vec.X = xOnMap; | ||||
vec.Z = zOnMap; | vec.Z = zOnMap; | ||||
vec.Y = g_Game->GetWorld()->GetTerrain()->GetExactGroundLevel(xOnMap, zOnMap); | vec.Y = g_Game->GetWorld()->GetTerrain()->GetExactGroundLevel(xOnMap, zOnMap); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 725 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator