2014-04-07 11:42:00 +00:00
|
|
|
#ifndef CSM_WOLRD_CELLCOORDINATES_H
|
|
|
|
#define CSM_WOLRD_CELLCOORDINATES_H
|
|
|
|
|
|
|
|
#include <iosfwd>
|
|
|
|
#include <string>
|
2016-03-12 12:19:51 +00:00
|
|
|
#include <utility>
|
2014-04-07 11:42:00 +00:00
|
|
|
|
|
|
|
#include <QMetaType>
|
|
|
|
|
2022-08-04 22:00:49 +00:00
|
|
|
namespace osg
|
|
|
|
{
|
|
|
|
class Vec3d;
|
|
|
|
}
|
2019-04-06 07:38:59 +00:00
|
|
|
|
2023-03-03 10:30:50 +00:00
|
|
|
namespace ESM
|
|
|
|
{
|
|
|
|
class RefId;
|
|
|
|
}
|
|
|
|
|
2014-04-07 11:42:00 +00:00
|
|
|
namespace CSMWorld
|
|
|
|
{
|
|
|
|
class CellCoordinates
|
|
|
|
{
|
|
|
|
int mX;
|
|
|
|
int mY;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CellCoordinates();
|
|
|
|
|
|
|
|
CellCoordinates(int x, int y);
|
|
|
|
|
|
|
|
CellCoordinates(const std::pair<int, int>& coordinates);
|
|
|
|
|
2016-03-12 12:19:51 +00:00
|
|
|
int getX() const;
|
|
|
|
|
2014-04-07 11:42:00 +00:00
|
|
|
int getY() const;
|
|
|
|
|
|
|
|
CellCoordinates move(int x, int y) const;
|
|
|
|
///< Return a copy of *this, moved by the given offset.
|
|
|
|
|
|
|
|
/// Generate cell id string from x and y coordinates
|
|
|
|
static std::string generateId(int x, int y);
|
|
|
|
|
2019-04-04 22:54:10 +00:00
|
|
|
std::string getId(const std::string& worldspace) const;
|
|
|
|
///< Return the ID for the cell at these coordinates.
|
|
|
|
|
2014-04-07 11:42:00 +00:00
|
|
|
static bool isExteriorCell(const std::string& id);
|
2015-10-12 16:00:44 +00:00
|
|
|
|
2023-03-03 10:30:50 +00:00
|
|
|
static bool isExteriorCell(const ESM::RefId& id);
|
|
|
|
|
2016-08-31 15:02:04 +00:00
|
|
|
/// \return first: CellCoordinates (or 0, 0 if cell does not have coordinates),
|
|
|
|
/// second: is cell paged?
|
2022-09-22 18:26:05 +00:00
|
|
|
///
|
2015-10-12 16:00:44 +00:00
|
|
|
/// \note The worldspace part of \a id is ignored
|
2016-08-31 15:02:04 +00:00
|
|
|
static std::pair<CellCoordinates, bool> fromId(const std::string& id);
|
|
|
|
|
2015-10-12 16:00:44 +00:00
|
|
|
/// \return cell coordinates such that given world coordinates are in it.
|
|
|
|
static std::pair<int, int> coordinatesToCellIndex(float x, float y);
|
2016-08-31 15:02:04 +00:00
|
|
|
|
2016-08-02 10:46:43 +00:00
|
|
|
/// Converts worldspace coordinates to global texture selection, taking in account the texture offset.
|
2016-03-12 12:19:51 +00:00
|
|
|
static std::pair<int, int> toTextureCoords(const osg::Vec3d& worldPos);
|
2019-04-04 22:54:10 +00:00
|
|
|
|
|
|
|
/// Converts worldspace coordinates to global vertex selection.
|
2019-05-09 17:31:36 +00:00
|
|
|
static std::pair<int, int> toVertexCoords(const osg::Vec3d& worldPos);
|
2019-04-04 22:54:10 +00:00
|
|
|
|
|
|
|
/// Converts global texture coordinate X to worldspace coordinate, offset by 0.25f.
|
2019-05-09 17:31:36 +00:00
|
|
|
static float textureGlobalXToWorldCoords(int textureGlobal);
|
2019-04-04 22:54:10 +00:00
|
|
|
|
2020-03-05 18:10:55 +00:00
|
|
|
/// Converts global texture coordinate Y to worldspace coordinate, offset by 0.25f.
|
|
|
|
static float textureGlobalYToWorldCoords(int textureGlobal);
|
|
|
|
|
|
|
|
/// Converts global vertex coordinate to worldspace coordinate
|
|
|
|
static float vertexGlobalToWorldCoords(int vertexGlobal);
|
2019-04-04 22:54:10 +00:00
|
|
|
|
|
|
|
/// Converts global vertex coordinate to local cell's heightmap coordinates
|
2019-05-11 18:07:22 +00:00
|
|
|
static int vertexGlobalToInCellCoords(int vertexGlobal);
|
2019-04-04 22:54:10 +00:00
|
|
|
|
2019-05-11 18:07:22 +00:00
|
|
|
/// Converts global texture coordinates to cell id
|
|
|
|
static std::string textureGlobalToCellId(const std::pair<int, int>& textureGlobal);
|
2019-04-04 22:54:10 +00:00
|
|
|
|
|
|
|
/// Converts global vertex coordinates to cell id
|
2019-05-11 18:07:22 +00:00
|
|
|
static std::string vertexGlobalToCellId(const std::pair<int, int>& vertexGlobal);
|
2014-04-07 11:42:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
bool operator==(const CellCoordinates& left, const CellCoordinates& right);
|
|
|
|
bool operator!=(const CellCoordinates& left, const CellCoordinates& right);
|
|
|
|
bool operator<(const CellCoordinates& left, const CellCoordinates& right);
|
|
|
|
|
|
|
|
std::ostream& operator<<(std::ostream& stream, const CellCoordinates& coordiantes);
|
|
|
|
}
|
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(CSMWorld::CellCoordinates)
|
|
|
|
|
|
|
|
#endif
|