11.scene manager

本文介绍了如何使用Ogre游戏引擎手动选择场景管理器并加载地图,以及如何创建模型,包括平面、实体、光照和手动对象,并利用StaticGeometry提高渲染效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

进入新的一章,建立新一个空项目,依然基于ExampleApplication,createscene()为空。

1.手选scene manager和加载地图

	virtual void chooseSceneManager(void)
	{
		ResourceGroupManager::getSingleton().addResourceLocation("../../media/packs/chiropteraDM.pk3",
			"Zip", ResourceGroupManager::getSingleton().getWorldResourceGroupName(), true);
		ResourceGroupManager::getSingleton().initialiseResourceGroup(ResourceGroupManager::getSingleton().getWorldResourceGroupName());
		mSceneMgr = mRoot ->createSceneManager("BspSceneManager");
		mSceneMgr ->setWorldGeometry("maps/chiropteradm.bsp");
	}

2.手动创建模型

	void createScene()
	{
		Ogre::Plane plane(Vector3::UNIT_Y, -10);
		Ogre::MeshManager::getSingleton().createPlane("plane", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
			plane, 1500, 1500, 200, 200, true, 1, 5, 5, Vector3::UNIT_Z);
		Ogre::Entity* ent = mSceneMgr ->createEntity("GrassPlane", "plane");
		mSceneMgr ->getRootSceneNode() ->createChildSceneNode() ->attachObject(ent);
		ent ->setMaterialName("Examples/GrassFloor");

		Ogre::Light* light = mSceneMgr ->createLight("Light1");
		light ->setType(Ogre::Light::LT_DIRECTIONAL);
		light ->setDirection(Ogre::Vector3(1, -1, 0));

		Ogre::ManualObject* manual = mSceneMgr ->createManualObject("grass");
		manual ->begin("Examples/GrassBlades", RenderOperation::OT_TRIANGLE_LIST);

		manual ->position(5.0, 0.0, 0.0);
		manual ->textureCoord(1, 1);
		manual ->position(-5.0, 10.0, 0.0);
		manual ->textureCoord(0, 0);
		manual ->position(-5.0, 0.0, 0.0);
		manual ->textureCoord(0, 1);
		manual ->position(5.0, 10.0, 0.0);
		manual ->textureCoord(1, 0);

		manual ->position(2.5, 0.0, 4.3);
		manual ->textureCoord(1, 1);
		manual ->position(-2.5, 10.0, -4.3);
		manual ->textureCoord(0, 0);
		manual ->position(-2.0, 0.0, -4.3);
		manual ->textureCoord(0, 1);
		manual ->position(2.5, 10.0, 4.3);
		manual ->textureCoord(1, 0);

		manual ->position(2.5, 0.0, -4.3);
		manual ->textureCoord(1, 1);
		manual ->position(-2.5, 10.0, 4.3);
		manual ->textureCoord(0, 0);
		manual ->position(-2.0, 0.0, 4.3);
		manual ->textureCoord(0, 1);
		manual ->position(2.5, 10.0, -4.3);
		manual ->textureCoord(1, 0);

		manual ->index(0);
		manual ->index(1);
		manual ->index(2);

		manual ->index(0);
		manual ->index(3);
		manual ->index(1);

		manual ->index(4);
		manual ->index(5);
		manual ->index(6);

		manual ->index(4);
		manual ->index(7);
		manual ->index(5);

		manual ->index(8);
		manual ->index(9);
		manual ->index(10);

		manual ->index(8);
		manual ->index(11);
		manual ->index(9);

		manual ->end();
		manual ->convertToMesh("BladesOfGrass");

		Ogre::StaticGeometry* field = mSceneMgr ->createStaticGeometry("FieldOfGrass");

		for(int i = 0; i < 50; i++)
		{
			for(int j = 0; j < 50; j++)
			{
				Ogre::Entity* ent = mSceneMgr ->createEntity("BladesOfGrass");
				field ->addEntity(ent, Ogre::Vector3(i * 5, -10, j * 5));
			}
		}
		field ->build();
	}
};
这次主要用到了staticGeometry,一般来说,这样可以大大加快渲染速度。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值