Ogre中OIS的输入的使用
2016-12-02 23:49
302 查看
OIS的使用有两种模式:缓冲模式和非缓冲模式。非缓冲方式能处理鼠标或键盘长按的事件,实时性强缓冲方式则不能长按事件,用于非实时响应。
非缓冲输入:
1、创建方式:其中 false 参数代表使用非缓冲模式
2、在监听帧中的用法:
---------------------------------------------------------------------------------------------------------------------------------
缓冲输入:
1创建方式:其中 true参数代表使用非缓冲模式
2、在监听帧中的用法:
首先,监听帧必须拥有回调的方法,就是说监听器应该这样:继承KeyListener,MouseListener
class ExitListener : public FrameListener,public OIS::KeyListener,public OIS::MouseListener
其次,监听帧必须实现以下方法:
bool mouseMoved(const OIS::MouseEvent &arg)
bool mousePressed(const OIS::MouseEvent &arg, OIS::MouseButtonID id)
bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id)
bool keyPressed(const OIS::KeyEvent &arg)
bool keyReleased(const OIS::KeyEvent &arg)
这些方法都是父类的纯虚接口,不得不实现他们。。正常运行时,发生事件后讲执行对应的函数。
要让这些函数起作用,还要做的事情是:
在 ExitListener 的构造函数(随便)中注册该类为回调类
最后,还要在每一帧更新输入
非缓冲输入以及缓冲输入使用效果的最大区别:
非缓冲能处理 键盘或者鼠标 按住的事件
缓冲不能处理 键盘或者鼠标 按住的事件
非缓冲模式创建代码:
参考链接:
http://blog.sina.com.cn/s/blog_68f6e8a90100xz0z.html http://blog.sina.com.cn/s/blog_515326f90100pici.html
非缓冲输入:
1、创建方式:其中 false 参数代表使用非缓冲模式
OIS::Keyboard* mKeyboard; OIS::Mouse* mMouse ; mKeyboard = static_cast<OIS::Keyboard*> (mInputManager->createInputObject(OIS::OISKeyboard, false)); mMouse = static_cast<OIS::Mouse*> (mInputManager->createInputObject(OIS::OISMouse, false));
2、在监听帧中的用法:
bool frameStarted(const FrameEvent& evt) { mKeyboard->capture(); mMouse->capture(); if(mKeyboard->isKeyDown(OIS::XXXX)) { } }
---------------------------------------------------------------------------------------------------------------------------------
缓冲输入:
1创建方式:其中 true参数代表使用非缓冲模式
mKeyboard = static_cast<OIS::Keyboard*> (mInputManager->createInputObject(OIS::OISKeyboard, true)); mMouse = static_cast<OIS::Mouse*> (mInputManager->createInputObject(OIS::OISMouse, true));
2、在监听帧中的用法:
首先,监听帧必须拥有回调的方法,就是说监听器应该这样:继承KeyListener,MouseListener
class ExitListener : public FrameListener,public OIS::KeyListener,public OIS::MouseListener
其次,监听帧必须实现以下方法:
bool mouseMoved(const OIS::MouseEvent &arg)
bool mousePressed(const OIS::MouseEvent &arg, OIS::MouseButtonID id)
bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id)
bool keyPressed(const OIS::KeyEvent &arg)
bool keyReleased(const OIS::KeyEvent &arg)
这些方法都是父类的纯虚接口,不得不实现他们。。正常运行时,发生事件后讲执行对应的函数。
要让这些函数起作用,还要做的事情是:
在 ExitListener 的构造函数(随便)中注册该类为回调类
mMouse->setEventCallback(this); mKeyboard->setEventCallback(this);
最后,还要在每一帧更新输入
bool frameStarted(const FrameEvent& evt) { mKeyboard->capture(); mMouse->capture(); }
非缓冲输入以及缓冲输入使用效果的最大区别:
非缓冲能处理 键盘或者鼠标 按住的事件
缓冲不能处理 键盘或者鼠标 按住的事件
非缓冲模式创建代码:
OIS::ParamList pl; std::ostringstream windowHndStr; windowHndStr << (size_t)hwnd; pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str())); //设置鼠标和键盘非游戏独占(鼠标可以显示在屏幕上并可以移动到窗口外) pl.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_FOREGROUND" ))); pl.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_NONEXCLUSIVE"))); m_InputManager = OIS::InputManager::createInputSystem(pl); //设置为缓冲模式,需要设置帧监听器继承方式public ExampleFrameListener, //public OIS::MouseListener, public OIS::KeyListener m_Keyboard = (OIS::Keyboard*)m_InputManager->createInputObject(OIS::OISKeyboard,true); m_Mouse = (OIS::Mouse*)m_InputManager->createInputObject(OIS::OISMouse,true); //注册侦听器 m_Keyboard->setEventCallback(this); m_Mouse->setEventCallback(this);
bool EditorFrameListener::mouseMoved(const OIS::MouseEvent &arg) { return true; } bool EditorFrameListener::mousePressed(const OIS::MouseEvent &arg, OIS::MouseButtonID id) { //std::ostringstream ss; //ss << "mousePressed_" << id; //LogManager::getSingletonPtr()->logMessage(ss.str().c_str()); return true; } bool EditorFrameListener::mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id) { //std::ostringstream ss; //ss << "mouseReleased_" << id; //LogManager::getSingletonPtr()->logMessage(ss.str().c_str()); return true; } bool EditorFrameListener::keyPressed(const OIS::KeyEvent &arg) { //std::ostringstream ss; //ss << "keyPressed" << arg.key; //LogManager::getSingletonPtr()->logMessage(ss.str().c_str()); return true; } bool EditorFrameListener::keyReleased(const OIS::KeyEvent &arg) { //std::ostringstream ss; //ss << "keyReleased" << arg.key; //LogManager::getSingletonPtr()->logMessage(ss.str().c_str()); return true; }
参考链接:
http://blog.sina.com.cn/s/blog_68f6e8a90100xz0z.html http://blog.sina.com.cn/s/blog_515326f90100pici.html
相关文章推荐
- 在Ogre中使用OIS的两种模式(非缓冲输入和缓冲输入)
- OGRE+CEGUI+OIS 鼠标非独占使用
- OGRE+OIS 帧监听FrameListener、非缓冲输入和缓冲输入
- OGRE+CEGUI+OIS 完美解决鼠标非独占使用
- OIS输入系统-1_OIS简介与使用
- Ogre 学习笔记 (一) 处理用户的输入事件 OIS
- OGRE+CEGUI+OIS 完美解决鼠标非独占使用
- OGRE+CEGUI+OIS 完美解决鼠标非独占使用
- OGRE使用OIS鼠标不准确问题
- OIS输入系统-1_OIS简介与使用----OIS几个重要的类的使用
- 关于Ogre自带输入系统OIS(Object-Oriented Input System)的源码分析
- Ogre 中使用OIS的两种模式
- OGRE+OIS 帧监听FrameListener、非缓冲输入和缓冲输入
- OIS输入系统-1_OIS简介与使用
- OGRE+CEGUI+OIS 完美解决鼠标非独占使用
- WINXP要使用本机,用户必须输入用户名和密码
- ASP.NET2.0中"无法显示 XML 页。 使用 XSL 样式表无法查看 XML 输入。"问题的解决
- 关于在asp.net中使用showDialogModal方式输入数据中存在的问题
- gnome中使用Emacs中文输入
- 验证输入是否为空的js - 使用正则表达式对象