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