chap4_1 自动档

来源:互联网 发布:比赛计时器软件 编辑:程序博客网 时间:2024/04/28 19:20
/*------------------------------------------------------------FrameListener.h -- define MyFrameListener class(c) Seamanj.2013/7/21------------------------------------------------------------*/#include "OgreFrameListener.h"using namespace Ogre;class MyFrameListener : public FrameListener {public:// ctor/dtorMyFrameListener() { m_timeElapsed = 0.0f; }virtual ~MyFrameListener() {}// We will provide some meat to this method overridevirtual bool frameStarted(const FrameEvent &evt);// We do not need to provide a body for either of these methods, since // Ogre provides a default implementation that does just this. However, for// the sake of illustration, we'll provide one here.virtual bool frameEnded(const FrameEvent &evt) { return true; }private:float m_timeElapsed;};

/*------------------------------------------------------------main.cpp -- achieve automation(c) Seamanj.2013/7/21------------------------------------------------------------*/#include "Ogre.h"#include "OgreErrorDialog.h"#include "FrameListener.h"#if defined(WIN32)#include <windows.h>#endifusing namespace Ogre;bool MyFrameListener::frameStarted(const FrameEvent &evt) {m_timeElapsed += evt.timeSinceLastFrame;if (m_timeElapsed > 15.0f) return false;elsereturn true;}#if defined (WIN32)INT WINAPI WinMain (    HINSTANCE hInstance,    HINSTANCE hPrevInstance,    LPSTR lpCmdLine,    int nCmdShow)#elseint main (int argc, char *argv[])#endif{MyFrameListener listener;// We wrap the entire process in a top-level try/catch, because Ogre will// throw exceptions in dire circumstances. In these cases, the catch block will// display the exception text, which is also logged to Ogre.log in the same directory// as the executable.Root *root = 0;try {root = new Root("plugins_d.cfg");/*默认构造函数Root(const String& pluginFileName = "plugins.cfg", const String& configFileName = "ogre.cfg", const String& logFileName = "Ogre.log");*/// try first to restore an existing configif (!root->restoreConfig()) {// if no existing config, or could not restore it, show the config dialogif (!root->showConfigDialog()) {// if the user pressed Cancel, clean up and exitdelete root;return 0;}}// initialize Root -- have it create a render window for usroot->initialise(true);// get a pointer to the auto-created windowRenderWindow *window = root->getAutoCreatedWindow();// get a pointer to the default base scene manager -- sufficient for our purposesSceneManager *sceneMgr = root->createSceneManager(ST_GENERIC);//知识点1 /*知识点1:场景管理器---------------------------------------------来自<<pro OGRE 3D Programming>> P66---------------------------------------------When Ogre loads its plug-ins, among those plug-ins can be various scene managerimplementations, as discussed previously. Each of these implementations will register itselfas a particular type of scene manager:• ST_GENERIC: Minimal scene manager implementation, not optimized for any particularscene content or structure. Most useful for minimally complex scenes (such as the GUIphases of an application).• ST_INTERIOR: Scene manager implementation optimized for rendering interior,close-quarter, potentially high-density scenes.• ST_EXTERIOR_CLOSE: Scene manager implementation optimized for rendering outdoorscenes with near-to-medium visibility, such as those based on tiled single-page terrainmesh or heightfield.• ST_EXTERIOR_FAR: Anachronism in Ogre, typically no longer used. Use ST_EXTERIOR_CLOSEor ST_EXTERIOR_REAL_FAR instead.• ST_EXTERIOR_REAL_FAR: Scene manager implementation typically suited for paged landscapeor paged scene construction. Paged landscapes often are huge, possibly entireplanets.*/// create a single camera, and a viewport that takes up the whole window (default behavior)Camera *camera = sceneMgr->createCamera("MainCam");Viewport *vp = window->addViewport(camera);vp->setDimensions(0.0f, 0.0f, 1.0f, 1.0f);camera->setAspectRatio((float)vp->getActualWidth() / (float) vp->getActualHeight());camera->setFarClipDistance(1000.0f);camera->setNearClipDistance(5.0f);// register our frame listenerroot->addFrameListener(&listener);// tell Ogre to start rendering -- our frame listener will cause the app to exit// after 15 seconds have elapsedroot->startRendering();}catch (Exception &e) {#if defined(WIN32)MessageBoxA(NULL,e.getFullDescription().c_str(),NULL,NULL);#elsestderr << e.getFullDescription() << endl;#endif}// clean up and exitdelete root;return 0;}