forked from mirror/openmw-tes3mp
Implemented the faced handle method to the engine. Faced handles will
be written to stdout every 10th frame.
This commit is contained in:
parent
c000bfb43d
commit
adc209d135
5 changed files with 27 additions and 7 deletions
|
@ -3,6 +3,7 @@
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
#include <components/misc/fileops.hpp>
|
#include <components/misc/fileops.hpp>
|
||||||
#include <components/bsa/bsa_archive.hpp>
|
#include <components/bsa/bsa_archive.hpp>
|
||||||
|
@ -68,6 +69,15 @@ bool OMW::Engine::frameStarted(const Ogre::FrameEvent& evt)
|
||||||
// update actors
|
// update actors
|
||||||
mEnvironment.mMechanicsManager->update();
|
mEnvironment.mMechanicsManager->update();
|
||||||
|
|
||||||
|
if (focusFrameCounter++ == focusUpdateFrame)
|
||||||
|
{
|
||||||
|
std::pair<std::string, float> handle = mEnvironment.mWorld->getMWScene()->getFacedHandle();
|
||||||
|
|
||||||
|
std::cout << "Object: " << handle.first << ", distance: " << handle.second << std::endl;
|
||||||
|
|
||||||
|
focusFrameCounter = 0;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,6 +240,8 @@ void OMW::Engine::go()
|
||||||
MWInput::MWInputManager input(mOgre, mEnvironment.mWorld->getPlayerPos(),
|
MWInput::MWInputManager input(mOgre, mEnvironment.mWorld->getPlayerPos(),
|
||||||
*mEnvironment.mWindowManager, mDebug);
|
*mEnvironment.mWindowManager, mDebug);
|
||||||
|
|
||||||
|
focusFrameCounter = 0;
|
||||||
|
|
||||||
std::cout << "\nPress Q/ESC or close window to exit.\n";
|
std::cout << "\nPress Q/ESC or close window to exit.\n";
|
||||||
|
|
||||||
mOgre.getRoot()->addFrameListener (this);
|
mOgre.getRoot()->addFrameListener (this);
|
||||||
|
|
|
@ -65,6 +65,9 @@ namespace OMW
|
||||||
Compiler::Context *mScriptContext;
|
Compiler::Context *mScriptContext;
|
||||||
OEngine::GUI::MyGUIManager *mGuiManager;
|
OEngine::GUI::MyGUIManager *mGuiManager;
|
||||||
|
|
||||||
|
int focusFrameCounter;
|
||||||
|
static const int focusUpdateFrame = 10;
|
||||||
|
|
||||||
// not implemented
|
// not implemented
|
||||||
Engine (const Engine&);
|
Engine (const Engine&);
|
||||||
Engine& operator= (const Engine&);
|
Engine& operator= (const Engine&);
|
||||||
|
|
|
@ -36,10 +36,10 @@ MWScene::MWScene(OEngine::Render::OgreRenderer &_rend)
|
||||||
mRaySceneQuery = rend.getScene()->createRayQuery(Ray());
|
mRaySceneQuery = rend.getScene()->createRayQuery(Ray());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MWScene::getFacedHandle(std::string& handle, float& distance)
|
std::pair<std::string, float> MWScene::getFacedHandle()
|
||||||
{
|
{
|
||||||
handle = "";
|
std::string handle = "";
|
||||||
distance = -1;
|
float distance = -1;
|
||||||
|
|
||||||
//get a ray pointing to the center of the viewport
|
//get a ray pointing to the center of the viewport
|
||||||
Ray centerRay = getCamera()->getCameraToViewportRay(
|
Ray centerRay = getCamera()->getCameraToViewportRay(
|
||||||
|
@ -74,11 +74,10 @@ void MWScene::getFacedHandle(std::string& handle, float& distance)
|
||||||
|
|
||||||
if ( nearest != result.end() )
|
if ( nearest != result.end() )
|
||||||
{
|
{
|
||||||
std::cout << "Nearest MovableObject: " << nearest->movable->getParentSceneNode()->getName()
|
|
||||||
<< " Distance: " << nearest->distance << std::endl;
|
|
||||||
|
|
||||||
handle = nearest->movable->getParentSceneNode()->getName();
|
handle = nearest->movable->getParentSceneNode()->getName();
|
||||||
distance = nearest->distance;
|
distance = nearest->distance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return std::pair<std::string, float>(handle, distance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#ifndef _GAME_RENDER_MWSCENE_H
|
#ifndef _GAME_RENDER_MWSCENE_H
|
||||||
#define _GAME_RENDER_MWSCENE_H
|
#define _GAME_RENDER_MWSCENE_H
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
#include <openengine/ogre/renderer.hpp>
|
#include <openengine/ogre/renderer.hpp>
|
||||||
|
|
||||||
namespace Ogre
|
namespace Ogre
|
||||||
|
@ -39,7 +40,10 @@ namespace MWRender
|
||||||
Ogre::RaySceneQuery *getRaySceneQuery() { return mRaySceneQuery; }
|
Ogre::RaySceneQuery *getRaySceneQuery() { return mRaySceneQuery; }
|
||||||
|
|
||||||
//gets the handle of the object the player is looking at
|
//gets the handle of the object the player is looking at
|
||||||
void getFacedHandle(std::string& handle, float& distance);
|
//pair<name, distance>
|
||||||
|
//name is empty and distance = -1 if there is no object which
|
||||||
|
//can be faced
|
||||||
|
std::pair<std::string, float> getFacedHandle();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,6 +80,8 @@ namespace MWWorld
|
||||||
const std::string& dataDir, bool newGame, Environment& environment);
|
const std::string& dataDir, bool newGame, Environment& environment);
|
||||||
|
|
||||||
~World();
|
~World();
|
||||||
|
|
||||||
|
MWRender::MWScene* getMWScene() { return &mScene; }
|
||||||
|
|
||||||
MWRender::PlayerPos& getPlayerPos();
|
MWRender::PlayerPos& getPlayerPos();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue