1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-15 22:49:48 +00:00
OpenMW/components/esm/util.hpp

41 lines
1.1 KiB
C++
Raw Normal View History

2024-05-02 01:09:13 +00:00
#ifndef OPENMW_COMPONENTS_ESM_UTIL_H
#define OPENMW_COMPONENTS_ESM_UTIL_H
#include <cmath>
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"
namespace ESM
{
inline bool isEsm4Ext(ESM::RefId worldspaceId)
2023-05-09 20:08:17 +00:00
{
return worldspaceId != ESM::Cell::sDefaultWorldspaceId;
}
inline int getCellSize(ESM::RefId worldspaceId)
2023-05-09 20:08:17 +00:00
{
return isEsm4Ext(worldspaceId) ? Constants::ESM4CellSizeInUnits : Constants::CellSizeInUnits;
2023-05-09 20:08:17 +00:00
}
// Vertex count of a side of a land record
int getLandSize(ESM::RefId worldspaceId);
inline ESM::ExteriorCellLocation positionToExteriorCellLocation(
float x, float y, ESM::RefId worldspaceId = ESM::Cell::sDefaultWorldspaceId)
{
const float cellSize = getCellSize(worldspaceId);
return { static_cast<int>(std::floor(x / cellSize)), static_cast<int>(std::floor(y / cellSize)), worldspaceId };
}
2024-05-02 01:09:13 +00:00
// Convert exterior cell location to position.
osg::Vec2f indexToPosition(const ESM::ExteriorCellLocation& cellIndex, bool centre = false);
}
#endif