The main cycle (Root: startRendering) of Ogre is similar to this:
1. The Root object calls the frameStarted method in all registered FrameListeners.
2. render a frame of the Root object.
3. The Root object calls the frameEnded method in all registered FrameListeners.
Frame Registration Method
MRoot-> addFrameListener (mFrameListener );
Each frame has the methods frameStarted and frameEnded.
Bool frameStarted (const FrameEvent & evt)
Bool frameEnded (const FrameEvent & evt)
The above two methods can be used to implement what needs to be done in each frame.
This enables non-buffering of the mouse and keyboard.
Steps:
1. Set the frame listener Inheritance Method public ExampleFrameListener
Set how to handle the mouse and keyboard
In the constructor: ExampleFrameListener (win, cam, false, false)
In frameStarted:
2. mouse and keyboard pointer capture events
MMouse-> capture ();
MKeyboard-> capture ();
3. process the event type accordingly.
If (mKeyboard-> isKeyDown (OIS: KC_ESCAPE ))
Return false;
If (mMouse-> getMouseState (). buttonDown (OIS: MB_Left ))
Return true;
Mouse and keyboard Buffering
1. Set the frame listener Inheritance Method public ExampleFrameListener, public OIS: MouseListener, public OIS: KeyListener
Set how to handle the mouse and keyboard
In the constructor: ExampleFrameListener (win, cam, true, true)
In this way, you no longer need to manually write the event capture code capture.
2. register the listener in the constructor
MMouse-> setEventCallback (this );
MKeyboard-> setEventCallback (this );
3. Implement Message Processing functions
// MouseListener
Bool mousemoved (const ois: mouseevent & E)
Bool mousepressed (const ois: mouseevent & E, ois: mousebuttonid ID)
Bool mousereleased (const ois: mouseevent & E, ois: mousebuttonid ID)
// Keylistener
Bool keypressed (const ois: keyevent & E)
Bool keyreleased (const ois: keyevent & E)