项目源码列表(1)

BaseApplication.h

Code:
  1. #ifndef __BaseApplication_h_   
  2. #define __BaseApplication_h_   
  3.     
  4. #include <OgreCamera.h>   
  5. #include <OgreEntity.h>   
  6. #include <OgreLogManager.h>   
  7. #include <OgreRoot.h>   
  8. #include <OgreViewport.h>   
  9. #include <OgreSceneManager.h>   
  10. #include <OgreRenderWindow.h>   
  11. #include <OgreConfigFile.h>   
  12.     
  13. #include <OISEvents.h>   
  14. #include <OISInputManager.h>   
  15. #include <OISKeyboard.h>   
  16. #include <OISMouse.h>   
  17.     
  18. #include <SdkTrays.h>   
  19. #include <SdkCameraMan.h>   
  20.   
  21. /* If you wanna a static linked product. then please define OGRE_STATIC_LIB in advance.   
  22. Then you should manully include necessary files and load the plugins. */  
  23. #ifdef OGRE_STATIC_LIB   
  24. #  include "OgreOggSoundPlugin.h"   
  25. #  include "RenderSystems/Direct3D9/OgreD3D9Plugin.h"   
  26. #  include "Plugins/ParticleFX/OgreParticleFXPlugin.h"   
  27. #  include "Plugins/OctreeSceneManager/OgreOctreePlugin.h"   
  28. #endif   
  29.   
  30. class BaseApplication : public Ogre::FrameListener, public Ogre::WindowEventListener, public OIS::KeyListener, public OIS::MouseListener, OgreBites::SdkTrayListener   
  31. {   
  32. public:   
  33.     BaseApplication(void);   
  34.     virtual ~BaseApplication(void);   
  35.     
  36.     virtual void go(void);   
  37.     
  38. protected:   
  39.   
  40.     // some basic frame fuctions   
  41.   
  42.     virtual bool setup();   
  43.     virtual bool configure(void);   
  44.     virtual void chooseSceneManager(void);   
  45.     virtual void createCamera(void);   
  46.     virtual void createFrameListener(void);   
  47.     virtual void createScene(void) = 0; // Override me!   
  48.     virtual void destroyScene(void);   
  49.     virtual void createViewports(void);   
  50.     virtual void setupResources(void);   
  51.     virtual void createResourceListener(void);   
  52.     virtual void loadResources(void);   
  53.     virtual bool frameRenderingQueued(const Ogre::FrameEvent& evt);   
  54.     
  55.     // functions to deal with inputs, include keyboard and mouse input.    
  56.   
  57.     virtual bool keyPressed( const OIS::KeyEvent &arg );   
  58.     virtual bool keyReleased( const OIS::KeyEvent &arg );   
  59.     virtual bool mouseMoved( const OIS::MouseEvent &arg );   
  60.     virtual bool mousePressed( const OIS::MouseEvent &arg, OIS::MouseButtonID id );   
  61.     virtual bool mouseReleased( const OIS::MouseEvent &arg, OIS::MouseButtonID id );   
  62.     
  63.     //Adjust mouse clipping area   
  64.     virtual void windowResized(Ogre::RenderWindow* rw);   
  65.   
  66.     //Unattach OIS before window shutdown (very important under Linux)   
  67.     virtual void windowClosed(Ogre::RenderWindow* rw);   
  68.     
  69.     Ogre::Root *mRoot;   
  70.     Ogre::Camera* mCamera;   
  71.     Ogre::SceneManager* mSceneMgr;   
  72.     Ogre::RenderWindow* mWindow;   
  73.     Ogre::String mResourcesCfg;   
  74.     Ogre::String mPluginsCfg;   
  75.     
  76.     // OgreBites   
  77.     OgreBites::SdkTrayManager*  mTrayMgr;   
  78.     OgreBites::SdkCameraMan* mCameraMan;        // basic camera controller   
  79.     OgreBites::ParamsPanel* mDetailsPanel;      // sample details panel   
  80.     bool mCursorWasVisible;                     // was cursor visible before dialog appeared   
  81.     bool mShutDown;   
  82.     
  83.     //OIS Input devices   
  84.     OIS::InputManager* mInputManager;   
  85.     OIS::Mouse*    mMouse;   
  86.     OIS::Keyboard* mKeyboard;   
  87.   
  88. /* If static link is used, we should use some variables in order to load plugins ourself. */  
  89. #ifdef OGRE_STATIC_LIB   
  90.     Ogre::ParticleFXPlugin* mParticleFXPlugin;   
  91.     Ogre::D3D9Plugin* mD3D9Plugin;   
  92.     Ogre::OctreePlugin* mOctreePlugin;   
  93.     #if defined __OGREOGGSOUNG__   
  94.     OgreOggSound::OgreOggSoundPlugin* mOgreOggSoundPlugin;   
  95.     #endif   
  96. #endif   
  97.   
  98. };   
  99.     
  100. #endif // #ifndef __BaseApplication_h_  

TutorialApplication.h

Code:
  1. /*  
  2. -----------------------------------------------------------------------------  
  3. Filename:    TutorialApplication.h  
  4. -----------------------------------------------------------------------------  
  5.    
  6. This source file is part of the  
  7.    ___                 __    __ _ _    _   
  8.   /___/__ _ _ __ ___  / / // / (_) | _(_)  
  9.  //  // _` | '__/ _ / / //  // / | |/ / |  
  10. / /_// (_| | | |  __/  /  //  /| |   <| |  
  11. /___/ /__, |_|  /___|   //  // |_|_|/_/_|  
  12.       |___/                                
  13.       Tutorial Framework  
  14.       http://www.ogre3d.org/tikiwiki/  
  15. -----------------------------------------------------------------------------  
  16. */  
  17. #ifndef __TutorialApplication_h_   
  18. #define __TutorialApplication_h_   
  19.   
  20. #include "BaseApplication.h"   
  21.   
  22. /* If we use OgreOggSound libs to provides sound support for the programe. */  
  23. #if defined __OGREOGGSOUNG__   
  24. #include "OgreOggSound.h"   
  25. #endif   
  26.   
  27. /* Use CEGUI system to render independent GUI and deal with some graphic inputs. */  
  28. #if defined __CEGUIOGRE__   
  29. #include <CEGUISystem.h>   
  30. #include <RendererModules/Ogre/CEGUIOgreRenderer.h>   
  31. #include <CEGUISchemeManager.h>   
  32.   
  33.     /* A cool wobbly effect of windows which has been implenmented in CEGUI samples SampleDemo7.  
  34.     But it somehow did not work in this system. I think it's becase of here I use CEGUIOgreRenderer.   
  35.     Maybe it is a bug in the renderer of CEGUIOgreRenderer. Just leave these codes here.   
  36.     */  
  37.     #ifdef __WOBBLLY_EFFECT__   
  38.   
  39.     #include <CEGUIRenderEffect.h>   
  40.     #include <CEGUIVertex.h>   
  41.        
  42.     // Sample subclass for CEGUI::RenderEffect.  This particluar implementation   
  43.     // provides a basic 'wobbly window' type effect.   
  44.     class MyEffect : public CEGUI::RenderEffect   
  45.     {   
  46.     public:   
  47.         MyEffect();   
  48.        
  49.         // implement required functions from RenderEffect interface.   
  50.         int getPassCount() const;   
  51.         void performPreRenderFunctions(const int pass);   
  52.         void performPostRenderFunctions();   
  53.         bool realiseGeometry(CEGUI::RenderingWindow& window, CEGUI::GeometryBuffer& geometry);   
  54.         bool update(const float elapsed, CEGUI::RenderingWindow& window);   
  55.        
  56.     protected:   
  57.         static const float tess_x;   
  58.         static const float tess_y;   
  59.         // tess_x * tess_y * vertex_per_quad   
  60.         static const int buffsize = (8 * 8 * 6);   
  61.        
  62.         bool initialised;   
  63.        
  64.         float lastX, lastY;   
  65.         float dragX, dragY;   
  66.         float elasX, elasY;   
  67.        
  68.         CEGUI::Vertex vb[buffsize];   
  69.     };   
  70.   
  71.     #endif   
  72.   
  73. #endif   
  74.   
  75. // STL dqeue to manage the path of the robot.    
  76. #include <deque>   
  77. //#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32   
  78. //#include "../res/resource.h"   
  79. //#endif   
  80.   
  81.   
  82. class ITutorial01 : public BaseApplication   
  83. {   
  84. public:   
  85.     ITutorial01(void);   
  86.     virtual ~ITutorial01(void);   
  87.     
  88. protected:   
  89.      virtual void createScene(void);   
  90.      virtual void createFrameListener(void);   
  91.      // find the next location for the robot to walk to.    
  92.      virtual bool nextLocation(void);   
  93.      virtual bool frameRenderingQueued(const Ogre::FrameEvent &evt);   
  94.      // Cause we need to query terrain, so choose sceneManager of type ST_EXTERIOR_CLOSE   
  95.      virtual void chooseSceneManager(void);   
  96.   
  97.      //mouse listener   
  98.      virtual bool mouseMoved(const OIS::MouseEvent &arg);   
  99.      virtual bool mousePressed(const OIS::MouseEvent &arg,OIS::MouseButtonID id);   
  100.      virtual bool mouseReleased(const OIS::MouseEvent &arg,OIS::MouseButtonID id);   
  101.   
  102. #if defined __CEGUIOGRE__   
  103.      virtual bool handleSlider(const CEGUI::EventArgs&);    // slider the voice control   
  104.      virtual bool overlayHandler(const CEGUI::EventArgs&);  // handler to the logo overlay   
  105.     #ifdef __WOBBLLY_EFFECT__   
  106.      virtual bool updateRTT(const CEGUI::EventArgs&);   
  107.      virtual bool handleRTTResize(const CEGUI::EventArgs&);   
  108.      virtual void initialiseRTTViewport(CEGUI::RenderingSurface* const);   
  109.     #endif   
  110.      CEGUI::OgreRenderer *mGUIRenderer;         // CEGUI renderer   
  111.      CEGUI::GeometryBuffer* d_logo_geometry;   
  112. #endif   
  113.   
  114.      Ogre::RaySceneQuery *mRaySceneQuery;   // The ray scene query pointer   
  115.      bool mLMouseDown, mRMouseDown;         // True if the mouse buttons are down   
  116.      float mRotateSpeed;   
  117.   
  118.      Ogre::Real mDistance;                  // The distance the object has left to travel   
  119.      Ogre::Vector3 mDirection;              // The direction the object is moving   
  120.      Ogre::Vector3 mDestination;            // The destination the object is moving towards   
  121.   
  122.      Ogre::AnimationState *mAnimationState; // The current animation state of the object   
  123.   
  124.      Ogre::Entity *mEntity;                 // The Entity we are animating   
  125.      Ogre::SceneNode *mNode,*mSoundNode;    // The SceneNode that the Entity is attached to   
  126.      std::deque<Ogre::Vector3> mWalkList;   // The list of points we are walking to   
  127.   
  128.      Ogre::Real mWalkSpeed;                 // The speed at which the object is moving   
  129.   
  130.      Ogre::RenderTexture *rtex;   
  131.   
  132. #if defined __OGREOGGSOUNG__   
  133.      bool mReplay;                                      // If the sound is playing now   
  134.      OgreOggSound::OgreOggSoundManager * mSoundManager; // Pointer to sound manager   
  135.      OgreOggSound::OgreOggISound *sound;                // pointer to sound   
  136. #endif   
  137.   
  138.      char exFlag;                       // Flag to distinguish different states   
  139.      Ogre::ParticleSystem* thrusters;   // Pointer of ParticleSystem, our boomb.    
  140.      Ogre::Camera *rttCam;              // Pointer of RTT camera   
  141. };   
  142.   
  143. #endif // #ifndef __TutorialApplication_h_   
Code:
  1. #include "BaseApplication.h"   
  2.     
  3. //-------------------------------------------------------------------------------------   
  4. BaseApplication::BaseApplication(void)   
  5.     : mRoot(0),   
  6.     mCamera(0),   
  7.     mSceneMgr(0),   
  8.     mWindow(0),   
  9.     mResourcesCfg(Ogre::StringUtil::BLANK),   
  10.     mPluginsCfg(Ogre::StringUtil::BLANK),   
  11.     mTrayMgr(0),   
  12.     mCameraMan(0),   
  13.     mDetailsPanel(0),   
  14.     mCursorWasVisible(false),   
  15.     mShutDown(false),   
  16.     mInputManager(0),   
  17.     mMouse(0),   
  18.     mKeyboard(0)   
  19. {   
  20. }   
  21.     
  22. //-------------------------------------------------------------------------------------   
  23. BaseApplication::~BaseApplication(void)   
  24. {   
  25.     if (mTrayMgr) delete mTrayMgr;   
  26.     if (mCameraMan) delete mCameraMan;   
  27.   
  28.     /* If you want to unload plugins early, you can do so by calling Root::uninstallPlugin   
  29.     although you don't have to do this since when Root shuts down, it automatically safely   
  30.     terminates and removes the plugins. Doing it manually has to be done carefully in case   
  31.     there are cross-plugin dependencies, e.g. one plugin creating rendersystem resources   
  32.     from another plugin.*/  
  33. #ifdef OGRE_STATIC_LIB   
  34.     mRoot->uninstallPlugin(mOgreOggSoundPlugin);   
  35. #endif   
  36.     
  37.     //Remove ourself as a Window listener   
  38.     Ogre::WindowEventUtilities::removeWindowEventListener(mWindow, this);   
  39.     windowClosed(mWindow);   
  40.     delete mRoot;   
  41.   
  42. /* In static link, we created the plugins manully with new method   
  43. so we should free them with delete method, manully too.   
  44. Delete your plugin instances at some point after Root has been shut down,   
  45. or after you manually uninstalled the plugin.  
  46. */  
  47. #ifdef OGRE_STATIC_LIB   
  48.     OGRE_DELETE mParticleFXPlugin;   
  49.     OGRE_DELETE mD3D9Plugin;   
  50.     OGRE_DELETE mOctreePlugin;   
  51.     #if defined __OGREOGGSOUNG__   
  52.     OGRE_DELETE mOgreOggSoundPlugin;   
  53.     #endif   
  54. #endif   
  55. }   
  56.     
  57. //-------------------------------------------------------------------------------------   
  58. bool BaseApplication::configure(void)   
  59. {   
  60.     // Show the configuration dialog and initialise the system   
  61.     // You can skip this and use root.restoreConfig() to load configuration   
  62.     // settings if you were sure there are valid ones saved in ogre.cfg   
  63.     if(mRoot->showConfigDialog())   
  64.     {   
  65.         // If returned true, user clicked OK so initialise   
  66.         // Here we choose to let the system create a default rendering window by passing 'true'   
  67.         mWindow = mRoot->initialise(true"TutorialApplication Render Window");   
  68.     
  69.         return true;   
  70.     }   
  71.     else  
  72.     {   
  73.         return false;   
  74.     }   
  75. }   
  76. //-------------------------------------------------------------------------------------   
  77. void BaseApplication::chooseSceneManager(void)   
  78. {   
  79.     // Get the SceneManager, in this case a generic one   
  80.     mSceneMgr = mRoot->createSceneManager(Ogre::ST_GENERIC);   
  81. }   
  82. //-------------------------------------------------------------------------------------   
  83. void BaseApplication::createCamera(void)   
  84. {   
  85.     // Create the camera   
  86.     mCamera = mSceneMgr->createCamera("PlayerCam");   
  87.     
  88.     // Position it at 80 in Z direction   
  89.     mCamera->setPosition(Ogre::Vector3(0,0,80));   
  90.     // Look back along -Z   
  91.     mCamera->lookAt(Ogre::Vector3(0,0,-300));   
  92.     mCamera->setNearClipDistance(5);   
  93.     
  94.     mCameraMan = new OgreBites::SdkCameraMan(mCamera);   // create a default camera controller   
  95. }   
  96. //-------------------------------------------------------------------------------------   
  97. void BaseApplication::createFrameListener(void)   
  98. {   
  99.     Ogre::LogManager::getSingletonPtr()->logMessage("*** Initializing OIS ***");   
  100.     OIS::ParamList pl;   
  101.     size_t windowHnd = 0;   
  102.     std::ostringstream windowHndStr;   
  103.     
  104.     mWindow->getCustomAttribute("WINDOW", &windowHnd);   
  105.     windowHndStr << windowHnd;   
  106.     pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));   
  107.     
  108.     mInputManager = OIS::InputManager::createInputSystem( pl );   
  109.     
  110.     mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject( OIS::OISKeyboard, true ));   
  111.     mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject( OIS::OISMouse, true ));   
  112.     
  113.     mMouse->setEventCallback(this);   
  114.     mKeyboard->setEventCallback(this);   
  115.     
  116.     //Set initial mouse clipping size   
  117.     windowResized(mWindow);   
  118.     
  119.     //Register as a Window listener   
  120.     Ogre::WindowEventUtilities::addWindowEventListener(mWindow, this);   
  121.     
  122.     mTrayMgr = new OgreBites::SdkTrayManager("InterfaceName", mWindow, mMouse, this);   
  123.     mTrayMgr->showFrameStats(OgreBites::TL_BOTTOMLEFT);   
  124.     mTrayMgr->toggleAdvancedFrameStats();   
  125.     mTrayMgr->showLogo(OgreBites::TL_BOTTOMRIGHT);   
  126.     mTrayMgr->hideCursor();   
  127.     
  128.     // create a params panel for displaying sample details   
  129.     Ogre::StringVector items;   
  130.     items.push_back("cam.pX");   
  131.     items.push_back("cam.pY");   
  132.     items.push_back("cam.pZ");   
  133.     items.push_back("");   
  134.     items.push_back("cam.oW");   
  135.     items.push_back("cam.oX");   
  136.     items.push_back("cam.oY");   
  137.     items.push_back("cam.oZ");   
  138.     items.push_back("");   
  139.     items.push_back("Filtering");   
  140.     items.push_back("Poly Mode");   
  141.     
  142.     mDetailsPanel = mTrayMgr->createParamsPanel(OgreBites::TL_NONE, "DetailsPanel", 200, items);   
  143.     mDetailsPanel->setParamValue(9, "Bilinear");   
  144.     mDetailsPanel->setParamValue(10, "Solid");   
  145.     mDetailsPanel->hide();   
  146.     
  147.     mRoot->addFrameListener(this);   
  148. }   
  149. //-------------------------------------------------------------------------------------   
  150. void BaseApplication::destroyScene(void)   
  151. {   
  152. }   
  153. //-------------------------------------------------------------------------------------   
  154. void BaseApplication::createViewports(void)   
  155. {   
  156.     // Create one viewport, entire window   
  157.     Ogre::Viewport* vp = mWindow->addViewport(mCamera);   
  158.     vp->setBackgroundColour(Ogre::ColourValue(0,0,0));   
  159.     
  160.     // Alter the camera aspect ratio to match the viewport   
  161.     mCamera->setAspectRatio(   
  162.         Ogre::Real(vp->getActualWidth()) / Ogre::Real(vp->getActualHeight()));   
  163. }   
  164. //-------------------------------------------------------------------------------------   
  165. void BaseApplication::setupResources(void)   
  166. {   
  167.     // Load resource paths from config file   
  168.     Ogre::ConfigFile cf;   
  169.     cf.load(mResourcesCfg);   
  170.     
  171.     // Go through all sections & settings in the file   
  172.     Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();   
  173.     
  174.     Ogre::String secName, typeName, archName;   
  175.     while (seci.hasMoreElements())   
  176.     {   
  177.         secName = seci.peekNextKey();   
  178.         Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();   
  179.         Ogre::ConfigFile::SettingsMultiMap::iterator i;   
  180.         for (i = settings->begin(); i != settings->end(); ++i)   
  181.         {   
  182.             typeName = i->first;   
  183.             archName = i->second;   
  184.             Ogre::ResourceGroupManager::getSingleton().addResourceLocation(   
  185.                 archName, typeName, secName);   
  186.         }   
  187.     }   
  188. }   
  189. //-------------------------------------------------------------------------------------   
  190. void BaseApplication::createResourceListener(void)   
  191. {   
  192.     
  193. }   
  194. //-------------------------------------------------------------------------------------   
  195. void BaseApplication::loadResources(void)   
  196. {   
  197.     Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();   
  198. }   
  199. //-------------------------------------------------------------------------------------   
  200. void BaseApplication::go(void)   
  201. {   
  202. #ifdef _DEBUG   
  203.     mResourcesCfg = "resources_d.cfg";   
  204.     mPluginsCfg = "plugins_d.cfg";   
  205. #else   
  206.     mResourcesCfg = "resources.cfg";   
  207.     mPluginsCfg = "plugins.cfg";   
  208. #endif   
  209.     
  210.     if (!setup())   
  211.         return;   
  212.     
  213.     mRoot->startRendering();   
  214.     
  215.     // clean up   
  216.     destroyScene();   
  217. }   
  218. //-------------------------------------------------------------------------------------   
  219. bool BaseApplication::setup(void)   
  220. {   
  221.     /*  
  222.     If we need to give a static link, then we should manully new an object of  
  223.     the plugins and install them. And since we create them with new method,   
  224.     do not forget to delete them before the programe exit.   
  225.     */  
  226. #ifdef OGRE_STATIC_LIB   
  227.     mRoot = OGRE_NEW Ogre::Root("""ogre.cfg""ogre.log");   
  228.     mParticleFXPlugin = OGRE_NEW Ogre::ParticleFXPlugin();   
  229.     mRoot->installPlugin(mParticleFXPlugin);   
  230.     mD3D9Plugin = OGRE_NEW Ogre::D3D9Plugin();   
  231.     mRoot->installPlugin(mD3D9Plugin);   
  232.     mOctreePlugin = OGRE_NEW Ogre::OctreePlugin();   
  233.     mRoot->installPlugin(mOctreePlugin);   
  234.     #if defined __OGREOGGSOUNG__   
  235.     mOgreOggSoundPlugin = OGRE_NEW OgreOggSound::OgreOggSoundPlugin();   
  236.     mRoot->installPlugin(mOgreOggSoundPlugin);   
  237.     #endif   
  238. #else   
  239.     mRoot = new Ogre::Root(mPluginsCfg);   
  240. #endif   
  241.     
  242.     setupResources();   
  243.     
  244.     bool carryOn = configure();   
  245.     if (!carryOn) return false;   
  246.     
  247.     chooseSceneManager();   
  248.     createCamera();   
  249.     createViewports();   
  250.     
  251.     // Set default mipmap level (NB some APIs ignore this)   
  252.     Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);   
  253.     
  254.     // Create any resource listeners (for loading screens)   
  255.     createResourceListener();   
  256.     // Load resources   
  257.     loadResources();   
  258.     
  259.     // Create the scene   
  260.     createScene();   
  261.     
  262.     createFrameListener();   
  263.     
  264.     return true;   
  265. };   
  266. //-------------------------------------------------------------------------------------   
  267. bool BaseApplication::frameRenderingQueued(const Ogre::FrameEvent& evt)   
  268. {   
  269.     if(mWindow->isClosed())   
  270.         return false;   
  271.     
  272.     if(mShutDown)   
  273.         return false;   
  274.     
  275.     //Need to capture/update each device   
  276.     mKeyboard->capture();   
  277.     mMouse->capture();   
  278.     
  279.     mTrayMgr->frameRenderingQueued(evt);   
  280.     
  281.     if (!mTrayMgr->isDialogVisible())   
  282.     {   
  283.         mCameraMan->frameRenderingQueued(evt);   // if dialog isn't up, then update the camera   
  284.         if (mDetailsPanel->isVisible())   // if details panel is visible, then update its contents   
  285.         {   
  286.             mDetailsPanel->setParamValue(0, Ogre::StringConverter::toString(mCamera->getDerivedPosition().x));   
  287.             mDetailsPanel->setParamValue(1, Ogre::StringConverter::toString(mCamera->getDerivedPosition().y));   
  288.             mDetailsPanel->setParamValue(2, Ogre::StringConverter::toString(mCamera->getDerivedPosition().z));   
  289.             mDetailsPanel->setParamValue(4, Ogre::StringConverter::toString(mCamera->getDerivedOrientation().w));   
  290.             mDetailsPanel->setParamValue(5, Ogre::StringConverter::toString(mCamera->getDerivedOrientation().x));   
  291.             mDetailsPanel->setParamValue(6, Ogre::StringConverter::toString(mCamera->getDerivedOrientation().y));   
  292.             mDetailsPanel->setParamValue(7, Ogre::StringConverter::toString(mCamera->getDerivedOrientation().z));   
  293.         }   
  294.     }   
  295.     
  296.     return true;   
  297. }   
  298. //-------------------------------------------------------------------------------------   
  299. bool BaseApplication::keyPressed( const OIS::KeyEvent &arg )   
  300. {   
  301.     if (mTrayMgr->isDialogVisible()) return true;   // don't process any more keys if dialog is up   
  302.     
  303.     if (arg.key == OIS::KC_F)   // toggle visibility of advanced frame stats   
  304.     {   
  305.         mTrayMgr->toggleAdvancedFrameStats();   
  306.     }   
  307.     else if (arg.key == OIS::KC_G)   // toggle visibility of even rarer debugging details   
  308.     {   
  309.         if (mDetailsPanel->getTrayLocation() == OgreBites::TL_NONE)   
  310.         {   
  311.             mTrayMgr->moveWidgetToTray(mDetailsPanel, OgreBites::TL_TOPRIGHT, 0);   
  312.             mDetailsPanel->show();   
  313.         }   
  314.         else  
  315.         {   
  316.             mTrayMgr->removeWidgetFromTray(mDetailsPanel);   
  317.             mDetailsPanel->hide();   
  318.         }   
  319.     }   
  320.     else if (arg.key == OIS::KC_T)   // cycle polygon rendering mode   
  321.     {   
  322.         Ogre::String newVal;   
  323.         Ogre::TextureFilterOptions tfo;   
  324.         unsigned int aniso;   
  325.     
  326.         switch (mDetailsPanel->getParamValue(9).asUTF8()[0])   
  327.         {   
  328.         case 'B':   
  329.             newVal = "Trilinear";   
  330.             tfo = Ogre::TFO_TRILINEAR;   
  331.             aniso = 1;   
  332.             break;   
  333.         case 'T':   
  334.             newVal = "Anisotropic";   
  335.             tfo = Ogre::TFO_ANISOTROPIC;   
  336.             aniso = 8;   
  337.             break;   
  338.         case 'A':   
  339.             newVal = "None";   
  340.             tfo = Ogre::TFO_NONE;   
  341.             aniso = 1;   
  342.             break;   
  343.         default:   
  344.             newVal = "Bilinear";   
  345.             tfo = Ogre::TFO_BILINEAR;   
  346.             aniso = 1;   
  347.         }   
  348.     
  349.         Ogre::MaterialManager::getSingleton().setDefaultTextureFiltering(tfo);   
  350.         Ogre::MaterialManager::getSingleton().setDefaultAnisotropy(aniso);   
  351.         mDetailsPanel->setParamValue(9, newVal);   
  352.     }   
  353.     else if (arg.key == OIS::KC_R)   // cycle polygon rendering mode   
  354.     {   
  355.         Ogre::String newVal;   
  356.         Ogre::PolygonMode pm;   
  357.     
  358.         switch (mCamera->getPolygonMode())   
  359.         {   
  360.         case Ogre::PM_SOLID:   
  361.             newVal = "Wireframe";   
  362.             pm = Ogre::PM_WIREFRAME;   
  363.             break;   
  364.         case Ogre::PM_WIREFRAME:   
  365.             newVal = "Points";   
  366.             pm = Ogre::PM_POINTS;   
  367.             break;   
  368.         default:   
  369.             newVal = "Solid";   
  370.             pm = Ogre::PM_SOLID;   
  371.         }   
  372.     
  373.         mCamera->setPolygonMode(pm);   
  374.         mDetailsPanel->setParamValue(10, newVal);   
  375.     }   
  376.     else if(arg.key == OIS::KC_F5)   // refresh all textures   
  377.     {   
  378.         Ogre::TextureManager::getSingleton().reloadAll();   
  379.     }   
  380.     else if (arg.key == OIS::KC_SYSRQ)   // take a screenshot   
  381.     {   
  382.         mWindow->writeContentsToTimestampedFile("screenshot"".jpg");   
  383.     }   
  384.     else if (arg.key == OIS::KC_ESCAPE)   
  385.     {   
  386.         mShutDown = true;   
  387.     }   
  388.     
  389.     mCameraMan->injectKeyDown(arg);   
  390.     return true;   
  391. }   
  392.     
  393. bool BaseApplication::keyReleased( const OIS::KeyEvent &arg )   
  394. {   
  395.     mCameraMan->injectKeyUp(arg);   
  396.     return true;   
  397. }   
  398.     
  399. bool BaseApplication::mouseMoved( const OIS::MouseEvent &arg )   
  400. {   
  401.     if (mTrayMgr->injectMouseMove(arg)) return true;   
  402.     mCameraMan->injectMouseMove(arg);   
  403.     return true;   
  404. }   
  405.     
  406. bool BaseApplication::mousePressed( const OIS::MouseEvent &arg, OIS::MouseButtonID id )   
  407. {   
  408.     if (mTrayMgr->injectMouseDown(arg, id)) return true;   
  409.     mCameraMan->injectMouseDown(arg, id);   
  410.     return true;   
  411. }   
  412.     
  413. bool BaseApplication::mouseReleased( const OIS::MouseEvent &arg, OIS::MouseButtonID id )   
  414. {   
  415.     if (mTrayMgr->injectMouseUp(arg, id)) return true;   
  416.     mCameraMan->injectMouseUp(arg, id);   
  417.     return true;   
  418. }   
  419.     
  420. //Adjust mouse clipping area   
  421. void BaseApplication::windowResized(Ogre::RenderWindow* rw)   
  422. {   
  423.     unsigned int width, height, depth;   
  424.     int left, top;   
  425.     rw->getMetrics(width, height, depth, left, top);   
  426.     
  427.     const OIS::MouseState &ms = mMouse->getMouseState();   
  428.     ms.width = width;   
  429.     ms.height = height;   
  430. }   
  431.     
  432. //Unattach OIS before window shutdown (very important under Linux)   
  433. void BaseApplication::windowClosed(Ogre::RenderWindow* rw)   
  434. {   
  435.     //Only close for window that created OIS (the main window in these demos)   
  436.     if( rw == mWindow )   
  437.     {   
  438.         if( mInputManager )   
  439.         {   
  440.             mInputManager->destroyInputObject( mMouse );   
  441.             mInputManager->destroyInputObject( mKeyboard );   
  442.     
  443.             OIS::InputManager::destroyInputSystem(mInputManager);   
  444.             mInputManager = 0;   
  445.         }   
  446.     }   
  447. }   

TutorialApplication.cpp

Code:
  1.  
  2. #include "TutorialApplication.h"  
  3. #include "OgreParticleAffector.h"  
  4. #include "OgreParticleEmitter.h"  
  5. #include "OgreParticleSystemManager.h"  
  6.  
  7. #if defined __CEGUIOGRE__  
  8.  
  9. #include "CEGUI.h"  
  10. #include <RendererModules/Ogre/CEGUIOgreTexture.h>  
  11. #include <RendererModules/Ogre/CEGUIOgreTextureTarget.h>   
  12.   
  13. CEGUI::MouseButton convertButton(OIS::MouseButtonID buttonID)   
  14. {   
  15.     switch (buttonID)   
  16.     {   
  17.     case OIS::MB_Left:   
  18.         return CEGUI::LeftButton;   
  19.     
  20.     case OIS::MB_Right:   
  21.         return CEGUI::RightButton;   
  22.     
  23.     case OIS::MB_Middle:   
  24.         return CEGUI::MiddleButton;   
  25.     
  26.     default:   
  27.         return CEGUI::LeftButton;   
  28.     }   
  29. }  
  30.     #ifdef __WOBBLLY_EFFECT__   
  31. //----------------------------------------------------------------------------//   
  32. // The following are related to the RenderEffect   
  33. //   
  34. // Note: This be the land of magic numbers and compound hacks upon hacks :-p   
  35. //       Any final version of this we might provide will likely be cleaned up   
  36. //       considerably.   
  37. //----------------------------------------------------------------------------//   
  38. const float MyEffect::tess_x = 8;   
  39. const float MyEffect::tess_y = 8;   
  40.   
  41. //----------------------------------------------------------------------------//   
  42. MyEffect::MyEffect() :   
  43.     initialised(false),   
  44.     dragX(0), dragY(0),   
  45.     elasX(0), elasY(0)   
  46. {   
  47. }   
  48.   
  49.   
  50. //----------------------------------------------------------------------------//   
  51. int MyEffect::getPassCount() const  
  52. {   
  53.     return 1;   
  54. }   
  55.   
  56. //----------------------------------------------------------------------------//   
  57. void MyEffect::performPreRenderFunctions(const int /*pass*/)   
  58. {   
  59.     // nothing we need here   
  60. }   
  61.   
  62. //----------------------------------------------------------------------------//   
  63. void MyEffect::performPostRenderFunctions()   
  64. {   
  65.     // nothing we need here   
  66. }   
  67.   
  68. //----------------------------------------------------------------------------//   
  69. bool MyEffect::realiseGeometry(CEGUI::RenderingWindow& window,   
  70.                                CEGUI::GeometryBuffer& geometry)   
  71. {   
  72.     using namespace CEGUI;   
  73.     Texture& tex = window.getTextureTarget().getTexture();   
  74.   
  75.     static const CEGUI::colour c(1, 1, 1, 1);   
  76.   
  77.     const float qw = window.getSize().d_width / tess_x;   
  78.     const float qh = window.getSize().d_height / tess_y;   
  79.     const float tcx = qw * tex.getTexelScaling().d_x;   
  80.     const float tcy =   
  81.         (window.getTextureTarget().isRenderingInverted() ? -qh : qh) *   
  82.             tex.getTexelScaling().d_y;   
  83.   
  84.     for (int j = 0; j < tess_y; ++j)   
  85.     {   
  86.         for (int i = 0; i < tess_x; ++i)   
  87.         {   
  88.             int idx = (j * tess_x + i) * 6;   
  89.   
  90.             float top_adj = dragX * ((1.0f / tess_x) * j);   
  91.             float bot_adj = dragX * ((1.0f / tess_x) * (j+1));   
  92.             top_adj = ((top_adj*top_adj) / 3) * (dragX < 0 ? -1 : 1);   
  93.             bot_adj = ((bot_adj*bot_adj) / 3) * (dragX < 0 ? -1 : 1);   
  94.   
  95.             float lef_adj = dragY * ((1.0f / tess_y) * i);   
  96.             float rig_adj = dragY * ((1.0f / tess_y) * (i+1));   
  97.             lef_adj = ((lef_adj*lef_adj) / 3) * (dragY < 0 ? -1 : 1);   
  98.             rig_adj = ((rig_adj*rig_adj) / 3) * (dragY < 0 ? -1 : 1);   
  99.   
  100.             // vertex 0   
  101.             vb[idx + 0].position   = Vector3(i * qw - top_adj, j * qh - lef_adj, 0.0f);   
  102.             vb[idx + 0].colour_val = c;   
  103.             vb[idx + 0].tex_coords = Vector2(i * tcx, j*tcy);   
  104.   
  105.             // vertex 1   
  106.             vb[idx + 1].position   = Vector3(i * qw - bot_adj, j * qh + qh - lef_adj, 0.0f);   
  107.             vb[idx + 1].colour_val = c;   
  108.             vb[idx + 1].tex_coords = Vector2(i*tcx, j*tcy+tcy);   
  109.   
  110.             // vertex 2   
  111.             vb[idx + 2].position   = Vector3(i * qw + qw - bot_adj, j * qh + qh - rig_adj, 0.0f);   
  112.             vb[idx + 2].colour_val = c;   
  113.             vb[idx + 2].tex_coords = Vector2(i*tcx+tcx, j*tcy+tcy);   
  114.   
  115.             // vertex 3   
  116.             vb[idx + 3].position   = Vector3(i * qw + qw - bot_adj, j * qh + qh - rig_adj, 0.0f);   
  117.             vb[idx + 3].colour_val = c;   
  118.             vb[idx + 3].tex_coords = Vector2(i*tcx+tcx, j*tcy+tcy);   
  119.   
  120.             // vertex 4   
  121.             vb[idx + 4].position   = Vector3(i * qw + qw - top_adj, j * qh - rig_adj, 0.0f);   
  122.             vb[idx + 4].colour_val = c;   
  123.             vb[idx + 4].tex_coords = Vector2(i*tcx+tcx, j*tcy);   
  124.   
  125.             // vertex 5   
  126.             vb[idx + 5].position   = Vector3(i * qw - top_adj, j * qh - lef_adj, 0.0f);   
  127.             vb[idx + 5].colour_val = c;   
  128.             vb[idx + 5].tex_coords = Vector2(i * tcx, j*tcy);   
  129.         }   
  130.     }   
  131.   
  132.     geometry.setActiveTexture(&tex);   
  133.     geometry.appendGeometry(vb, buffsize);   
  134.   
  135.     // false, because we do not want the default geometry added!   
  136.     return false;   
  137. }   
  138.   
  139. //----------------------------------------------------------------------------//   
  140. bool MyEffect::update(const float elapsed, CEGUI::RenderingWindow& window)   
  141. {   
  142.     using namespace CEGUI;   
  143.        
  144.     // initialise ourself upon the first update call.   
  145.     if (!initialised)   
  146.     {   
  147.         initialised=true;   
  148.         lastX = window.getPosition().d_x;   
  149.         lastY = window.getPosition().d_y;   
  150.         return true;   
  151.     }   
  152.   
  153.     const Vector2 pos(window.getPosition());   
  154.   
  155.     //   
  156.     // Set up for X axis animation.   
  157.     //   
  158.     if (pos.d_x != lastX)   
  159.     {   
  160.         dragX += (pos.d_x - lastX) * 0.2;   
  161.         elasX = 0.05f;   
  162.         lastX = pos.d_x;   
  163.   
  164.         if (dragX > 25)   
  165.             dragX = 25;   
  166.         else if (dragX < -25)   
  167.             dragX = -25;   
  168.     }   
  169.   
  170.     //   
  171.     // Set up for y axis animation   
  172.     //   
  173.     if (pos.d_y != lastY)   
  174.     {   
  175.         dragY += (pos.d_y - lastY) * 0.2f;   
  176.         elasY = 0.05f;   
  177.         lastY = pos.d_y;   
  178.   
  179.         if (dragY > 25)   
  180.             dragY = 25;   
  181.         else if (dragY < -25)   
  182.             dragY = -25;   
  183.     }   
  184.   
  185.     //   
  186.     // Perform required animation steps   
  187.     //   
  188.     if ((dragX != 0) || (dragY != 0))   
  189.     {   
  190.         if (dragX < 0)   
  191.         {   
  192.             dragX += (elasX * 800 * elapsed);   
  193.             elasX += 0.075 * elapsed;   
  194.             if (dragX >0)   
  195.                 dragX = 0;   
  196.         }   
  197.         else  
  198.         {   
  199.             dragX -= (elasX * 800 * elapsed);   
  200.             elasX += 0.075 * elapsed;   
  201.             if (dragX < 0)   
  202.                 dragX = 0;   
  203.         }   
  204.   
  205.         if (dragY < 0)   
  206.         {   
  207.             dragY += elasY * 800 * elapsed;   
  208.             elasY += 0.075 * elapsed;   
  209.             if (dragY >0)   
  210.                 dragY = 0;   
  211.         }   
  212.         else  
  213.         {   
  214.             dragY -= elasY * 800 * elapsed;   
  215.             elasY += 0.075 * elapsed;   
  216.             if (dragY < 0)   
  217.                 dragY = 0;   
  218.         }   
  219.   
  220.         // note we just need system to redraw the geometry; we do not need a   
  221.         // full redraw of all window/widget content - which is unchanged.   
  222.         System::getSingleton().signalRedraw();   
  223.         return false;   
  224.     }   
  225.   
  226.     return true;   
  227. }  
  228.  
  229.     #endif  
  230. #endif   
  231.   
  232. ITutorial01::ITutorial01(void):mRaySceneQuery(0),exFlag(0),mReplay(false)   
  233. {   
  234. }   
  235.   
  236. ITutorial01::~ITutorial01(void)   
  237. {   
  238.     mWalkList.clear();   
  239.     // We created the query, and we are also responsible for deleting it.   
  240.     if(mRaySceneQuery)   
  241.     {   
  242.         mSceneMgr->destroyQuery(mRaySceneQuery);   
  243.     }   
  244. }   
  245.   
  246. void ITutorial01::createScene(void)   
  247. {   
  248.     // Set ambient light   
  249.     mSceneMgr->setAmbientLight(Ogre::ColourValue(0.2f, 0.2f, 0.2f));   
  250.     mSceneMgr->setSkyBox(true"Examples/SpaceSkyBox", 5000);  // set our skybox   
  251.   
  252.     // World geometry   
  253.     mSceneMgr->setWorldGeometry("terrain.cfg");   
  254.   
  255.     // Set camera look point   
  256.     mCamera->setPosition(Ogre::Vector3(2500, 30, 3980));   
  257.     //mCamera->setDirection(0,-1,0);   
  258.     mCamera->lookAt(Ogre::Vector3(2600, 100, 3615));   
  259.     mCamera->setNearClipDistance(0.5);   
  260.   
  261.     // Create the entity   
  262.     mEntity = mSceneMgr->createEntity("Robot""robot.mesh");   
  263.   
  264.     // Create the scene node   
  265.     mNode = mSceneMgr->getRootSceneNode()->   
  266.         createChildSceneNode("RobotNode", Ogre::Vector3(2680, 30, 4030));   
  267.     mNode->attachObject(mEntity);   
  268.     mNode->setScale(0.3f,0.3f,0.3f);   
  269.   
  270.     // Create the walking list   
  271.     mWalkList.push_back(Ogre::Vector3(2300, 0, 3760));   
  272.     mWalkList.push_back(Ogre::Vector3(2700, 0, 3250));   
  273.   
  274.     rttCam = mSceneMgr->createCamera("RTTCam");   
  275.     rttCam->setNearClipDistance(1);   
  276.   
  277.     //RTT   
  278.     Ogre::TexturePtr tex = mRoot->getTextureManager()->createManual("RTT",Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,   
  279.         Ogre::TEX_TYPE_2D,512,512,0,Ogre::PF_R8G8B8,Ogre::TU_RENDERTARGET);   
  280.   
  281.     rtex = tex->getBuffer()->getRenderTarget();   
  282.   
  283.     Ogre::Viewport *v = rtex->addViewport(mSceneMgr->getCamera("RTTCam"));   
  284.     v->setOverlaysEnabled(false);   
  285.     v->setClearEveryFrame(true);   
  286.     v->setBackgroundColour(Ogre::ColourValue::Black);   
  287.   
  288.     // create a particle system with 200 quota, then set its material and dimensions   
  289.     thrusters = mSceneMgr->createParticleSystem("thrusters",25);   
  290.     thrusters ->setMaterialName("Examples/Flare");   
  291.     thrusters ->setDefaultDimensions(15, 15);   
  292.   
  293.     // create emitter for our thruster particle system   
  294.     Ogre::ParticleEmitter* emitter = thrusters ->addEmitter("Point");  // add a point emitter   
  295.   
  296.     Ogre::Vector3 direct = mCamera->getDirection();   
  297.     // set the emitter properties   
  298.     emitter->setAngle(Ogre::Degree(5));   
  299.     emitter->setTimeToLive(0.5);   
  300.     emitter->setEmissionRate(20);   
  301.     emitter->setParticleVelocity(10);   
  302.     emitter->setDirection(Ogre::Vector3::ZERO);   
  303.     emitter->setColour(Ogre::ColourValue::White, Ogre::ColourValue::Red);   
  304.     emitter->setPosition(Ogre::Vector3(0,0,0));   
  305.   
  306.     // attach our thruster particles to the rear of the ship   
  307.     mSceneMgr->getRootSceneNode()->createChildSceneNode("emitter")->attachObject(thrusters);   
  308.     rttCam->detachFromParent();   
  309.     mSceneMgr->getSceneNode("emitter")->attachObject(rttCam);   
  310.     mSceneMgr->getSceneNode("emitter")->setPosition(mCamera->getPosition()+15*direct-Ogre::Vector3(0,10,0));   
  311.   
  312.     // Create objects so we can see movement   
  313.     Ogre::Entity *ent;   
  314.     Ogre::SceneNode *node;   
  315.   
  316.     ent = mSceneMgr->createEntity("Sphere1""sphere.mesh");   
  317.     node = mSceneMgr->getRootSceneNode()->createChildSceneNode("Sphere0Node");   
  318.     node->attachObject(ent);   
  319.     node->setScale(0.02f, 0.02f, 0.02f);   
  320.   
  321.     ent = mSceneMgr->createEntity("Sphere2""sphere.mesh");   
  322.     node = mSceneMgr->getRootSceneNode()->createChildSceneNode("Sphere1Node");   
  323.     node->attachObject(ent);   
  324.     node->setScale(0.02f, 0.02f, 0.02f);   
  325.   
  326.     ent = mSceneMgr->createEntity("Sphere3""sphere.mesh");   
  327.     node = mSceneMgr->getRootSceneNode()->createChildSceneNode("Sphere2Node");   
  328.     node->attachObject(ent);   
  329.     node->setScale(0.02f, 0.02f, 0.02f);  
  330.  
  331. #if defined __OGREMINISCREEN__   
  332.     //Ogre miniScreen render to texture   
  333.     Ogre::Rectangle2D *mMiniScreen = new Ogre::Rectangle2D(true);   
  334.     mMiniScreen->setCorners(0.5f, -0.5f, 1.0f, -1.0f);   
  335.     mMiniScreen->setBoundingBox(Ogre::AxisAlignedBox(-100000.0f * Ogre::Vector3::UNIT_SCALE, 100000.0f * Ogre::Vector3::UNIT_SCALE));   
  336.   
  337.     Ogre::SceneNode* miniScreenNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("MiniScreenNode");   
  338.     miniScreenNode->attachObject(mMiniScreen);   
  339.     Ogre::MaterialPtr renderMaterial = Ogre::MaterialManager::getSingleton().create("RttMat", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);   
  340.     Ogre::Technique* matTechnique = renderMaterial->createTechnique();   
  341.     matTechnique->createPass();   
  342.     renderMaterial->getTechnique(0)->getPass(0)->setLightingEnabled(false);   
  343.     renderMaterial->getTechnique(0)->getPass(0)->createTextureUnitState("RTT");   
  344.     mMiniScreen->setMaterial("RttMat");  
  345. #endif  
  346.  
  347. #if defined __CEGUIOGRE__   
  348.   
  349.     // CEGUI setup   
  350.     mGUIRenderer = &CEGUI::OgreRenderer::bootstrapSystem();  
  351.  
  352. #ifdef __WOBBLLY_EFFECT__   
  353.     // Register our effect with the system   
  354.     CEGUI::RenderEffectManager::getSingleton().addEffect<MyEffect>("WobblyWindow");   
  355.   
  356.     // Now we make a Falagard mapping for a frame window that uses this effect.   
  357.     // We create a type "TaharezLook/WobblyFrameWindow", which is subsequently   
  358.     // referenced in the layout file loaded below.  Note that it wold be more   
  359.     // usual for this mapping to be specified in the scheme xml file, though   
  360.     // here we are doing in manually to save from needing either multiple   
  361.     // versions of the schemes or from having demo specific definitions in   
  362.     // the schemes.   
  363.     CEGUI::WindowFactoryManager::getSingleton().addFalagardWindowMapping(   
  364.         "TaharezLook/WobblyFrameWindow",    // type to create   
  365.         "CEGUI/FrameWindow",                // 'base' widget type   
  366.         "TaharezLook/FrameWindow",          // WidgetLook to use.   
  367.         "Falagard/FrameWindow",             // WindowRenderer to use.   
  368.         "WobblyWindow");                    // effect to use.  
  369. #endif   
  370.   
  371.     // Mouse   
  372.     CEGUI::SchemeManager::getSingleton().create((CEGUI::utf8*)"TaharezLook.scheme");   
  373.     CEGUI::System::getSingleton().setDefaultMouseCursor("TaharezLook""MouseArrow");   
  374.     CEGUI::MouseCursor::getSingleton().setImage("TaharezLook""MouseArrow");   
  375.   
  376.     /// CEGUI logo render //   
  377.     // setup required to do direct rendering   
  378.     const CEGUI::Size hsz = mGUIRenderer->getDisplaySize() * 0.5f;   
  379.     const CEGUI::Rect scrn(CEGUI::Vector2(0, 0), hsz * 2);   
  380.   
  381.     // setup for logo   
  382.     CEGUI::ImagesetManager::getSingleton().createFromImageFile("cegui_logo""logo.png""Imagesets");   
  383.     d_logo_geometry = &mGUIRenderer->createGeometryBuffer();   
  384.     d_logo_geometry->setClippingRegion(scrn);   
  385.     d_logo_geometry->setPivot(CEGUI::Vector3(hsz.d_width, 34.75f, 0));   
  386.     d_logo_geometry->setTranslation(CEGUI::Vector3(0, hsz.d_height * 2 - 80, 0));   
  387.     CEGUI::ImagesetManager::getSingleton().get("cegui_logo").getImage("full_image").draw(*d_logo_geometry,   
  388.         CEGUI::Rect(hsz.d_width - 50, 0, hsz.d_width + 50, 69.5f), 0);   
  389.   
  390.     // clearing this queue actually makes sure it's created(!)   
  391.     mGUIRenderer->getDefaultRenderingRoot().clearGeometry(CEGUI::RQ_OVERLAY);   
  392.   
  393.     // subscribe handler to render overlay items   
  394.     mGUIRenderer->getDefaultRenderingRoot().subscribeEvent(CEGUI::RenderingSurface::EventRenderQueueStarted,   
  395.         CEGUI::Event::Subscriber(&ITutorial01::overlayHandler,this));   
  396.   
  397.     ///   
  398.   
  399.     CEGUI::Texture &guiTex = mGUIRenderer->createTexture(tex);   
  400.     CEGUI::Imageset &imageSet = CEGUI::ImagesetManager::getSingleton().create("RTTImageset", guiTex);   
  401.     imageSet.defineImage("RTTImage",CEGUI::Point(0.0f, 0.0f),CEGUI::Size(guiTex.getSize().d_width,   
  402.         guiTex.getSize().d_height), CEGUI::Point(0.0f, 0.0f));   
  403.   
  404.     // CEGUI GUI sheet setup   
  405.     CEGUI::Window * sheet = CEGUI::WindowManager::getSingleton().createWindow("DefaultWindow""Root");   
  406.     CEGUI::System::getSingleton().setGUISheet(sheet);   
  407.   
  408.     // RTTFrameWindow  
  409. #ifdef __WOBBLLY_EFFECT__   
  410.     CEGUI::Window *si = CEGUI::WindowManager::getSingleton().createWindow("TaharezLook/WobblyFrameWindow""RTTFrameWindow");  
  411. #else   
  412.     CEGUI::Window *si = CEGUI::WindowManager::getSingleton().createWindow("TaharezLook/FrameWindow""RTTFrameWindow");  
  413. #endif   
  414.   
  415.     sheet->addChildWindow(si);   
  416.     si->setPosition(CEGUI::UVector2(CEGUI::UDim(0.0f, 0), CEGUI::UDim(0.0f, 0)));   
  417.     si->setProperty("CloseButtonEnabled","False");   
  418.     si->setProperty("Text","Sound");   
  419.     si->setProperty("ClientAreaColour","7F141B38");   
  420.   
  421.     si = CEGUI::WindowManager::getSingleton().createWindow("TaharezLook/Slider""slider");   
  422.     CEGUI::WindowManager::getSingleton().getWindow("RTTFrameWindow")->addChildWindow(si);   
  423.     si->setSize(CEGUI::UVector2(CEGUI::UDim(0.2f, 0), CEGUI::UDim(1.0f, 0)));   
  424.     si->setPosition(CEGUI::UVector2(CEGUI::UDim(0.4f, 0), CEGUI::UDim(0.0f, 0)));   
  425.     si->setProperty("MaximumValue""1");   
  426.     si->setProperty("CurrentValue""0.7");   
  427.     si->subscribeEvent(CEGUI::Slider::EventValueChanged, CEGUI::Event::Subscriber(&ITutorial01::handleSlider,this));   
  428.     si = CEGUI::WindowManager::getSingleton().getWindow("RTTFrameWindow");   
  429.     si->setSize(CEGUI::UVector2(CEGUI::UDim(0.15f, 0), CEGUI::UDim(0.5f, 0)));   
  430.     ((CEGUI::FrameWindow*)si)->toggleRollup();   
  431.   
  432.     si = CEGUI::WindowManager::getSingleton().createWindow("TaharezLook/StaticImage""RTTWindow");   
  433.     si->setProperty("BackgroundEnabled","False");   
  434.     si->setSize(CEGUI::UVector2(CEGUI::UDim(0.5f, 0), CEGUI::UDim(0.4f, 0)));   
  435.     si->setPosition(CEGUI::UVector2(CEGUI::UDim(0.5f, 0), CEGUI::UDim(0.0f, 0)));   
  436.     si->setProperty("Image", CEGUI::PropertyHelper::imageToString(&imageSet.getImage("RTTImage")));   
  437.     sheet->addChildWindow(si);   
  438.     si->setVisible(false);  
  439.  
  440.     #ifdef __CEGUI_RTT__   
  441.     // get rendering surface used by FrameWindow.   
  442.     CEGUI::RenderingSurface* surface = &si->getTargetRenderingSurface();   
  443.        
  444.     // if there's no surface, skip the RTT setup parts!   
  445.     if (surface)   
  446.     {   
  447.         initialiseRTTViewport(surface);   
  448.   
  449.         // Since we set the Ogre RTT above to not be auto updated, we'll use an   
  450.         // event subscription to decide when to render that content manually.   
  451.         // Basically this needs to be done after other UI content is drawn but   
  452.         // before anything gets put on screen.  We need to use an appropriate   
  453.         // RenderingSurface for this - not the surface used for the window we   
  454.         // will render directly to - but something higher up.  For this demo   
  455.         // (and many other scenarios) the RenderingRoot will suffice.  We use   
  456.         // the EventRenderQueueStarted because we want to update the content   
  457.         // /before/ it's drawn to the surface (here that would be the screen).   
  458.         mGUIRenderer->getDefaultRenderingRoot().subscribeEvent(CEGUI::RenderingSurface::EventRenderQueueEnded,   
  459.             CEGUI::Event::Subscriber(&ITutorial01::updateRTT, this));   
  460.   
  461.         // subscribe to hear about resize events.  This is needed because   
  462.         // when the underlying texture gets resized, all the associated objects   
  463.         // must be assumed to be lost also   
  464.         si->subscribeEvent(CEGUI::Window::EventSized,CEGUI::Event::Subscriber(&ITutorial01::handleRTTResize, this));   
  465.     }  
  466.     #endif  
  467. #endif  
  468.  
  469. #if defined __OGREOGGSOUNG__   
  470.     //OgreOggSound setup   
  471.     mSoundNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("soundNode",mCamera->getPosition());   
  472.   
  473.     if(mSoundManager->init())   
  474.     {   
  475.         mSoundNode->attachObject(mSoundManager->getListener());   
  476.   
  477.         /** prebuffered, streamed, looping */  
  478.         // but I've changed it here   
  479.         sound = 0;   
  480.         if ( sound = mSoundManager->createSound("PointSound""WA121.wav") )   
  481.         {   
  482.             sound->disable3D(true);   
  483.         }   
  484.   
  485.         /** streamed, looping, EFX Direct filter */  
  486.         sound = 0;   
  487.         sound = mSoundManager->createSound("background""p42.ogg"truetrue);   
  488.         if ( sound )    
  489.         {   
  490.             sound->disable3D(true);   
  491.             sound->play();   
  492.         }   
  493.   
  494.         sound = 0;   
  495.         sound = mSoundManager->createSound("Fire""WD366.wav"falsefalsetrue);   
  496.         if ( sound )    
  497.         {   
  498.             sound->disable3D(true);   
  499.         }   
  500.   
  501.         /** prebuffered, streamed, looping */  
  502.         sound = 0;   
  503.         if ( sound = sound = mSoundManager->createSound("Explosion","WD309.wav"falsefalsetrue) )   
  504.         {   
  505.             sound->setMaxDistance(3000);   
  506.             sound->setReferenceDistance(1000);   
  507.             mSceneMgr->getSceneNode("emitter")->attachObject(sound);   
  508.         }   
  509.   
  510.         /** prebuffered, streamed, looping */  
  511.         sound = 0;   
  512.         if ( sound = mSoundManager->createSound("Emitter""WD299.wav"truetrue) )   
  513.         {   
  514.             sound->setMaxDistance(150);   
  515.             sound->setReferenceDistance(50);   
  516.             mSceneMgr->getSceneNode("emitter")->attachObject(sound);   
  517.             sound->play();   
  518.             sound->setLoopOffset(5.f);   
  519.         }   
  520.   
  521.         sound = 0;   
  522.         if ( sound = mSoundManager->createSound("StepSound""WF038.wav"falsetrue) )   
  523.         {   
  524.             sound->setMaxDistance(300);   
  525.             sound->setReferenceDistance(100);   
  526.             mNode->attachObject(sound);   
  527.         }   
  528.   
  529.         mSoundManager->setMasterVolume(0.7f);   
  530.     }  
  531. #endif   
  532.   
  533. }  
  534.  
  535. #if defined __CEGUIOGRE__  
  536.     #ifdef __CEGUI_RTT__   
  537. void ITutorial01::initialiseRTTViewport(CEGUI::RenderingSurface* const surface)   
  538. {   
  539.     const Ogre::RenderTexture* const old_rtt = rtex;   
  540.   
  541.     // extract the Ogre render target at for the surface   
  542.     rtex = dynamic_cast<CEGUI::OgreTexture&>(dynamic_cast<CEGUI::OgreTextureTarget&>(   
  543.         surface->getRenderTarget()).getTexture()).getOgreTexture()->getBuffer()->getRenderTarget();   
  544.   
  545.     // only do set up if target is changed.   
  546.     if (old_rtt != rtex)   
  547.     {   
  548.         // tell Ogre not to draw this target automatically (else you get   
  549.         // visible flickering).   
  550.         //rtex->setAutoUpdated(false);   
  551.   
  552.         // setup viewport.   
  553.         Ogre::Viewport *v = rtex->addViewport(mSceneMgr->getCamera("RTTCam"));   
  554.         v->setOverlaysEnabled(false);   
  555.         v->setClearEveryFrame(true);   
  556.         v->setBackgroundColour(Ogre::ColourValue::Black);   
  557.     }   
  558. }   
  559.   
  560. bool ITutorial01::updateRTT(const CEGUI::EventArgs& args)   
  561. {   
  562.     // There are many rendering queues that may (or may not) be present for   
  563.     // a RenderingSurface.  For our purposes, we can hook the 'default' of   
  564.     // RQ_BASE. - and we need to do our rendering /before/ this queue   
  565.     if (static_cast<const CEGUI::RenderQueueEventArgs&>(args).queueID != CEGUI::RQ_BASE)   
  566.         return false;   
  567.     // get the target to draw itself.   
  568.     rtex->update();   
  569.     // Reset the initial CEGUI rendering states.   
  570.     mGUIRenderer->initialiseRenderStateSettings();   
  571.     // (Re)Activate the appropriate CEGUI render target.   
  572.     mGUIRenderer->getDefaultRenderingRoot().getRenderTarget().activate();   
  573.     return true;   
  574. }   
  575.   
  576. bool ITutorial01::handleRTTResize(const CEGUI::EventArgs& args)   
  577. {   
  578.     // get rendering surface used by FrameWindow.   
  579.     CEGUI::RenderingSurface* surface = static_cast<const CEGUI::WindowEventArgs&>(args).window   
  580.         ->getRenderingSurface();   
  581.   
  582.     // if there's no surface, skip the RTT setup parts!   
  583.     if (surface)   
  584.     {   
  585.         initialiseRTTViewport(surface);   
  586.     }   
  587.   
  588.     return true;   
  589. }  
  590.     #endif   
  591.   
  592. bool ITutorial01::overlayHandler(const CEGUI::EventArgs& args)   
  593. {   
  594.     if (static_cast<const CEGUI::RenderQueueEventArgs&>(args).queueID != CEGUI::RQ_OVERLAY)   
  595.         return false;   
  596.     d_logo_geometry->draw();   
  597.     return true;   
  598. }   
  599.   
  600. bool ITutorial01::handleSlider(const CEGUI::EventArgs& args)   
  601. {   
  602.     float val = static_cast<CEGUI::Slider*>(static_cast<const CEGUI::WindowEventArgs&>(args).window)->getCurrentValue();   
  603.     mSoundManager->setMasterVolume(val);   
  604.     return true;   
  605. }  
  606.  
  607. #endif   
  608.   
  609. void ITutorial01::createFrameListener(void)   
  610. {   
  611.     // Set idle animation   
  612.     mAnimationState = mEntity->getAnimationState("Idle");   
  613.     mAnimationState->setLoop(true);   
  614.     mAnimationState->setEnabled(true);   
  615.   
  616.     // Set default values for variables   
  617.     mWalkSpeed = 50.0f;   
  618.     mDirection = Ogre::Vector3::ZERO;   
  619.   
  620.     // Setup default variables   
  621.     mLMouseDown = false;   
  622.     mRMouseDown = false;   
  623.   
  624.     // Reduce rotate speed   
  625.     mRotateSpeed =.1f;   
  626.     // Create RaySceneQuery   
  627.     mRaySceneQuery = mSceneMgr->createRayQuery(Ogre::Ray());   
  628.     BaseApplication::createFrameListener();   
  629. }   
  630. bool ITutorial01::nextLocation(void)   
  631. {   
  632.     if (mWalkList.empty())   
  633.         return false;   
  634.     mDestination = mWalkList.front();  // this gets the front of the deque   
  635.     mWalkList.pop_front();             // this removes the front of the deque   
  636.   
  637.     // in order to just rotate the robot in XZ plane, we make the Y axis be the same   
  638.     mDirection = mDestination - mNode->getPosition();   
  639.     mDirection.y = 0;   
  640.     mDistance = mDirection.normalise();   
  641.     return true;   
  642. }   
  643.     
  644. bool ITutorial01::frameRenderingQueued(const Ogre::FrameEvent &evt)   
  645. {  
  646.       
  647. #if defined __CEGUIOGRE__   
  648.     // update logo rotation   
  649.     static float rot = 0.0f;   
  650.     d_logo_geometry->setRotation(CEGUI::Vector3(rot, 0, 0));   
  651.     rot += 180.0f * (evt.timeSinceLastFrame);   
  652.     if (rot > 360.0f)   
  653.         rot -= 360.0f;  
  654. #endif  
  655.  
  656. #if defined __OGREOGGSOUNG__   
  657.     //update the listener's postion   
  658.     mSoundNode->setPosition(mCamera->getPosition());   
  659.     mSoundManager->update(evt.timeSinceLastFrame);  
  660. #endif   
  661.   
  662.     // Setup the scene query   
  663.     Ogre::Vector3 nodePos = mNode->getPosition();   
  664.     Ogre::Ray nodeRay(Ogre::Vector3(nodePos.x, 5000.0f, nodePos.z), Ogre::Vector3::NEGATIVE_UNIT_Y);   
  665.     mRaySceneQuery->setRay(nodeRay);   
  666.   
  667.     // Perform the scene query   
  668.     Ogre::RaySceneQueryResult &result = mRaySceneQuery->execute();   
  669.     Ogre::RaySceneQueryResult::iterator itr = result.begin();   
  670.   
  671.     // Get the results, set the RobotNode height   
  672.     if (itr != result.end() && itr->worldFragment)   
  673.     {   
  674.         Ogre::Real terrainHeight = itr->worldFragment->singleIntersection.y;   
  675.         if ((terrainHeight) != nodePos.y)   
  676.             mNode->setPosition( nodePos.x, terrainHeight, nodePos.z );   
  677.     }   
  678.   
  679.     // Setup the scene query. For the camera   
  680.     nodePos = mCamera->getPosition();   
  681.     nodeRay.setOrigin(Ogre::Vector3(nodePos.x, 5000.0f, nodePos.z));   
  682.     mRaySceneQuery->setRay(nodeRay);   
  683.   
  684.     // Perform the scene query   
  685.     result = mRaySceneQuery->execute();   
  686.     itr = result.begin();   
  687.   
  688.     // Get the results, set the camera height   
  689.     if (itr != result.end() && itr->worldFragment)   
  690.     {   
  691.         Ogre::Real terrainHeight = itr->worldFragment->singleIntersection.y;   
  692.         if ((terrainHeight + 10.0f) >= nodePos.y)   
  693.             mCamera->setPosition( nodePos.x, terrainHeight + 10.0f, nodePos.z );   
  694.     }   
  695.   
  696.     // Here nodePos is just a vector of direction   
  697.     nodePos = thrusters->getEmitter(0)->getDirection();   
  698.     if(!nodePos.isZeroLength())   
  699.     {   
  700.         mSceneMgr->getSceneNode("emitter")->translate(nodePos * 150 * evt.timeSinceLastFrame);   
  701.         if(!(exFlag & 0x01))   
  702.         {   
  703.             nodePos = mSceneMgr->getSceneNode("emitter")->getPosition();   
  704.             if((nodePos - mCamera->getPosition()).squaredLength() > 25000000)   
  705.             {   
  706.                 thrusters->getEmitter(0)->setDirection(Ogre::Vector3::ZERO);   
  707.                 exFlag |= 0x01;   
  708.             }   
  709.             else  
  710.             {   
  711.                 nodeRay.setOrigin(nodePos);   
  712.                 nodeRay.setDirection(thrusters->getEmitter(0)->getDirection());   
  713.                 mRaySceneQuery->setRay(nodeRay);   
  714.                 // Execute query   
  715.                 result = mRaySceneQuery->execute();   
  716.                 // And I think it is more intelligent to use query mask here.   
  717.                 for(itr = result.begin();itr != result.end();++itr)   
  718.                 {   
  719.                     if(itr->distance < 0.5f && itr->movable && !itr->movable->getName().compare("Robot"))   
  720.                     {   
  721.                         thrusters->getEmitter(0)->setDirection(Ogre::Vector3::ZERO);   
  722.                         exFlag |= 0x01;   
  723.                         exFlag |= 0x02;   
  724.                         break;   
  725.                     }   
  726.                     if (itr->distance < 3.0f && itr->worldFragment)   
  727.                     {   
  728.                         thrusters->getEmitter(0)->setDirection(Ogre::Vector3::ZERO);   
  729.                         exFlag |= 0x01;   
  730.                         break;   
  731.                     } // if   
  732.                 }   
  733.             }   
  734.         }   
  735.     }   
  736.   
  737.     static float size = 15.0f;  
  738.  
  739. #if defined __CEGUIOGRE__   
  740.     if(exFlag & 0x04)   
  741.     {   
  742.         size += evt.timeSinceLastFrame;   
  743.         if(size > 15.7f)   
  744.         {   
  745.             CEGUI::WindowManager::getSingleton().getWindow("RTTWindow")->setVisible(false);   
  746.             size = 15.0f;   
  747.             exFlag &= ~0x04;   
  748.         }   
  749.     }   
  750.     else 
  751. #endif   
  752.   
  753.     if(exFlag & 0x01)   
  754.     {  
  755.  
  756. #if defined __OGREOGGSOUNG__   
  757.         if(size < 15.001f)   
  758.         {   
  759.             mSoundManager->getSound("Emitter")->pause();   
  760.             mSoundManager->getSound("Explosion")->play();   
  761.         }  
  762. #endif   
  763.   
  764.         // when it goes into an explosion, we just let its size increase rapidly   
  765.         // but I can guarantee that's not a exponential growth.   
  766.         size *= (1 + 2.5f * evt.timeSinceLastFrame);   
  767.         thrusters->setDefaultDimensions(size,size);   
  768.         if(thrusters->getDefaultHeight() >= 900)   
  769.         {   
  770.             thrusters->setDefaultDimensions(15,15);   
  771.             size = 15.0f;   
  772.             thrusters->getEmitter(0)->setEnabled(false);   
  773.             if(exFlag & 0x02)   
  774.             {   
  775.                 mNode->setVisible(false);   
  776.                 mDistance = 0.0f;   
  777.                 exFlag &= ~0x02;   
  778.             }   
  779.             exFlag &= ~0x01;   
  780.             exFlag |= 0x04;   
  781.         }   
  782.     }   
  783.   
  784.     if (mDirection == Ogre::Vector3::ZERO)    
  785.     {   
  786.         if (nextLocation())    
  787.         {  
  788.  
  789. #if defined __OGREOGGSOUNG__   
  790.             mSoundManager->getSound("StepSound")->play();  
  791. #endif   
  792.             // Set walking animation   
  793.             mAnimationState = mEntity->getAnimationState("Walk");   
  794.             mAnimationState->setLoop(true);   
  795.             mAnimationState->setEnabled(true);   
  796.             // Rotation Code will go here   
  797.             Ogre::Vector3 src = mNode->getOrientation() * Ogre::Vector3::UNIT_X;   
  798.             if ((1.0f + src.dotProduct(mDirection)) < 0.0001f)    
  799.             {   
  800.                 mNode->yaw(Ogre::Degree(180));   
  801.             }   
  802.             else  
  803.             {   
  804.                 Ogre::Quaternion quat = src.getRotationTo(mDirection);   
  805.                 mNode->rotate(quat);   
  806.             } // else   
  807.         }   
  808.     }   
  809.     else  
  810.     {   
  811.         Ogre::Real move = mWalkSpeed * evt.timeSinceLastFrame;   
  812.         mDistance -= move;   
  813.         if (mDistance <= 0.0f)   
  814.         {   
  815.             mNode->setPosition(mDestination);   
  816.             mDirection = Ogre::Vector3::ZERO;   
  817.             // Set animation based on if the robot has another point to walk to.    
  818.             if (! nextLocation())   
  819.             {  
  820.  
  821. #if defined __OGREOGGSOUNG__   
  822.                 mSoundManager->getSound("StepSound")->stop();  
  823. #endif   
  824.                 // Set Idle animation                        
  825.                 mAnimationState = mEntity->getAnimationState("Idle");   
  826.                 mAnimationState->setLoop(true);   
  827.                 mAnimationState->setEnabled(true);   
  828.             }    
  829.             else  
  830.             {   
  831.                 // Rotation Code will go here later   
  832.                 Ogre::Vector3 src = mNode->getOrientation() * Ogre::Vector3::UNIT_X;   
  833.                 if ((1.0f + src.dotProduct(mDirection)) < 0.0001f)    
  834.                 {   
  835.                     mNode->yaw(Ogre::Degree(180));   
  836.                 }   
  837.                 else  
  838.                 {   
  839.                     Ogre::Quaternion quat = src.getRotationTo(mDirection);   
  840.                     mNode->rotate(quat);   
  841.                 } // else   
  842.             }   
  843.         }   
  844.         else if(!(exFlag & 0x02))   
  845.         {   
  846.             mNode->translate(mDirection * move);   
  847.         } // else   
  848.     } // if   
  849.   
  850.     mAnimationState->addTime(evt.timeSinceLastFrame);   
  851.   
  852.     return BaseApplication::frameRenderingQueued(evt);   
  853. }   
  854. void ITutorial01::chooseSceneManager(void)   
  855. {   
  856.     // Use the terrain scene manager.   
  857.     // Not this method always success, sometimes it isn't a good situation   
  858.     mSceneMgr = mRoot->createSceneManager(Ogre::ST_EXTERIOR_CLOSE);  
  859.       
  860. #if defined __OGREOGGSOUNG__   
  861.     mSoundManager = OgreOggSound::OgreOggSoundManager::getSingletonPtr();  
  862. #endif   
  863. }   
  864.   
  865. bool ITutorial01::mouseMoved(const OIS::MouseEvent &arg)   
  866. {   
  867.     if (mRMouseDown)   
  868.     {   
  869.         mCamera->yaw(Ogre::Degree(-arg.state.X.rel * mRotateSpeed));   
  870.         mCamera->pitch(Ogre::Degree(-arg.state.Y.rel * mRotateSpeed));   
  871.     } // else if  
  872. #if defined __CEGUIOGRE__   
  873.     else  
  874.     {   
  875.         // Update CEGUI with the mouse motion   
  876.         if (arg.state.Z.rel)   
  877.         {   
  878.             CEGUI::System::getSingleton().injectMouseWheelChange(arg.state.Z.rel / 120.0f);   
  879.         }   
  880.         CEGUI::System::getSingleton().injectMouseMove(arg.state.X.rel, arg.state.Y.rel);   
  881.     }  
  882. #endif   
  883.   
  884.     return true;   
  885. }   
  886.   
  887. bool ITutorial01::mousePressed(const OIS::MouseEvent &arg, OIS::MouseButtonID id)   
  888. {   
  889.     if (id == OIS::MB_Right)   
  890.     {  
  891. #if defined __CEGUIOGRE__   
  892.         CEGUI::System::getSingleton().setDefaultMouseCursor("TaharezLook""MouseTarget");   
  893.         CEGUI::MouseCursor::getSingleton().setImage("TaharezLook""MouseTarget");   
  894.         CEGUI::MouseCursor::getSingleton().setPosition(CEGUI::Point(arg.state.width*0.5,arg.state.height*0.5));  
  895. #endif   
  896.         mRMouseDown = true;   
  897.     }   
  898.     else  
  899.     {  
  900. #if defined __CEGUIOGRE__   
  901.         CEGUI::System::getSingleton().injectMouseButtonDown(convertButton(id));  
  902. #endif   
  903.         // Left mouse button down   
  904.         if (id == OIS::MB_Left && !(exFlag & 0x05))   
  905.         {   
  906.             if(mRMouseDown)   
  907.             {  
  908. #if defined __CEGUIOGRE__   
  909.                 CEGUI::WindowManager::getSingleton().getWindow("RTTWindow")->setVisible(true);  
  910. #endif  
  911.  
  912. #if defined __OGREOGGSOUNG__   
  913.                 sound = mSoundManager->getSound("Fire");   
  914.                 if(sound->isPlaying())  sound->stop();   
  915.                 sound->play();   
  916.                 mSoundManager->getSound("Emitter")->play();  
  917. #endif   
  918.   
  919.                 Ogre::Vector3 tor = mCamera->getDirection();   
  920.                 //here we get the boomb flying   
  921.                 mSceneMgr->getSceneNode("emitter")->setPosition(mCamera->getPosition());   
  922.                 thrusters->getEmitter(0)->setDirection(tor);   
  923.                 thrusters->getEmitter(0)->setEnabled(true);   
  924.                 tor.y = 0.0f;   
  925.                 // we use a cross product to got a right look of RTTcam   
  926.                 tor = tor.crossProduct(Ogre::Vector3::UNIT_Y).normalisedCopy();   
  927.                 //tor.y = 0.4f;   
  928.                 // we've let the CamraNode move with the emitter   
  929.                 // so we just set relative position of the rttcam   
  930.                 // Note: here the emitter have the same position with mCamera   
  931.                 tor *= 5;   
  932.                 tor -= mCamera->getDirection() * 55;   
  933.                 rttCam->setPosition(tor);   
  934.                 rttCam->lookAt(mCamera->getPosition());   
  935.             }   
  936.             else  
  937.             {  
  938. #if defined __CEGUIOGRE__   
  939.                 // Setup the ray scene query, use CEGUI's mouse position   
  940.                 CEGUI::Point mousePos = CEGUI::MouseCursor::getSingleton().getPosition();   
  941.                 Ogre::Ray mouseRay = mCamera->getCameraToViewportRay(mousePos.d_x/float(arg.state.width), mousePos.d_y/float(arg.state.height));  
  942. #else   
  943.                 Ogre::Ray mouseRay = mCamera->getCameraToViewportRay(0.5,0.5);  
  944. #endif   
  945.                 mRaySceneQuery->setRay(mouseRay);   
  946.                 // Execute query   
  947.                 Ogre::RaySceneQueryResult &result = mRaySceneQuery->execute();   
  948.                 Ogre::RaySceneQueryResult::iterator itr = result.begin( );   
  949.   
  950.                 // Get results, create a node/entity on the position   
  951.                 if (itr != result.end() && itr->worldFragment)   
  952.                 {  
  953.  
  954. #if defined __OGREOGGSOUNG__   
  955.                     sound = mSoundManager->getSound("PointSound");   
  956.                     if(sound->isPlaying()) sound->stop();   
  957.                     sound->play();  
  958. #endif   
  959.   
  960.                     if(mNode->getAttachedObject(0)->isVisible())   
  961.                     {   
  962.                         char name[16] = {0};   
  963.                         static size_t i=0;   
  964.                         sprintf_s(name,sizeof(name)-1,"Sphere%dNode",i++%3);   
  965.                         mSceneMgr->getSceneNode(name)->setPosition(itr->worldFragment->singleIntersection + Ogre::Vector3(0,2,0));   
  966.                         mWalkList.push_back(itr->worldFragment->singleIntersection);   
  967.                     }   
  968.                     else  
  969.                     {   
  970.                         mWalkList.clear();  
  971. #if defined __OGREOGGSOUNG__   
  972.                         mSoundManager->getSound("StepSound")->stop();  
  973. #endif   
  974.                         // Set Idle animation                        
  975.                         mAnimationState = mEntity->getAnimationState("Idle");   
  976.                         mAnimationState->setLoop(true);   
  977.                         mAnimationState->setEnabled(true);   
  978.                         mNode->setPosition(itr->worldFragment->singleIntersection);   
  979.                         mNode->setVisible(true);   
  980.                     }   
  981.                 } // if   
  982.             }   
  983.         } // if   
  984.     }   
  985.     return true;   
  986. }   
  987.   
  988. bool ITutorial01::mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id)   
  989. {   
  990.     if (id == OIS::MB_Right)   
  991.     {  
  992. #if defined __CEGUIOGRE__   
  993.         CEGUI::System::getSingleton().setDefaultMouseCursor("TaharezLook""MouseArrow");   
  994.         CEGUI::MouseCursor::getSingleton().setImage("TaharezLook""MouseArrow");  
  995. #endif   
  996.         mRMouseDown = false;   
  997.     } // else if  
  998. #if defined __CEGUIOGRE__   
  999.     else  
  1000.     {   
  1001.         CEGUI::System::getSingleton().injectMouseButtonUp(convertButton(id));   
  1002.     }  
  1003. #endif   
  1004.     return true;   
  1005. }  
  1006.  
  1007. #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32  
  1008. #define WIN32_LEAN_AND_MEAN  
  1009. #include "windows.h"  
  1010. #endif  
  1011.  
  1012. #ifdef __cplusplus   
  1013. extern "C" {  
  1014. #endif  
  1015.  
  1016. #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32   
  1017.     INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )  
  1018. #else   
  1019.     int main(int argc, char *argv[])  
  1020. #endif   
  1021.     {   
  1022.         // Create application object   
  1023.         ITutorial01 app;   
  1024.   
  1025.         try {   
  1026.             app.go();   
  1027.         } catch( Ogre::Exception& e ) {  
  1028. #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32   
  1029.             MessageBoxA( NULL, e.getFullDescription().c_str(), "An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL);  
  1030. #else   
  1031.             std::cerr << "An exception has occurred: " <<   
  1032.                 e.getFullDescription().c_str() << std::endl;  
  1033. #endif   
  1034.         }   
  1035.   
  1036.         return 0;   
  1037.     }  
  1038.  
  1039. #ifdef __cplusplus   
  1040. }  
  1041. #endif  

资源文件:

resource.h

Code:
  1. //{{NO_DEPENDENCIES}}   
  2. // Microsoft Visual C++ generated include file.   
  3. // Used by OgreWin32Resources.rc   
  4. //  
  5. #define IDD_DLG_VIDEO                   101  
  6. #define IDD_DLG_CONFIG                  101  
  7. #define IDI_ICON1                       103  
  8. #define IDB_SPLASH                      106  
  9. #define IDD_DLG_ERROR                   107  
  10. #define IDI_OGREICON                    111  
  11. #define IDC_CBO_VIDEO                   1001  
  12. #define IDC_VIDEO_MODE                  1002  
  13. #define ID_LBL_RES                      1003  
  14. #define IDC_CBO_RESOLUTION              1004  
  15. #define IDC_CBO_VIDEOMODE               1004  
  16. #define IDC_COLOUR_DEPTH                1005  
  17. #define IDC_CBO_COLOUR_DEPTH            1006  
  18. #define IDC_CHK_FULLSCREEN              1007  
  19. #define IDC_CBO_RENDERSYSTEM            1009  
  20. #define IDC_OPTFRAME                    1010  
  21. #define IDC_CBO_OPTION                  1011  
  22. #define IDC_LST_OPTIONS                 1013  
  23. #define IDC_LBL_OPTION                  1014  
  24. #define IDC_ERRMSG                      1018  
  25. #define IDC_SELECT_VIDEO                -1   
  26.   
  27. // Next default values for new objects   
  28. //   
  29. #ifdef APSTUDIO_INVOKED  
  30. #ifndef APSTUDIO_READONLY_SYMBOLS  
  31. #define _APS_NEXT_RESOURCE_VALUE        115  
  32. #define _APS_NEXT_COMMAND_VALUE         40001  
  33. #define _APS_NEXT_CONTROL_VALUE         1020  
  34. #define _APS_NEXT_SYMED_VALUE           101  
  35. #endif  
  36. #endif  

winresrc.h

Code:
  1. #include <winresrc.h>   
  2.   
  3. #ifdef IDC_STATIC   
  4. #undef IDC_STATIC   
  5. #endif   
  6. #define IDC_STATIC      (-1)  

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值