ogre 种草

ogre 种草
ogre中来创建一个草地。
class TutorialApplication : public BaseApplication
{
public:
    TutorialApplication(void);
    virtual ~TutorialApplication(void);
	CEGUI::MouseButton convertButton(OIS::MouseButtonID buttonID);	
protected:
    virtual void createScene(void);

	void setupCEGui();

	CEGUI::OgreRenderer* mRenderer;
	bool quit(const CEGUI::EventArgs &e);
	virtual bool mouseMoved(const OIS::MouseEvent &arg);
	virtual bool mousePressed(const OIS::MouseEvent &arg, OIS::MouseButtonID id);
	virtual bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id);	
	virtual void destroyScene();	
	void createGrassMesh();
private:
	
};

//---------------------------------------------------------------------------
TutorialApplication::TutorialApplication(void):mRenderer(0)
{
}
//---------------------------------------------------------------------------
TutorialApplication::~TutorialApplication(void)
{
	CEGUI::OgreRenderer::destroySystem();
	
}

//---------------------------------------------------------------------------
void TutorialApplication::createScene(void)
{
    // Create your scene here :)
	setupCEGui();
	createGrassMesh();
	mSceneMgr->setAmbientLight(Ogre::ColourValue(1.0, 1.0, 1.0));
	mCamera->setPosition(150,50,150);
	mCamera->lookAt(0,0,0);

	Ogre::Entity* robot = mSceneMgr->createEntity("robot","robot.mesh");
	mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(robot);

	Ogre::Plane plane;
	plane.normal = Ogre::Vector3::UNIT_Y;
	plane.d = 0;

	Ogre::MeshManager::getSingleton().createPlane(
		"floor",
		Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
		plane,
		450.0, 450.0,
		10, 10, true, 1,
		50.0, 50.0,
		Ogre::Vector3::UNIT_Z);

	Ogre::Entity* planeEntity = mSceneMgr->createEntity("floor"); 
	planeEntity->setMaterialName("Examples/GrassFloor");
	planeEntity->setCastShadows(false);
	mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(planeEntity);

	Ogre::Entity* grass = mSceneMgr->createEntity("GrassBladesMesh");
	Ogre::StaticGeometry* sg = mSceneMgr->createStaticGeometry("GrassArea");
	const int size = 375;
	const int amount = 20;

	sg->setRegionDimensions(Ogre::Vector3(size, size, size));
	sg->setOrigin(Ogre::Vector3(-size/2, 0, -size/2));

	for (int x = -size/2; x < size/2; x += (size / amount))
	{
		for (int z = -size/2; z < size/2; z += (size / amount))
		{
			Ogre::Real r = size / (float)amount / 2;
			Ogre::Vector3 pos(
				x + Ogre::Math::RangeRandom(-r, r),
				0,
				z + Ogre::Math::RangeRandom(-r, r));

			Ogre::Vector3 scale(1, Ogre::Math::RangeRandom(0.9, 1.1), 1);

			Ogre::Quaternion orientation;
			orientation.FromAngleAxis(
				Ogre::Degree(Ogre::Math::RangeRandom(0, 359)),
				Ogre::Vector3::UNIT_Y);

			sg->addEntity(grass, pos, orientation, scale);
		}
	}

	sg->build();
}

bool TutorialApplication::quit(const CEGUI::EventArgs &e)
{
	mShutDown = true;
	return true;
}

//---------------------------------------------------------------------------
bool TutorialApplication::mouseMoved(const OIS::MouseEvent &arg)
{
	//关联鼠标
	if(CEGUI::System::getSingleton().getDefaultGUIContext().injectMouseMove(arg.state.X.rel, arg.state.Y.rel))
	{
		return true;
	}
	
	return BaseApplication::mouseMoved(arg);
}
//---------------------------------------------------------------------------
bool TutorialApplication::mousePressed(const OIS::MouseEvent &arg, OIS::MouseButtonID id)
{
	CEGUI::GUIContext& context = CEGUI::System::getSingleton().getDefaultGUIContext();
	if(context.injectMouseButtonDown(convertButton(id)))
	{
		if (id == OIS::MB_Left)
		{			

		}
		else if (id == OIS::MB_Right)
		{
			
		}
		return true;
	}
	

	//关联鼠标	
	return BaseApplication::mousePressed(arg,id);
}
//---------------------------------------------------------------------------
bool TutorialApplication::mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id)
{
	if (id == OIS::MB_Left)
	{		
	}
	
	//关联鼠标
	if(CEGUI::System::getSingleton().getDefaultGUIContext().injectMouseButtonUp(convertButton(id))) return true;
	return BaseApplication::mouseReleased(arg,id);
}

CEGUI::MouseButton TutorialApplication::convertButton(OIS::MouseButtonID buttonID)
{
	//关联鼠标按键
	switch (buttonID)
	{
	case OIS::MB_Left:
		return CEGUI::LeftButton;
		break;

	case OIS::MB_Right:
		return CEGUI::RightButton;
		break;

	case OIS::MB_Middle:
		return CEGUI::MiddleButton;
		break;

	default:
		return CEGUI::LeftButton;
		break;
	}
}

void TutorialApplication::setupCEGui()
{
	Ogre::LogManager::getSingletonPtr()->logMessage("*** Initializing CEGUI ***");

	mRenderer = &CEGUI::OgreRenderer::bootstrapSystem();

	//设置资源路径
	CEGUI::ImageManager::setImagesetDefaultResourceGroup("Imagesets");
	CEGUI::Font::setDefaultResourceGroup("Fonts");
	CEGUI::Scheme::setDefaultResourceGroup("Schemes");
	CEGUI::WidgetLookManager::setDefaultResourceGroup("LookNFeel");
	CEGUI::WindowManager::setDefaultResourceGroup("Layouts");


	//设置鼠标图片
	CEGUI::SchemeManager::getSingleton().createFromFile("TaharezLook.scheme");
	CEGUI::FontManager::getSingleton().createFromFile("DejaVuSans-10.font");
	CEGUI::System::getSingleton().getDefaultGUIContext().getMouseCursor().setDefaultImage("TaharezLook/MouseArrow");

	CEGUI::GUIContext& context = CEGUI::System::getSingleton().getDefaultGUIContext();

	context.setDefaultFont("DejaVuSans-10");
	context.getMouseCursor().setDefaultImage("TaharezLook/MouseArrow");

	Ogre::LogManager::getSingletonPtr()->logMessage("Finished");


	//创建窗口
	CEGUI::WindowManager& wmgr = CEGUI::WindowManager::getSingleton();
	CEGUI::Window* rootWin = wmgr.createWindow("DefaultWindow", "CEGUIDemo/Sheet");
	CEGUI::System::getSingleton().getDefaultGUIContext().setRootWindow(rootWin);
}

void TutorialApplication::destroyScene()
{

}

void TutorialApplication::createGrassMesh()
{
	const float width = 25;
	const float height = 30;
	Ogre::Vector3 vec(width/2,0,0);
	Ogre::ManualObject obj("GrassObject");

	Ogre::Quaternion quat;
	quat.FromAngleAxis(Ogre::Degree(60),Ogre::Vector3::UNIT_Y);

	obj.begin("Examples/GrassBlades",Ogre::RenderOperation::OT_TRIANGLE_LIST);

	for (int i = 0;i < 3;++i)
	{
		obj.position(-vec.x, height, -vec.z);
		obj.textureCoord(0, 0);
		obj.position(vec.x, height, vec.z);
		obj.textureCoord(1, 0);
		obj.position(-vec.x, 0, -vec.z);
		obj.textureCoord(0, 1);
		obj.position(vec.x, 0, vec.z);
		obj.textureCoord(1, 1);

		int offset = 4 * i;
		obj.triangle(offset, offset + 3, offset + 1);
		obj.triangle(offset, offset + 2, offset + 3);

		vec = quat * vec;
	}

	obj.end();
	obj.convertToMesh("GrassBladesMesh");
}
createGrassMesh 我们建立了一个草的mesh,sg->addEntity我们把它铺到了地面上。

摘 要 随着互联网影视产业的迅速发展,电影资源呈指数级增长,类型也愈加多样化,但是用户面对如此庞大的影片库时,会遇到信息过载、筛选效率低下、观影决策成本高这些难题,而传统的电影平台大多只是对基本的分类和热度进行展示,并没有提供个性化的推荐服务,社交互动以及一体化管理的能力也比较薄弱。 该系统使用的是Spring Boot+Vue前后端分离的方式进行开发,设计并开发了一个电影推荐和评论系统。开发系统中存在三个问题,即无法准确地判断出用户的喜好、电影推荐功能上线之初没有用户数据,因此推荐效果不佳、大量用户同时评论打分时系统容易出现不稳定的情况。为了克服上述问题,本文查阅相关资料,不断迭代开发原型,并进行实际测试,完成整个系统的全部过程,即系统需求分析、架构设计、功能开发、系统测试。系统分为普通用户和管理员两种身份,具有注册登录、电影浏览、电影推荐、评分评论、影片收藏、个人中心、后台管理等功能,采用结合用户喜好和电影热度的简单推荐方式,提供热门电影推荐和个性化推荐,很好地解决了推荐功能初始没有数据、数据较少的问题。项目用接口来完成前后端的数据交互,使用MySQL数据库存储用户、电影、评论、收藏等各种数据,并且加入权限验证、密码加密等安全措施,保证系统安全稳定并且便于后期扩展。除此之外,系统还增加了电影资讯查看、首页轮播图设置、编辑资讯等功能,使整个电影平台的服务更加全面,使用更加高效。经过全面的功能测试、接口测试和性能测试,系统各个模块运行稳定,推荐接口响应时间小于300ms,主要的互动操作成功率大于98%,可以大大降低用户的选片成本,提高观影决策的速度和社区互动的效果。 本文给出一套轻量级、易部署、可复用的电影推荐类Web应用工程实现方案,相比于传统的单一列表展示型平台,个性化服务、社交互动体验和后台管理效率都有明显的提高,可以给影视文化数字化传播、推荐算法轻量化工程实践
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值