Changeset 1345

Show
Ignore:
Timestamp:
08/09/08 17:20:02 (4 months ago)
Author:
JonNeal
Message:

Ticket #900:

  • Added in basic fog support through a property.
  • Changed a few checks in Planar.pym to asserts
Location:
trunk/pysoy
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/pysoy/include/soy.scenes.pxd

    r1340 r1345  
    6868  cdef soy._internals.PointerSet  _callFields 
    6969  cdef soy.colors.Color           _ambient 
     70  cdef float                      _fogDensity 
    7071  cdef void*                      _stepMutex 
    7172  cdef void                       _stepLock       ( self )                nogil 
     
    9899  cdef Vert*                      _vertArray 
    99100  cdef gl.GLuint                  _vertBuffer 
     101  cdef Vert*                      _backArray 
     102  cdef gl.GLuint                  _backBuffer 
    100103  cdef Quad*                      _faceArray 
    101104  cdef gl.GLuint                  _faceBuffer 
  • trunk/pysoy/src/scenes/Planar.pym

    r1317 r1345  
    129129      return self._material 
    130130    def __set__(self, value) : 
    131       if not isinstance(value, soy.materials.Material) : 
    132         raise TypeError('Must provide an instance of soy.materials.Material') 
     131      assert isinstance(value, soy.materials.Material), \ 
     132        "Must provide an instance of soy.materials.Material" 
    133133      self._material = value 
    134134 
     
    151151    def __set__(self, value) : 
    152152      cdef ode.dVector3 _normal 
    153       if type(value) != list or type(value) != tuple : 
    154         raise TypeError("A tuple or list must be provided.") 
     153      assert type(value) == list and type(value) == tuple, \ 
     154          "A tuple or list must be provided." 
    155155      _normal[0] = -(value[0]) 
    156156      _normal[1] = -(value[1]) 
  • trunk/pysoy/src/scenes/Scene.pym

    r1339 r1345  
    4545    self._lights       = soy._internals.Children() 
    4646    self._ambient      = gray 
     47    self._fogDensity   = 0.0 
    4748    self._stepSize     = 0.01 
    4849    self._friction     = 0 
     
    7879 
    7980    return '<Scene with %s>' % ', '.join(report) 
     81   
     82  ############################################################################ 
     83  # 
     84  # Properties 
     85  # 
     86   
     87  property fog : 
     88    '''Scene fog 
     89 
     90    This is a scene-wide layer of fog of which the density is set by you 
     91 
     92    Takes a float for fog density from 0-2, fog is disabled when at 0. 
     93    ''' 
     94    def __get__(self) : 
     95      return self._fogDensity 
     96     
     97    def __set__(self, value) : 
     98      assert type(value) == float and value <= 2 and value >= 0, \ 
     99          "Fog density must be a float in the range of 0-2." 
     100      self._fogDensity = value 
    80101 
    81102  ############################################################################ 
     
    127148                          gl.GLdouble _znear, gl.GLdouble _zfar) : 
    128149    cdef int _i 
    129     cdef gl.GLfloat _density, _fogColor[4] 
    130     _density = .3 
     150    cdef gl.GLfloat _fogColor[4] 
    131151    _fogColor[0] = .5 
    132152    _fogColor[1] = .5 
     
    145165    gl.glEnable(gl.GL_LIGHTING) 
    146166    gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, self._ambient._rgba) 
     167     
     168    if self._fogDensity > 0 : 
     169      # 
     170      # Turn on some fog! 
     171      gl.glClearColor(0.5,0.5,0.5,1.0)  # We'll Clear To The Color Of The Fog ( Modified ) 
     172      gl.glEnable(gl.GL_FOG)                    #Enables GL_FOG 
     173      gl.glFogi(gl.GL_FOG_MODE, gl.GL_EXP2)     #Fog Mode 
     174      gl.glFogfv(gl.GL_FOG_COLOR, _fogColor)    #Set Fog Color 
     175      gl.glFogf(gl.GL_FOG_DENSITY, self._fogDensity/10)        #How Dense Will The Fog Be 
     176      gl.glHint(gl.GL_FOG_HINT, gl.GL_NICEST)   #Fog Hint Value 
     177      gl.glFogf(gl.GL_FOG_START, 1.0)           #Fog Start Depth 
     178      gl.glFogf(gl.GL_FOG_END, 50.0)             #Fog End Depth 
     179 
    147180    # 
    148181    # Turn on each light, keep it's iteration locked against mod until done 
     
    151184      # This is a quick hack (gl.GL_LIGHT0 + _i) 
    152185      (<soy.bodies.Light> self._lights._list[_i])._on(gl.GL_LIGHT0 + _i) 
    153      
    154     # 
    155     # Turn on some fog! 
    156     gl.glFogi(gl.GL_FOG_MODE, gl.GL_EXP2) 
    157     gl.glFogfv(gl.GL_FOG_COLOR, _fogColor) 
    158     gl.glFogf(gl.GL_FOG_DENSITY, _density) 
    159     gl.glHint (gl.GL_FOG_HINT, gl.GL_NICEST) 
    160     gl.glEnable(gl.GL_FOG) 
     186  
     187 
    161188     
    162189    # 
     
    169196         (<soy.bodies.Body> self._bodies._list[_i])) 
    170197    self._bodies._iterDone() 
    171     gl.glDisable(gl.GL_FOG) 
    172198     
    173199    # 
     
    177203      (<soy.bodies.Light> self._lights._list[_i])._off(gl.GL_LIGHT0 + _i) 
    178204    self._lights._iterDone() 
     205     
     206    if self._fogDensity > 0 : 
     207      gl.glDisable(gl.GL_FOG) 
    179208    gl.glDisable(gl.GL_LIGHTING) 
    180209    gl.glDisable(gl.GL_DEPTH_TEST)