mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-31 00:15:35 +00:00
Convert position on construction
This commit is contained in:
parent
33ef7fc8ca
commit
b64069156d
1 changed files with 14 additions and 20 deletions
|
@ -877,15 +877,19 @@ namespace MWRender
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
osg::Vec2f clampToCell(const osg::Vec3f& cellPos, const osg::Vec2i& cell)
|
||||||
|
{
|
||||||
|
return osg::Vec2f(std::clamp<float>(cellPos.x(), cell.x(), cell.x() + 1),
|
||||||
|
std::clamp<float>(cellPos.y(), cell.y(), cell.y() + 1));
|
||||||
|
}
|
||||||
|
|
||||||
class CollectIntersecting
|
class CollectIntersecting
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit CollectIntersecting(
|
explicit CollectIntersecting(
|
||||||
bool activeGridOnly, const osg::Vec3f& position, const osg::Vec2i& cell, ESM::RefId worldspace)
|
bool activeGridOnly, const osg::Vec3f& position, const osg::Vec2i& cell, ESM::RefId worldspace)
|
||||||
: mActiveGridOnly(activeGridOnly)
|
: mActiveGridOnly(activeGridOnly)
|
||||||
, mPosition(position)
|
, mPosition(clampToCell(position / getCellSize(worldspace), cell))
|
||||||
, mCell(cell)
|
|
||||||
, mWorldspace(worldspace)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -893,33 +897,23 @@ namespace MWRender
|
||||||
{
|
{
|
||||||
if (mActiveGridOnly && !std::get<2>(id))
|
if (mActiveGridOnly && !std::get<2>(id))
|
||||||
return;
|
return;
|
||||||
if (intersects(id, mPosition))
|
if (intersects(id))
|
||||||
mCollected.insert(id);
|
mCollected.insert(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::set<ChunkId>& getCollected() const { return mCollected; }
|
const std::set<ChunkId>& getCollected() const { return mCollected; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool intersects(ChunkId id, osg::Vec3f pos) const
|
bool intersects(ChunkId id) const
|
||||||
{
|
{
|
||||||
pos /= getCellSize(mWorldspace);
|
const osg::Vec2f center = std::get<0>(id);
|
||||||
clampToCell(pos);
|
const float halfSize = std::get<1>(id) / 2;
|
||||||
osg::Vec2f center = std::get<0>(id);
|
return mPosition.x() >= center.x() - halfSize && mPosition.y() >= center.y() - halfSize
|
||||||
float halfSize = std::get<1>(id) / 2;
|
&& mPosition.x() <= center.x() + halfSize && mPosition.y() <= center.y() + halfSize;
|
||||||
return pos.x() >= center.x() - halfSize && pos.y() >= center.y() - halfSize
|
|
||||||
&& pos.x() <= center.x() + halfSize && pos.y() <= center.y() + halfSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
void clampToCell(osg::Vec3f& cellPos) const
|
|
||||||
{
|
|
||||||
cellPos.x() = std::clamp<float>(cellPos.x(), mCell.x(), mCell.x() + 1);
|
|
||||||
cellPos.y() = std::clamp<float>(cellPos.y(), mCell.y(), mCell.y() + 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool mActiveGridOnly;
|
bool mActiveGridOnly;
|
||||||
osg::Vec3f mPosition;
|
osg::Vec2f mPosition;
|
||||||
osg::Vec2i mCell;
|
|
||||||
ESM::RefId mWorldspace;
|
|
||||||
std::set<ChunkId> mCollected;
|
std::set<ChunkId> mCollected;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue