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:
As I said, no errors are returned, the mouselook and movement just won't work. Any help or suggestions would be very appreciated.
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.