Implemented the faced handle method to the engine. Faced handles will

be written to stdout every 10th frame.
pull/7/head
Armin Preiml 15 years ago
parent c000bfb43d
commit adc209d135

@ -3,6 +3,7 @@
#include <cassert>
#include <iostream>
#include <utility>
#include <components/misc/fileops.hpp>
#include <components/bsa/bsa_archive.hpp>
@ -68,6 +69,15 @@ bool OMW::Engine::frameStarted(const Ogre::FrameEvent& evt)
// update actors
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;
}
@ -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);

@ -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&);

@ -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<std::string, float> 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<std::string, float>(handle, distance);
}

@ -1,6 +1,7 @@
#ifndef _GAME_RENDER_MWSCENE_H
#define _GAME_RENDER_MWSCENE_H
#include <utility>
#include <openengine/ogre/renderer.hpp>
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, 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);
~World();
MWRender::MWScene* getMWScene() { return &mScene; }
MWRender::PlayerPos& getPlayerPos();

Loading…
Cancel
Save