00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
00061 destroyScene();
00062 }
00063
00064 protected:
00065 Root *mRoot;
00066 Camera* mCamera;
00067 SceneManager* mSceneMgr;
00068 ExampleFrameListener* mFrameListener;
00069 RenderWindow* mWindow;
00070
00071
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
00087 TextureManager::getSingleton().setDefaultNumMipmaps(5);
00088
00089
00090 createResourceListener();
00091
00092 loadResources();
00093
00094
00095 createScene();
00096
00097 createFrameListener();
00098
00099 return true;
00100
00101 }
00103 virtual bool configure(void)
00104 {
00105
00106
00107
00108 if(mRoot->showConfigDialog())
00109 {
00110
00111
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
00124 mSceneMgr = mRoot->getSceneManager(ST_GENERIC);
00125 }
00126 virtual void createCamera(void)
00127 {
00128
00129 mCamera = mSceneMgr->createCamera("PlayerCam");
00130
00131
00132 mCamera->setPosition(Vector3(0,0,500));
00133
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
00142 mRoot->addFrameListener(mFrameListener);
00143 }
00144
00145 virtual void createScene(void) = 0;
00146
00147 virtual void destroyScene(void){}
00148
00149 virtual void createViewports(void)
00150 {
00151
00152 Viewport* vp = mWindow->addViewport(mCamera);
00153 vp->setBackgroundColour(ColourValue(0,0,0));
00154
00155
00156 mCamera->setAspectRatio(
00157 Real(vp->getActualWidth()) / Real(vp->getActualHeight()));
00158 }
00159
00161 virtual void setupResources(void)
00162 {
00163
00164 ConfigFile cf;
00165 cf.load("resources.cfg");
00166
00167
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
00197 ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
00198
00199 }
00200
00201
00202
00203 };
00204
00205
00206 #endif