diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 43a01b271e..d7d215d023 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -68,6 +69,15 @@ bool OMW::Engine::frameStarted(const Ogre::FrameEvent& evt) // update actors mEnvironment.mMechanicsManager->update(); + if (focusFrameCounter++ == focusUpdateFrame) + { + std::pair handle = mEnvironment.mWorld->getMWScene()->getFacedHandle(); + + std::cout << "Object: " << handle.first << ", distance: " << handle.second << std::endl; + + focusFrameCounter = 0; + } + return true; } @@ -230,6 +240,8 @@ void OMW::Engine::go() MWInput::MWInputManager input(mOgre, mEnvironment.mWorld->getPlayerPos(), *mEnvironment.mWindowManager, mDebug); + focusFrameCounter = 0; + std::cout << "\nPress Q/ESC or close window to exit.\n"; mOgre.getRoot()->addFrameListener (this); diff --git a/apps/openmw/engine.hpp b/apps/openmw/engine.hpp index 9923f49906..412c4fa736 100644 --- a/apps/openmw/engine.hpp +++ b/apps/openmw/engine.hpp @@ -65,6 +65,9 @@ namespace OMW Compiler::Context *mScriptContext; OEngine::GUI::MyGUIManager *mGuiManager; + int focusFrameCounter; + static const int focusUpdateFrame = 10; + // not implemented Engine (const Engine&); Engine& operator= (const Engine&); diff --git a/apps/openmw/mwrender/mwscene.cpp b/apps/openmw/mwrender/mwscene.cpp index 7ba75193a2..15163d7a28 100644 --- a/apps/openmw/mwrender/mwscene.cpp +++ b/apps/openmw/mwrender/mwscene.cpp @@ -36,10 +36,10 @@ MWScene::MWScene(OEngine::Render::OgreRenderer &_rend) mRaySceneQuery = rend.getScene()->createRayQuery(Ray()); } -void MWScene::getFacedHandle(std::string& handle, float& distance) +std::pair MWScene::getFacedHandle() { - handle = ""; - distance = -1; + std::string handle = ""; + float distance = -1; //get a ray pointing to the center of the viewport Ray centerRay = getCamera()->getCameraToViewportRay( @@ -74,11 +74,10 @@ void MWScene::getFacedHandle(std::string& handle, float& distance) if ( nearest != result.end() ) { - std::cout << "Nearest MovableObject: " << nearest->movable->getParentSceneNode()->getName() - << " Distance: " << nearest->distance << std::endl; - handle = nearest->movable->getParentSceneNode()->getName(); distance = nearest->distance; } + + return std::pair(handle, distance); } diff --git a/apps/openmw/mwrender/mwscene.hpp b/apps/openmw/mwrender/mwscene.hpp index fcd63df395..ce04efc92e 100644 --- a/apps/openmw/mwrender/mwscene.hpp +++ b/apps/openmw/mwrender/mwscene.hpp @@ -1,6 +1,7 @@ #ifndef _GAME_RENDER_MWSCENE_H #define _GAME_RENDER_MWSCENE_H +#include #include namespace Ogre @@ -39,7 +40,10 @@ namespace MWRender Ogre::RaySceneQuery *getRaySceneQuery() { return mRaySceneQuery; } //gets the handle of the object the player is looking at - void getFacedHandle(std::string& handle, float& distance); + //pair + //name is empty and distance = -1 if there is no object which + //can be faced + std::pair getFacedHandle(); }; } diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index 953fe93e43..88267abe8b 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -80,6 +80,8 @@ namespace MWWorld const std::string& dataDir, bool newGame, Environment& environment); ~World(); + + MWRender::MWScene* getMWScene() { return &mScene; } MWRender::PlayerPos& getPlayerPos();