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>
|
|
|
|
|
2019-04-06 07:38:59 +00:00
|
|
|
#include <osg/Vec3d>
|
|
|
|
|
2014-04-07 11:42:00 +00:00
|
|
|
namespace CSMWorld
|
|
|
|
{
|
|
|
|
class CellCoordinates
|
|
|
|
{
|
|
|
|
int mX;
|
|
|
|
int mY;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
CellCoordinates();
|
|
|
|
|
|
|
|
CellCoordinates (int x, int y);
|
|
|
|
|
2016-03-12 12:19:51 +00:00
|
|
|
CellCoordinates (const std::pair<int, int>& coordinates);
|
|
|
|
|
2014-04-07 11:42:00 +00:00
|
|
|
int getX() const;
|
|
|
|
|
|
|
|
int getY() const;
|
|
|
|
|
|
|
|
CellCoordinates move (int x, int y) const;
|
|
|
|
///< Return a copy of *this, moved by the given offset.
|
|
|
|
|
2019-04-04 22:54:10 +00:00
|
|
|
///Generate cell id string from x and y coordinates
|
|
|
|
static std::string generateId (int x, int y);
|
|
|
|
|
2014-04-07 11:42:00 +00:00
|
|
|
std::string getId (const std::string& worldspace) const;
|
|
|
|
///< Return the ID for the cell at these coordinates.
|
2015-10-12 16:00:44 +00:00
|
|
|
|
2016-08-31 15:02:04 +00:00
|
|
|
static bool isExteriorCell (const std::string& id);
|
|
|
|
|
2015-10-12 16:00:44 +00:00
|
|
|
/// \return first: CellCoordinates (or 0, 0 if cell does not have coordinates),
|
|
|
|
/// second: is cell paged?
|
|
|
|
///
|
|
|
|
/// \note The worldspace part of \a id is ignored
|
|
|
|
static std::pair<CellCoordinates, bool> fromId (const std::string& id);
|
2016-08-31 15:02:04 +00:00
|
|
|
|
2016-08-02 10:46:43 +00:00
|
|
|
/// \return cell coordinates such that given world coordinates are in it.
|
2016-03-12 12:19:51 +00:00
|
|
|
static std::pair<int, int> coordinatesToCellIndex (float x, float y);
|
2019-04-04 22:54:10 +00:00
|
|
|
|
|
|
|
///Converts worldspace coordinates to global texture selection, taking in account the texture offset.
|
2019-05-09 17:31:36 +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 to worldspace coordinate that is at the upper left corner of the selected texture.
|
2019-05-11 18:07:22 +00:00
|
|
|
static float textureGlobalToWorldCoords(int textureGlobal);
|
2019-04-04 22:54:10 +00:00
|
|
|
|
|
|
|
///Converts global vertex coordinate to worldspace coordinate
|
2019-05-11 18:07:22 +00:00
|
|
|
static float vertexGlobalToWorldCoords(int vertexGlobal);
|
2019-04-04 22:54:10 +00:00
|
|
|
|
2019-05-11 18:07:22 +00:00
|
|
|
///Converts global vertex coordinate to local cell's heightmap coordinates
|
|
|
|
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-05-06 09:56:04 +00:00
|
|
|
|
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
|