kingb
05-01-2006 09:00:39
Hi All,
I'm relatively new to PyOGRE and have gone through the first 5 beginner PyOGRE tutorials. As part of learning more about PyOGRE, I have started converting the beginner OGRE tutorial 6 to PyOGRE tutorial 6. Since I'm an outsider to the PyOGRE community and don't know if I have permission to create the http://www.ogre3d.org/wiki/index.php/Py ... Tutorial_6 page, I thought I would post the code and xml and ask for permission/advice?
If adding the PyOGRE Beginner Tutorial 6 would be of use, I'll go ahead and finish it (I'll clean up the Python code and add more comments and docstrings before doing so). I'm also interested in converting the intermediate ogre tutorials to PyOGRE tutorials... should I do this? Anyone else working on these? Anything else I can do to help out with PyOGRE?
PyOGRE Beginner Tutorial 6 (beginner_6.py)
beginner_6_layout.xml
I'm relatively new to PyOGRE and have gone through the first 5 beginner PyOGRE tutorials. As part of learning more about PyOGRE, I have started converting the beginner OGRE tutorial 6 to PyOGRE tutorial 6. Since I'm an outsider to the PyOGRE community and don't know if I have permission to create the http://www.ogre3d.org/wiki/index.php/Py ... Tutorial_6 page, I thought I would post the code and xml and ask for permission/advice?
If adding the PyOGRE Beginner Tutorial 6 would be of use, I'll go ahead and finish it (I'll clean up the Python code and add more comments and docstrings before doing so). I'm also interested in converting the intermediate ogre tutorials to PyOGRE tutorials... should I do this? Anyone else working on these? Anything else I can do to help out with PyOGRE?
PyOGRE Beginner Tutorial 6 (beginner_6.py)
# this code is in the public domain
# http://www.ogre3d.org/wiki/index.php/PyOgre_Beginner_Tutorial_6
from pyogre import ogre
from pyogre import cegui
import SampleFramework
def convertOgreButtonToCegui(buttonId):
"""
Converts ogre button into cegui button
"""
if buttonId == ogre.MouseEvent.BUTTON0_MASK:
return cegui.LeftButton
elif buttonId == ogre.MouseEvent.BUTTON1_MASK:
return cegui.RightButton
elif buttonId == ogre.MouseEvent.BUTTON2_MASK:
return cegui.MiddleButton
elif buttonId == ogre.MouseEvent.Button3_MASK:
return cegui.X1Button
else:
return cegui.LeftButton
class GuiFrameListener(SampleFramework.FrameListener):
def __init__(self, renderWindow, camera, sceneManager):
SampleFramework.FrameListener.__init__(self, renderWindow, camera)
self.sceneManager = sceneManager
self.shutdownRequested = False
def _setupInput(self):
self.eventProcessor = ogre.EventProcessor()
self.eventProcessor.initialise(self.renderWindow)
self.eventProcessor.startProcessingEvents()
# register as a listener for events
self.eventProcessor.addKeyListener(self)
self.eventProcessor.addMouseListener(self)
self.eventProcessor.addMouseMotionListener(self)
def requestShutdown(self):
self.shutdownRequested = True
def frameStarted(self, evt):
if self.shutdownRequested:
return False
else:
return True
def frameEnded(self, evt):
if self.shutdownRequested:
return False
else:
return SampleFramework.FrameListener.frameEnded(self, evt)
def mouseMoved(self, evt):
cegui.System.getSingleton().injectMouseMove(evt.relX * self.sceneManager.width,
evt.relY * self.sceneManager.height)
evt.consume()
def mouseDragged(self, evt):
self.mouseMoved(evt)
def mousePressed(self, evt):
cegui.System.getSingleton().injectMouseButtonDown(convertOgreButtonToCegui(evt.buttonID))
evt.consume()
def mouseReleased(self, evt):
cegui.System.getSingleton().injectMouseButtonUp(convertOgreButtonToCegui(evt.buttonID))
evt.consume()
def mouseClicked(self, evt):
pass
def mouseEntered(self, evt):
pass
def mouseExited(self, evt):
pass
def keyPressed(self, evt):
if evt.getKey() == ogre.KC_ESCAPE:
self.shutdownRequested = True
e.consume()
return
cegui.System.getSingleton().injectKeyDown(evt.getKey())
cegui.System.getSingleton().injectChar(evt.getKeyChar())
def keyReleased(self, evt):
cegui.System.getSingleton().injectKeyUp(evt.getKey())
evt.consume()
def keyClicked(self, evt):
evt.consume()
class TutorialApplication(SampleFramework.Application):
def __del__(self):
"Clear variables, this is needed to ensure the correct order of deletion"
del self.camera
del self.sceneManager
del self.frameListener
del self.system
del self.guiRenderer
del self.root
del self.renderWindow
def _createScene(self):
#Setup ambient light
sceneManager = self.sceneManager
sceneManager.ambientLight = 0.5, 0.5, 0.5
#Setup GUI system
##self.guiRenderer = cegui.OgreCEGUIRenderer(self.renderWindow, ogre.RENDER_QUEUE_OVERLAY, False, 3000)
self.guiRenderer = cegui.OgreCEGUIRenderer(self.renderWindow)
#NOTE!! if you are using the "ST_EXTERIOR_CLOSE" sceneManager you will need to replace this line with the following:
#self.guiRenderer = cegui.OgreCEGUIRenderer(self.renderWindow, ogre.RENDER_QUEUE_OVERLAY, False, 3000, self.sceneManager);
#with self.sceneManager being your scene manager
self.system = cegui.System(self.guiRenderer)
cegui.Logger.getSingleton().loggingLevel = cegui.Informative
# Load Cegui Scheme
cegui.SchemeManager.getSingleton().loadScheme("TaharezLook.scheme")
self.system.defaultMouseCursor = "TaharezLook", "MouseArrow"
cegui.FontManager.getSingleton().createFont("tahoma-12.font")
#Lets add a quit button
#Hold on to your buttons, so they won't die... i.e. cegui doesn't hold on to them,
#so if you don't want python to delete them, you might want to hold on to it.
#Manual Layout Method
#self.editorGuiSheet = cegui.WindowManager.getSingleton().createWindow("DefaultWindow", "Sheet")
#self.system.guiSheet = self.editorGuiSheet
##self.quitButton = cegui.WindowManager.getSingleton().createWindow("TaharezLook/Button", "Quit")
##self.editorGuiSheet.addChildWindow(self.quitButton)
##self.quitButton.position = cegui.Vector2(0.35, 0.45)
##self.quitButton.size = cegui.Size(0.3, 0.1)
##self.quitButton.text = "Quit"
#XML Layout Method
self.editorGuiSheet = cegui.WindowManager.getSingleton().loadWindowLayout("beginner_6_layout.xml")
self.system.guiSheet = self.editorGuiSheet
self.quitButton = cegui.WindowManager.getSingleton().getWindow("Quit")
self.setupEventHandlers()
def _createFrameListener(self):
self.frameListener = GuiFrameListener(self.renderWindow, self.camera, self.guiRenderer)
self.root.addFrameListener(self.frameListener)
def setupEventHandlers(self):
self.quitButton.subscribeEvent(self.quitButton.EventClicked, self.handleQuit)
def handleQuit(self, evt):
self.frameListener.requestShutdown()
return True
if __name__ == '__main__':
ta = TutorialApplication()
ta.go()
beginner_6_layout.xml
<?xml version="1.0" ?>
<GUILayout>
<Window Type="DefaultWindow" Name="Tutorial Gui">
<Window Type="TaharezLook/Button" Name="Quit">
<Property Name="AbsoluteRect" Value="l:224.000000 t:216.000000 r:416.000000 b:264.000000" />
<Property Name="RelativeRect" Value="l:0.350000 t:0.450000 r:0.650000 b:0.550000" />
<Property Name="Text" Value="Quit" />
</Window>
</Window>
</GUILayout>