From 06fa310e292ebc7db3e270a804dc6b5b03630dd4 Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 23 Mar 2012 15:00:48 +0100 Subject: [PATCH] player arrow rotated correctly --- apps/openmw/mwgui/layouts.hpp | 9 ++++++++- apps/openmw/mwgui/window_manager.cpp | 5 +++++ apps/openmw/mwgui/window_manager.hpp | 1 + apps/openmw/mwrender/localmap.cpp | 3 ++- apps/openmw/mwrender/localmap.hpp | 5 +++-- apps/openmw/mwrender/renderingmanager.cpp | 2 +- 6 files changed, 20 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwgui/layouts.hpp b/apps/openmw/mwgui/layouts.hpp index 49b956f0a..7ae28b4d8 100644 --- a/apps/openmw/mwgui/layouts.hpp +++ b/apps/openmw/mwgui/layouts.hpp @@ -14,6 +14,8 @@ #include "../mwmechanics/stat.hpp" #include "window_base.hpp" +#include + /* This file contains classes corresponding to window layouts defined in resources/mygui/ *.xml. @@ -144,11 +146,16 @@ namespace MWGui mLocalMap->setViewOffset(pos); mPlayerArrow->setPosition(MyGUI::IntPoint(x*512-16, y*512-16)); + } + void setPlayerDir(const float x, const float y) + { + if (!mVisible) return; MyGUI::ISubWidget* main = mPlayerArrow->getSubWidgetMain(); MyGUI::RotatingSkin* rotatingSubskin = main->castType(); rotatingSubskin->setCenter(MyGUI::IntPoint(16,16)); - rotatingSubskin->setAngle(3.141); + float angle = std::atan2(x,y); + rotatingSubskin->setAngle(angle); } void onDragStart(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id) diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index c7ee1438e..a263ee2a0 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -429,3 +429,8 @@ void WindowManager::setPlayerPos(const float x, const float y) { map->setPlayerPos(x,y); } + +void WindowManager::setPlayerDir(const float x, const float y) +{ + map->setPlayerDir(x,y); +} diff --git a/apps/openmw/mwgui/window_manager.hpp b/apps/openmw/mwgui/window_manager.hpp index 922009e4d..582f438e8 100644 --- a/apps/openmw/mwgui/window_manager.hpp +++ b/apps/openmw/mwgui/window_manager.hpp @@ -155,6 +155,7 @@ namespace MWGui void changeCell(MWWorld::Ptr::CellStore* cell); ///< change the active cell void setPlayerPos(const float x, const float y); ///< set player position in map space + void setPlayerDir(const float x, const float y); ///< set player view direction in map space void setInteriorMapTexture(const int x, const int y); ///< set the index of the map texture that should be used (for interiors) diff --git a/apps/openmw/mwrender/localmap.cpp b/apps/openmw/mwrender/localmap.cpp index e7a7c9f05..83fe40166 100644 --- a/apps/openmw/mwrender/localmap.cpp +++ b/apps/openmw/mwrender/localmap.cpp @@ -225,7 +225,7 @@ void LocalMap::render(const float x, const float y, mRendering->getScene()->setFog(FOG_LINEAR, clr, 0, fStart, fEnd); } -void LocalMap::setPlayerPosition (const Ogre::Vector3& position) +void LocalMap::updatePlayer (const Ogre::Vector3& position, const Ogre::Vector3& direction) { if (sFogOfWarSkip != 0) { @@ -276,6 +276,7 @@ void LocalMap::setPlayerPosition (const Ogre::Vector3& position) texName = mInteriorName + "_" + coordStr(x,y); } mEnvironment->mWindowManager->setPlayerPos(u, v); + mEnvironment->mWindowManager->setPlayerDir(direction.x, -direction.z); // explore radius (squared) const float sqrExploreRadius = 0.01 * sFogOfWarResolution*sFogOfWarResolution; diff --git a/apps/openmw/mwrender/localmap.hpp b/apps/openmw/mwrender/localmap.hpp index 13e01b7f4..3bef475ea 100644 --- a/apps/openmw/mwrender/localmap.hpp +++ b/apps/openmw/mwrender/localmap.hpp @@ -40,12 +40,13 @@ namespace MWRender Ogre::AxisAlignedBox bounds); /** - * Set the position of the player. + * Set the position & direction of the player. * @remarks This is used to draw a "fog of war" effect * to hide areas on the map the player has not discovered yet. * @param position (OGRE coordinates) + * @param view direction (OGRE coordinates) */ - void setPlayerPosition (const Ogre::Vector3& position); + void updatePlayer (const Ogre::Vector3& position, const Ogre::Vector3& direction); /** * Save the fog of war for the current cell to disk. diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 6b7c21e51..e2aea19c6 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -141,7 +141,7 @@ void RenderingManager::update (float duration){ mRendering.update(duration); - mLocalMap->setPlayerPosition( mRendering.getCamera()->getRealPosition() ); + mLocalMap->updatePlayer( mRendering.getCamera()->getRealPosition(), mRendering.getCamera()->getRealDirection() ); } void RenderingManager::skyEnable ()