frenchtoaster
28-11-2008 02:52:55
When I try to do
inputManager.createInputObject(ois.OISMouse, True)
I get the error
">> Failed to set coop level".
I found a solution to it from the pyOgre days where you could do this:
oisParams = {
"WINDOW": str(hwnd),
"w32_mouse" : ["DISCL_NONEXCLUSIVE", "DISCL_FOREGROUND"]
}
And pass that in to the InputManager.createInputSystem. Unfortunately for me, the OIS version in python-ogre won't accept a dict as its argument. According to
http://www.ogre3d.org/wiki/index.php/Using_OIS its looking for an OIS::ParamList which isn't available as far as I can tell by looking at dir(ois). According to other references on the internet this is just a typedefed std::map<string, string> , so If I could have access to that it may work as intended.
Any help regarding how to fix this exception would be greatly appreciated.
dermont
28-11-2008 03:25:50
params = [("WINDOW",str(windowHnd)), ("w32_mouse","DISCL_FOREGROUND"), ("w32_mouse", "DISCL_NONEXCLUSIVE")]
self.InputManager = OIS.createPythonInputSystem( params )
If your using the SampleFrameWork FrameListener you can supply the mouse parameters in the _inputSystemParameters method, take a look at the Demo_Hikari_01 demo.
As per Dermont's advice you can use ogre/renderer/OGRE/sf_OIS.py as a reference... See the _setupInput function where we use a helper function to make things easy.
Another approach would be to do something like:pl = ogre.SettingsMultiMap()
windowHndStr = str(windowHnd)
pl.insert("WINDOW", windowHndStr)
im = OIS.InputManager.createInputSystem( pl )
Note that we have to use the SettingsMultiMap from the ogre module as we intentionally don't expose it in the OIS module as we only want a single instance of the multimap so boost doesn't complain at module load time..
Andy
frenchtoaster
03-12-2008 06:40:55
My copy of python-ogre doesn't have any method ois.InputManager.createPythonInputSystem()
Another approach would be to do something like:pl = ogre.SettingsMultiMap()
windowHndStr = str(windowHnd)
pl.insert("WINDOW", windowHndStr)
im = OIS.InputManager.createInputSystem( pl )
I still get the error "Failed to set coop level" when I that plus
pl.insert("w32_mouse","DISCL_NONEXCLUSIVE")
pl.insert("w32_mouse","ISCL_FOREGROUND")
Edit: For clarification I am embedding the ogre window in a wxFrame. Must I use the wx mouse listeners rather than ogre?
Sorry -- OIS.createPythonInputSystem() -- look at sf_OIS.py for the details...
And you have a typo in the 2nd line -- should read DISCL_xxx not ISCL_xxx as in your example...
Andy
frenchtoaster
03-12-2008 07:07:03
Sorry -- OIS.createPythonInputSystem() -- look at sf_OIS.py for the details...
And you have a typo in the 2nd line -- should read DISCL_xxx not ISCL_xxx as in your example...
Andy
Sorry, you are correct on the createPythonInputSystem, but when I use it I still get the error "RuntimeError: Win32Mouse::Win32Mouse >> Failed to set coop level"
params = [("WINDOW",str(externalHandle)),
("w32_mouse", "DISCL_NONEXCLUSIVE"),
("w32_mouse", "DISCL_FOREGROUND")]
self.inputManager = ois.createPythonInputSystem( params )
self.m_Mouse = (self.inputManager.createInputObject(ois.OISMouse,True))
Can you post a complete test program that shows the problem as I can't make it fail on my system...
Andy
frenchtoaster
03-12-2008 08:01:39
Can you post a complete test program that shows the problem as I can't make it fail on my system...
Andy
Heres about the smallest case possible for this example:
import wx
import ogre.renderer.OGRE as ogre
import ogre.io.OIS as ois
class MyFrame1(wx.Frame):
def __init__(self, *args, **kwds):
kwds["style"] = wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
self.pnl = wx.Panel(self, -1)
szr = wx.BoxSizer(wx.HORIZONTAL)
szr.Add(self.pnl, 1, wx.EXPAND, 0)
self.SetSizer(szr)
self.Layout()
self.SetSize((640,480))
def GetOgrePanelHandle(self):
return str(self.pnl.GetHandle())
def GetOgrePanelSize(self):
return self.pnl.GetSize()
class OgreWrapper:
def __init__( self, externalHandle, (w,h) ):
self.root = ogre.Root("plugins.cfg")
if self.root == None:
print "Could not initialize root from plugins.cfg"
exit(1)
if( not self.root.restoreConfig() ):
self.root.showConfigDialog()
self.root.initialise(False)
self.sceneManager = self.root.createSceneManager(ogre.ST_GENERIC)
renderParameters = ogre.NameValuePairList()
renderParameters['externalWindowHandle'] = str(externalHandle)
self.renderWindow = self.root.createRenderWindow('Example',w,h,False,renderParameters )
self.renderWindow.active = True
self.camera = self.sceneManager.createCamera("camera")
self.camera.position = (0,0,500)
self.camera.lookAt((0,0,-100))
self.camera.nearClipDistance = 10
self.viewport = self.renderWindow.addViewport(self.camera)
self.viewport.backgroundColor = (0,0,0)
params = [("WINDOW",str(externalHandle)),
("w32_mouse", "DISCL_FOREGROUND"),
("w32_mouse", "DISCL_NONEXCLUSIVE")
]
self.inputManager = ois.createPythonInputSystem( params )
self.m_Mouse = (self.inputManager.createInputObject(ois.OISMouse,True))
def Update(self):
self.root.renderOneFrame()
if __name__ == "__main__":
app = wx.PySimpleApp(0)
frame = MyFrame1(None,-1,"")
app.SetTopWindow(frame)
o = OgreWrapper( frame.GetOgrePanelHandle(), frame.GetOgrePanelSize() )
frame.Show()
o.Update()
app.MainLoop()
dermont
03-12-2008 09:22:24
You need to pass a top level window handle to createPythonInputSystem.
http://www.wreckedgames.com/forum/index ... 342.0.html
..
def GetMainWindowHandle(self):
return str(self.GetHandle())
class OgreWrapper:
def __init__( self, externalHandle, mainHandle, (w,h) ):
..
params = [("WINDOW",str(mainHandle)),
("w32_mouse", "DISCL_FOREGROUND"),
("w32_mouse", "DISCL_NONEXCLUSIVE")
]
self.inputManager = ois.createPythonInputSystem( params )
self.m_Mouse = (self.inputManager.createInputObject(ois.OISMouse,True))
o = OgreWrapper( frame.GetOgrePanelHandle(), frame.GetMainWindowHandle(), frame.GetOgrePanelSize() )