Author: JonNeal
Date: 2008-08-09 17:20:02 -0400 (Sat, 09 Aug 2008)
New Revision: 1345

Modified:
   trunk/pysoy/include/soy.scenes.pxd
   trunk/pysoy/src/scenes/Planar.pym
   trunk/pysoy/src/scenes/Scene.pym
Log:
Ticket #900:
  * Added in basic fog support through a property.
  * Changed a few checks in Planar.pym to asserts


Modified: trunk/pysoy/include/soy.scenes.pxd
===================================================================
--- trunk/pysoy/include/soy.scenes.pxd  2008-07-19 06:34:56 UTC (rev 1344)
+++ trunk/pysoy/include/soy.scenes.pxd  2008-08-09 21:20:02 UTC (rev 1345)
@@ -67,6 +67,7 @@
   cdef soy._internals.PointerSet  _giveFields
   cdef soy._internals.PointerSet  _callFields
   cdef soy.colors.Color           _ambient
+  cdef float                      _fogDensity
   cdef void*                      _stepMutex
   cdef void                       _stepLock       ( self )                nogil
   cdef int                        _stepTryLock    ( self )                nogil
@@ -97,6 +98,8 @@
   cdef soy.materials.Material     _material
   cdef Vert*                      _vertArray
   cdef gl.GLuint                  _vertBuffer
+  cdef Vert*                      _backArray
+  cdef gl.GLuint                  _backBuffer
   cdef Quad*                      _faceArray
   cdef gl.GLuint                  _faceBuffer
   cdef void                       _createBuffer   ( self )

Modified: trunk/pysoy/src/scenes/Planar.pym
===================================================================
--- trunk/pysoy/src/scenes/Planar.pym   2008-07-19 06:34:56 UTC (rev 1344)
+++ trunk/pysoy/src/scenes/Planar.pym   2008-08-09 21:20:02 UTC (rev 1345)
@@ -128,8 +128,8 @@
     def __get__(self) :
       return self._material
     def __set__(self, value) :
-      if not isinstance(value, soy.materials.Material) :
-        raise TypeError('Must provide an instance of soy.materials.Material')
+      assert isinstance(value, soy.materials.Material), \
+        "Must provide an instance of soy.materials.Material"
       self._material = value
 
 
@@ -150,8 +150,8 @@
     
     def __set__(self, value) :
       cdef ode.dVector3 _normal
-      if type(value) != list or type(value) != tuple :
-        raise TypeError("A tuple or list must be provided.")
+      assert type(value) == list and type(value) == tuple, \
+          "A tuple or list must be provided."
       _normal[0] = -(value[0])
       _normal[1] = -(value[1])
       _normal[2] = -(value[2])

Modified: trunk/pysoy/src/scenes/Scene.pym
===================================================================
--- trunk/pysoy/src/scenes/Scene.pym    2008-07-19 06:34:56 UTC (rev 1344)
+++ trunk/pysoy/src/scenes/Scene.pym    2008-08-09 21:20:02 UTC (rev 1345)
@@ -44,6 +44,7 @@
     self._joints       = soy._internals.Children()
     self._lights       = soy._internals.Children()
     self._ambient      = gray
+    self._fogDensity   = 0.0
     self._stepSize     = 0.01
     self._friction     = 0
     self._prevTime     = _time()
@@ -77,7 +78,27 @@
       report.append('%d lights' % self._lights._current)
 
     return '<Scene with %s>' % ', '.join(report)
+  
+  ############################################################################
+  #
+  # Properties
+  #
+  
+  property fog :
+    '''Scene fog
 
+    This is a scene-wide layer of fog of which the density is set by you
+
+    Takes a float for fog density from 0-2, fog is disabled when at 0.
+    '''
+    def __get__(self) :
+      return self._fogDensity
+    
+    def __set__(self, value) :
+      assert type(value) == float and value <= 2 and value >= 0, \
+          "Fog density must be a float in the range of 0-2."
+      self._fogDensity = value
+
   ############################################################################
   #
   # C functions
@@ -126,8 +147,7 @@
   cdef void _render(self, gl.GLdouble _fovy,  gl.GLdouble _aspect,
                           gl.GLdouble _znear, gl.GLdouble _zfar) :
     cdef int _i
-    cdef gl.GLfloat _density, _fogColor[4]
-    _density = .3
+    cdef gl.GLfloat _fogColor[4]
     _fogColor[0] = .5
     _fogColor[1] = .5
     _fogColor[2] = .5
@@ -144,22 +164,29 @@
     gl.glEnable(gl.GL_DEPTH_TEST)
     gl.glEnable(gl.GL_LIGHTING)
     gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, self._ambient._rgba)
+    
+    if self._fogDensity > 0 :
+      #
+      # Turn on some fog!
+      gl.glClearColor(0.5,0.5,0.5,1.0)  # We'll Clear To The Color Of The Fog 
( Modified )
+      gl.glEnable(gl.GL_FOG)                    #Enables GL_FOG
+      gl.glFogi(gl.GL_FOG_MODE, gl.GL_EXP2)     #Fog Mode
+      gl.glFogfv(gl.GL_FOG_COLOR, _fogColor)    #Set Fog Color
+      gl.glFogf(gl.GL_FOG_DENSITY, self._fogDensity/10)        #How Dense Will 
The Fog Be
+      gl.glHint(gl.GL_FOG_HINT, gl.GL_NICEST)   #Fog Hint Value
+      gl.glFogf(gl.GL_FOG_START, 1.0)           #Fog Start Depth
+      gl.glFogf(gl.GL_FOG_END, 50.0)             #Fog End Depth
+
     #
     # Turn on each light, keep it's iteration locked against mod until done
     self._lights._iterStart()
     for _i from 0 <= _i < self._lights._current :
       # This is a quick hack (gl.GL_LIGHT0 + _i)
       (<soy.bodies.Light> self._lights._list[_i])._on(gl.GL_LIGHT0 + _i)
+ 
+
     
     #
-    # Turn on some fog!
-    gl.glFogi(gl.GL_FOG_MODE, gl.GL_EXP2)
-    gl.glFogfv(gl.GL_FOG_COLOR, _fogColor)
-    gl.glFogf(gl.GL_FOG_DENSITY, _density)
-    gl.glHint (gl.GL_FOG_HINT, gl.GL_NICEST)
-    gl.glEnable(gl.GL_FOG)
-    
-    #
     # Iterate over bodies
     self._bodies._iterStart()
     for _i from 0 <= _i < self._bodies._current :
@@ -168,7 +195,6 @@
          (<soy.bodies.Body> self._bodies._list[_i])._model)._render(
          (<soy.bodies.Body> self._bodies._list[_i]))
     self._bodies._iterDone()
-    gl.glDisable(gl.GL_FOG)
     
     #
     # Turn off all lights and finish iteration loop
@@ -176,6 +202,9 @@
       # This is a quick hack (gl.GL_LIGHT0 + _i)
       (<soy.bodies.Light> self._lights._list[_i])._off(gl.GL_LIGHT0 + _i)
     self._lights._iterDone()
+    
+    if self._fogDensity > 0 :
+      gl.glDisable(gl.GL_FOG)
     gl.glDisable(gl.GL_LIGHTING)
     gl.glDisable(gl.GL_DEPTH_TEST)
 

_______________________________________________
PySoy-SVN mailing list
PySoy-SVN@pysoy.org
http://www.pysoy.org/mailman/listinfo/pysoy-svn

Reply via email to