From 9e8251e6b4f64b99b6e693c494e0d4629d66c9a7 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sun, 22 Aug 2010 21:30:48 +0200 Subject: [PATCH] finally got rid of the nasty coordinates bug --- apps/openmw/mwrender/playerpos.hpp | 4 +-- apps/openmw/mwscript/cellextensions.cpp | 8 +++--- apps/openmw/mwworld/world.cpp | 35 ++++++++++++++++++++----- apps/openmw/mwworld/world.hpp | 6 +++++ 4 files changed, 41 insertions(+), 12 deletions(-) diff --git a/apps/openmw/mwrender/playerpos.hpp b/apps/openmw/mwrender/playerpos.hpp index e83ee216d..59a0e1b41 100644 --- a/apps/openmw/mwrender/playerpos.hpp +++ b/apps/openmw/mwrender/playerpos.hpp @@ -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. diff --git a/apps/openmw/mwscript/cellextensions.cpp b/apps/openmw/mwscript/cellextensions.cpp index 27251a728..7d633b59d 100644 --- a/apps/openmw/mwscript/cellextensions.cpp +++ b/apps/openmw/mwscript/cellextensions.cpp @@ -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); } }; diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index ff8ca7c52..2c8c4a542 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -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 (position.pos[0] / cellSize); - int y = static_cast (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 (x/cellSize); - int cellY = static_cast (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 (x/cellSize); + + if (x<0) + --cellX; + + cellY = static_cast (y/cellSize); + + if (y<0) + --cellY; + } } diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index 000d79037..2ff2d3ccc 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -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 }; }