OGRE中的buffered Input
相对于上一篇中的unBuffered Input在每一帧监听鼠标和键盘事件,buffered Input则是直接控制鼠标和键盘。
主要的代码:
void TutorialApplication::createScene(void)
{
mSceneMgr->setAmbientLight(Ogre::ColourValue(0.25, 0.25, 0.25));
Ogre::Entity* ninjaEntity = mSceneMgr->createEntity("Ninja", "ninja.mesh");
Ogre::SceneNode *node = mSceneMgr->getRootSceneNode()->createChildSceneNode("NinjaNode");
node->attachObject(ninjaEntity);
Ogre::Light* pointLight = mSceneMgr->createLight("pointLight");
pointLight->setType(Ogre::Light::LT_POINT);
pointLight->setPosition(Ogre::Vector3(250, 150, 250));
pointLight->setDiffuseColour(Ogre::ColourValue::White);
pointLight->setSpecularColour(Ogre::ColourValue::White);
// Create the scene node
node = mSceneMgr->getRootSceneNode()->createChildSceneNode("CamNode1", Ogre::Vector3(-400, 200, 400));
// Make it look towards the ninja
node->yaw(Ogre::Degree(-45));
// Create the pitch node
node = node->createChildSceneNode("PitchNode1");
node->attachObject(mCamera);
// create the second camera node/pitch node
node = mSceneMgr->getRootSceneNode()->createChildSceneNode("CamNode2", Ogre::Vector3(0, 200, 400));
node = node->createChildSceneNode("PitchNode2");
}
//-------------------------------------------------------------------------------------
void TutorialApplication::createFrameListener(void)
{
BaseApplication::createFrameListener();
// Populate the camera container
mCamNode = mCamera->getParentSceneNode();
// set the rotation and move speed
mRotate = 0.13;
mMove = 250;
mDirection = Ogre::Vector3::ZERO;
}
// OIS::KeyListener
bool TutorialApplication::keyPressed( const OIS::KeyEvent& evt )
{
switch (evt.key)
{
//esc键退出
case OIS::KC_ESCAPE:
mShutDown = true;
break;
//1,2键切换视角
case OIS::KC_1:
mCamera->getParentSceneNode()->detachObject(mCamera);
mCamNode = mSceneMgr->getSceneNode("CamNode1");
mCamNode->attachObject(mCamera);
break;
case OIS::KC_2:
mCamera->getParentSceneNode()->detachObject(mCamera);
mCamNode = mSceneMgr->getSceneNode("CamNode2");
mCamNode->attachObject(mCamera);
break;
//wsad和上下左右
case OIS::KC_UP:
case OIS::KC_W:
mDirection.z = -mMove;
break;
case OIS::KC_DOWN:
case OIS::KC_S:
mDirection.z = mMove;
break;
case OIS::KC_LEFT:
case OIS::KC_A:
mDirection.x = -mMove;
break;
case OIS::KC_RIGHT:
case OIS::KC_D:
mDirection.x = mMove;
break;
case OIS::KC_PGDOWN:
case OIS::KC_E:
mDirection.y = -mMove;
break;
case OIS::KC_PGUP:
case OIS::KC_Q:
mDirection.y = mMove;
break;
default:
break;
}
return true;
}
bool TutorialApplication::keyReleased( const OIS::KeyEvent& evt )
{
switch (evt.key)
{
case OIS::KC_UP:
case OIS::KC_W:
mDirection.z = 0;
break;
case OIS::KC_DOWN:
case OIS::KC_S:
mDirection.z = 0;
break;
case OIS::KC_LEFT:
case OIS::KC_A:
mDirection.x = 0;
break;
case OIS::KC_RIGHT:
case OIS::KC_D:
mDirection.x = 0;
break;
case OIS::KC_PGDOWN:
case OIS::KC_E:
mDirection.y = 0;
break;
case OIS::KC_PGUP:
case OIS::KC_Q:
mDirection.y = 0;
break;
default:
break;
}
return true;
}
// OIS::MouseListener
bool TutorialApplication::mouseMoved( const OIS::MouseEvent& evt )
{
if (evt.state.buttonDown(OIS::MB_Right))
{
mCamNode->yaw(Ogre::Degree(-mRotate * evt.state.X.rel), Ogre::Node::TS_WORLD);
mCamNode->pitch(Ogre::Degree(-mRotate * evt.state.Y.rel), Ogre::Node::TS_LOCAL);
}
return true;
}
bool TutorialApplication::mousePressed( const OIS::MouseEvent& evt, OIS::MouseButtonID id )
{
Ogre::Light *light = mSceneMgr->getLight("pointLight");
switch (id)
{
case OIS::MB_Left:
light->setVisible(! light->isVisible());
break;
default:
break;
}
return true;
}
bool TutorialApplication::mouseReleased( const OIS::MouseEvent& evt, OIS::MouseButtonID id ){return true;}
//-------------------------------------------------------------------------------------
bool TutorialApplication::frameRenderingQueued(const Ogre::FrameEvent& evt)
{
mCamNode->translate(mDirection * evt.timeSinceLastFrame, Ogre::Node::TS_LOCAL);
if (mWindow->isClosed()) return false;
if (mShutDown) return false;
mKeyboard->capture();
mMouse->capture();
mTrayMgr->frameRenderingQueued(evt);
return true;
}
最终效果:
2012-7-17
分享到:
相关推荐
最新版本的OGRE-SDK,强大的3D开源引擎
OGRE-草地的制作 OGRE-草地的制作 OGRE-草地的制作 OGRE-草地的制作
ogre-1.12.11.zip
This is an earth demo using ogre-es. Study mobile program.
Ogre开发包,版本:ogre-sdk-1.11.1-vc15-x64,三维图形引擎源代码。
ogre的sdk,我从官网下载的,版本1.12.10,vc15,64位
Pro-Ogre-3D-Programming
1. 类似于Ogre-wiki上的set up your first application with CMake(没成功过下载和编译过) 2. Ogre是binary的形式, 不用下载ogre源代码和依赖库 3. 可以在此基础上,学习ogre及编写新的程序 4. 基于《Ogre 3d 1.7...
This is a 3D car demo using ogre-es. To study mobile programing.
ogre-1.12.1.tar.gz 源代码,Ogre渲染引擎三维开发开源代码
最新版本的OGRE-SDK,强大的3D开源引擎
这个是我自己总结的OGRE-API,很多都不是很好,但是希望对你会有帮助。
OGRE3D(面向对象的图形渲染引擎) Ogre是3D图形渲染引擎。不要与提供网络,声音,物理等功能的游戏引擎混淆。 Ogre 2.3进行了大刀阔斧的改革,以使用面向数据的设计将高性能图形聚焦于以下方面: 缓存友好的实体...
在 Linux/OS X 上安装比如你要创建ogre-myapp1 ,大致步骤如下: git clone https://github.com/rafis/ogre-sample.gitcp -ar ogre-sample ogre-myapp1cd ogre-myapp1sed -i 's/ogre-sample/ogre-myapp1/g' CMa
Ogre-1.12.1源代码。OGRE引擎,是开源3D游戏制作引擎。OGRE能被用于开发游戏,但是OGRE被设计成只提供一个世界级的图形解决方案;对于其他的特性,如:音效、网络、人工智能、碰撞检测、物理等子系统,你则需要将其...
最新版本的OGRE-SDK,强大的3D开源引擎
ogre-1.11.6源代码集合 OGRE是一个开源图形渲染引擎,它是面向对象的,并且高效,抽象化了不同的API和平台,这样可以以场景为对象来使用物体,支持多种场景 请注意LGPL的使用规则 自用
最新版本的OGRE-SDK,强大的3D开源引擎,总共四部分
ogre的sdk,我从官网下载的,版本1.11.6,vc15,64位
ogre的sdk,我从官网下载的,版本v2.2.4,vc19,64位