Changeset 919 for code/branches/network/src/orxonox/InputHandler.cc
- Timestamp:
- Mar 24, 2008, 1:12:31 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/orxonox/InputHandler.cc
r918 r919 22 22 * Reto Grieder 23 23 * Co-authors: 24 * ...24 * Some guy writing the example code from Ogre 25 25 * 26 26 */ … … 34 34 #include "OrxonoxStableHeaders.h" 35 35 36 #include <OgreRenderWindow.h> 37 36 #include "Orxonox.h" 38 37 #include "InputHandler.h" 39 38 … … 42 41 //using namespace OIS; 43 42 43 /** 44 @brief Constructor only resets the pointer values to 0. 45 */ 44 46 InputHandler::InputHandler() 45 47 { 46 RegisterObject(InputHandler); 47 } 48 49 void InputHandler::initialise(Ogre::RenderWindow *renderWindow) 48 /*if (orxonox::Identifier::isCreatingHierarchy() && !this->getParents()) 49 this->createParents(); 50 this->setIdentifier(orxonox::ClassManager<InputHandler>::getIdentifier()->registerClass(this->getParents(), "InputHandler", true)); 51 if (orxonox::Identifier::isCreatingHierarchy() && this->getParents()) 52 this->getParents()->insert(this->getParents()->end(), this->getIdentifier()); 53 orxonox::ClassManager<InputHandler>::getIdentifier()->addObject(this);*/ 54 55 //RegisterObject(InputHandler); 56 57 this->mouse_ = 0; 58 this->keyboard_ = 0; 59 this->inputSystem_ = 0; 60 61 //this->setConfigValues(); 62 } 63 64 void InputHandler::setConfigValues() 65 { 66 //SetConfigValue(codeFire_, 4).description("test value"); 67 68 ConfigValueContainer *containercodeFire_ = new ConfigValueContainer("asdfblah", "codeFire_", 4); 69 containercodeFire_->getValue(&codeFire_).description("test"); 70 //containercodeFire_-> 71 } 72 73 /** 74 @brief The one instance of the InputHandler is stored in this function. 75 @return The pointer to the only instance of the InputHandler 76 */ 77 InputHandler* InputHandler::getSingleton() 78 { 79 static InputHandler theOnlyInstance; 80 return &theOnlyInstance; 81 } 82 83 /** 84 @brief Creates the OIS::InputMananger, the keyboard and the mouse 85 @param windowHnd The window handle of the render window 86 @param windowWidth The width of the render window 87 @param windowHeight The height of the render window 88 */ 89 void InputHandler::initialise(size_t windowHnd, int windowWidth, int windowHeight) 50 90 { 51 91 if (!inputSystem_) … … 53 93 // Setup basic variables 54 94 OIS::ParamList paramList; 55 size_t windowHnd = 0;56 95 std::ostringstream windowHndStr; 57 58 // Get window handle59 renderWindow->getCustomAttribute("WINDOW", &windowHnd);60 96 61 97 // Fill parameter list … … 67 103 68 104 // If possible create a buffered keyboard 69 // (note: if below line doesn't compile, try: if (inputSystem_->getNumberOfDevices(OIS::OISKeyboard) > 0) {70 105 if (inputSystem_->numKeyboards() > 0) 71 106 { 72 //if (inputSystem_->getNumberOfDevices(OIS::OISKeyboard) > 0)73 //{74 107 keyboard_ = static_cast<OIS::Keyboard*>(inputSystem_->createInputObject(OIS::OISKeyboard, true)); 75 108 keyboard_->setEventCallback(this); … … 77 110 78 111 // If possible create a buffered mouse 79 // (note: if below line doesn't compile, try: if (inputSystem_->getNumberOfDevices(OIS::OISMouse) > 0) {80 112 if (inputSystem_->numMice() > 0 ) 81 113 { 82 //if (inputSystem_->getNumberOfDevices(OIS::OISMouse) > 0)83 //{84 114 mouse_ = static_cast<OIS::Mouse*>(inputSystem_->createInputObject(OIS::OISMouse, true)); 85 115 mouse_->setEventCallback(this); 86 116 87 // Get window size88 unsigned int width, height, depth;89 int left, top;90 renderWindow->getMetrics(width, height, depth, left, top);91 92 117 // Set mouse region 93 this->setWindowExtents(wi dth, height);118 this->setWindowExtents(windowWidth, windowHeight); 94 119 } 95 120 } 96 121 } 97 122 123 /** 124 @brief Updates the InputHandler 125 @param dt Delta time 126 */ 98 127 void InputHandler::tick(float dt) 99 128 { … … 110 139 } 111 140 141 /** 142 @brief Adjusts the mouse window metrics. 143 This method has to be called every time the size of the window changes. 144 @param width The new width of the render window 145 @param height the new height of the render window 146 */ 112 147 void InputHandler::setWindowExtents(int width, int height) 113 148 { … … 118 153 } 119 154 155 /** 156 @brief Event handler for the keyPressed Event. 157 @param e Event information 158 */ 120 159 bool InputHandler::keyPressed(const OIS::KeyEvent &e) 121 160 { 122 return true; 123 } 124 161 if (e.key == OIS::KC_ESCAPE) 162 Orxonox::getSingleton()->abortRequest(); 163 return true; 164 } 165 166 /** 167 @brief Event handler for the keyReleased Event. 168 @param e Event information 169 */ 125 170 bool InputHandler::keyReleased(const OIS::KeyEvent &e) 126 171 { … … 128 173 } 129 174 175 /** 176 @brief Event handler for the mouseMoved Event. 177 @param e Event information 178 */ 130 179 bool InputHandler::mouseMoved(const OIS::MouseEvent &e) 131 180 { … … 133 182 } 134 183 184 /** 185 @brief Event handler for the mousePressed Event. 186 @param e Event information 187 @param id The ID of the mouse button 188 */ 135 189 bool InputHandler::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id) 136 190 { … … 138 192 } 139 193 194 /** 195 @brief Event handler for the mouseReleased Event. 196 @param e Event information 197 @param id The ID of the mouse button 198 */ 140 199 bool InputHandler::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id) 141 200 {
Note: See TracChangeset
for help on using the changeset viewer.