OGRE + OIS frame monitoring FrameListener, non-buffered input, and buffered Input

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.