Index: /code/branches/FICN/src/orxonox/CMakeLists.txt
===================================================================
--- /code/branches/FICN/src/orxonox/CMakeLists.txt	(revision 511)
+++ /code/branches/FICN/src/orxonox/CMakeLists.txt	(revision 512)
@@ -16,4 +16,5 @@
   main.cc
   graphicsEngine.cc
+  InputManager.cc
 )
 
Index: /code/branches/FICN/src/orxonox/InputManager.cc
===================================================================
--- /code/branches/FICN/src/orxonox/InputManager.cc	(revision 512)
+++ /code/branches/FICN/src/orxonox/InputManager.cc	(revision 512)
@@ -0,0 +1,388 @@
+#include "InputManager.h"
+
+InputManager *InputManager::mInputManager;
+
+InputManager::InputManager( void ) :
+    mMouse( 0 ), mKeyboard( 0 ), mInputSystem( 0 ) {}
+
+InputManager::~InputManager( void ) {
+  if( mInputSystem ) {
+    if( mMouse ) {
+      mInputSystem->destroyInputObject( mMouse );
+      mMouse = 0;
+    }
+
+    if( mKeyboard ) {
+      mInputSystem->destroyInputObject( mKeyboard );
+      mKeyboard = 0;
+    }
+
+    if( mJoysticks.size() > 0 ) {
+      itJoystick    = mJoysticks.begin();
+      itJoystickEnd = mJoysticks.end();
+      for(; itJoystick != itJoystickEnd; ++itJoystick ) {
+        mInputSystem->destroyInputObject( *itJoystick );
+      }
+
+      mJoysticks.clear();
+    }
+
+        // If you use OIS1.0RC1 or above, uncomment this line
+        // and comment the line below it
+    mInputSystem->destroyInputSystem( mInputSystem );
+        //mInputSystem->destroyInputSystem();
+    mInputSystem = 0;
+
+        // Clear Listeners
+    mKeyListeners.clear();
+    mMouseListeners.clear();
+    mJoystickListeners.clear();
+  }
+}
+
+void InputManager::initialise( Ogre::RenderWindow *renderWindow ) {
+  if( !mInputSystem ) {
+        // Setup basic variables
+    OIS::ParamList paramList;
+    size_t windowHnd = 0;
+    std::ostringstream windowHndStr;
+
+        // Get window handle
+    renderWindow->getCustomAttribute( "WINDOW", &windowHnd );
+
+        // Fill parameter list
+    windowHndStr << (unsigned int) windowHnd;
+    paramList.insert( std::make_pair( std::string( "WINDOW" ), windowHndStr.str() ) );
+
+        // Create inputsystem
+    mInputSystem = OIS::InputManager::createInputSystem( paramList );
+
+        // If possible create a buffered keyboard
+        // (note: if below line doesn't compile, try:  if (mInputSystem->getNumberOfDevices(OIS::OISKeyboard) > 0) {
+      if( mInputSystem->numKeyboards() > 0 ) {
+//     if (mInputSystem->getNumberOfDevices(OIS::OISKeyboard) > 0) {
+      mKeyboard = static_cast<OIS::Keyboard*>( mInputSystem->createInputObject( OIS::OISKeyboard, true ) );
+      mKeyboard->setEventCallback( this );
+    }
+
+        // If possible create a buffered mouse
+        // (note: if below line doesn't compile, try:  if (mInputSystem->getNumberOfDevices(OIS::OISMouse) > 0) {
+      if( mInputSystem->numMice() > 0 ) {
+//     if (mInputSystem->getNumberOfDevices(OIS::OISMouse) > 0) {
+      mMouse = static_cast<OIS::Mouse*>( mInputSystem->createInputObject( OIS::OISMouse, true ) );
+      mMouse->setEventCallback( this );
+
+            // Get window size
+      unsigned int width, height, depth;
+      int left, top;
+      renderWindow->getMetrics( width, height, depth, left, top );
+
+            // Set mouse region
+      this->setWindowExtents( width, height );
+    }
+
+        // If possible create all joysticks in buffered mode
+        // (note: if below line doesn't compile, try:  if (mInputSystem->getNumberOfDevices(OIS::OISJoyStick) > 0) {
+    if( mInputSystem->numJoySticks() > 0 ) {
+//     if (mInputSystem->getNumberOfDevices(OIS::OISJoyStick) > 0) {
+       mJoysticks.resize( mInputSystem->numJoySticks() );
+//       mJoysticks.resize( mInputSystem->getNumberOfDevices(OIS::OISJoyStick) );
+
+      itJoystick    = mJoysticks.begin();
+      itJoystickEnd = mJoysticks.end();
+      for(; itJoystick != itJoystickEnd; ++itJoystick ) {
+        (*itJoystick) = static_cast<OIS::JoyStick*>( mInputSystem->createInputObject( OIS::OISJoyStick, true ) );
+        (*itJoystick)->setEventCallback( this );
+      }
+    }
+  }
+}
+
+void InputManager::capture( void ) {
+    // Need to capture / update each device every frame
+  if( mMouse ) {
+    mMouse->capture();
+  }
+
+  if( mKeyboard ) {
+    mKeyboard->capture();
+  }
+
+  if( mJoysticks.size() > 0 ) {
+    itJoystick    = mJoysticks.begin();
+    itJoystickEnd = mJoysticks.end();
+    for(; itJoystick != itJoystickEnd; ++itJoystick ) {
+      (*itJoystick)->capture();
+    }
+  }
+}
+
+void InputManager::addKeyListener( OIS::KeyListener *keyListener, const std::string& instanceName ) {
+  if( mKeyboard ) {
+        // Check for duplicate items
+    itKeyListener = mKeyListeners.find( instanceName );
+    if( itKeyListener == mKeyListeners.end() ) {
+      mKeyListeners[ instanceName ] = keyListener;
+    }
+    else {
+            // Duplicate Item
+    }
+  }
+}
+
+void InputManager::addMouseListener( OIS::MouseListener *mouseListener, const std::string& instanceName ) {
+  if( mMouse ) {
+        // Check for duplicate items
+    itMouseListener = mMouseListeners.find( instanceName );
+    if( itMouseListener == mMouseListeners.end() ) {
+      mMouseListeners[ instanceName ] = mouseListener;
+    }
+    else {
+            // Duplicate Item
+    }
+  }
+}
+
+void InputManager::addJoystickListener( OIS::JoyStickListener *joystickListener, const std::string& instanceName ) {
+  if( mJoysticks.size() > 0 ) {
+        // Check for duplicate items
+    itJoystickListener = mJoystickListeners.find( instanceName );
+    if( itJoystickListener == mJoystickListeners.end() ) {
+      mJoystickListeners[ instanceName ] = joystickListener;
+    }
+    else {
+            // Duplicate Item
+    }
+  }
+}
+
+void InputManager::removeKeyListener( const std::string& instanceName ) {
+    // Check if item exists
+  itKeyListener = mKeyListeners.find( instanceName );
+  if( itKeyListener != mKeyListeners.end() ) {
+    mKeyListeners.erase( itKeyListener );
+  }
+  else {
+        // Doesn't Exist
+  }
+}
+
+void InputManager::removeMouseListener( const std::string& instanceName ) {
+    // Check if item exists
+  itMouseListener = mMouseListeners.find( instanceName );
+  if( itMouseListener != mMouseListeners.end() ) {
+    mMouseListeners.erase( itMouseListener );
+  }
+  else {
+        // Doesn't Exist
+  }
+}
+
+void InputManager::removeJoystickListener( const std::string& instanceName ) {
+    // Check if item exists
+  itJoystickListener = mJoystickListeners.find( instanceName );
+  if( itJoystickListener != mJoystickListeners.end() ) {
+    mJoystickListeners.erase( itJoystickListener );
+  }
+  else {
+        // Doesn't Exist
+  }
+}
+
+void InputManager::removeKeyListener( OIS::KeyListener *keyListener ) {
+  itKeyListener    = mKeyListeners.begin();
+  itKeyListenerEnd = mKeyListeners.end();
+  for(; itKeyListener != itKeyListenerEnd; ++itKeyListener ) {
+    if( itKeyListener->second == keyListener ) {
+      mKeyListeners.erase( itKeyListener );
+      break;
+    }
+  }
+}
+
+void InputManager::removeMouseListener( OIS::MouseListener *mouseListener ) {
+  itMouseListener    = mMouseListeners.begin();
+  itMouseListenerEnd = mMouseListeners.end();
+  for(; itMouseListener != itMouseListenerEnd; ++itMouseListener ) {
+    if( itMouseListener->second == mouseListener ) {
+      mMouseListeners.erase( itMouseListener );
+      break;
+    }
+  }
+}
+
+void InputManager::removeJoystickListener( OIS::JoyStickListener *joystickListener ) {
+  itJoystickListener    = mJoystickListeners.begin();
+  itJoystickListenerEnd = mJoystickListeners.end();
+  for(; itJoystickListener != itJoystickListenerEnd; ++itJoystickListener ) {
+    if( itJoystickListener->second == joystickListener ) {
+      mJoystickListeners.erase( itJoystickListener );
+      break;
+    }
+  }
+}
+
+void InputManager::removeAllListeners( void ) {
+  mKeyListeners.clear();
+  mMouseListeners.clear();
+  mJoystickListeners.clear();
+}
+
+void InputManager::removeAllKeyListeners( void ) {
+  mKeyListeners.clear();
+}
+
+void InputManager::removeAllMouseListeners( void ) {
+  mMouseListeners.clear();
+}
+
+void InputManager::removeAllJoystickListeners( void ) {
+  mJoystickListeners.clear();
+}
+
+void InputManager::setWindowExtents( int width, int height ) {
+    // Set mouse region (if window resizes, we should alter this to reflect as well)
+  const OIS::MouseState &mouseState = mMouse->getMouseState();
+  mouseState.width  = width;
+  mouseState.height = height;
+}
+
+OIS::Mouse* InputManager::getMouse( void ) {
+  return mMouse;
+}
+
+OIS::Keyboard* InputManager::getKeyboard( void ) {
+  return mKeyboard;
+}
+
+OIS::JoyStick* InputManager::getJoystick( unsigned int index ) {
+    // Make sure it's a valid index
+  if( index < mJoysticks.size() ) {
+    return mJoysticks[ index ];
+  }
+
+  return 0;
+}
+
+int InputManager::getNumOfJoysticks( void ) {
+    // Cast to keep compiler happy ^^
+  return (int) mJoysticks.size();
+}
+
+bool InputManager::keyPressed( const OIS::KeyEvent &e ) {
+  itKeyListener    = mKeyListeners.begin();
+  itKeyListenerEnd = mKeyListeners.end();
+  for(; itKeyListener != itKeyListenerEnd; ++itKeyListener ) {
+    if(!itKeyListener->second->keyPressed( e ))
+      break;
+  }
+
+  return true;
+}
+
+bool InputManager::keyReleased( const OIS::KeyEvent &e ) {
+  itKeyListener    = mKeyListeners.begin();
+  itKeyListenerEnd = mKeyListeners.end();
+  for(; itKeyListener != itKeyListenerEnd; ++itKeyListener ) {
+    if(!itKeyListener->second->keyReleased( e ))
+      break;
+  }
+
+  return true;
+}
+
+bool InputManager::mouseMoved( const OIS::MouseEvent &e ) {
+  itMouseListener    = mMouseListeners.begin();
+  itMouseListenerEnd = mMouseListeners.end();
+  for(; itMouseListener != itMouseListenerEnd; ++itMouseListener ) {
+    if(!itMouseListener->second->mouseMoved( e ))
+      break;
+  }
+
+  return true;
+}
+
+bool InputManager::mousePressed( const OIS::MouseEvent &e, OIS::MouseButtonID id ) {
+  itMouseListener    = mMouseListeners.begin();
+  itMouseListenerEnd = mMouseListeners.end();
+  for(; itMouseListener != itMouseListenerEnd; ++itMouseListener ) {
+    if(!itMouseListener->second->mousePressed( e, id ))
+      break;
+  }
+
+  return true;
+}
+
+bool InputManager::mouseReleased( const OIS::MouseEvent &e, OIS::MouseButtonID id ) {
+  itMouseListener    = mMouseListeners.begin();
+  itMouseListenerEnd = mMouseListeners.end();
+  for(; itMouseListener != itMouseListenerEnd; ++itMouseListener ) {
+    if(!itMouseListener->second->mouseReleased( e, id ))
+      break;
+  }
+
+  return true;
+}
+
+bool InputManager::povMoved( const OIS::JoyStickEvent &e, int pov ) {
+  itJoystickListener    = mJoystickListeners.begin();
+  itJoystickListenerEnd = mJoystickListeners.end();
+  for(; itJoystickListener != itJoystickListenerEnd; ++itJoystickListener ) {
+    if(!itJoystickListener->second->povMoved( e, pov ))
+      break;
+  }
+
+  return true;
+}
+
+bool InputManager::axisMoved( const OIS::JoyStickEvent &e, int axis ) {
+  itJoystickListener    = mJoystickListeners.begin();
+  itJoystickListenerEnd = mJoystickListeners.end();
+  for(; itJoystickListener != itJoystickListenerEnd; ++itJoystickListener ) {
+    if(!itJoystickListener->second->axisMoved( e, axis ))
+      break;
+  }
+
+  return true;
+}
+
+bool InputManager::sliderMoved( const OIS::JoyStickEvent &e, int sliderID ) {
+  itJoystickListener    = mJoystickListeners.begin();
+  itJoystickListenerEnd = mJoystickListeners.end();
+  for(; itJoystickListener != itJoystickListenerEnd; ++itJoystickListener ) {
+    if(!itJoystickListener->second->sliderMoved( e, sliderID ))
+      break;
+  }
+
+  return true;
+}
+
+bool InputManager::buttonPressed( const OIS::JoyStickEvent &e, int button ) {
+  itJoystickListener    = mJoystickListeners.begin();
+  itJoystickListenerEnd = mJoystickListeners.end();
+  for(; itJoystickListener != itJoystickListenerEnd; ++itJoystickListener ) {
+    if(!itJoystickListener->second->buttonPressed( e, button ))
+      break;
+  }
+
+  return true;
+}
+
+bool InputManager::buttonReleased( const OIS::JoyStickEvent &e, int button ) {
+  itJoystickListener    = mJoystickListeners.begin();
+  itJoystickListenerEnd = mJoystickListeners.end();
+  for(; itJoystickListener != itJoystickListenerEnd; ++itJoystickListener ) {
+    if(!itJoystickListener->second->buttonReleased( e, button ))
+      break;
+  }
+
+  return true;
+}
+
+InputManager* InputManager::getSingletonPtr( void ) {
+  if( !mInputManager ) {
+    mInputManager = new InputManager();
+  }
+
+  return mInputManager;
+}
Index: /code/branches/FICN/src/orxonox/InputManager.h
===================================================================
--- /code/branches/FICN/src/orxonox/InputManager.h	(revision 512)
+++ /code/branches/FICN/src/orxonox/InputManager.h	(revision 512)
@@ -0,0 +1,84 @@
+#ifndef InputManager_H
+#define InputManager_H
+
+#include <OISMouse.h>
+#include <OISKeyboard.h>
+#include <OISJoyStick.h>
+#include <OISInputManager.h>
+
+#include <OgreRenderWindow.h>
+
+class InputManager : public OIS::KeyListener, public OIS::MouseListener, public OIS::JoyStickListener {
+  public:
+    virtual ~InputManager( void );
+
+    void initialise( Ogre::RenderWindow *renderWindow );
+    void capture( void );
+
+    void addKeyListener( OIS::KeyListener *keyListener, const std::string& instanceName );
+    void addMouseListener( OIS::MouseListener *mouseListener, const std::string& instanceName );
+    void addJoystickListener( OIS::JoyStickListener *joystickListener, const std::string& instanceName );
+
+    void removeKeyListener( const std::string& instanceName );
+    void removeMouseListener( const std::string& instanceName );
+    void removeJoystickListener( const std::string& instanceName );
+
+    void removeKeyListener( OIS::KeyListener *keyListener );
+    void removeMouseListener( OIS::MouseListener *mouseListener );
+    void removeJoystickListener( OIS::JoyStickListener *joystickListener );
+
+    void removeAllListeners( void );
+    void removeAllKeyListeners( void );
+    void removeAllMouseListeners( void );
+    void removeAllJoystickListeners( void );
+
+    void setWindowExtents( int width, int height );
+
+    OIS::Mouse*    getMouse( void );
+    OIS::Keyboard* getKeyboard( void );
+    OIS::JoyStick* getJoystick( unsigned int index );
+
+    int getNumOfJoysticks( void );
+
+    static InputManager* getSingletonPtr( void );
+  private:
+    InputManager( void );
+    InputManager( const InputManager& ) { }
+    InputManager & operator = ( const InputManager& );
+
+    bool keyPressed( const OIS::KeyEvent &e );
+    bool keyReleased( const OIS::KeyEvent &e );
+
+    bool mouseMoved( const OIS::MouseEvent &e );
+    bool mousePressed( const OIS::MouseEvent &e, OIS::MouseButtonID id );
+    bool mouseReleased( const OIS::MouseEvent &e, OIS::MouseButtonID id );
+
+    bool povMoved( const OIS::JoyStickEvent &e, int pov );
+    bool axisMoved( const OIS::JoyStickEvent &e, int axis );
+    bool sliderMoved( const OIS::JoyStickEvent &e, int sliderID );
+    bool buttonPressed( const OIS::JoyStickEvent &e, int button );
+    bool buttonReleased( const OIS::JoyStickEvent &e, int button );
+
+    OIS::Mouse        *mMouse;
+    OIS::Keyboard     *mKeyboard;
+    OIS::InputManager *mInputSystem;
+
+    std::vector<OIS::JoyStick*> mJoysticks;
+    std::vector<OIS::JoyStick*>::iterator itJoystick;
+    std::vector<OIS::JoyStick*>::iterator itJoystickEnd;
+
+    std::map<std::string, OIS::KeyListener*> mKeyListeners;
+    std::map<std::string, OIS::MouseListener*> mMouseListeners;
+    std::map<std::string, OIS::JoyStickListener*> mJoystickListeners;
+
+    std::map<std::string, OIS::KeyListener*>::iterator itKeyListener;
+    std::map<std::string, OIS::MouseListener*>::iterator itMouseListener;
+    std::map<std::string, OIS::JoyStickListener*>::iterator itJoystickListener;
+
+    std::map<std::string, OIS::KeyListener*>::iterator itKeyListenerEnd;
+    std::map<std::string, OIS::MouseListener*>::iterator itMouseListenerEnd;
+    std::map<std::string, OIS::JoyStickListener*>::iterator itJoystickListenerEnd;
+
+    static InputManager *mInputManager;
+};
+#endif
Index: /code/branches/FICN/src/orxonox/orxonox.cc
===================================================================
--- /code/branches/FICN/src/orxonox/orxonox.cc	(revision 511)
+++ /code/branches/FICN/src/orxonox/orxonox.cc	(revision 512)
@@ -122,5 +122,5 @@
 
         if(moved) {
-          if (mouseY<0)
+          if (mouseY<=0)
             steering->rotateUp(-mouseY*rotate);
           if (mouseY>0)
@@ -128,8 +128,8 @@
           if (mouseX>0)
             steering->rotateRight(mouseX*rotate);
-          if (mouseX<0)
+          if (mouseX<=0)
             steering->rotateLeft(-mouseX*rotate);
-	  mouseY = 0;
-	  mouseX = 0;
+          mouseY = 0;
+          mouseX = 0;
           moved = false;
         }
@@ -361,5 +361,5 @@
   {
     SceneManager *mgr = ogre_->getSceneManager();
-    
+
     Camera *cam = mgr->createCamera("Camera");
     cam->setPosition(Vector3(0,0,-250));
@@ -372,6 +372,6 @@
     node->attachObject(head);
     node->attachObject(cam);
-    
-    
+
+
 
     Entity* head1 = mgr->createEntity("head1", "ogrehead.mesh");
