handle cell transitions when moving objects

move
Marc Zinnschlag 9 years ago
parent fa9689c5e7
commit d6b8033b46

@ -1,5 +1,7 @@
#include "cellcoordinates.hpp"
#include <cmath>
#include <ostream>
#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 (const std::pair<int, int>& coordinates)
: mX (coordinates.first), mY (coordinates.second) {}
int CSMWorld::CellCoordinates::getX() const
{
return mX;
@ -49,6 +54,13 @@ std::pair<CSMWorld::CellCoordinates, bool> CSMWorld::CellCoordinates::fromId (
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)
{
return left.getX()==right.getX() && left.getY()==right.getY();

@ -3,6 +3,7 @@
#include <iosfwd>
#include <string>
#include <utility>
#include <QMetaType>
@ -19,6 +20,8 @@ namespace CSMWorld
CellCoordinates (int x, int y);
CellCoordinates (const std::pair<int, int>& coordinates);
int getX() const;
int getY() const;
@ -34,6 +37,8 @@ namespace CSMWorld
///
/// \note The worldspace part of \a id is ignored
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);

@ -2,6 +2,10 @@
#include <cmath>
#include <sstream>
#include "cellcoordinates.hpp"
CSMWorld::CellRef::CellRef()
{
mRefNum.mIndex = 0;
@ -10,8 +14,5 @@ CSMWorld::CellRef::CellRef()
std::pair<int, int> CSMWorld::CellRef::getCellIndex() const
{
const int cellSize = 8192;
return std::make_pair (
std::floor (mPos.pos[0]/cellSize), std::floor (mPos.pos[1]/cellSize));
return CellCoordinates::coordinatesToCellIndex (mPos.pos[0], mPos.pos[1]);
}

@ -20,6 +20,7 @@
#include "../../model/world/commands.hpp"
#include "../../model/world/universalid.hpp"
#include "../../model/world/commandmacro.hpp"
#include "../../model/world/cellcoordinates.hpp"
#include <components/resource/scenemanager.hpp>
#include <components/sceneutil/lightutil.hpp>
@ -542,6 +543,17 @@ void CSVRender::Object::apply (CSMWorld::CommandMacro& commands)
commands.push (new CSMWorld::ModifyCommand (*model,
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)

Loading…
Cancel
Save