Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/network/src/orxonox/InputHandler.cc @ 918

Last change on this file since 918 was 918, checked in by rgrieder, 16 years ago
  • created basic construct for the InputHandler (mere copy of InputManager but without the Listeners)
  • some msvc related fixes with winsocks.h and winsocks2.h
  • fix in Tickable.h (due to lazy displacement to new folder)
File size: 3.8 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *
4 *
5 *   License notice:
6 *
7 *   This program is free software; you can redistribute it and/or
8 *   modify it under the terms of the GNU General Public License
9 *   as published by the Free Software Foundation; either version 2
10 *   of the License, or (at your option) any later version.
11 *
12 *   This program is distributed in the hope that it will be useful,
13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 *   GNU General Public License for more details.
16 *
17 *   You should have received a copy of the GNU General Public License
18 *   along with this program; if not, write to the Free Software
19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 *
21 *   Author:
22 *      Reto Grieder
23 *   Co-authors:
24 *      ...
25 *
26 */
27
28/**
29 @file
30 @brief Implementation of a little Input handler that distributes everything
31        coming from OIS.
32 */
33
34#include "OrxonoxStableHeaders.h"
35
36#include <OgreRenderWindow.h>
37
38#include "InputHandler.h"
39
40namespace orxonox
41{
42  //using namespace OIS;
43
44  InputHandler::InputHandler()
45  {
46    RegisterObject(InputHandler);
47  }
48
49  void InputHandler::initialise(Ogre::RenderWindow *renderWindow)
50  {
51    if (!inputSystem_)
52    {
53      // Setup basic variables
54      OIS::ParamList paramList;
55      size_t windowHnd = 0;
56      std::ostringstream windowHndStr;
57
58      // Get window handle
59      renderWindow->getCustomAttribute("WINDOW", &windowHnd);
60
61      // Fill parameter list
62      windowHndStr << (unsigned int)windowHnd;
63      paramList.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
64
65      // Create inputsystem
66      inputSystem_ = OIS::InputManager::createInputSystem(paramList);
67
68      // If possible create a buffered keyboard
69      // (note: if below line doesn't compile, try:  if (inputSystem_->getNumberOfDevices(OIS::OISKeyboard) > 0) {
70      if (inputSystem_->numKeyboards() > 0)
71      {
72        //if (inputSystem_->getNumberOfDevices(OIS::OISKeyboard) > 0)
73        //{
74        keyboard_ = static_cast<OIS::Keyboard*>(inputSystem_->createInputObject(OIS::OISKeyboard, true));
75        keyboard_->setEventCallback(this);
76      }
77
78      // If possible create a buffered mouse
79      // (note: if below line doesn't compile, try:  if (inputSystem_->getNumberOfDevices(OIS::OISMouse) > 0) {
80      if (inputSystem_->numMice() > 0 )
81      {
82        //if (inputSystem_->getNumberOfDevices(OIS::OISMouse) > 0)
83        //{
84        mouse_ = static_cast<OIS::Mouse*>(inputSystem_->createInputObject(OIS::OISMouse, true));
85        mouse_->setEventCallback(this);
86
87        // Get window size
88        unsigned int width, height, depth;
89        int left, top;
90        renderWindow->getMetrics(width, height, depth, left, top);
91
92        // Set mouse region
93        this->setWindowExtents(width, height);
94      }
95    }
96  }
97
98  void InputHandler::tick(float dt)
99  {
100    // capture all the input. That calls the event handlers.
101    if (mouse_)
102    {
103      mouse_->capture();
104    }
105
106    if (keyboard_)
107    {
108      keyboard_->capture();
109    }
110  }
111
112  void InputHandler::setWindowExtents(int width, int height)
113  {
114    // Set mouse region (if window resizes, we should alter this to reflect as well)
115    const OIS::MouseState &mouseState = mouse_->getMouseState();
116    mouseState.width  = width;
117    mouseState.height = height;
118  }
119
120  bool InputHandler::keyPressed(const OIS::KeyEvent &e)
121  {
122    return true;
123  }
124
125  bool InputHandler::keyReleased(const OIS::KeyEvent &e)
126  {
127    return true;
128  }
129
130  bool InputHandler::mouseMoved(const OIS::MouseEvent &e)
131  {
132    return true;
133  }
134
135  bool InputHandler::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id)
136  {
137    return true;
138  }
139
140  bool InputHandler::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id)
141  {
142    return true;
143  }
144
145}
Note: See TracBrowser for help on using the repository browser.