2014-12-31 21:27:19 +01:00
|
|
|
#ifndef OPENMW_ESM_UTIL_H
|
|
|
|
#define OPENMW_ESM_UTIL_H
|
|
|
|
|
2015-06-01 21:41:13 +02:00
|
|
|
#include <osg/Quat>
|
|
|
|
#include <osg/Vec3f>
|
|
|
|
|
2023-05-02 22:37:18 +02:00
|
|
|
#include <components/esm/refid.hpp>
|
|
|
|
|
2014-12-31 21:27:19 +01:00
|
|
|
namespace ESM
|
|
|
|
{
|
|
|
|
|
|
|
|
// format 0, savegames only
|
2015-06-03 21:37:21 +02:00
|
|
|
|
2015-06-01 21:41:13 +02:00
|
|
|
struct Quaternion
|
|
|
|
{
|
|
|
|
float mValues[4];
|
2014-12-31 21:27:19 +01:00
|
|
|
|
2015-06-01 21:41:13 +02:00
|
|
|
Quaternion() = default;
|
2014-12-31 21:27:19 +01:00
|
|
|
|
|
|
|
Quaternion(const osg::Quat& q)
|
|
|
|
{
|
2015-06-01 21:41:13 +02:00
|
|
|
mValues[0] = q.w();
|
|
|
|
mValues[1] = q.x();
|
|
|
|
mValues[2] = q.y();
|
2014-12-31 21:27:19 +01:00
|
|
|
mValues[3] = q.z();
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2014-12-31 21:27:19 +01:00
|
|
|
|
2021-06-24 00:26:15 +02:00
|
|
|
operator osg::Quat() const { return osg::Quat(mValues[1], mValues[2], mValues[3], mValues[0]); }
|
2022-09-22 21:26:05 +03:00
|
|
|
};
|
2015-06-03 21:37:21 +02:00
|
|
|
|
2015-06-01 21:41:13 +02:00
|
|
|
struct Vector3
|
|
|
|
{
|
|
|
|
float mValues[3];
|
2014-12-31 21:27:19 +01:00
|
|
|
|
2015-06-01 21:41:13 +02:00
|
|
|
Vector3() = default;
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2015-06-01 21:41:13 +02:00
|
|
|
Vector3(const osg::Vec3f& v)
|
|
|
|
{
|
|
|
|
mValues[0] = v.x();
|
|
|
|
mValues[1] = v.y();
|
|
|
|
mValues[2] = v.z();
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
|
|
|
|
2015-06-01 21:41:13 +02:00
|
|
|
operator osg::Vec3f() const { return osg::Vec3f(mValues[0], mValues[1], mValues[2]); }
|
2014-12-31 21:27:19 +01:00
|
|
|
};
|
|
|
|
|
2023-05-02 22:37:18 +02:00
|
|
|
struct ExteriorCellIndex
|
|
|
|
{
|
|
|
|
int mX, mY;
|
|
|
|
ESM::RefId mWorldspace;
|
|
|
|
|
|
|
|
bool operator==(const ExteriorCellIndex& other) const
|
|
|
|
{
|
|
|
|
return mX == other.mX && mY == other.mY && mWorldspace == other.mWorldspace;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator<(const ExteriorCellIndex& other) const
|
|
|
|
{
|
|
|
|
return std::make_tuple(mX, mY, mWorldspace) < std::make_tuple(other.mX, other.mY, other.mWorldspace);
|
|
|
|
}
|
|
|
|
|
|
|
|
friend struct std::hash<ExteriorCellIndex>;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace std
|
|
|
|
{
|
|
|
|
template <>
|
|
|
|
struct hash<ESM::ExteriorCellIndex>
|
|
|
|
{
|
|
|
|
std::size_t operator()(const ESM::ExteriorCellIndex& toHash) const
|
|
|
|
{
|
|
|
|
// Compute individual hash values for first,
|
|
|
|
// second and third and combine them using XOR
|
|
|
|
// and bit shifting:
|
|
|
|
|
|
|
|
return ((hash<int>()(toHash.mX) ^ (hash<int>()(toHash.mY) << 1)) >> 1)
|
|
|
|
^ (hash<ESM::RefId>()(toHash.mWorldspace) << 1);
|
|
|
|
}
|
|
|
|
};
|
2014-12-31 21:27:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|