D:/Papagan/490.2006/490.2006/korsan/Papagan/490.2006/korsan/Papagan/ExampleApplication.h

Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of OGRE
00004 (Object-oriented Graphics Rendering Engine)
00005 For the latest info, see http://www.ogre3d.org/
00006 
00007 Copyright (c) 2000-2005 The OGRE Team
00008 Also see acknowledgements in Readme.html
00009 
00010 You may use this sample code for anything you like, it is not covered by the
00011 LGPL like the rest of the engine.
00012 -----------------------------------------------------------------------------
00013 */
00014 /*
00015 -----------------------------------------------------------------------------
00016 Filename:    ExampleApplication.h
00017 Description: Base class for all the OGRE examples
00018 -----------------------------------------------------------------------------
00019 */
00020 
00021 #ifndef __ExampleApplication_H__
00022 #define __ExampleApplication_H__
00023 
00024 #include "Ogre.h"
00025 #include "OgreConfigFile.h"
00026 #include "ExampleFrameListener.h"
00027 
00028 
00029 using namespace Ogre;
00030 
00034 class ExampleApplication
00035 {
00036 public:
00038     ExampleApplication()
00039     {
00040         mFrameListener = 0;
00041         mRoot = 0;
00042     }
00044     virtual ~ExampleApplication()
00045     {
00046         if (mFrameListener)
00047             delete mFrameListener;
00048         if (mRoot)
00049             delete mRoot;
00050     }
00051 
00053     virtual void go(void)
00054     {
00055         if (!setup())
00056             return;
00057 
00058         mRoot->startRendering();
00059 
00060         // clean up
00061         destroyScene();
00062     }
00063 
00064 protected:
00065     Root *mRoot;
00066     Camera* mCamera;
00067     SceneManager* mSceneMgr;
00068     ExampleFrameListener* mFrameListener;
00069     RenderWindow* mWindow;
00070 
00071     // These internal methods package up the stages in the startup process
00073     virtual bool setup(void)
00074     {
00075         mRoot = new Root();
00076 
00077         setupResources();
00078 
00079         bool carryOn = configure();
00080         if (!carryOn) return false;
00081 
00082         chooseSceneManager();
00083         createCamera();
00084         createViewports();
00085 
00086         // Set default mipmap level (NB some APIs ignore this)
00087         TextureManager::getSingleton().setDefaultNumMipmaps(5);
00088 
00089                 // Create any resource listeners (for loading screens)
00090                 createResourceListener();
00091                 // Load resources
00092                 loadResources();
00093 
00094                 // Create the scene
00095         createScene();
00096 
00097         createFrameListener();
00098 
00099         return true;
00100 
00101     }
00103     virtual bool configure(void)
00104     {
00105         // Show the configuration dialog and initialise the system
00106         // You can skip this and use root.restoreConfig() to load configuration
00107         // settings if you were sure there are valid ones saved in ogre.cfg
00108         if(mRoot->showConfigDialog())
00109         {
00110             // If returned true, user clicked OK so initialise
00111             // Here we choose to let the system create a default rendering window by passing 'true'
00112             mWindow = mRoot->initialise(true);
00113             return true;
00114         }
00115         else
00116         {
00117             return false;
00118         }
00119     }
00120 
00121     virtual void chooseSceneManager(void)
00122     {
00123         // Get the SceneManager, in this case a generic one
00124         mSceneMgr = mRoot->getSceneManager(ST_GENERIC);
00125     }
00126     virtual void createCamera(void)
00127     {
00128         // Create the camera
00129         mCamera = mSceneMgr->createCamera("PlayerCam");
00130 
00131         // Position it at 500 in Z direction
00132         mCamera->setPosition(Vector3(0,0,500));
00133         // Look back along -Z
00134         mCamera->lookAt(Vector3(0,0,-300));
00135         mCamera->setNearClipDistance(5);
00136 
00137     }
00138     virtual void createFrameListener(void)
00139     {
00140         mFrameListener= new ExampleFrameListener(mWindow, mCamera);
00141         //mFrameListener->showDebugOverlay(true);
00142         mRoot->addFrameListener(mFrameListener);
00143     }
00144 
00145     virtual void createScene(void) = 0;    // pure virtual - this has to be overridden
00146 
00147     virtual void destroyScene(void){}    // Optional to override this
00148 
00149     virtual void createViewports(void)
00150     {
00151         // Create one viewport, entire window
00152         Viewport* vp = mWindow->addViewport(mCamera);
00153         vp->setBackgroundColour(ColourValue(0,0,0));
00154 
00155         // Alter the camera aspect ratio to match the viewport
00156         mCamera->setAspectRatio(
00157             Real(vp->getActualWidth()) / Real(vp->getActualHeight()));
00158     }
00159 
00161     virtual void setupResources(void)
00162     {
00163         // Load resource paths from config file
00164         ConfigFile cf;
00165         cf.load("resources.cfg");
00166 
00167         // Go through all sections & settings in the file
00168         ConfigFile::SectionIterator seci = cf.getSectionIterator();
00169 
00170         String secName, typeName, archName;
00171         while (seci.hasMoreElements())
00172         {
00173             secName = seci.peekNextKey();
00174             ConfigFile::SettingsMultiMap *settings = seci.getNext();
00175             ConfigFile::SettingsMultiMap::iterator i;
00176             for (i = settings->begin(); i != settings->end(); ++i)
00177             {
00178                 typeName = i->first;
00179                 archName = i->second;
00180                 ResourceGroupManager::getSingleton().addResourceLocation(
00181                     archName, typeName, secName);
00182             }
00183         }
00184     }
00185 
00187         virtual void createResourceListener(void)
00188         {
00189 
00190         }
00191 
00194         virtual void loadResources(void)
00195         {
00196                 // Initialise, parse scripts etc
00197                 ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
00198 
00199         }
00200 
00201 
00202 
00203 };
00204 
00205 
00206 #endif

Generated on Mon May 29 01:10:33 2006 for Papagan by  doxygen 1.4.6-NO