2024-05-02 01:09:13 +00:00
|
|
|
#ifndef OPENMW_COMPONENTS_ESM_UTIL_H
|
|
|
|
#define OPENMW_COMPONENTS_ESM_UTIL_H
|
|
|
|
|
2023-05-09 22:06:40 +00:00
|
|
|
#include <cmath>
|
2014-12-31 20:27:19 +00:00
|
|
|
|
2024-05-02 01:09:13 +00:00
|
|
|
#include <osg/Vec2f>
|
|
|
|
|
|
|
|
#include "components/esm3/loadcell.hpp"
|
|
|
|
#include "components/misc/constants.hpp"
|
2015-06-01 19:41:13 +00:00
|
|
|
|
2024-05-02 01:09:13 +00:00
|
|
|
#include "exteriorcelllocation.hpp"
|
|
|
|
#include "refid.hpp"
|
2023-05-02 20:37:18 +00:00
|
|
|
|
2014-12-31 20:27:19 +00:00
|
|
|
namespace ESM
|
|
|
|
{
|
2023-05-12 10:04:04 +00:00
|
|
|
inline bool isEsm4Ext(ESM::RefId worldspaceId)
|
2023-05-09 20:08:17 +00:00
|
|
|
{
|
|
|
|
return worldspaceId != ESM::Cell::sDefaultWorldspaceId;
|
|
|
|
}
|
|
|
|
|
2023-05-12 10:04:04 +00:00
|
|
|
inline int getCellSize(ESM::RefId worldspaceId)
|
2023-05-09 20:08:17 +00:00
|
|
|
{
|
2023-05-12 10:04:04 +00:00
|
|
|
return isEsm4Ext(worldspaceId) ? Constants::ESM4CellSizeInUnits : Constants::CellSizeInUnits;
|
2023-05-09 20:08:17 +00:00
|
|
|
}
|
2023-05-09 22:06:40 +00:00
|
|
|
|
2023-05-18 09:56:45 +00:00
|
|
|
// Vertex count of a side of a land record
|
|
|
|
int getLandSize(ESM::RefId worldspaceId);
|
|
|
|
|
2023-05-26 23:18:17 +00:00
|
|
|
inline ESM::ExteriorCellLocation positionToExteriorCellLocation(
|
2023-05-12 10:04:04 +00:00
|
|
|
float x, float y, ESM::RefId worldspaceId = ESM::Cell::sDefaultWorldspaceId)
|
2023-05-09 22:06:40 +00:00
|
|
|
{
|
2023-05-12 10:04:04 +00:00
|
|
|
const float cellSize = getCellSize(worldspaceId);
|
|
|
|
return { static_cast<int>(std::floor(x / cellSize)), static_cast<int>(std::floor(y / cellSize)), worldspaceId };
|
2023-05-09 22:06:40 +00:00
|
|
|
}
|
|
|
|
|
2024-05-02 01:09:13 +00:00
|
|
|
// Convert exterior cell location to position.
|
|
|
|
osg::Vec2f indexToPosition(const ESM::ExteriorCellLocation& cellIndex, bool centre = false);
|
2014-12-31 20:27:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|