/*------------------------------------------------------------
FrameListener.h -- define MyFrameListener class
(c) Seamanj.2013/7/21
------------------------------------------------------------*/
#include "OgreFrameListener.h"
using namespace Ogre;
class MyFrameListener : public FrameListener {
public:
// ctor/dtor
MyFrameListener() { m_timeElapsed = 0.0f; }
virtual ~MyFrameListener() {}
// We will provide some meat to this method override
virtual 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>
#endif
using namespace Ogre;
bool MyFrameListener::frameStarted(const FrameEvent &evt) {
m_timeElapsed += evt.timeSinceLastFrame;
if (m_timeElapsed > 15.0f)
return false;
else
return true;
}
#if defined (WIN32)
INT WINAPI WinMain (
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
#else
int 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 config
if (!root->restoreConfig()) {
// if no existing config, or could not restore it, show the config dialog
if (!root->showConfigDialog()) {
// if the user pressed Cancel, clean up and exit
delete root;
return 0;
}
}
// initialize Root -- have it create a render window for us
root->initialise(true);
// get a pointer to the auto-created window
RenderWindow *window = root->getAutoCreatedWindow();
// get a pointer to the default base scene manager -- sufficient for our purposes
SceneManager *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 manager
implementations, as discussed previously. Each of these implementations will register itself
as a particular type of scene manager:
• ST_GENERIC: Minimal scene manager implementation, not optimized for any particular
scene content or structure. Most useful for minimally complex scenes (such as the GUI
phases 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 outdoor
scenes with near-to-medium visibility, such as those based on tiled single-page terrain
mesh or heightfield.
• ST_EXTERIOR_FAR: Anachronism in Ogre, typically no longer used. Use ST_EXTERIOR_CLOSE
or ST_EXTERIOR_REAL_FAR instead.
• ST_EXTERIOR_REAL_FAR: Scene manager implementation typically suited for paged landscape
or paged scene construction. Paged landscapes often are huge, possibly entire
planets.
*/
// 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 listener
root->addFrameListener(&listener);
// tell Ogre to start rendering -- our frame listener will cause the app to exit
// after 15 seconds have elapsed
root->startRendering();
}
catch (Exception &e) {
#if defined(WIN32)
MessageBoxA(NULL,e.getFullDescription().c_str(),NULL,NULL);
#else
stderr << e.getFullDescription() << endl;
#endif
}
// clean up and exit
delete root;
return 0;
}