学习OGRE制作简单人物行走demo(二)
2009-08-14 10:55
429 查看
汗,写了一天,居然一点提交,毛都没留下。郁闷。
重来吧。
为了实现通过键盘控制角色移动,首先要获取键盘消息,因为默认情况下已经对键盘鼠标做了处理,所以首先先清除默认的。
创建TutorialFrameListener
添加TutorialApplication::createFrameListener方法
我们就可以对人物进行左右滑动了。
代码步骤是:
1.覆盖ExampleFrameListener的方法
frameStarted, frameRenderingQueued.
我这里在frameRenderingQueued什么也不做,就已经把默认的处理全清除了。
在frameStarted里控制角色节点移动, 而移动的mDirection是通过键盘处理得到的.
如果按ESC键,frameStarted返回了mContinue,这时为false,所以程序退出了。
我们暂时只关心X,Z轴上的偏移.如果要弄飞的效果,就要考虑Y 轴了。
接下来是摄像头的控制,获得游戏一样的效果,可以转动,可以随着角色移动。
重来吧。
为了实现通过键盘控制角色移动,首先要获取键盘消息,因为默认情况下已经对键盘鼠标做了处理,所以首先先清除默认的。
创建TutorialFrameListener
class TutorialFrameListener : public ExampleFrameListener, public OIS::MouseListener, public OIS::KeyListener { public: TutorialFrameListener(RenderWindow* win, Camera* cam, SceneManager *sceneMgr) : ExampleFrameListener(win, cam, true, true) { // Populate the camera and scene manager containers mCamNode = cam->getParentSceneNode(); mSceneMgr = sceneMgr; mPlayerNode = mSceneMgr->getSceneNode("NinjaNode"); // 设置旋转和移动速度 mRotate = 0.13; mMove = 50; // 继续渲染 mContinue = true; mMouse->setEventCallback(this); mKeyboard->setEventCallback(this); mDirection = Vector3::ZERO; } bool frameStarted(const FrameEvent &evt) { if(mMouse) mMouse->capture(); if(mKeyboard) mKeyboard->capture(); mPlayerNode->translate(mDirection * evt.timeSinceLastFrame, Node::TS_LOCAL); return mContinue; } bool frameRenderingQueued(const FrameEvent& evt) { return true; } // MouseListener bool mouseMoved(const OIS::MouseEvent &e) { return true; } bool mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id) { return true; } bool mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id) { return true; } // KeyListener bool keyPressed(const OIS::KeyEvent &e) { switch (e.key) { case OIS::KC_ESCAPE: mContinue = false; break; 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; } return true; } bool keyReleased(const OIS::KeyEvent &e) { switch (e.key) { 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; } // switch return true; } protected: Real mRotate; // The rotate constant Real mMove; // The movement constant SceneManager *mSceneMgr; // The current SceneManager SceneNode *mCamNode; // The SceneNode the camera is currently attached to SceneNode *mPlayerNode; bool mContinue; // Whether to continue rendering or not Vector3 mDirection; // Value to move in the correct direction };
添加TutorialApplication::createFrameListener方法
void createFrameListener(void) { mFrameListener = new TutorialFrameListener(mWindow, mCamera, mSceneMgr); mRoot->addFrameListener(mFrameListener); }
我们就可以对人物进行左右滑动了。
代码步骤是:
1.覆盖ExampleFrameListener的方法
frameStarted, frameRenderingQueued.
我这里在frameRenderingQueued什么也不做,就已经把默认的处理全清除了。
在frameStarted里控制角色节点移动, 而移动的mDirection是通过键盘处理得到的.
如果按ESC键,frameStarted返回了mContinue,这时为false,所以程序退出了。
我们暂时只关心X,Z轴上的偏移.如果要弄飞的效果,就要考虑Y 轴了。
接下来是摄像头的控制,获得游戏一样的效果,可以转动,可以随着角色移动。
相关文章推荐
- 学习OGRE制作简单人物行走demo(一)
- 学习OGRE制作简单人物行走demo(四)
- 学习OGRE制作简单人物行走demo(三)
- Unity模拟龙之谷人物行走简单控制
- 写在Demo战斗系统之前,先用原型工具做套UI第二篇-人物选择界面制作
- 如何使用AEditor制作一个简单的H5交互页demo
- unity3d制作小地图(MiniMap)的简单Demo
- Angularjs制作简单的路由功能demo
- ZendStudio php WebService制作一:简单WebService Demo
- unity3d制作小地图(MiniMap)的简单Demo
- unity普通的3D地图+人物行走demo
- UIdemo 制作一个简单的iPhone相册
- 写在Demo战斗系统之前,先用原型工具做套UI第六篇-人物装备UI界面制作
- 简单天气获取demo的制作(一)
- 一个仿dota,点击鼠标让人物行走的简易demo
- Qt制作的简单密码框Demo
- 仙剑人物MMD制作详细教程,包含模型提取和3DMAX简单操作
- Unity模拟龙之谷人物行走简单控制
- 利用unity3d自带的CharacterController包制作第一人称控制模型的简单Demo
- 仿照imooc《帝堵抢车位动画制作》做的一个超简单停车demo