mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 07:23:54 +00:00
handle cell transitions when moving objects
This commit is contained in:
parent
fa9689c5e7
commit
d6b8033b46
4 changed files with 34 additions and 4 deletions
|
@ -1,5 +1,7 @@
|
||||||
#include "cellcoordinates.hpp"
|
#include "cellcoordinates.hpp"
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
@ -7,6 +9,9 @@ CSMWorld::CellCoordinates::CellCoordinates() : mX (0), mY (0) {}
|
||||||
|
|
||||||
CSMWorld::CellCoordinates::CellCoordinates (int x, int y) : mX (x), mY (y) {}
|
CSMWorld::CellCoordinates::CellCoordinates (int x, int y) : mX (x), mY (y) {}
|
||||||
|
|
||||||
|
CSMWorld::CellCoordinates::CellCoordinates (const std::pair<int, int>& coordinates)
|
||||||
|
: mX (coordinates.first), mY (coordinates.second) {}
|
||||||
|
|
||||||
int CSMWorld::CellCoordinates::getX() const
|
int CSMWorld::CellCoordinates::getX() const
|
||||||
{
|
{
|
||||||
return mX;
|
return mX;
|
||||||
|
@ -49,6 +54,13 @@ std::pair<CSMWorld::CellCoordinates, bool> CSMWorld::CellCoordinates::fromId (
|
||||||
return std::make_pair (CellCoordinates(), false);
|
return std::make_pair (CellCoordinates(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::pair<int, int> CSMWorld::CellCoordinates::coordinatesToCellIndex (float x, float y)
|
||||||
|
{
|
||||||
|
const int cellSize = 8192;
|
||||||
|
|
||||||
|
return std::make_pair (std::floor (x/cellSize), std::floor (y/cellSize));
|
||||||
|
}
|
||||||
|
|
||||||
bool CSMWorld::operator== (const CellCoordinates& left, const CellCoordinates& right)
|
bool CSMWorld::operator== (const CellCoordinates& left, const CellCoordinates& right)
|
||||||
{
|
{
|
||||||
return left.getX()==right.getX() && left.getY()==right.getY();
|
return left.getX()==right.getX() && left.getY()==right.getY();
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
#include <QMetaType>
|
#include <QMetaType>
|
||||||
|
|
||||||
|
@ -19,6 +20,8 @@ namespace CSMWorld
|
||||||
|
|
||||||
CellCoordinates (int x, int y);
|
CellCoordinates (int x, int y);
|
||||||
|
|
||||||
|
CellCoordinates (const std::pair<int, int>& coordinates);
|
||||||
|
|
||||||
int getX() const;
|
int getX() const;
|
||||||
|
|
||||||
int getY() const;
|
int getY() const;
|
||||||
|
@ -34,6 +37,8 @@ namespace CSMWorld
|
||||||
///
|
///
|
||||||
/// \note The worldspace part of \a id is ignored
|
/// \note The worldspace part of \a id is ignored
|
||||||
static std::pair<CellCoordinates, bool> fromId (const std::string& id);
|
static std::pair<CellCoordinates, bool> fromId (const std::string& id);
|
||||||
|
|
||||||
|
static std::pair<int, int> coordinatesToCellIndex (float x, float y);
|
||||||
};
|
};
|
||||||
|
|
||||||
bool operator== (const CellCoordinates& left, const CellCoordinates& right);
|
bool operator== (const CellCoordinates& left, const CellCoordinates& right);
|
||||||
|
|
|
@ -2,6 +2,10 @@
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
#include "cellcoordinates.hpp"
|
||||||
|
|
||||||
CSMWorld::CellRef::CellRef()
|
CSMWorld::CellRef::CellRef()
|
||||||
{
|
{
|
||||||
mRefNum.mIndex = 0;
|
mRefNum.mIndex = 0;
|
||||||
|
@ -10,8 +14,5 @@ CSMWorld::CellRef::CellRef()
|
||||||
|
|
||||||
std::pair<int, int> CSMWorld::CellRef::getCellIndex() const
|
std::pair<int, int> CSMWorld::CellRef::getCellIndex() const
|
||||||
{
|
{
|
||||||
const int cellSize = 8192;
|
return CellCoordinates::coordinatesToCellIndex (mPos.pos[0], mPos.pos[1]);
|
||||||
|
|
||||||
return std::make_pair (
|
|
||||||
std::floor (mPos.pos[0]/cellSize), std::floor (mPos.pos[1]/cellSize));
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include "../../model/world/commands.hpp"
|
#include "../../model/world/commands.hpp"
|
||||||
#include "../../model/world/universalid.hpp"
|
#include "../../model/world/universalid.hpp"
|
||||||
#include "../../model/world/commandmacro.hpp"
|
#include "../../model/world/commandmacro.hpp"
|
||||||
|
#include "../../model/world/cellcoordinates.hpp"
|
||||||
|
|
||||||
#include <components/resource/scenemanager.hpp>
|
#include <components/resource/scenemanager.hpp>
|
||||||
#include <components/sceneutil/lightutil.hpp>
|
#include <components/sceneutil/lightutil.hpp>
|
||||||
|
@ -542,6 +543,17 @@ void CSVRender::Object::apply (CSMWorld::CommandMacro& commands)
|
||||||
commands.push (new CSMWorld::ModifyCommand (*model,
|
commands.push (new CSMWorld::ModifyCommand (*model,
|
||||||
model->index (recordIndex, column), mPositionOverride.pos[i]));
|
model->index (recordIndex, column), mPositionOverride.pos[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int column = collection.findColumnIndex (static_cast<CSMWorld::Columns::ColumnId> (
|
||||||
|
CSMWorld::Columns::ColumnId_Cell));
|
||||||
|
|
||||||
|
std::pair<int, int> cellIndex = collection.getRecord (recordIndex).get().getCellIndex();
|
||||||
|
|
||||||
|
/// \todo figure out worldspace (not important until multiple worldspaces are supported)
|
||||||
|
std::string cellId = CSMWorld::CellCoordinates (cellIndex).getId ("");
|
||||||
|
|
||||||
|
commands.push (new CSMWorld::ModifyCommand (*model,
|
||||||
|
model->index (recordIndex, column), QString::fromUtf8 (cellId.c_str())));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mOverrideFlags & Override_Rotation)
|
if (mOverrideFlags & Override_Rotation)
|
||||||
|
|
Loading…
Reference in a new issue