OGRE+CEGUI+OIS 完美解决鼠标非独占使用

最近在用Ogre+CEGUI+OIS做游戏。在开发的过程出现了种种问题,现将问题一一整理,并将解决方案释出,供同好参阅。

OIS默认鼠标占用模式是鼠标独占使用,表现为鼠标指针无法移除当前窗口。那么如果想把鼠标指针移除窗体怎么解决呢?让OIS使用鼠标协作模式啊!代码如下:

 

//创建设备

OIS::ParamList pl;

size_t windowHnd = 0;

std::ostringstream windowHndStr;

 

m_Window->getCustomAttribute(Ogre::String(”WINDOW”), &windowHnd);

windowHndStr << windowHnd;

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 );

 

 

这下好了,鼠标可以移除当前窗体了,突然发现没对,怎么有两个鼠标指针?好嘛,我就在当前窗口隐藏掉系统的指针!代码如下:

 

ShowCursor(0); //隐藏系统鼠标指针

 

这回应该没问题了吧~~~啦啦啦,还是没对哦!鼠标定位不准确~~~~~~~~,行!那就在mouse::MouseMoved 事件中把 Moved(e.state.X.rel, e.state.Y.rel) 替换成Postion(e.state.X.abs, e.state.Y.abs)

 

在编译运行,矣~~~~~~咋个指针在一个很小范围内移动呢?哦,原来OIS默认宽和高是50px啊,来设置成RenderWindow的宽高即可!代码如下:

 

_mouse->getMouseState().width=_render_window->getWidth();

_mouse->getMouseState().height=_render_window->getHeight();

 

嘿嘿,这下完美了!ohmy god~~~~~~~~为什么这样对我?鼠标都移除窗体了,为什么窗体内的那个指针还要动,那我就在MouseMoved中做边界检查,对了为了防止误点,还要在mousePressed mouseReleased 做边界检查,代码就不啰嗦了!~~~=

 

 

       至此OGRE+OIS+CEGUI鼠标非独占使用,完美解决!

posted @ 2009-04-17 00:54  虾虾  阅读(6039)  评论(6编辑  收藏  举报