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
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • 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)