19.10 Input


19.10 Input

Using a frame listener in OGRE means that reading input from either the mouse or keyboard becomes simple. A frame listener holds an InputDevice object, which represents the state of input devices such as the mouse and keyboard. On each frame, the InputDevice needs to be updated to record the latest state of input devices. To do this, the capture method can be called. Once the snapshot of input hardware has been taken, it can then be polled (questioned) to see which buttons were pressed or the current (x, y) cursor position of the mouse. Subsequent sections examine the keyboard and mouse input in more detail.

      bool frameStarted(const FrameEvent &evt)      {         //Called when the frame begins         mInputDevice->capture();         return ExampleFrameListener::frameStarted(evt);      } 

19.10.1 Keyboard Input

Once the input device has been captured, information can be read from the keyboard and mouse. To poll whether a specific key on the keyboard is pressed, the isKeyDown method should be called.

      bool Pressed = mInputDevice->isKeyDown(KC_ESCAPE); 
Note 

Please see Appendix D for OGRE key codes.

19.10.2 Mouse Input

Once the input device has been captured, information can also be read from the mouse, including which buttons are pressed, the cursor position, and the current wheel offset. Consider the following code:

      bool Pressed = mInputDevice->getMouseButton(0);      int MouseX = mInputDevice->getMouseAbsX();      int MouseY = mInputDevice->getMouseAbsY(); 




Introduction to Game Programming with C++
Introduction to Game Programming with C++ (Wordware Game Developers Library)
ISBN: 1598220322
EAN: 2147483647
Year: 2007
Pages: 225
Authors: Alan Thorn

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net