Ogre中OIS的输入的使用
OIS的使用有两种模式:缓冲模式和非缓冲模式。非缓冲方式能处理鼠标或键盘长按的事件,实时性强缓冲方式则不能长按事件,用于非实时响应。
非缓冲输入:
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 中使用OIS的两种模式
关于OIS的输入 要开始考虑游戏输入的问题了,以及开始加入CEGUI也要考虑加入输入的问题.先把OIS的输入简单回忆一下. OIS有两种输入模式:非缓冲输入以及缓冲输入. 无论用哪种输入方式,都应该有 ...
- 教你一招:在PowerPoint中自定义可输入文本的占位符
日常生活中,当我们设计多媒体课件时,默认的版式其实已经够用了.但是,很多时候,我们需要更加个性一点,所以,我们需要自定义很多东西.本文介绍在PowerPoint中自定义可输入文本的占位符. 一.占位符 ...
- firefox浏览器中silverlight无法输入问题
firefox浏览器中silverlight无法输入问题 今天用firefox浏览silverlight网页,想在文本框中输入内容,却没想到silverlight插件意外崩溃了.google一下,发现 ...
- 在Ogre中加载自己的资源包
转自:http://www.cnblogs.com/minggoddess/archive/2011/02/19/1958472.html 由于数据保护的需要,一款游戏一般都会有自己独有的资源包,这样 ...
- Android中EditText设置输入条件
一.应用场景 之前做商城应用时,会有对用户资料的设置情况进行限制,如下: (1)用户邮箱,应当只允许输入英文字母,数字和@.两个符号, (2)用户手机,应当只能输入数字,禁止输入其他字符. (3)用户 ...
- Settings > Editor > Live Templates 中自定义快速输入
Settings > Editor > Live Templates 中自定义快速输入
- OGRE中Any 类型的实现
[OGRE中Any类型的实现] OGRE中实现了一个class Any,使用Any 可以在上下文中传递任意类型的数据.其本质实现原理就是通过指针. Any 只包含一个成员变量,类型为 placehol ...
- unigui 在单据中,某输入为必填项的 JS代码
给大家分享下在单据中,某输入为必填项,用红框标示的简单处理方法:UniSession.AddJS(UniEdit1.JSName+ '.el.setStyle({"border" ...
- Axiom3D:Ogre中Mesh网格分解成点线面。
这个需求可能比较古怪,一般Mesh我们组装好顶点,索引数据后,直接放入索引缓冲渲染就好了.但是如果有些特殊需要,如需要标注出Mesh的顶点,线,面这些信息,以及特殊显示这些信息. 最开始我想的是自己分 ...
随机推荐
- 在Win7 64位操作系统下安装Oracle 10g
参见网址http://www.cnblogs.com/newstar/archive/2010/12/01/1878026.html 1.下载安装程序,可以到这个网址去下载 http://www.or ...
- SQL Server 2005中的CTE递归查询得到一棵树
感觉这个CTE递归查询蛮好用的,先举个例子: use City; go create table Tree ( ID int identity(1,1) primary key not null, N ...
- mstsc连接服务器时如何避免每次在登陆窗口输入密码(rdp passwd decrypted )
http://blog.chinaunix.net/uid-1835840-id-2831518.html 我们经常需要连接很多服务器,或者服务器的ip经常变动.把连接的密码保存在rdp配置文件里,用 ...
- Fiddler-1 安装
1 进入Fiddler官网:http://www.telerik.com/fiddler 点击[Free download]:填写一些信息后就可以下载. 2 双击安装包--下一步dinghanhua下 ...
- Android 数据库管理— — —添加数据
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android=" ...
- SQL Server 简介
什么是数据库? 数据库(Database)是按照数据结构来组织.存储和管理数据的仓库.是以一定方式储存在一起.能为多个用户共享.具有尽可能小的冗余度的特点.是与应用程序彼此独立的数据集合. SQL S ...
- job console部署
1. iis配置 1.1 应用程序池配置成经典模式 1.2 增加mini类型.svc,application/octet-stream 1.3 增加脚本映射,*.svc,%windir%\Micros ...
- Java SCP copy local file to remote implementation
最近做的项目中,有一个小需求,需要通过SCP把本地文件copy到远程服务器.查了好多资料,最终解决方案简单快速,分享一下. 在这里,需要用到4个jar包,分别是ant-jsch.jar,ant-lau ...
- 用javascript简单封装AJAX
1.创建一个AJAX引擎对象 var CreateAjax = function () { var xhr = null; if (window.XMLHttpRequest) { //非IE游览器 ...
- 基于eclipse-java的平台上搭建安卓开发环境
首先感谢好人的分享!http://www.mamicode.com/info-detail-516839.html 系统:windows 7 若想直接安装eclipse—android的,请启动如下传 ...