Author: ArcRiley
Date: 2008-03-21 17:25:58 -0400 (Fri, 21 Mar 2008)
New Revision: 1192

Added:
   trunk/pysoy/src/colors/_getValues.pxi
Modified:
   trunk/pysoy/src/_core/Window-w32.pxi
   trunk/pysoy/src/_core/Window-x11.pxi
   trunk/pysoy/src/bodies/Light.pxi
   trunk/pysoy/src/colors/Color.pxi
   trunk/pysoy/src/colors/soy.colors.pxd
   trunk/pysoy/src/colors/soy.colors.pyx
   trunk/pysoy/src/materials/Material.pxi
   trunk/pysoy/src/materials/soy.materials.pxd
   trunk/pysoy/src/models/Liquid.pxi
   trunk/pysoy/src/scenes/Scene.pxi
   trunk/pysoy/src/textures/Print.pxi
Log:
Ticket #951 :
  * eliminated _getRGBA with basically a rewrite of colors.Color
  * replaced all access to _getRGBA and old values to Color._rgba
  * renamed Material._is_transparent to Material._isTransparent
  * CollideBlocks: it's a SUPER PINK, SUPER PINK, it's SUPER PINKY, YE-AH! :-)


Modified: trunk/pysoy/src/_core/Window-w32.pxi
===================================================================
--- trunk/pysoy/src/_core/Window-w32.pxi        2008-03-20 09:06:53 UTC (rev 
1191)
+++ trunk/pysoy/src/_core/Window-w32.pxi        2008-03-21 21:25:58 UTC (rev 
1192)
@@ -3,16 +3,16 @@
 # Copyright (C) 2006,2007,2008 PySoy Group
 #
 #  This program is free software; you can redistribute it and/or modify
-#  it under the terms of the GNU Affero General Public License as published
-#  by the Free Software Foundation, either version 3 of the License, or
+#  it under the terms of the GNU Affero General Public License as published
+#  by the Free Software Foundation, either version 3 of the License, or
 #  (at your option) any later version.
 #
 #  This program is distributed in the hope that it will be useful,
 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#  GNU Affero General Public License for more details.
+#  GNU Affero General Public License for more details.
 #
-#  You should have received a copy of the GNU Affero General Public License
+#  You should have received a copy of the GNU Affero General Public License
 #  along with this program; if not, see http://www.gnu.org/licenses
 #
 # $Id$
@@ -214,8 +214,8 @@
     #
     # Setup for rendering
     gl.glViewport(0, 0, self._width, self._height)
-    gl.glClearColor(self._background._r, self._background._g,
-                    self._background._b, 0.0)
+    gl.glClearColor(self._background._rgba[0], self._background._rgba[1],
+                    self._background._rgba[2], 0.0)
     gl.glClearDepth(1.0)
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     gl.glEnableClientState(gl.GL_VERTEX_ARRAY)

Modified: trunk/pysoy/src/_core/Window-x11.pxi
===================================================================
--- trunk/pysoy/src/_core/Window-x11.pxi        2008-03-20 09:06:53 UTC (rev 
1191)
+++ trunk/pysoy/src/_core/Window-x11.pxi        2008-03-21 21:25:58 UTC (rev 
1192)
@@ -187,8 +187,8 @@
     #
     glx.glXMakeCurrent(_display, self._windowID, _glxContext)
     gl.glViewport(0, 0, self._width, self._height)
-    gl.glClearColor(self._background._r, self._background._g,
-                    self._background._b, 1.0)
+    gl.glClearColor(self._background._rgba[0], self._background._rgba[1],
+                    self._background._rgba[2], 1.0)
     gl.glClear(gl.GL_COLOR_BUFFER_BIT)
     #
     # For some reason we've yet to discover, these client states MUST be

Modified: trunk/pysoy/src/bodies/Light.pxi
===================================================================
--- trunk/pysoy/src/bodies/Light.pxi    2008-03-20 09:06:53 UTC (rev 1191)
+++ trunk/pysoy/src/bodies/Light.pxi    2008-03-21 21:25:58 UTC (rev 1192)
@@ -118,21 +118,22 @@
   #
 
   cdef void _on(self, int _id) :
-    cdef gl.GLfloat _ambient[4]
-    cdef gl.GLfloat _diffuse[4]
-    cdef gl.GLfloat _specular[4]
     cdef gl.GLfloat _position[4]
-    gl.glEnable(_id)
-    (<soy.colors.Color>  self._ambient)._getRGBA(_ambient)
-    (<soy.colors.Color>  self._diffuse)._getRGBA(_diffuse)
-    (<soy.colors.Color> self._specular)._getRGBA(_specular)
+    #
+    # we do this only because glLightfv takes four parameters
     _position[0] = self._position[0]
     _position[1] = self._position[1]
     _position[2] = self._position[2]
     _position[3] = 1.0
-    gl.glLightfv(_id, gl.GL_AMBIENT,  _ambient)
-    gl.glLightfv(_id, gl.GL_DIFFUSE,  _diffuse)
-    gl.glLightfv(_id, gl.GL_SPECULAR, _specular)
+    #
+    # enable the light of the given _id
+    gl.glEnable(_id)
+    gl.glLightfv(_id, gl.GL_AMBIENT,
+                 (<soy.colors.Color> self._ambient)._rgba)
+    gl.glLightfv(_id, gl.GL_DIFFUSE,
+                 (<soy.colors.Color> self._diffuse)._rgba)
+    gl.glLightfv(_id, gl.GL_SPECULAR,
+                 (<soy.colors.Color> self._specular)._rgba)
     gl.glLightfv(_id, gl.GL_POSITION, _position)
     #
     # for spotlights
@@ -142,5 +143,6 @@
       # gl.glLightf (_id, gl.GL_SPOT_EXPODENT, [[0-128, default 0]])
       # gl.glLightfv(_id, gl.GL_SPOT_DIRECTION, [[direction, as per Body]])
 
+
   cdef void _off(self, int _id) :
     gl.glDisable(_id)

Modified: trunk/pysoy/src/colors/Color.pxi
===================================================================
--- trunk/pysoy/src/colors/Color.pxi    2008-03-20 09:06:53 UTC (rev 1191)
+++ trunk/pysoy/src/colors/Color.pxi    2008-03-21 21:25:58 UTC (rev 1192)
@@ -55,10 +55,10 @@
         val = val[0]*2 + val[1:]
       elif vlen > 8 :
         raise('ARGB hex must not exceed 8 characters')
-      self._a = float(int(val[0:2],16)) / 255.0
-      self._r = float(int(val[2:4],16)) / 255.0
-      self._g = float(int(val[4:6],16)) / 255.0
-      self._b = float(int(val[6:8],16)) / 255.0
+      self._rgba[1] = float(int(val[2:4],16)) / 255.0
+      self._rgba[2] = float(int(val[4:6],16)) / 255.0
+      self._rgba[3] = float(int(val[6:8],16)) / 255.0
+      self._rgba[0] = float(int(val[0:2],16)) / 255.0
     elif type(value) == tuple or type(value) == list :
       if type(value)!=tuple and type(value)!=list :
         raise TypeError('Color.floats must be either a tuple or list')
@@ -68,111 +68,143 @@
         value = (value[0], value[0], value[0], value[1])
       if len(value) == 3 :
         value = (value[0], value[1], value[2], 1.0)
-      self._r = value[0]
-      self._g = value[1]
-      self._b = value[2]
-      self._a = value[3]
+      self._rgba[0] = value[0]
+      self._rgba[1] = value[1]
+      self._rgba[2] = value[2]
+      self._rgba[3] = value[3]
     else :
       raise TypeError('color value must be string, tuple, or list')
 
-  def __div__(self, value) :
-    if type(value) == int or type(value) == float :
-      return Color( ((<Color> self)._r / value, (<Color> self)._g / value,
-                     (<Color> self)._b / value, (<Color> self)._a / value)
-                    [:(3,4)[(<Color> self)._a !=1.0]] )
-    elif isinstance(value, Color) :
-      return Color( ((<Color> self)._r / (<Color> value)._r,
-                     (<Color> self)._g / (<Color> value)._g,
-                     (<Color> self)._b / (<Color> value)._b,
-                     (<Color> self)._a / (<Color> value)._a )
-                    [:(3,4)[(<Color> self)._a !=1.0 or \
-                            (<Color> value)._a!=1.0]] )
-    else :
-      return NotImplemented
 
+  def __div__(valueL, valueR) :
+    cdef object      _error
+    cdef gl.GLfloat  _rgba[2][4]
+    #
+    # get the _rgba for each value
+    _error = _getValues((valueL, valueR), <gl.GLfloat**> _rgba)    
+    #
+    # if error, return now
+    if _error :
+      return _error
+    #
+    # return calculated Color
+    return Color(_rgba[0][0] / _rgba[1][0],
+                 _rgba[0][1] / _rgba[1][1],
+                 _rgba[0][2] / _rgba[1][2],
+                 _rgba[0][3] / _rgba[1][3])
+
+
   def __mul__(self, value) :
-    if type(value) == int or type(value) == float :
-      return Color( ((<Color> self)._r * value, (<Color> self)._g * value,
-                     (<Color> self)._b * value, (<Color> self)._a * value)
-                    [:(3,4)[(<Color> self)._a !=1.0]] )
-    elif isinstance(value, Color) :
-      return Color( ((<Color> self)._r * (<Color> value)._r,
-                     (<Color> self)._g * (<Color> value)._g,
-                     (<Color> self)._b * (<Color> value)._b,
-                     (<Color> self)._a * (<Color> value)._a)
-                    [:(3,4)[(<Color> self)._a !=1.0 or \
-                            (<Color> value)._a!=1.0]] )
-    else :
-      return NotImplemented
+    cdef object      _error
+    cdef gl.GLfloat  _rgba[2][4]
+    #
+    # get the _rgba for each value
+    _error = _getValues((valueL, valueR), <gl.GLfloat**> _rgba)    
+    #
+    # if error, return now
+    if _error :
+      return _error
+    #
+    # return calculated Color
+    return Color(_rgba[0][0] * _rgba[1][0],
+                 _rgba[0][1] * _rgba[1][1],
+                 _rgba[0][2] * _rgba[1][2],
+                 _rgba[0][3] * _rgba[1][3])
 
+
   def __add__(self, value) :
-    if type(value) == int or type(value) == float :
-      return Color( ((<Color> self)._r + value, (<Color> self)._g + value,
-                     (<Color> self)._b + value, (<Color> self)._a + value)
-                    [:(3,4)[(<Color> self)._a !=1.0]] )
-    elif isinstance(value, Color) :
-      return Color( ((<Color> self)._r + (<Color> value)._r,
-                     (<Color> self)._g + (<Color> value)._g,
-                     (<Color> self)._b + (<Color> value)._b,
-                     (<Color> self)._a + (<Color> value)._a)
-                    [:(3,4)[(<Color> self)._a !=1.0 or \
-                            (<Color> value)._a!=1.0]] )
-    else :
-      return NotImplemented
+    cdef object      _error
+    cdef gl.GLfloat  _rgba[2][4]
+    #
+    # get the _rgba for each value
+    _error = _getValues((valueL, valueR), <gl.GLfloat**> _rgba)    
+    #
+    # if error, return now
+    if _error :
+      return _error
+    #
+    # return calculated Color
+    return Color(_rgba[0][0] + _rgba[1][0],
+                 _rgba[0][1] + _rgba[1][1],
+                 _rgba[0][2] + _rgba[1][2],
+                 _rgba[0][3] + _rgba[1][3])
 
+
   def __repr__(self) :
     return '<%s>' % self.__str__()
 
-  def __richcmp__(self, that, oper) :
-    if not isinstance(that, Color) :
+
+  def __richcmp__(self, value, oper) :
+    #
+    # This compares two colors
+    #
+    cdef Color _this, _that
+    cdef int _r, _g, _b, _a
+    #
+    # ensure that we're working with two colors
+    if not isinstance(self, Color) :
       return NotImplemented
-    cdef int _r, _g, _b, _a
-    _r = ((<Color> self)._r <  (<Color> that)._r,
-          (<Color> self)._r <= (<Color> that)._r,
-          (<Color> self)._r == (<Color> that)._r,
-          (<Color> self)._r == (<Color> that)._r,
-          (<Color> self)._r >  (<Color> that)._r,
-          (<Color> self)._r >= (<Color> that)._r)[oper]
-    _g = ((<Color> self)._g <  (<Color> that)._g,
-          (<Color> self)._g <= (<Color> that)._g,
-          (<Color> self)._g == (<Color> that)._g,
-          (<Color> self)._g == (<Color> that)._g,
-          (<Color> self)._g >  (<Color> that)._g,
-          (<Color> self)._g >= (<Color> that)._g)[oper]
-    _b = ((<Color> self)._b <  (<Color> that)._b,
-          (<Color> self)._b <= (<Color> that)._b,
-          (<Color> self)._b == (<Color> that)._b,
-          (<Color> self)._b == (<Color> that)._b,
-          (<Color> self)._b >  (<Color> that)._b,
-          (<Color> self)._b >= (<Color> that)._b)[oper]
-    _a = ((<Color> self)._a <  (<Color> that)._a or 
-           ((<Color> self)._a == 1 and (<Color> that)._a == 1),
-          (<Color> self)._a <= (<Color> that)._a,
-          (<Color> self)._a == (<Color> that)._a,
-          (<Color> self)._a == (<Color> that)._a,
-          (<Color> self)._a >  (<Color> that)._a or
-           ((<Color> self)._a == 1 and (<Color> that)._a == 1),
-          (<Color> self)._a >= (<Color> that)._a)[oper]
+    if not isinstance(value, Color) :
+      return NotImplemented
+    #
+    # set _this and _that    
+    _this = <Color> self
+    _that = <Color> value
+    #
+    # this calcs for each possible operator
+    # yes, this is a bit slower, but simpler
+    _r = (_this._rgba[0] <  _that._rgba[0],
+          _this._rgba[0] <= _that._rgba[0],
+          _this._rgba[0] == _that._rgba[0],
+          _this._rgba[0] == _that._rgba[0],
+          _this._rgba[0] >  _that._rgba[0],
+          _this._rgba[0] >= _that._rgba[0])[oper]
+    _g = (_this._rgba[1] <  _that._rgba[1],
+          _this._rgba[1] <= _that._rgba[1],
+          _this._rgba[1] == _that._rgba[1],
+          _this._rgba[1] == _that._rgba[1],
+          _this._rgba[1] >  _that._rgba[1],
+          _this._rgba[1] >= _that._rgba[1])[oper]
+    _b = (_this._rgba[2] <  _that._rgba[2],
+          _this._rgba[2] <= _that._rgba[2],
+          _this._rgba[2] == _that._rgba[2],
+          _this._rgba[2] == _that._rgba[2],
+          _this._rgba[2] >  _that._rgba[2],
+          _this._rgba[2] >= _that._rgba[2])[oper]
+    _a = (_this._rgba[3] <  _that._rgba[3] or 
+           (_this._rgba[3] == 1 and _that._rgba[3] == 1),
+          _this._rgba[3] <= _that._rgba[3],
+          _this._rgba[3] == _that._rgba[3],
+          _this._rgba[3] == _that._rgba[3],
+          _this._rgba[3] >  _that._rgba[3] or
+           (_this._rgba[3] == 1 and _that._rgba[3] == 1),
+          _this._rgba[3] >= _that._rgba[3])[oper]
+    #
+    # if the operation is !=, invert it here -- note we tested for == above
     if oper == 3 :
       return (True, False)[_r&_g&_b&_a]
     else :
       return (False, True)[_r&_g&_b&_a]
 
+
   def __sub__(self, value) :
-    if type(value) == int or type(value) == float :
-      return Color( ((<Color> self)._r - value, (<Color> self)._g - value,
-                     (<Color> self)._b - value, (<Color> self)._a - value)
-                    [:(3,4)[(<Color> self)._a !=1.0]] )
-    elif isinstance(value, Color) :
-      return Color( ((<Color> self)._r - (<Color> value)._r,
-                     (<Color> self)._g - (<Color> value)._g,
-                     (<Color> self)._b - (<Color> value)._b,
-                     (<Color> self)._a - (<Color> value)._a)
-                    [:(3,4)[(<Color> self)._a !=1.0 or \
-                            (<Color> value)._a!=1.0]] )
-    else :
-      return NotImplemented
+    cdef object      _error
+    cdef gl.GLfloat  _rgba[2][4]
+    #
+    # get the _rgba for each value
+    _error = _getValues((valueL, valueR), <gl.GLfloat**> _rgba)    
+    #
+    # if error, return now
+    if _error :
+      return _error
+    #
+    # return calculated Color
+    return Color(_rgba[0][0] - _rgba[1][0],
+                 _rgba[0][1] - _rgba[1][1],
+                 _rgba[0][2] - _rgba[1][2],
+                 _rgba[0][3] - _rgba[1][3])
 
+
   def __str__(self) :
     cdef object _parts
     _parts = self.hex.split(' ',1)
@@ -182,13 +214,6 @@
       return "soy.colors.Color('%s') %s" % (_parts[0], _parts[1])
 
 
-  cdef void _getRGBA(self, float* ret) :
-    ret[0] = self._r
-    ret[1] = self._g
-    ret[2] = self._b
-    ret[3] = self._a
-
-
   property hex :
     '''Color hex
 
@@ -200,21 +225,22 @@
       cdef float _bottom
       #
       # Find the highest number of all the channels
-      _top = self._r
-      if self._g > _top :
-        _top = self._g
-      if self._b > _top :
-        _top = self._b
-      if self._a != 1.0 and self._a > _top :
-        _top = self._a
+      _top = self._rgba[0]
+      if self._rgba[1] > _top :
+        _top = self._rgba[1]
+      if self._rgba[2] > _top :
+        _top = self._rgba[2]
+      if self._rgba[3] != 1.0 and self._rgba[3] > _top :
+        _top = self._rgba[3]
       #  
-      _bottom = self._r
-      if self._g < _bottom :
-        _bottom = self._g
-      if self._b < _bottom :
-        _bottom = self._b
-      if self._a != 1.0 and self._a < _bottom :
-        _bottom = self._a
+      # Find the lowest number of all the channels
+      _bottom = self._rgba[0]
+      if self._rgba[1] < _bottom :
+        _bottom = self._rgba[1]
+      if self._rgba[2] < _bottom :
+        _bottom = self._rgba[2]
+      if self._rgba[3] != 1.0 and self._rgba[3] < _bottom :
+        _bottom = self._rgba[3]
       #        
       # Test the highest and lowest values and, when the color is complex,
       # calculate it as a complex statement which could be processed to 
@@ -222,25 +248,25 @@
       #
       if _top < 0 :
         if _top < 1.0 :
-          chans = (self._a*255/_bottom, self._r*255/_bottom,
-                   self._g*255/_bottom, self._b*255/_bottom) [self._a==1.0:]
+          chans = (self._rgba[3]*255/_bottom, self._r*255/_bottom,
+                   self._rgba[1]*255/_bottom, self._rgba[2]*255/_bottom) 
[self._rgba[3]==1.0:]
           multi = _bottom
         else :
-          chans = (self._a*255*_bottom, self._r*255*_bottom,
-                   self._g*255*_bottom, self._b*255*_bottom) [self._a==1.0:]
+          chans = (self._rgba[3]*255*_bottom, self._r*255*_bottom,
+                   self._rgba[1]*255*_bottom, self._rgba[2]*255*_bottom) 
[self._rgba[3]==1.0:]
           multi = _bottom
       elif _bottom < 0 :
         # This is not correct
-        chans = (self._a*255-_bottom, self._r*255-_bottom,
-                 self._g*255-_bottom, self._b*255-_bottom) [self._a==1.0:]
+        chans = (self._rgba[3]*255-_bottom, self._r*255-_bottom,
+                 self._rgba[1]*255-_bottom, self._rgba[2]*255-_bottom) 
[self._rgba[3]==1.0:]
         multi = 1.0
       elif _top > 1.0 :
-        chans = (self._a*255/_top, self._r*255/_top,
-                 self._g*255/_top, self._b*255/_top) [self._a==1.0:]
+        chans = (self._rgba[3]*255/_top, self._r*255/_top,
+                 self._rgba[1]*255/_top, self._rgba[2]*255/_top) 
[self._rgba[3]==1.0:]
         multi = _top
       else :
-        chans = (self._a*255, self._r*255,
-                 self._g*255, self._b*255) [self._a==1.0:]
+        chans = (self._rgba[3]*255, self._r*255,
+                 self._rgba[1]*255, self._rgba[2]*255) [self._rgba[3]==1.0:]
         multi = 1.0
       #
       # The following code contains some Python trickery, abusing slice to
@@ -261,6 +287,7 @@
       # Finally, return the compiled string
       return '#%s%s' % (chans, multi)
 
+
   property floats :
     '''Color floats
     
@@ -268,4 +295,5 @@
     (r, g, b, a)
     '''
     def __get__(self) :
-      return (self._r, self._g, self._b, self._a) [:(self._a!=1.0)+3]
+      return (self._rgba[0], self._rgba[1], 
+              self._rgba[2], self._rgba[3])[:(self._rgba[3]!=1.0)+3]

Added: trunk/pysoy/src/colors/_getValues.pxi
===================================================================
--- trunk/pysoy/src/colors/_getValues.pxi                               (rev 0)
+++ trunk/pysoy/src/colors/_getValues.pxi       2008-03-21 21:25:58 UTC (rev 
1192)
@@ -0,0 +1,54 @@
+# PySoy's colors._getValues function
+#
+# Copyright (C) 2006,2007,2008 PySoy Group
+#
+#  This program is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU Affero General Public License as published
+#  by the Free Software Foundation, either version 3 of the License, or
+#  (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU Affero General Public License for more details.
+#
+#  You should have received a copy of the GNU Affero General Public License
+#  along with this program; if not, see http://www.gnu.org/licenses
+#
+# $Id: Color.pxi 1191 2008-03-20 09:06:53Z ArcRiley $
+
+cdef object _getValues(object values, gl.GLfloat** _rgba) :
+  #
+  # This is just a helper for various Color math functions
+  #
+  cdef int _chans, _d, _i
+  #
+  # handle errors first
+  for _d from 0 <= _d < 2 :
+    if type(values[_d]) != int and type(values[_d]) != float and \
+       not isinstance(values[_d], Color) :
+      return NotImplemented
+  #
+  # calculate _chans
+  _chans = 3
+  for _d from 0 <= _d < 2 :
+    if isinstance(values[_d], Color) and (<Color> values[_d])._rgba[3] != 1.0 :
+      _chans = 4
+  #
+  # populate _rgba
+  for _d from 0 <= _d < 2 :
+    if type(values[_d]) == int or type(values[_d]) == float :
+      #
+      # if the value is a number, copy it to each channel
+      for _i from 0 <= _i < _chans :
+        _rgba[_d][_i] = values[_d]
+      #
+      # if we're only calculating RGB, drop 1.0 into alpha
+      if _chans == 3 :
+        _rgba[_d][3] = 1.0
+    else :
+      #
+      # this value is a color, just copy it over
+      for _i from 0 <= _i < 4 :
+        _rgba[_d][_i] = (<Color> value[_d])._rgba[_i]
+  return None

Modified: trunk/pysoy/src/colors/soy.colors.pxd
===================================================================
--- trunk/pysoy/src/colors/soy.colors.pxd       2008-03-20 09:06:53 UTC (rev 
1191)
+++ trunk/pysoy/src/colors/soy.colors.pxd       2008-03-21 21:25:58 UTC (rev 
1192)
@@ -19,9 +19,7 @@
 
 cimport gl
 
+cdef object        _getValues          (object, gl.GLfloat**)
+
 cdef class Color :
-  cdef gl.GLfloat  _r
-  cdef gl.GLfloat  _g
-  cdef gl.GLfloat  _b
-  cdef gl.GLfloat  _a
-  cdef void        _getRGBA(self, gl.GLfloat*)
+  cdef gl.GLfloat  _rgba[4]

Modified: trunk/pysoy/src/colors/soy.colors.pyx
===================================================================
--- trunk/pysoy/src/colors/soy.colors.pyx       2008-03-20 09:06:53 UTC (rev 
1191)
+++ trunk/pysoy/src/colors/soy.colors.pyx       2008-03-21 21:25:58 UTC (rev 
1192)
@@ -23,6 +23,7 @@
               'by '+'$Author$'[9:-2]
 __version__ = 'Trunk (r'+'$Rev$'[6:-2]+')'
 
+include "_getValues.pxi"
 include "Color.pxi"
 include "a.pxi"
 include "b.pxi"

Modified: trunk/pysoy/src/materials/Material.pxi
===================================================================
--- trunk/pysoy/src/materials/Material.pxi      2008-03-20 09:06:53 UTC (rev 
1191)
+++ trunk/pysoy/src/materials/Material.pxi      2008-03-21 21:25:58 UTC (rev 
1192)
@@ -67,43 +67,23 @@
   def __repr__(self) :
     return '<Material>'
 
-  cdef int _is_transparent(self):
-    cdef gl.GLfloat _ambient[4]
-    cdef gl.GLfloat _diffuse[4]
-    cdef gl.GLfloat _specular[4]
+  cdef int _isTransparent(self):
+    #
+    # check color texture
+    if self._color and (<soy.textures.Texture> self._color)._chans %2 == 0 :
+      return 1
+    if (<soy.colors.Color> self._ambient)._rgba[3] != 1.0 :
+      return 1
+    if (<soy.colors.Color> self._diffuse)._rgba[3] != 1.0 :
+      return 1
+    if (<soy.colors.Color> self._specular)._rgba[3] != 1.0 :
+      return 1
+    return 0
 
-    (<soy.colors.Color> self._ambient)._getRGBA(_ambient)
-    (<soy.colors.Color> self._diffuse)._getRGBA(_diffuse)
-    (<soy.colors.Color> self._specular)._getRGBA(_specular)
 
-    if self._color:
-      if ( <soy.textures.Texture> self._color)._chans %2 == 0:
-        return 1
-      else:
-        return 0
-    else:
-      if _ambient[3] != 1.0:
-        return 1
-      if _diffuse[3] != 1.0:
-        return 1
-      if _specular[3] != 1.0:
-        return 1
-      return 0
-
-
   cdef void _coreBind(self) :
-    cdef gl.GLfloat _ambient[4]
-    cdef gl.GLfloat _diffuse[4]
-    cdef gl.GLfloat _specular[4]
-    cdef gl.GLfloat _emissive[4]
     #
-    # Get each color
-    (<soy.colors.Color> self._ambient)._getRGBA(_ambient)
-    (<soy.colors.Color> self._diffuse)._getRGBA(_diffuse)
-    (<soy.colors.Color> self._specular)._getRGBA(_specular)
-    (<soy.colors.Color> self._emissive)._getRGBA(_emissive)
-    #
-    #
+    # set _shades value
     if self._shades == 0 :
       gl.glShadeModel(gl.GL_SMOOTH)
     else :
@@ -112,13 +92,14 @@
     #
     if self._shadeless:
       gl.glDisable(gl.GL_LIGHTING)
-      gl.glColor4f(_diffuse[0], _diffuse[1], _diffuse[2], _diffuse[3])
+      gl.glColor4f(self._diffuse._rgba[0], self._diffuse._rgba[1], 
+                   self._diffuse._rgba[2], self._diffuse._rgba[3]) 
     else: 
-      gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT, _ambient)
-      gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, _diffuse)
+      gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT,   self._ambient._rgba) 
+      gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE,   self._diffuse._rgba) 
+      gl.glMaterialfv(gl.GL_FRONT, gl.GL_SPECULAR,  self._specular._rgba) 
+      gl.glMaterialfv(gl.GL_FRONT, gl.GL_EMISSION,  self._emissive._rgba) 
       gl.glMaterialf (gl.GL_FRONT, gl.GL_SHININESS, self._shininess)    
-      gl.glMaterialfv(gl.GL_FRONT, gl.GL_SPECULAR, _specular)
-      gl.glMaterialfv(gl.GL_FRONT, gl.GL_EMISSION, _emissive)
 
     if self._color :
       (<soy.textures.Texture> self._color)._enable()
@@ -128,7 +109,7 @@
       gl.glBlendFunc(gl.GL_DST_COLOR, gl.GL_ZERO)
       gl.glEnable(gl.GL_POLYGON_OFFSET_FILL)
       gl.glPolygonOffset(0,-2)
-    elif self._is_transparent():
+    elif self._isTransparent():
       gl.glEnable(gl.GL_BLEND)
       gl.glBlendFunc(self._blend_func_src, self._blend_func_dst)
 
@@ -140,7 +121,7 @@
       gl.glDisable(gl.GL_BLEND)
       gl.glDisable(gl.GL_POLYGON_OFFSET_FILL)
       gl.glPolygonOffset(0,0)
-    elif self._is_transparent():
+    elif self._isTransparent():
       gl.glDisable(gl.GL_BLEND)
 
     if self._shadeless:
@@ -277,7 +258,7 @@
   
   property transparent:
     def __get__(self):
-      return self._is_transparent()
+      return self._isTransparent()
 
 
   property shadeless:

Modified: trunk/pysoy/src/materials/soy.materials.pxd
===================================================================
--- trunk/pysoy/src/materials/soy.materials.pxd 2008-03-20 09:06:53 UTC (rev 
1191)
+++ trunk/pysoy/src/materials/soy.materials.pxd 2008-03-21 21:25:58 UTC (rev 
1192)
@@ -43,4 +43,4 @@
   cdef void   _coreUnBind(self)
   cdef void   _coreBindBumpPass(self)
   cdef void   _coreUnBindBumpPass(self)
-  cdef int    _is_transparent(self)
+  cdef int    _isTransparent(self)

Modified: trunk/pysoy/src/models/Liquid.pxi
===================================================================
--- trunk/pysoy/src/models/Liquid.pxi   2008-03-20 09:06:53 UTC (rev 1191)
+++ trunk/pysoy/src/models/Liquid.pxi   2008-03-21 21:25:58 UTC (rev 1192)
@@ -3,16 +3,16 @@
 # Copyright (C) 2006,2007,2008 PySoy Group
 #
 #  This program is free software; you can redistribute it and/or modify
-#  it under the terms of the GNU Affero General Public License as published
-#  by the Free Software Foundation, either version 3 of the License, or
+#  it under the terms of the GNU Affero General Public License as published
+#  by the Free Software Foundation, either version 3 of the License, or
 #  (at your option) any later version.
 #
 #  This program is distributed in the hope that it will be useful,
 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#  GNU Affero General Public License for more details.
+#  GNU Affero General Public License for more details.
 #
-#  You should have received a copy of the GNU Affero General Public License
+#  You should have received a copy of the GNU Affero General Public License
 #  along with this program; if not, see http://www.gnu.org/licenses
 #
 # $Id$
@@ -80,10 +80,8 @@
     cdef int                _i
     cdef soy.scenes.Scene   _scene
     cdef ode.dReal*         _pos
-    cdef gl.GLfloat         _diffuse[4]
     cdef float              _halfSize[3]
     _pos = (<soy.bodies.Body> _body)._position
-    (<soy.colors.Color> self._color)._getRGBA(_diffuse)
     _halfSize[0] = self._size[0]/2.0
     _halfSize[1] = self._size[1]/2.0
     _halfSize[2] = self._size[2]/2.0
@@ -103,7 +101,7 @@
     gl.glEnable(gl.GL_FOG)
     gl.glEnableClientState(gl.GL_FOG_COORDINATE_ARRAY_EXT)
     gl.glFogi(gl.GL_FOG_MODE, gl.GL_LINEAR)
-    gl.glFogfv(gl.GL_FOG_COLOR, _diffuse)
+    gl.glFogfv(gl.GL_FOG_COLOR, (<soy.colors.Color> self._color)._rgba)
     gl.glFogf(gl.GL_FOG_START, pos[1] + _halfSize[1])
     gl.glFogf(gl.GL_FOG_END, pos[1] - _halfSize[1])
     gl.glHint(gl.GL_FOG_HINT, gl.GL_NICEST)
@@ -153,13 +151,13 @@
 
   cdef void _renderBottom(self) :
     cdef float       _halfSize[3]
-    cdef gl.GLfloat  _diffuse[4]
     _halfSize[0] = self._size[0]/2.0
     _halfSize[1] = self._size[1]/2.0
     _halfSize[2] = self._size[2]/2.0
-    (<soy.colors.Color> self._color)._getRGBA(_diffuse)
     gl.glDisable(gl.GL_LIGHTING)
-    gl.glColor3f(_diffuse[0], _diffuse[1], _diffuse[2])
+    gl.glColor3f((<soy.colors.Color> self._color)._rgba[0],
+                 (<soy.colors.Color> self._color)._rgba[1],
+                 (<soy.colors.Color> self._color)._rgba[2])
     gl.glBegin(gl.GL_TRIANGLES)
     gl.glNormal3f(0, 1, 0) #LIQUID FACE
     gl.glVertex3f(-1000, -_halfSize[1], 1000 )

Modified: trunk/pysoy/src/scenes/Scene.pxi
===================================================================
--- trunk/pysoy/src/scenes/Scene.pxi    2008-03-20 09:06:53 UTC (rev 1191)
+++ trunk/pysoy/src/scenes/Scene.pxi    2008-03-21 21:25:58 UTC (rev 1192)
@@ -120,14 +120,13 @@
 
   cdef void _render(self) :
     cdef int   _i
-    cdef float _ambientLight[4]
     #
     # Setup scene-level rendering
     gl.glClear(gl.GL_DEPTH_BUFFER_BIT)
     gl.glEnable(gl.GL_DEPTH_TEST)
     gl.glEnable(gl.GL_LIGHTING)
-    (<soy.colors.Color> self._ambient)._getRGBA(_ambientLight)
-    gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, _ambientLight)
+    gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, 
+                      (<soy.colors.Color> self._ambient)._rgba)
     #
     # Turn on each light, keep it's iteration locked against mod until done
     self._lights._iterStart()
@@ -321,4 +320,4 @@
       if isinstance(value, int):
         self._friction = value
       else: 
-        raise TypeError("Friction must be an int of some sort")
\ No newline at end of file
+        raise TypeError("Friction must be an int of some sort")

Modified: trunk/pysoy/src/textures/Print.pxi
===================================================================
--- trunk/pysoy/src/textures/Print.pxi  2008-03-20 09:06:53 UTC (rev 1191)
+++ trunk/pysoy/src/textures/Print.pxi  2008-03-21 21:25:58 UTC (rev 1192)
@@ -109,8 +109,8 @@
     # It uses Cairo to (re)draw the texture based on these parameters
     # to self._texels which the WindowLoop will then update the texture from.
     #
-    cdef gl.GLfloat _bg[4]
-    cdef gl.GLfloat _fg[4]
+    cdef gl.GLfloat* _bg
+    cdef gl.GLfloat* _fg
     #
     # Don't bother rendering if either the font or text don't exist
     if not (self._font and self._text) :
@@ -121,7 +121,7 @@
     #
     # Clear the background
     cairo.cairo_save(self._context)
-    (<soy.colors.Color> self._background)._getRGBA(_bg)
+    _bg = (<soy.colors.Color> self._background)._rgba
     cairo.cairo_set_source_rgba(self._context, _bg[0], _bg[1], _bg[2], _bg[3])
     cairo.cairo_set_operator(self._context, cairo.CAIRO_OPERATOR_SOURCE)
     cairo.cairo_paint(self._context)
@@ -133,7 +133,7 @@
                                  cairo.CAIRO_FONT_SLANT_NORMAL, 
                                  cairo.CAIRO_FONT_WEIGHT_BOLD)
     cairo.cairo_set_font_size(self._context, 32.0)
-    (<soy.colors.Color> self._foreground)._getRGBA(_fg)
+    _fg = (<soy.colors.Color> self._foreground)._rgba
     cairo.cairo_set_source_rgba(self._context, _fg[0], _fg[1], _fg[2], _fg[3])
     cairo.cairo_move_to(self._context, 10.0, 50.0)
     cairo.cairo_show_text(self._context, self._text)

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

Reply via email to