mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-01 07:39:47 +00:00
indexToPosition moved from world -> esm/util.hpp
This commit is contained in:
parent
1cf0cd5628
commit
3d06cabf6a
8 changed files with 23 additions and 26 deletions
|
@ -313,9 +313,6 @@ namespace MWBase
|
|||
/// relative to \a referenceObject (but the object may be placed somewhere else if the wanted location is
|
||||
/// obstructed).
|
||||
|
||||
virtual osg::Vec2 indexToPosition(const ESM::ExteriorCellIndex& cellIndex, bool centre = false) const = 0;
|
||||
///< Convert cell numbers to position.
|
||||
|
||||
virtual void queueMovement(const MWWorld::Ptr& ptr, const osg::Vec3f& velocity) = 0;
|
||||
///< Queues movement for \a ptr (in local space), to be applied in the next call to
|
||||
/// doPhysics.
|
||||
|
|
|
@ -124,7 +124,7 @@ namespace MWScript
|
|||
const MWWorld::Ptr playerPtr = world->getPlayerPtr();
|
||||
|
||||
osg::Vec2 posFromIndex
|
||||
= world->indexToPosition(ESM::ExteriorCellIndex(x, y, ESM::Cell::sDefaultWorldspaceId), true);
|
||||
= ESM::indexToPosition(ESM::ExteriorCellIndex(x, y, ESM::Cell::sDefaultWorldspaceId), true);
|
||||
pos.pos[0] = posFromIndex.x();
|
||||
pos.pos[1] = posFromIndex.y();
|
||||
pos.pos[2] = 0;
|
||||
|
|
|
@ -565,7 +565,7 @@ void MWState::StateManager::loadGame(const Character* character, const std::file
|
|||
Log(Debug::Warning) << "Warning: Player character's cell no longer exists, changing to the default cell";
|
||||
ESM::ExteriorCellIndex cellIndex(0, 0, ESM::Cell::sDefaultWorldspaceId);
|
||||
MWWorld::CellStore& cell = MWBase::Environment::get().getWorldModel()->getExterior(cellIndex);
|
||||
osg::Vec2 posFromIndex = MWBase::Environment::get().getWorld()->indexToPosition(cellIndex, false);
|
||||
osg::Vec2 posFromIndex = ESM::indexToPosition(cellIndex, false);
|
||||
ESM::Position pos;
|
||||
pos.pos[0] = posFromIndex.x();
|
||||
pos.pos[1] = posFromIndex.y();
|
||||
|
|
|
@ -516,7 +516,7 @@ namespace MWWorld
|
|||
|
||||
if (currentGridCenter)
|
||||
{
|
||||
osg::Vec2 center = mWorld.indexToPosition(
|
||||
osg::Vec2 center = ESM::indexToPosition(
|
||||
ESM::ExteriorCellIndex(currentGridCenter->x(), currentGridCenter->y(), worldspace), true);
|
||||
float distance = std::max(std::abs(center.x() - pos.x()), std::abs(center.y() - pos.y()));
|
||||
float cellSize = ESM::getCellSize(isEsm4Ext);
|
||||
|
@ -1167,7 +1167,7 @@ namespace MWWorld
|
|||
cellY = mCurrentGridCenter.y();
|
||||
ESM::RefId extWorldspace = mWorld.getCurrentWorldspace();
|
||||
|
||||
osg::Vec2 center = mWorld.indexToPosition(ESM::ExteriorCellIndex(cellX, cellY, extWorldspace), true);
|
||||
osg::Vec2 center = ESM::indexToPosition(ESM::ExteriorCellIndex(cellX, cellY, extWorldspace), true);
|
||||
|
||||
bool esm4Ext = ESM::isEsm4Ext(extWorldspace);
|
||||
float cellSize = ESM::getCellSize(esm4Ext);
|
||||
|
@ -1181,7 +1181,7 @@ namespace MWWorld
|
|||
continue; // only care about the outer (not yet loaded) part of the grid
|
||||
|
||||
osg::Vec2 thisCellCenter
|
||||
= mWorld.indexToPosition(ESM::ExteriorCellIndex(cellX + dx, cellY + dy, extWorldspace), true);
|
||||
= ESM::indexToPosition(ESM::ExteriorCellIndex(cellX + dx, cellY + dy, extWorldspace), true);
|
||||
|
||||
float dist = std::max(
|
||||
std::abs(thisCellCenter.x() - playerPos.x()), std::abs(thisCellCenter.y() - playerPos.y()));
|
||||
|
|
|
@ -1495,21 +1495,6 @@ namespace MWWorld
|
|||
return placed;
|
||||
}
|
||||
|
||||
osg::Vec2 World::indexToPosition(const ESM::ExteriorCellIndex& cellIndex, bool centre) const
|
||||
{
|
||||
const int cellSize = ESM::getCellSize(ESM::isEsm4Ext(cellIndex.mWorldspace));
|
||||
|
||||
float x = static_cast<float>(cellSize * cellIndex.mX);
|
||||
float y = static_cast<float>(cellSize * cellIndex.mY);
|
||||
|
||||
if (centre)
|
||||
{
|
||||
x += cellSize / 2;
|
||||
y += cellSize / 2;
|
||||
}
|
||||
return osg::Vec2(x, y);
|
||||
}
|
||||
|
||||
void World::queueMovement(const Ptr& ptr, const osg::Vec3f& velocity)
|
||||
{
|
||||
mPhysics->queueObjectMovement(ptr, velocity);
|
||||
|
|
|
@ -400,9 +400,6 @@ namespace MWWorld
|
|||
|
||||
float getMaxActivationDistance() const override;
|
||||
|
||||
osg::Vec2 indexToPosition(const ESM::ExteriorCellIndex& cellIndex, bool centre = false) const override;
|
||||
///< Convert cell numbers to position.
|
||||
|
||||
void queueMovement(const Ptr& ptr, const osg::Vec3f& velocity) override;
|
||||
///< Queues movement for \a ptr (in local space), to be applied in the next call to
|
||||
/// doPhysics.
|
||||
|
|
16
components/esm/util.cpp
Normal file
16
components/esm/util.cpp
Normal file
|
@ -0,0 +1,16 @@
|
|||
#include "util.hpp"
|
||||
|
||||
osg::Vec2 ESM::indexToPosition(const ESM::ExteriorCellIndex& cellIndex, bool centre)
|
||||
{
|
||||
const int cellSize = ESM::getCellSize(ESM::isEsm4Ext(cellIndex.mWorldspace));
|
||||
|
||||
float x = static_cast<float>(cellSize * cellIndex.mX);
|
||||
float y = static_cast<float>(cellSize * cellIndex.mY);
|
||||
|
||||
if (centre)
|
||||
{
|
||||
x += cellSize / 2;
|
||||
y += cellSize / 2;
|
||||
}
|
||||
return osg::Vec2(x, y);
|
||||
}
|
|
@ -90,6 +90,8 @@ namespace ESM
|
|||
return { static_cast<int>(std::floor(x / cellSize)), static_cast<int>(std::floor(y / cellSize)) };
|
||||
}
|
||||
|
||||
osg::Vec2 indexToPosition(const ESM::ExteriorCellIndex& cellIndex, bool centre = false);
|
||||
///< Convert cell numbers to position.
|
||||
}
|
||||
|
||||
namespace std
|
||||
|
|
Loading…
Reference in a new issue