forked from teamnwah/openmw-tes3coop
finally got rid of the nasty coordinates bug
This commit is contained in:
parent
15878b12fd
commit
9e8251e6b4
4 changed files with 41 additions and 12 deletions
|
@ -58,8 +58,8 @@ namespace MWRender
|
|||
// Get new camera position, converting back to MW coords.
|
||||
Vector3 pos = camera->getPosition();
|
||||
relX = pos[0];
|
||||
relY = pos[2];
|
||||
relZ = -pos[1];
|
||||
relY = -pos[2];
|
||||
relZ = pos[1];
|
||||
|
||||
// TODO: Collision detection must be used to find the REAL new
|
||||
// position.
|
||||
|
|
|
@ -62,13 +62,13 @@ namespace MWScript
|
|||
Interpreter::Type_Integer y = runtime[0].mInteger;
|
||||
runtime.pop();
|
||||
|
||||
const int cellSize = 8192;
|
||||
|
||||
ESM::Position pos;
|
||||
pos.pos[0] = cellSize * (x+0.5);
|
||||
pos.pos[1] = cellSize * (y+0.5);
|
||||
|
||||
context.getWorld().indexToPosition (x, y, pos.pos[0], pos.pos[1]);
|
||||
pos.pos[2] = 0;
|
||||
|
||||
pos.rot[0] = pos.rot[1] = pos.rot[2] = 0;
|
||||
|
||||
context.getWorld().changeToExteriorCell (pos);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -633,10 +633,10 @@ namespace MWWorld
|
|||
|
||||
void World::changeToExteriorCell (const ESM::Position& position)
|
||||
{
|
||||
const int cellSize = 8192;
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
|
||||
int x = static_cast<int> (position.pos[0] / cellSize);
|
||||
int y = static_cast<int> (position.pos[1] / cellSize);
|
||||
positionToIndex (position.pos[0], position.pos[1], x, y);
|
||||
|
||||
changeCell (x, y, position);
|
||||
}
|
||||
|
@ -692,10 +692,10 @@ namespace MWWorld
|
|||
if (!(active->first->cell->data.flags & ESM::Cell::Interior))
|
||||
{
|
||||
// exterior -> adjust loaded cells
|
||||
const int cellSize = 8192;
|
||||
int cellX = 0;
|
||||
int cellY = 0;
|
||||
|
||||
int cellX = static_cast<int> (x/cellSize);
|
||||
int cellY = static_cast<int> (y/cellSize);
|
||||
positionToIndex (x, y, cellX, cellY);
|
||||
|
||||
if (active->first->cell->data.gridX!=cellX || active->first->cell->data.gridY!=cellY)
|
||||
{
|
||||
|
@ -707,4 +707,27 @@ namespace MWWorld
|
|||
|
||||
// TODO cell change for non-player ref
|
||||
}
|
||||
|
||||
void World::indexToPosition (int cellX, int cellY, float &x, float &y) const
|
||||
{
|
||||
const int cellSize = 8192;
|
||||
|
||||
x = cellSize * cellX;
|
||||
y = cellSize * cellY;
|
||||
}
|
||||
|
||||
void World::positionToIndex (float x, float y, int &cellX, int &cellY) const
|
||||
{
|
||||
const int cellSize = 8192;
|
||||
|
||||
cellX = static_cast<int> (x/cellSize);
|
||||
|
||||
if (x<0)
|
||||
--cellX;
|
||||
|
||||
cellY = static_cast<int> (y/cellSize);
|
||||
|
||||
if (y<0)
|
||||
--cellY;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -153,6 +153,12 @@ namespace MWWorld
|
|||
void deleteObject (Ptr ptr);
|
||||
|
||||
void moveObject (Ptr ptr, float x, float y, float z);
|
||||
|
||||
void indexToPosition (int cellX, int cellY, float &x, float &y) const;
|
||||
///< Convert cell numbers to position.
|
||||
|
||||
void positionToIndex (float x, float y, int &cellX, int &cellY) const;
|
||||
///< Convert position to cell numbers
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue