chap4_1 自动档

/*------------------------------------------------------------
	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;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值