|
|
|
@ -5,8 +5,16 @@
|
|
|
|
|
#include <ostream>
|
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
|
|
#include <components/esm/loadland.hpp>
|
|
|
|
|
#include <components/misc/constants.hpp>
|
|
|
|
|
|
|
|
|
|
namespace
|
|
|
|
|
{
|
|
|
|
|
const int cellSize {ESM::Land::REAL_SIZE};
|
|
|
|
|
const int landSize {ESM::Land::LAND_SIZE};
|
|
|
|
|
const int landTextureSize {ESM::Land::LAND_TEXTURE_SIZE};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CSMWorld::CellCoordinates::CellCoordinates() : mX (0), mY (0) {}
|
|
|
|
|
|
|
|
|
|
CSMWorld::CellCoordinates::CellCoordinates (int x, int y) : mX (x), mY (y) {}
|
|
|
|
@ -32,11 +40,13 @@ CSMWorld::CellCoordinates CSMWorld::CellCoordinates::move (int x, int y) const
|
|
|
|
|
std::string CSMWorld::CellCoordinates::getId (const std::string& worldspace) const
|
|
|
|
|
{
|
|
|
|
|
// we ignore the worldspace for now, since there is only one (will change in 1.1)
|
|
|
|
|
std::ostringstream stream;
|
|
|
|
|
|
|
|
|
|
stream << "#" << mX << " " << mY;
|
|
|
|
|
return generateId(mX, mY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return stream.str();
|
|
|
|
|
std::string CSMWorld::CellCoordinates::generateId (int x, int y)
|
|
|
|
|
{
|
|
|
|
|
std::string cellId = "#" + std::to_string(x) + " " + std::to_string(y);
|
|
|
|
|
return cellId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CSMWorld::CellCoordinates::isExteriorCell (const std::string& id)
|
|
|
|
@ -66,6 +76,50 @@ std::pair<int, int> CSMWorld::CellCoordinates::coordinatesToCellIndex (float x,
|
|
|
|
|
return std::make_pair (std::floor (x / Constants::CellSizeInUnits), std::floor (y / Constants::CellSizeInUnits));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::pair<int, int> CSMWorld::CellCoordinates::toTextureCoords(osg::Vec3d worldPos)
|
|
|
|
|
{
|
|
|
|
|
const auto xd = static_cast<float>(worldPos.x() * landTextureSize / cellSize - 0.25f);
|
|
|
|
|
const auto yd = static_cast<float>(worldPos.y() * landTextureSize / cellSize + 0.25f);
|
|
|
|
|
|
|
|
|
|
const auto x = static_cast<int>(std::floor(xd));
|
|
|
|
|
const auto y = static_cast<int>(std::floor(yd));
|
|
|
|
|
|
|
|
|
|
return std::make_pair(x, y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::pair<int, int> CSMWorld::CellCoordinates::toVertexCoords(osg::Vec3d worldPos)
|
|
|
|
|
{
|
|
|
|
|
const auto xd = static_cast<float>(worldPos.x() * (landSize - 1) / cellSize + 0.5f);
|
|
|
|
|
const auto yd = static_cast<float>(worldPos.y() * (landSize - 1) / cellSize + 0.5f);
|
|
|
|
|
|
|
|
|
|
const auto x = static_cast<int>(std::floor(xd));
|
|
|
|
|
const auto y = static_cast<int>(std::floor(yd));
|
|
|
|
|
|
|
|
|
|
return std::make_pair(x, y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float CSMWorld::CellCoordinates::textureSelectionToWorldCoords(int pos)
|
|
|
|
|
{
|
|
|
|
|
return cellSize * static_cast<float>(pos) / landTextureSize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float CSMWorld::CellCoordinates::vertexSelectionToWorldCoords(int pos)
|
|
|
|
|
{
|
|
|
|
|
return cellSize * static_cast<float>(pos) / (landSize - 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int CSMWorld::CellCoordinates::vertexSelectionToInCellCoords(int pos)
|
|
|
|
|
{
|
|
|
|
|
return static_cast<int>(pos - std::floor(static_cast<float>(pos) / (landSize - 1)) * (landSize - 1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string CSMWorld::CellCoordinates::vertexGlobalToCellId(std::pair<int, int> vertexGlobal)
|
|
|
|
|
{
|
|
|
|
|
int x = std::floor(static_cast<float>(vertexGlobal.first) / (landSize - 1));
|
|
|
|
|
int y = std::floor(static_cast<float>(vertexGlobal.second) / (landSize - 1));
|
|
|
|
|
return generateId(x, y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CSMWorld::operator== (const CellCoordinates& left, const CellCoordinates& right)
|
|
|
|
|
{
|
|
|
|
|
return left.getX()==right.getX() && left.getY()==right.getY();
|
|
|
|
|