forked from mirror/openmw-tes3mp
center map on the player, dynamic map size
This commit is contained in:
parent
9106e5307c
commit
f49401bb53
4 changed files with 93 additions and 29 deletions
|
@ -258,6 +258,7 @@ MapWindow::MapWindow(MWBase::WindowManager& parWindowManager, const std::string&
|
||||||
setCoord(500,0,320,300);
|
setCoord(500,0,320,300);
|
||||||
|
|
||||||
mGlobalMapRender = new MWRender::GlobalMap(cacheDir);
|
mGlobalMapRender = new MWRender::GlobalMap(cacheDir);
|
||||||
|
mGlobalMapRender->render();
|
||||||
|
|
||||||
getWidget(mLocalMap, "LocalMap");
|
getWidget(mLocalMap, "LocalMap");
|
||||||
getWidget(mGlobalMap, "GlobalMap");
|
getWidget(mGlobalMap, "GlobalMap");
|
||||||
|
@ -293,13 +294,12 @@ void MapWindow::setCellName(const std::string& cellName)
|
||||||
|
|
||||||
void MapWindow::addVisitedLocation(const std::string& name, int x, int y)
|
void MapWindow::addVisitedLocation(const std::string& name, int x, int y)
|
||||||
{
|
{
|
||||||
const int cellSize = 24;
|
float worldX, worldY;
|
||||||
|
mGlobalMapRender->cellTopLeftCornerToImageSpace (x, y, worldX, worldY);
|
||||||
int size = 24 * 61;
|
|
||||||
|
|
||||||
MyGUI::IntCoord widgetCoord(
|
MyGUI::IntCoord widgetCoord(
|
||||||
(x+30)*cellSize+6,
|
worldX * mGlobalMapRender->getWidth()+6,
|
||||||
(size-1) - (y+30)*cellSize+6,
|
worldY * mGlobalMapRender->getHeight()+6,
|
||||||
12, 12);
|
12, 12);
|
||||||
|
|
||||||
|
|
||||||
|
@ -349,6 +349,9 @@ void MapWindow::onWorldButtonClicked(MyGUI::Widget* _sender)
|
||||||
|
|
||||||
mButton->setCaptionWithReplacing( mGlobal ? "#{sLocal}" :
|
mButton->setCaptionWithReplacing( mGlobal ? "#{sLocal}" :
|
||||||
"#{sWorld}");
|
"#{sWorld}");
|
||||||
|
|
||||||
|
if (mGlobal)
|
||||||
|
globalMapUpdatePlayer ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapWindow::onPinToggled()
|
void MapWindow::onPinToggled()
|
||||||
|
@ -360,10 +363,8 @@ void MapWindow::open()
|
||||||
{
|
{
|
||||||
mGlobalMapImage->setImageTexture("GlobalMap.png");
|
mGlobalMapImage->setImageTexture("GlobalMap.png");
|
||||||
|
|
||||||
int size = 24 * 61;
|
mGlobalMap->setCanvasSize (mGlobalMapRender->getWidth(), mGlobalMapRender->getHeight());
|
||||||
|
mGlobalMapImage->setSize(mGlobalMapRender->getWidth(), mGlobalMapRender->getHeight());
|
||||||
mGlobalMap->setCanvasSize (size, size);
|
|
||||||
mGlobalMapImage->setSize(size, size);
|
|
||||||
|
|
||||||
for (unsigned int i=0; i<mGlobalMapImage->getChildCount (); ++i)
|
for (unsigned int i=0; i<mGlobalMapImage->getChildCount (); ++i)
|
||||||
{
|
{
|
||||||
|
@ -371,18 +372,28 @@ void MapWindow::open()
|
||||||
mGlobalMapImage->getChildAt (i)->castType<MyGUI::Button>()->setImageResource("DoorMarker");
|
mGlobalMapImage->getChildAt (i)->castType<MyGUI::Button>()->setImageResource("DoorMarker");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
globalMapUpdatePlayer();
|
||||||
|
|
||||||
|
mPlayerArrowGlobal->setImageTexture ("textures\\compass.dds");
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapWindow::globalMapUpdatePlayer ()
|
||||||
|
{
|
||||||
Ogre::Vector3 pos = MWBase::Environment::get().getWorld ()->getPlayer ().getPlayer().getRefData ().getBaseNode ()->_getDerivedPosition ();
|
Ogre::Vector3 pos = MWBase::Environment::get().getWorld ()->getPlayer ().getPlayer().getRefData ().getBaseNode ()->_getDerivedPosition ();
|
||||||
Ogre::Quaternion orient = MWBase::Environment::get().getWorld ()->getPlayer ().getPlayer().getRefData ().getBaseNode ()->_getDerivedOrientation ();
|
Ogre::Quaternion orient = MWBase::Environment::get().getWorld ()->getPlayer ().getPlayer().getRefData ().getBaseNode ()->_getDerivedOrientation ();
|
||||||
Ogre::Vector2 dir (orient.yAxis ().x, -orient.yAxis().z);
|
Ogre::Vector2 dir (orient.yAxis ().x, -orient.yAxis().z);
|
||||||
|
|
||||||
float worldX = ((pos.x / 8192.f-0.5) / 30.f+1)/2.f;
|
float worldX, worldY;
|
||||||
float worldY = ((pos.z / 8192.f+1.5) / 30.f+1)/2.f;
|
mGlobalMapRender->worldPosToImageSpace (pos.x, pos.z, worldX, worldY);
|
||||||
|
worldX *= mGlobalMapRender->getWidth();
|
||||||
|
worldY *= mGlobalMapRender->getHeight();
|
||||||
|
|
||||||
|
|
||||||
// for interiors, we have no choice other than using the last position & direction.
|
// for interiors, we have no choice other than using the last position & direction.
|
||||||
/// \todo save this last position in the savegame?
|
/// \todo save this last position in the savegame?
|
||||||
if (MWBase::Environment::get().getWorld ()->isCellExterior ())
|
if (MWBase::Environment::get().getWorld ()->isCellExterior ())
|
||||||
{
|
{
|
||||||
mPlayerArrowGlobal->setPosition(MyGUI::IntPoint(size * worldX - 16, size * worldY - 16));
|
mPlayerArrowGlobal->setPosition(MyGUI::IntPoint(worldX - 16, worldY - 16));
|
||||||
|
|
||||||
MyGUI::ISubWidget* main = mPlayerArrowGlobal->getSubWidgetMain();
|
MyGUI::ISubWidget* main = mPlayerArrowGlobal->getSubWidgetMain();
|
||||||
MyGUI::RotatingSkin* rotatingSubskin = main->castType<MyGUI::RotatingSkin>();
|
MyGUI::RotatingSkin* rotatingSubskin = main->castType<MyGUI::RotatingSkin>();
|
||||||
|
@ -391,5 +402,8 @@ void MapWindow::open()
|
||||||
rotatingSubskin->setAngle(angle);
|
rotatingSubskin->setAngle(angle);
|
||||||
}
|
}
|
||||||
|
|
||||||
mPlayerArrowGlobal->setImageTexture ("textures\\compass.dds");
|
// set the view offset so that player is in the center
|
||||||
|
MyGUI::IntSize viewsize = mGlobalMap->getSize();
|
||||||
|
MyGUI::IntPoint viewoffs(0.5*viewsize.width - worldX, 0.5*viewsize.height - worldY);
|
||||||
|
mGlobalMap->setViewOffset(viewoffs);
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,6 +76,8 @@ namespace MWGui
|
||||||
void onMouseDrag(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id);
|
void onMouseDrag(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id);
|
||||||
void onWorldButtonClicked(MyGUI::Widget* _sender);
|
void onWorldButtonClicked(MyGUI::Widget* _sender);
|
||||||
|
|
||||||
|
void globalMapUpdatePlayer();
|
||||||
|
|
||||||
MyGUI::ScrollView* mGlobalMap;
|
MyGUI::ScrollView* mGlobalMap;
|
||||||
MyGUI::ImageBox* mGlobalMapImage;
|
MyGUI::ImageBox* mGlobalMapImage;
|
||||||
MyGUI::ImageBox* mPlayerArrowLocal;
|
MyGUI::ImageBox* mPlayerArrowLocal;
|
||||||
|
|
|
@ -19,6 +19,8 @@ namespace MWRender
|
||||||
|
|
||||||
GlobalMap::GlobalMap(const std::string &cacheDir)
|
GlobalMap::GlobalMap(const std::string &cacheDir)
|
||||||
: mCacheDir(cacheDir)
|
: mCacheDir(cacheDir)
|
||||||
|
, mMinX(0), mMaxX(0)
|
||||||
|
, mMinY(0), mMaxY(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,21 +29,34 @@ namespace MWRender
|
||||||
{
|
{
|
||||||
Ogre::TexturePtr tex;
|
Ogre::TexturePtr tex;
|
||||||
|
|
||||||
if (!boost::filesystem::exists(mCacheDir + "/GlobalMap.png"))
|
// get the size of the world
|
||||||
|
const ESMS::CellList::ExtCells& extCells = MWBase::Environment::get().getWorld ()->getStore ().cells.extCells;
|
||||||
|
for (ESMS::CellList::ExtCells::const_iterator it = extCells.begin(); it != extCells.end(); ++it)
|
||||||
{
|
{
|
||||||
|
if (it->first.first < mMinX)
|
||||||
|
mMinX = it->first.first;
|
||||||
|
if (it->first.first > mMaxX)
|
||||||
|
mMaxX = it->first.first;
|
||||||
|
if (it->first.second < mMinY)
|
||||||
|
mMinY = it->first.second;
|
||||||
|
if (it->first.second > mMaxY)
|
||||||
|
mMaxY = it->first.second;
|
||||||
|
}
|
||||||
|
|
||||||
int cellSize = 24;
|
int cellSize = 24;
|
||||||
|
mWidth = cellSize*(mMaxX-mMinX+1);
|
||||||
|
mHeight = cellSize*(mMaxY-mMinY+1);
|
||||||
|
|
||||||
|
|
||||||
|
if (!boost::filesystem::exists(mCacheDir + "/GlobalMap.png"))
|
||||||
|
{
|
||||||
Ogre::Image image;
|
Ogre::Image image;
|
||||||
|
|
||||||
int width = cellSize*61;
|
Ogre::uchar data[mWidth * mHeight * 3];
|
||||||
int height = cellSize*61;
|
|
||||||
|
|
||||||
Ogre::uchar data[width * height * 3];
|
for (int x = mMinX; x <= mMaxX; ++x)
|
||||||
|
|
||||||
for (int x = -30; x <= 30; ++x)
|
|
||||||
{
|
{
|
||||||
for (int y = -30; y <= 30; ++y)
|
for (int y = mMinY; y <= mMaxY; ++y)
|
||||||
{
|
{
|
||||||
ESM::Land* land = MWBase::Environment::get().getWorld ()->getStore ().lands.search (x,y);
|
ESM::Land* land = MWBase::Environment::get().getWorld ()->getStore ().lands.search (x,y);
|
||||||
|
|
||||||
|
@ -61,8 +76,8 @@ namespace MWRender
|
||||||
int vertexY = float(cellY)/float(cellSize) * ESM::Land::LAND_SIZE;
|
int vertexY = float(cellY)/float(cellSize) * ESM::Land::LAND_SIZE;
|
||||||
|
|
||||||
|
|
||||||
int texelX = (x+30) * cellSize + cellX;
|
int texelX = (x-mMinX) * cellSize + cellX;
|
||||||
int texelY = (height-1) - ((y+30) * cellSize + cellY);
|
int texelY = (mHeight-1) - ((y-mMinY) * cellSize + cellY);
|
||||||
|
|
||||||
Ogre::ColourValue waterShallowColour(0.15, 0.2, 0.19);
|
Ogre::ColourValue waterShallowColour(0.15, 0.2, 0.19);
|
||||||
Ogre::ColourValue waterDeepColour(0.1, 0.14, 0.13);
|
Ogre::ColourValue waterDeepColour(0.1, 0.14, 0.13);
|
||||||
|
@ -123,20 +138,23 @@ namespace MWRender
|
||||||
b = waterDeepColour.b * 255;
|
b = waterDeepColour.b * 255;
|
||||||
}
|
}
|
||||||
|
|
||||||
data[texelY * height * 3 + texelX * 3] = r;
|
// uncomment this line to outline cell borders
|
||||||
data[texelY * height * 3 + texelX * 3+1] = g;
|
//if (cellX == 0 || cellX == cellSize-1 || cellY == 0|| cellY == cellSize-1) r = 255;
|
||||||
data[texelY * height * 3 + texelX * 3+2] = b;
|
|
||||||
|
data[texelY * mWidth * 3 + texelX * 3] = r;
|
||||||
|
data[texelY * mWidth * 3 + texelX * 3+1] = g;
|
||||||
|
data[texelY * mWidth * 3 + texelX * 3+2] = b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
image.loadDynamicImage (data, width, height, Ogre::PF_B8G8R8);
|
image.loadDynamicImage (data, mWidth, mHeight, Ogre::PF_B8G8R8);
|
||||||
|
|
||||||
image.save (mCacheDir + "/GlobalMap.png");
|
image.save (mCacheDir + "/GlobalMap.png");
|
||||||
|
|
||||||
tex = Ogre::TextureManager::getSingleton ().createManual ("GlobalMap.png", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
tex = Ogre::TextureManager::getSingleton ().createManual ("GlobalMap.png", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
||||||
Ogre::TEX_TYPE_2D, width, height, 0, Ogre::PF_B8G8R8, Ogre::TU_DEFAULT);
|
Ogre::TEX_TYPE_2D, mWidth, mHeight, 0, Ogre::PF_B8G8R8, Ogre::TU_DEFAULT);
|
||||||
tex->loadImage(image);
|
tex->loadImage(image);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -145,4 +163,20 @@ namespace MWRender
|
||||||
tex->load();
|
tex->load();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GlobalMap::worldPosToImageSpace(float x, float z, float& imageX, float& imageY)
|
||||||
|
{
|
||||||
|
imageX = float(x / 8192.f - mMinX) / (mMaxX - mMinX + 1);
|
||||||
|
|
||||||
|
imageY = 1.f-float(-z / 8192.f - mMinY) / (mMaxY - mMinY + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GlobalMap::cellTopLeftCornerToImageSpace(int x, int y, float& imageX, float& imageY)
|
||||||
|
{
|
||||||
|
imageX = float(x - mMinX) / (mMaxX - mMinX + 1);
|
||||||
|
|
||||||
|
// NB y + 1, because we want the top left corner, not bottom left where the origin of the cell is
|
||||||
|
imageY = 1.f-float(y - mMinY + 1) / (mMaxY - mMinY + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,8 +13,22 @@ namespace MWRender
|
||||||
|
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
|
int getWidth() { return mWidth; }
|
||||||
|
int getHeight() { return mHeight; }
|
||||||
|
|
||||||
|
void worldPosToImageSpace(float x, float z, float& imageX, float& imageY);
|
||||||
|
///< @param x x ogre coords
|
||||||
|
/// @param z z ogre coords
|
||||||
|
|
||||||
|
void cellTopLeftCornerToImageSpace(int x, int y, float& imageX, float& imageY);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string mCacheDir;
|
std::string mCacheDir;
|
||||||
|
|
||||||
|
int mWidth;
|
||||||
|
int mHeight;
|
||||||
|
|
||||||
|
int mMinX, mMaxX, mMinY, mMaxY;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue