Problems with Mouselook and OIS *Resolved*

Gandalf20000

21-07-2009 18:31:51

I'm new to Python-Ogre (only been using it for a week or so), but I've enjoyed it quite a bit, because of it's speed and simplicity. However, I'm having some issues with my code. It compiles fine, and Ogre runs fine, but my code won't work correctly. I'm using Intermediate Tutorial 2. Problem is this: The mouselook won't work, and even though it never interferes with the Sample Framework's movement code, the W,A,S, and D keys don't provide movement. For the mouselook, it's not that it's not receiving the mouse input, because the cursor disappears as it should.

Here is the code I'm using:
import ogre.renderer.OGRE as ogre
import ogre.gui.CEGUI as CEGUI
import ogre.io.OIS as OIS
import SampleFramework as sf

class MouseQueryListener(sf.FrameListener,OIS.MouseListener):
"""A FrameListener class for basic mouse input"""

def __init__(self,win,cam,sc,renderer):
#Subclass any Python-Ogre class, and you must call it's constructor.
sf.FrameListener.__init__(self,win,cam,True,True)
OIS.MouseListener.__init__(self)

self.sceneManager=sc
self.renderer=renderer
self.camera=cam

#Register this so we can get mouse events
self.Mouse.setEventCallback(self)

#Initialize variables
self.raySceneQuery = None
self.leftMouseDown = False
self.rightMouseDown = False
self.robotCount = 0
self.currentObject = None
self.moveSpeed = 50
self.rotateSpeed = 1/500.0

#Create RaySceneQuery
self.raySceneQuery = self.sceneManager.createRayQuery(ogre.Ray())


def frameStarted(self,evt):
return sf.FrameListener.frameStarted(self,evt)

def mouseMoved(self,evt):
#Update CEGUI with the mouse motion
CEGUI.System.getSingleton().injectMouseMove(evt.get_state().X.rel,evt.get_state().Y.rel)
return True

def mousePressed(self,evt,id):
#Check which button has been pressed
if id == OIS.MB_Left:
self.leftMouseDown = True
elif id == OIS.MB_Right:
CEGUI.MouseCursor.getSingleton().hide()
self.rightMouseButton = True
return True

def mouseReleased(self,evt,id):
if id == OIS.MB_Left:
self.leftMouseDown = False
elif id == OIS.MB_Right:
CEGUI.MouseCursor.getSingleton().show()
self.rightMouseButton = False

#If we are dragging the left mouse button.
if self.leftMouseDown:
pass
#If we are dragging the right mouse button.
elif self.rightMouseDown:
self.camera.yaw(ogre.Degree(-evt.get_state().X.rel * self.rotateSpeed))
self.camera.pitch(ogre.Degree(-evt.get_state().Y.rel * self.rotateSpeed))
return True

def _processUnbufferedMouseInput(self,frameEvent):
pass

class TutorialApplication(sf.Application):
"""Application Class"""

def _chooseSceneManager(self):
self.sceneManager = self.root.createSceneManager(ogre.ST_EXTERIOR_CLOSE, "TerrainSM")

def _createScene(self):


#Set up a simple scene with some terrain
self.sceneManager.setAmbientLight((0.5,0.5,0.5))
self.sceneManager.setSkyDome(True,"Examples/CloudySky",5,8)

self.sceneManager.setWorldGeometry("terrain.cfg")

self.camera.setPosition(40,100,580)
self.camera.pitch(ogre.Degree(-30))
self.camera.yaw(ogre.Degree(-45))

#Set up the CEGUI renderer
self.ceguiRenderer = CEGUI.OgreCEGUIRenderer(self.renderWindow,ogre.RENDER_QUEUE_OVERLAY,False,3000,self.sceneManager)
self.ceguiSystem = CEGUI.System(self.ceguiRenderer)

#Show the cursor
CEGUI.SchemeManager.getSingleton().loadScheme("TaharezLookSkin.scheme")
CEGUI.MouseCursor.getSingleton().setImage("TaharezLook","MouseArrow")

def _createFrameListener(self):
self.frameListener = MouseQueryListener(self.renderWindow,
self.camera,
self.sceneManager,
self.ceguiRenderer)
self.root.addFrameListener(self.frameListener)
self.frameListener.showDebugOverlay(True)

if __name__ == '__main__':
ta = TutorialApplication()
ta.go()


As I said, no errors are returned, the mouselook and movement just won't work. Any help or suggestions would be very appreciated.

charpe6

22-07-2009 00:29:47

It's because you're using buffered input and the sf.FrameListener you are inheriting from only has methods for dealing with unbuffered input. Change the sf.FrameListener.__init__(self,win,cam,True,True) to sf.FrameListener.__init__(self,win,cam,False,False) and it will work how you expect.

I guess whoever wrote the sample framework didn't have time to make buffered input work seamlessly. You're going to have to move the camera yourself.

charpe6

22-07-2009 00:43:43

Sorry I just looked at the Intermediate tutorial 2 and it has nothing to do you using buffered input. It's that your mouseMoved method is missing code. Compare your code to the code at the bottom of the tutorial and make sure you're not missing anything else.

Gandalf20000

25-07-2009 22:39:12

Thanks! Yeah, I put some code in the wrong place, and I mislabeled something (must be a real function, because Ogre didn't crash) as well, but I managed to get it working. Thanks a lot! :D

charpe6

26-07-2009 01:06:13

No problem. Glad you got it working. 8)