Revision: 416
http://python-ogre.svn.sourceforge.net/python-ogre/?rev=416&view=rev
Author: andy_miller
Date: 2007-10-11 06:50:16 -0700 (Thu, 11 Oct 2007)
Log Message:
-----------
Updated caelum demo
Modified Paths:
--------------
trunk/python-ogre/demos/caelum/Demo_Caelum01.py
Modified: trunk/python-ogre/demos/caelum/Demo_Caelum01.py
===================================================================
--- trunk/python-ogre/demos/caelum/Demo_Caelum01.py 2007-10-11 13:13:35 UTC (rev 415)
+++ trunk/python-ogre/demos/caelum/Demo_Caelum01.py 2007-10-11 13:50:16 UTC (rev 416)
@@ -8,8 +8,9 @@
import ogre.io.OIS as ois
import ogre.addons.caelum as caelum
import SampleFramework as sf
+import sys
+import ctypes
-
## ------------------------------------------------------------------
## our basic Python Ogre TerrainFrame Listener
## ------------------------------------------------------------------
@@ -21,7 +22,7 @@
self.sceneManager = sceneManager
self.camera = camera
self.moveSpeed = 50.0
-
+ self.updateRay = ogre.Ray()
## basic terrain ray query
pos = camera.getPosition()
d = ogre.Vector3.NEGATIVE_UNIT_Y
@@ -34,18 +35,17 @@
ret = sf.FrameListener.frameStarted(self, frameEvent)
## clamp camera to terrain
- updateRay = ogre.Ray()
- updateRay.setOrigin (self.camera.getPosition())
- updateRay.setDirection (ogre.Vector3.NEGATIVE_UNIT_Y)
- self.raySceneQuery.Ray = updateRay
+ self.updateRay.setOrigin (self.camera.getPosition())
+ self.updateRay.setDirection (ogre.Vector3.NEGATIVE_UNIT_Y)
+ self.raySceneQuery.Ray = self.updateRay
for queryResult in self.raySceneQuery.execute():
if queryResult.worldFragment is not None:
pos = self.camera.getPosition()
self.camera.setPosition (pos.x, pos.y - queryResult.distance + 10.0, pos.z)
break
-## mCamera->setPosition(mCamera->getPosition().x,
-## i->worldFragment->singleIntersection.y + 10,
-## mCamera->getPosition().z);
+## mCamera.setPosition(mCamera.getPosition().x,
+## i.worldFragment.singleIntersection.y + 10,
+## mCamera.getPosition().z)
return ret
@@ -57,58 +57,65 @@
TerrainFrameListener.__init__(self, renderWindow, camera, sceneManager)
self.caelumSystem = caelumSystem
- self.speedFactor = caelumSystem.getUniversalClock().getTimeScale()
+ self.speedFactor = 0
self.paused = False
- self.timeTillNextUpdate = 0.0
+ self.timeTillNextUpdate = 0
self.PostFiltering = False
-
+
+ self.UpdateSpeedFactor(self.caelumSystem.getUniversalClock ().getTimeScale ())
+
## ------------------------------------------------------------------
## our own function to set time scale dependent on paused state
## saves a few if / else
## ------------------------------------------------------------------
- def _setTimeScale(self, paused, t1, t2 ):
- t = t1
- if not paused:
- t = t2
- self.caelumSystem.getUniversalClock().setTimeScale(t)
+# def _setTimeScale(self, paused, t1, t2 ):
+# t = t1
+# if not paused:
+# t = t2
+# self.caelumSystem.getUniversalClock().setTimeScale(t)
+
+ ## Update speed factors.
+ def UpdateSpeedFactor(self, factor):
+ self.speedFactor = factor
+ if self.paused:
+ t = 0
+ else:
+ t= self.speedFactor
+ self.caelumSystem.getUniversalClock ().setTimeScale (t)
+ ogre.ControllerManager.getSingleton().setTimeFactor (t)
-
## ------------------------------------------------------------------
def frameStarted(self, frameEvent):
# clamp to terrain
ret = TerrainFrameListener.frameStarted(self, frameEvent)
- t = self.caelumSystem.getUniversalClock().getCurrentRelativeTime()
- self.caelumSystem.getSun().getSunPositionModel().setJulianDate(t)
-
+ t = self.caelumSystem.getSun().getSunPositionModel()
+ espm = caelum.castAsEarthSunPositionModel ( t )
+
+ if espm :
+ espm.setJulianDate (self.caelumSystem.getUniversalClock ().getCurrentRelativeTime ())
+
self.timeTillNextUpdate-= frameEvent.timeSinceLastFrame
## keyboard input
if (self.timeTillNextUpdate<= 0):
if (self.Keyboard.isKeyDown (ois.KC_SPACE)):
-
self.timeTillNextUpdate = 1
- self._setTimeScale(self.paused, self.speedFactor, 0)
self.paused = not self.paused
+ self.UpdateSpeedFactor(self.speedFactor)
if (self.Keyboard.isKeyDown(ois.KC_X)):
-
self.timeTillNextUpdate = 0.25
- self.speedFactor *= 0.5
- self._setTimeScale(self.paused, 0, self.speedFactor)
+ self.UpdateSpeedFactor(self.speedFactor/2)
if (self.Keyboard.isKeyDown(ois.KC_C)):
-
self.timeTillNextUpdate = 0.25
- self.speedFactor *= 2
- self._setTimeScale(self.paused, 0, self.speedFactor)
+ self.UpdateSpeedFactor(self.speedFactor*2)
if (self.Keyboard.isKeyDown(ois.KC_Z)):
-
self.timeTillNextUpdate = 1
- self.speedFactor *= -1
- self._setTimeScale(self.paused, 0, self.speedFactor)
+ self.UpdateSpeedFactor(self.speedFactor * -1)
if (self.Keyboard.isKeyDown(ois.KC_F1)):
self.timeTillNextUpdate = 1
@@ -116,6 +123,7 @@
self.PostFiltering = False
else:
self.PostFiltering = True
+ ogre.CompositorManager.getSingleton().setCompositorEnabled (self.window.getViewport (0), "Bloom", self.postFiltering)
## EXTRA! Update the haze sun light position
mat = ogre.MaterialManager.getSingleton().getByName("CaelumDemoTerrain")
@@ -149,18 +157,19 @@
## Sun dtor deletes the SunPositionalModel. However in createScene we
## need to hold a reference to SunPositionModel (self.spm) other
## seg faults when it goes out of scope. Doing so means that a seg fault
- ## when C++ tries to delete the sun->EarthSunPositionModel. Temp workaround
+ ## when C++ tries to delete the sun.EarthSunPositionModel. Temp workaround
## comment out the following in Sun.cpp and handle deletion ouselves.
##
## /*
- ## if (mSunPositionModel) {
- ## delete mSunPositionModel;
- ## mSunPositionModel = 0;
- ## }
+ ## if (mSunPositionModel) {
+ ## delete mSunPositionModel
+ ## mSunPositionModel = 0
+ ## }
## */
##
## ====================================================================
- self.spm = None
+ if self.spm:
+ self.spm = 0
if self.caelumSystem:
self.caelumSystem.shutdown(False)
self.caelumSystem = None
@@ -184,58 +193,72 @@
def _createScene(self):
sceneManager = self.sceneManager
camera = self.camera
-
- ogre.CompositorManager.getSingleton().addCompositor(self.renderWindow.getViewport(0),"Bloom")
+ clouds = True
+ skyDome = True
+
+ ## a little hack to let me test this on a machine with a crap graphics card
+ capabilities = ogre.Root.getSingleton().getRenderSystem().capabilities
+ if not capabilities.hasCapability(ogre.RSC_VERTEX_PROGRAM) or\
+ not capabilities.hasCapability(ogre.RSC_FRAGMENT_PROGRAM):
+ skyDome = False
+ clouds = False
+ else:
+ ogre.CompositorManager.getSingleton().addCompositor(self.renderWindow.getViewport(0),"Bloom")
camera.setNearClipDistance(0.01)
## Initialise Caelum
- self.caelumSystem = caelum.CaelumSystem(self.root, self.sceneManager)
- self.spm = caelum.EarthSunPositionModel(ogre.Radian(ogre.Degree(37)), 0.5)
-
- ## Setup lighting parameters.
- self.caelumSystem.getSun().setAmbientMultiplier(ogre.ColourValue(0.5, 0.5, 0.5))
- self.caelumSystem.getSun().setDiffuseMultiplier(ogre.ColourValue(3, 3, 2.7))
+ try:
+ self.caelumSystem = caelum.CaelumSystem(self.root, self.sceneManager
+ ,createSkyDome=skyDome, createClouds=clouds
+ )
+ except RuntimeError, e:
+ print "\nError occured when creating the CaelumSystem - do you have a graphics card that supports vertex programs?\n"
+ sys.exit(-1)
+ except:
+ print "Exception Occured:", sys.exc_info()[0]
+ sys.exit(-1)
+
+ ## Setup sun position model.
+ self.spm = caelum.SimpleSunPositionModel (ogre.Degree (13))
+ ## IMHO EarthSunPositionModel is broken, so it default to sspm.
+ ##caelum.SunPositionModel *spm = new caelum.EarthSunPositionModel (ogre.Radian (ogre.Degree (37)), 0.5)
+
+ ## Setup sun options
+ self.caelumSystem.getSun ().setAmbientMultiplier (ogre.ColourValue(0.5, 0.5, 0.5))
+ self.caelumSystem.getSun ().setDiffuseMultiplier (ogre.ColourValue(3, 3, 2.7))
## For green terrain:
- ## self.caelumSystem.getSun().setDiffuseMultiplier(ogre.ColourValue(0.1, 3, 0.1))
-
- self.caelumSystem.getSun().setSpecularMultiplier(ogre.ColourValue(5, 5, 5))
- self.caelumSystem.getSun().setSunPositionModel(self.spm)
- self.caelumSystem.getSun().setManageAmbientLight(True)
-
-
- ## Create and configure the sky colours model to use
- self.caelumModel = caelum.StoredImageElvBasedSkyColourModel()
- ## Call this before changing the gradients image!!
- self.caelumSystem.setSkyColourModel(self.caelumModel)
-
- self.caelumModel.setSkyGradientsImage("EarthClearSky2.png")
+ ##self.caelumSystem.getSun ().setDiffuseMultiplier (ogre.ColourValue(0.1, 3, 0.1))
+ self.caelumSystem.getSun ().setSpecularMultiplier (ogre.ColourValue(5, 5, 5))
+ self.caelumSystem.getSun ().setSunPositionModel (self.spm)
+ self.caelumSystem.getSun ().setManageAmbientLight (True)
+
+ ## Basic fogging setup.
+ ## This is a hack until proper fogging is implemented.
+ self.caelumSystem.getSkyColourModel().setFogDensityMultiplier(0.0015)
self.caelumSystem.setManageFog(True)
- self.caelumModel.setFogDensity(0.0015)
+
+ ## Setup cloud options
+ if clouds:
+ self.caelumSystem.getClouds ().setCloudSpeed(ogre.Vector2(-0.00001, 0.00001))
+
+ ## Setup starfield options
+ self.caelumSystem.getStarfield ().setInclination (ogre.Degree (13))
+
+ ## Set some time parameters
+ self.caelumSystem.getUniversalClock ().setTimeScale (512)
+ self.caelumSystem.getUniversalClock ().setCurrentTime (18000) ## Jan 1st, 5am
- ## Create a starfield
- self.caelumSystem.getStarfield().setInclination(ogre.Degree (13))
- self.caelumSystem.createStarfield("Starfield.jpg")
## Register all to the render window
self.renderWindow.addListener(self.caelumSystem)
- ## Set some time parameters
- #t = time(&t);
- #struct tm *t2 = localtime (&t);
-
- self.caelumSystem.getUniversalClock().setTimeScale(512)
- ## Jan 1st, 5am
- self.caelumSystem.getUniversalClock().setCurrentTime(18000)
-
+
## Put some terrain in the scene
terrain_cfg = "terrain.cfg"
- #if ogre.OGRE_PLATFORM == ogre.OGRE_PLATFORM_APPLE:
- # terrain_cfg = resourcePath + terrain_cfg
self.sceneManager.setWorldGeometry( terrain_cfg )
- ##self.sceneManager.setAmbientLight(ogre.ColourValue.Black)
+
-
def _createFrameListener(self):
# pass
# return
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|