Added rendering loop and keyboard listener

actorid
Nicolay Korslund 15 years ago
parent 4cadf70abe
commit edca830845

@ -7,6 +7,7 @@
#include "ogre/renderer.hpp" #include "ogre/renderer.hpp"
#include "tools/fileops.hpp" #include "tools/fileops.hpp"
#include "input/oismanager.hpp" #include "input/oismanager.hpp"
#include "input/listener.hpp"
using namespace std; using namespace std;
@ -43,17 +44,26 @@ void maintest()
// Create the window // Create the window
ogre.createWindow("OpenMW"); ogre.createWindow("OpenMW");
Render::MWScene scene; cout << "\nSetting up cell rendering (not done)\n";
scene.setup(&ogre);
// Sets up camera, scene manager etc
Render::MWScene scene(ogre);
// This doesn't do anything yet. // This doesn't do anything yet.
Render::CellRender rend(cell); Render::CellRender rend(cell);
Input::OISManager input; cout << "Setting up input system\n";
input.setup(&ogre);
// Sets up the input system
Input::OISManager input(ogre);
// Add the frame and input listener
Input::ExitListener frame(ogre, input);
cout << "\nStart! Press Q/ESC or close window to exit.\n";
// Add the frame listener // Start the main rendering loop
//root->addFrameListener(&mFrameListener); ogre.start();
cout << "\nThat's all for now!\n"; cout << "\nThat's all for now!\n";
} }

@ -5,13 +5,11 @@
using namespace Render; using namespace Render;
using namespace Ogre; using namespace Ogre;
void MWScene::setup(OgreRenderer *_rend) MWScene::MWScene(OgreRenderer &_rend)
: rend(_rend)
{ {
rend = _rend; Root *root = rend.getRoot();
assert(rend); RenderWindow *window = rend.getWindow();
Root *root = rend->getRoot();
RenderWindow *window = rend->getWindow();
// Get the SceneManager, in this case a generic one // Get the SceneManager, in this case a generic one
sceneMgr = root->createSceneManager(ST_GENERIC); sceneMgr = root->createSceneManager(ST_GENERIC);

@ -6,10 +6,13 @@
namespace Render namespace Render
{ {
/** Class responsible for Morrowind-specific interfaces to OGRE. /** Class responsible for Morrowind-specific interfaces to OGRE.
This might be refactored partially into a non-mw specific
counterpart in ogre/ at some point.
*/ */
class MWScene class MWScene
{ {
OgreRenderer *rend; OgreRenderer &rend;
Ogre::SceneManager *sceneMgr; Ogre::SceneManager *sceneMgr;
Ogre::Camera *camera; Ogre::Camera *camera;
Ogre::Viewport *vp; Ogre::Viewport *vp;
@ -20,7 +23,7 @@ namespace Render
Ogre::SceneNode *mwRoot; Ogre::SceneNode *mwRoot;
public: public:
void setup(OgreRenderer *_rend); MWScene(OgreRenderer &_rend);
}; };
} }

@ -0,0 +1,89 @@
#ifndef _INPUT_LISTENER_H
#define _INPUT_LISTENER_H
#include "oismanager.hpp"
#include "ogre/renderer.hpp"
#include <iostream>
namespace Input
{
struct ExitListener : Ogre::FrameListener,
OIS::KeyListener,
OIS::MouseListener
{
ExitListener(Render::OgreRenderer &rend,
Input::OISManager &input)
: doExit(false)
{
// Set up component pointers
mWindow = rend.getWindow();
mMouse = input.mouse;
mKeyboard = input.keyboard;
// Add ourself to the managers
rend.getRoot() -> addFrameListener(this);
mKeyboard -> setEventCallback(this);
mMouse -> setEventCallback(this);
}
// Call this to exit the main loop
void exitNow() { doExit = true; }
bool frameStarted(const Ogre::FrameEvent &evt)
{
if(mWindow->isClosed() || doExit)
return false;
// Capture keyboard and mouse events
mKeyboard->capture();
mMouse->capture();
return Ogre::FrameListener::frameStarted(evt);
}
bool keyPressed( const OIS::KeyEvent &arg )
{
/*
std::cout << "KeyPressed {" << arg.key
<< ", " << ((OIS::Keyboard*)(arg.device))->getAsString(arg.key)
<< "} || Character (" << (char)arg.text << ")\n";
*/
using namespace OIS;
if(arg.key == KC_Q ||
arg.key == KC_ESCAPE)
exitNow();
return true;
}
bool keyReleased( const OIS::KeyEvent &arg )
{
return true;
}
bool mouseMoved( const OIS::MouseEvent &arg )
{
return true;
}
bool mousePressed( const OIS::MouseEvent &arg, OIS::MouseButtonID id )
{
return true;
}
bool mouseReleased( const OIS::MouseEvent &arg, OIS::MouseButtonID id )
{
return true;
}
private:
Ogre::RenderWindow *mWindow;
OIS::Mouse *mMouse;
OIS::Keyboard *mKeyboard;
bool doExit;
};
}
#endif

@ -10,11 +10,9 @@ using namespace OIS;
#include <iostream> #include <iostream>
using namespace std; using namespace std;
void OISManager::setup(Render::OgreRenderer *rend) OISManager::OISManager(Render::OgreRenderer &rend)
{ {
assert(rend); RenderWindow *window = rend.getWindow();
RenderWindow *window = rend->getWindow();
assert(window); assert(window);
size_t windowHnd; size_t windowHnd;
@ -62,15 +60,9 @@ void OISManager::setup(Render::OgreRenderer *rend)
const MouseState &ms = mouse->getMouseState(); const MouseState &ms = mouse->getMouseState();
ms.width = window->getWidth(); ms.width = window->getWidth();
ms.height = window->getHeight(); ms.height = window->getHeight();
/*
// Register the input listener
keyboard -> setEventCallback( &mInput );
mouse -> setEventCallback( &mInput );
*/
} }
void OISManager::cleanup() OISManager::~OISManager()
{ {
if(inputMgr == NULL) return; if(inputMgr == NULL) return;

@ -6,15 +6,14 @@
namespace Input namespace Input
{ {
class OISManager struct OISManager
{ {
OIS::InputManager *inputMgr; OIS::InputManager *inputMgr;
OIS::Mouse *mouse; OIS::Mouse *mouse;
OIS::Keyboard *keyboard; OIS::Keyboard *keyboard;
public: OISManager(Render::OgreRenderer &rend);
void setup(Render::OgreRenderer *rend); ~OISManager();
void cleanup();
}; };
} }
#endif #endif

@ -33,7 +33,13 @@ namespace Render
/// Kill the renderer. /// Kill the renderer.
void cleanup(); void cleanup();
/// Start the main rendering loop
void start() { mRoot->startRendering(); }
/// Get the Root
Ogre::Root *getRoot() { return mRoot; } Ogre::Root *getRoot() { return mRoot; }
/// Get the rendering window
Ogre::RenderWindow *getWindow() { return mWindow; } Ogre::RenderWindow *getWindow() { return mWindow; }
}; };
} }

@ -148,11 +148,6 @@ extern "C" void ogre_setFog(float rf, float gf, float bf, // Fog color
vp->setBackgroundColour(fogColor); vp->setBackgroundColour(fogColor);
} }
extern "C" void ogre_startRendering()
{
mRoot->startRendering();
}
// Copy a scene node and all its children // Copy a scene node and all its children
void cloneNode(SceneNode *from, SceneNode *to, char* name) void cloneNode(SceneNode *from, SceneNode *to, char* name)
{ {

Loading…
Cancel
Save