Code & comments for basic tutorial 6 in ogre3d Wiki

Source: Internet
Author: User

Copyright mikefeng QQ: 76848502

Basic tutorial 5 has complete source code on the official wiki. See here

The code in this article comes from the basic tutorial 6 of the Ogre official website wiki. This Code uses the example framework provided by ogre to implement the following functions:

  1. Use of cegui in ogre
  2. Handling mouse and keyboard events

As follows:

The following code is used:

/* Upload this source file is part of ogre (object-oriented Graphics Rendering Engine) for the latest info, see http://www.ogre3d.org/Copyright (c) 2000-2006 torus knot software ltdalso see acknowledgements in readme.html you may use this sample code for anything you like, it is not covered by thelgpl like the rest of the engine.- ---------------------------------------------------------------------------- * // **/File demo. h/brief specialisation of Ogre's framework application to show the cegui rendering plugin * // mem probs without this next one # include <ogrenomemorymacros. h> # include <cegui/ceguiimageset. h> # include <cegui/ceguisystem. h> # include <cegui/ceguilogger. h> # include <cegui/ceguischememanager. h> # include <cegui/cegu Iwindowmanager. h> # include <cegui/ceguiwindow. h> # include <cegui/elements/ceguipushbutton. h> # include "ogreceguirenderer. H "# include" ogreceguiresourceprovider. H "// regular mem handler # include <ogrememorymacros. h> # include "exampleapplication. H "class guiframelistener: Public exampleframelistener, public ois: mouselistener, public ois: keylistener {PRIVATE: cegui: Renderer * mguirenderer; bool mshutdo Wnrequested; public: // using buffered input guiframelistener (renderwindow * Win, Camera * cam, cegui: Renderer * Renderer): exampleframelistener (Win, Cam, true ), mguirenderer (Renderer), mshutdownrequested (false) {mmouse-> seteventcallback (this); mkeyboard-> seteventcallback (this );} // tell the frame listener to exit at the end of the next frame void requestshutdown (void) {mshutdownreques Ted = true;} bool frameended (const frameevent & EVT) {If (mshutdownrequested) return false; else return exampleframelistener: frameended (EVT);} bool mousemoved (const ois :: mouseevent & E) {using namespace OIS; cegui: System: getsingleton (). injectmousemove (E. state. x. rel, E. state. y. rel); Return true;} bool mousepressed (const ois: mouseevent & E, ois: mousebuttonid ID) {using namespace OIS; cegui:: System: getsingleton (). injectmousebuttondown (Response (ID); Return true;} bool mousereleased (const ois: mouseevent & E, ois: mousebuttonid ID) {cegui: System: getsingleton (). injectmousebuttonup (convertogrebuttontocegui (ID); Return true;} bool keypressed (const ois: keyevent & E) {If (E. key = ois: kc_escape) {mshutdownrequested = true; return true;} cegui: System: getsingl Eton (). injectkeydown (E. key); cegui: System: getsingleton (). injectchar (E. text); Return true;} bool keyreleased (const ois: keyevent & E) {cegui: System: getsingleton (). injectkeyup (E. key); return true;} cegui: mousebutton convertogrebuttontocegui (INT buttonid) {Switch (buttonid) {Case ois: mb_left: Return cegui: leftbutton; Case ois: mb_right: return cegui: rightbutton; Case ois: mb_middle: Ret Urn cegui: middlebutton; // case mouseevent: button3_mask: // return cegui: x1button; default: Return cegui: leftbutton ;}}; class app: public exampleapplication {PRIVATE: cegui: ogreceguirenderer * mguirenderer; cegui: System * mguisystem; cegui: window * meditorguisheet; public: APP (): mguirenderer (0 ), mguisystem (0), meditorguisheet (0 ){}~ APP () {If (meditorguisheet) {cegui: windowmanager: getsingleton (). destroywindow (region) ;}if (region) {Delete mguisystem; mguisystem = 0 ;}if (mguirenderer) {Delete mguirenderer; mguirenderer = 0 ;}} protected: void createscene (void) {// set ambient light mscenemgr-> setambientlight (colourvalue (0.5, 0.5, 0.5); // set up GUI system mguirenderer = new cegui: ogreceguirenderer (mwindow, ogre :: render_queue_overlay, false, 3000, mscenemgr); mguisystem = new cegui: System (mguirenderer); cegui: logger: getsingleton (). setlogginglevel (cegui: informative); // using the 'taharez look' cegui: schememanager: getsingleton (). loadscheme (cegui: utf8 *) "taharezlookskin. scheme "); mguisystem-> setdefaultmousecursor (cegui: utf8 *)" taharezlook ", (cegui: utf8 *)" mousearrow "); cegui: mousecursor :: getsingleton (). setimage ("taharezlook", "mousearrow"); mguisystem-> setdefaultfont (cegui: utf8 *) "BlueHighway-12"); // quit push button. meditorguisheet = cegui: windowmanager: getsingleton (). loadwindowlayout (cegui: utf8 *) "tutorial GUI. XML "); mguisystem-> setguisheet (meditorguisheet); cegui: Pushbutton * quitbutton = (cegui: Pushbutton *) cegui: windowmanager: getsingleton (). getwindow (cegui: utf8 *) "quit"); // meditorguisheet = cegui: windowmanager: getsingleton (). createwindow (cegui: utf8 *) "defaultwindow", (cegui: utf8 *) "sheet"); // mguisystem-> setguisheet (meditorguisheet); // cegui :: pushbutton * quitbutton = (cegui: Pushbutton *) cegui: windowmanager: getsingleton (). createwindow ("taharezlook/button", (cegui: utf8 *) "quit"); // meditorguisheet-> addchildwindow (quitbutton); // quitbutton-> setposition (cegui :: uvector2 (Response (0.35f), cegui_reldim (0.45f); // quitbutton-> setsize (cegui: uvector2 (Response (0.35f), cegui_reldim (0.1f ))); // quitbutton-> settext ("quit"); setupeventhandlers ();} void createframelistener (void) {mframelistener = new guiframelistener (mwindow, mcamera, mguirenderer ); mroot-> addframelistener (mframelistener);} void setupeventhandlers (void) {cegui: windowmanager & wmgr = cegui: windowmanager: getsingleton (); wmgr. getwindow (cegui: utf8 *) "quit")-> subscribeevent (cegui: Pushbutton: eventclicked, cegui: Event: subscriber (& App: handlequit, this);} bool handlequit (const cegui: eventargs & E) {static_cast <guiframelistener *> (mframelistener)-> requestshutdown (); Return true ;}};

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.