[Orxonox-commit 3166] r7859 - in code/trunk/src: libraries/core/input orxonox/controllers

landauf at orxonox.net landauf at orxonox.net
Sat Feb 12 11:34:40 CET 2011


Author: landauf
Date: 2011-02-12 11:34:40 +0100 (Sat, 12 Feb 2011)
New Revision: 7859

Modified:
   code/trunk/src/libraries/core/input/HalfAxis.h
   code/trunk/src/libraries/core/input/KeyBinder.cc
   code/trunk/src/libraries/core/input/KeyBinder.h
   code/trunk/src/orxonox/controllers/NewHumanController.cc
   code/trunk/src/orxonox/controllers/NewHumanController.h
Log:
implemented feature to reset the mouse cursor to the center
used in NewHumanController to set cursor to the center of the screen every time the ControllableEntity is changed
avoids turning of the spaceship right after spawn, if the player looked around in spectator mode

needs testing with derived mouse input (joysticks should be unchanged).
input system experts may have a look at this. ;)

Modified: code/trunk/src/libraries/core/input/HalfAxis.h
===================================================================
--- code/trunk/src/libraries/core/input/HalfAxis.h	2011-02-12 10:30:33 UTC (rev 7858)
+++ code/trunk/src/libraries/core/input/HalfAxis.h	2011-02-12 10:34:40 UTC (rev 7859)
@@ -57,6 +57,7 @@
         bool execute();
         bool addParamCommand(ParamCommand* command);
         void clear();
+        void reset();
 
         // axis related
         float relVal_;
@@ -76,6 +77,13 @@
             success = paramCommands_[i]->execute(absVal_, relVal_) && success;
         return success;
     }
+
+    inline void HalfAxis::reset()
+    {
+        this->relVal_ = 0.0f;
+        this->absVal_ = 0.0f;
+        this->hasChanged_ = true;
+    }
 }
 
 #endif /* _HalfAxis_H__ */

Modified: code/trunk/src/libraries/core/input/KeyBinder.cc
===================================================================
--- code/trunk/src/libraries/core/input/KeyBinder.cc	2011-02-12 10:30:33 UTC (rev 7858)
+++ code/trunk/src/libraries/core/input/KeyBinder.cc	2011-02-12 10:34:40 UTC (rev 7859)
@@ -387,15 +387,22 @@
     void KeyBinder::resetJoyStickAxes()
     {
         for (unsigned int iDev = 0; iDev < joySticks_.size(); ++iDev)
-        {
             for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; i++)
-            {
-                (*joyStickAxes_[iDev])[i].absVal_ = 0.0f;
-                (*joyStickAxes_[iDev])[i].relVal_ = 0.0f;
-            }
-        }
+                (*joyStickAxes_[iDev])[i].reset();
     }
 
+    /**
+        @brief Sets the position of the mouse back to 0/0.
+    */
+    void KeyBinder::resetMouseAxes()
+    {
+        this->mousePosition_[0] = 0.0f;
+        this->mousePosition_[1] = 0.0f;
+
+        for (unsigned int i = 0; i < MouseAxisCode::numberOfAxes * 2; i++)
+            mouseAxes_[i].reset();
+    }
+
     void KeyBinder::mouseUpdated(float dt)
     {
         if (bDeriveMouseInput_)

Modified: code/trunk/src/libraries/core/input/KeyBinder.h
===================================================================
--- code/trunk/src/libraries/core/input/KeyBinder.h	2011-02-12 10:30:33 UTC (rev 7858)
+++ code/trunk/src/libraries/core/input/KeyBinder.h	2011-02-12 10:34:40 UTC (rev 7859)
@@ -73,6 +73,7 @@
             { return this->filename_; }
         void setConfigValues();
         void resetJoyStickAxes();
+        void resetMouseAxes();
 
     protected: // functions
         void loadBindings();

Modified: code/trunk/src/orxonox/controllers/NewHumanController.cc
===================================================================
--- code/trunk/src/orxonox/controllers/NewHumanController.cc	2011-02-12 10:30:33 UTC (rev 7858)
+++ code/trunk/src/orxonox/controllers/NewHumanController.cc	2011-02-12 10:34:40 UTC (rev 7859)
@@ -37,6 +37,8 @@
 
 #include "core/CoreIncludes.h"
 #include "core/command/ConsoleCommand.h"
+#include "core/input/KeyBinder.h"
+#include "core/input/KeyBinderManager.h"
 #include "worldentities/ControllableEntity.h"
 #include "worldentities/pawns/Pawn.h"
 #include "infos/PlayerInfo.h"
@@ -348,6 +350,14 @@
         hideArrows();
     }
 
+    void NewHumanController::centerCursor()
+    {
+        this->currentYaw_ = 0;
+        this->currentPitch_ = 0;
+
+        KeyBinderManager::getInstance().getCurrent()->resetMouseAxes();
+    }
+
     void NewHumanController::updateTarget()
     {
         Ogre::RaySceneQuery * rsq = HumanController::localController_s->getControllableEntity()->getScene()->getSceneManager()->createRayQuery(Ogre::Ray());
@@ -480,8 +490,7 @@
     void NewHumanController::changedControllableEntity()
     {
         this->controlMode_ = 0;
-        this->currentYaw_ = 0;
-        this->currentPitch_ = 0;
+        this->centerCursor();
         if (this->getControllableEntity() && (this->getControllableEntity()->isExactlyA(ClassByString("SpaceShip")) || this->getControllableEntity()->isExactlyA(ClassByString("Rocket"))))
         {
             this->showOverlays_ = true;

Modified: code/trunk/src/orxonox/controllers/NewHumanController.h
===================================================================
--- code/trunk/src/orxonox/controllers/NewHumanController.h	2011-02-12 10:30:33 UTC (rev 7858)
+++ code/trunk/src/orxonox/controllers/NewHumanController.h	2011-02-12 10:34:40 UTC (rev 7859)
@@ -60,6 +60,8 @@
             static void unfire();
             virtual void doUnfire();
 
+            void centerCursor();
+
             static void changeMode();
 
             virtual void changedControllableEntity();




More information about the Orxonox-commit mailing list