Author: ArcRiley
Date: 2008-12-01 01:26:35 -0500 (Mon, 01 Dec 2008)
New Revision: 1384

Modified:
   trunk/pysoy/examples/pysoy_primer.py
   trunk/pysoy/src/models/Axis.pym
Log:
Changed scale matrix calc


Modified: trunk/pysoy/examples/pysoy_primer.py
===================================================================
--- trunk/pysoy/examples/pysoy_primer.py        2008-12-01 05:44:55 UTC (rev 
1383)
+++ trunk/pysoy/examples/pysoy_primer.py        2008-12-01 06:26:35 UTC (rev 
1384)
@@ -28,7 +28,8 @@
 
 # Rotate the cube 1 unit in the X-axis, 1 unit in the Y-axis and 1 unit in the 
Z-axis
 body.rotation = (1, 1, 1)
+body.model.size = .5
 
 #  Main loop: each run through this loop keeps the window open and rotates the 
cube
 while True:
-    sleep(.1)
+    sleep(.1)

Modified: trunk/pysoy/src/models/Axis.pym
===================================================================
--- trunk/pysoy/src/models/Axis.pym     2008-12-01 05:44:55 UTC (rev 1383)
+++ trunk/pysoy/src/models/Axis.pym     2008-12-01 06:26:35 UTC (rev 1384)
@@ -1,291 +1,297 @@
-# PySoy's models.Axis class
-#
-# 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$
-
-cdef class Axis (Model) :
-  '''soy.models.Axis
-
-    This :class:`~soy.model.Model` renders a "XYZ axis" oriented to each 
-    body it's attached to.  This is useful for debugging.
-  '''
-  def __cinit__(self, size=None,*args, **kw):
-    if size == None:    
-      self._size = 0;
-    else:
-      #assert isinstance(size,int)
-      self._size = size;
+# PySoy's models.Axis class
+#
+# 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$
 
-  property size :
+cdef class Axis (Model) :
+  '''soy.models.Axis
+
+    This :class:`~soy.model.Model` renders a "XYZ axis" oriented to each 
+    body it's attached to.  This is useful for debugging.
+  '''
+  def __cinit__(self, size=1.0, *args, **kw):
+    self._size = size
+
+
+  ############################################################################
+  #
+  # Properties
+  #
+
+  property size:
     def __get__(self):
       return self._size
+
     def __set__(self, value):
+      if value == 0.0 :
+        raise ValueError('Cannot set size to 0.0')
       self._size = value
-    
-  ############################################################################
-  #
-  # WindowLoop Functions
-  #
-
-  cdef void _render(self, soy.bodies.Body _body) :
-    cdef VertPC      _vert[20]     # contains vertex position and color data
-    cdef Line        _elmt[20]     # contains indices to verts to render lines
-    cdef gl.GLfloat  _mtx[16]
-    #
-    ######################################
-    #
-    # get model's matrix
-    #
-    _mtx[0]  = _body._rotation[0] * self._size
-    _mtx[1]  = _body._rotation[4]
-    _mtx[2]  = _body._rotation[8]
-    _mtx[3]  = 0.0  
-    _mtx[4]  = _body._rotation[1]
-    _mtx[5]  = _body._rotation[5] * self._size
-    _mtx[6]  = _body._rotation[9]
-    _mtx[7]  = 0.0  
-    _mtx[8]  = _body._rotation[2]
-    _mtx[9]  = _body._rotation[6]
-    _mtx[10] = _body._rotation[10] * self._size
-    _mtx[11] = 0.0 
-    _mtx[12] = _body._position[0] 
-    _mtx[13] = _body._position[1] 
-    _mtx[14] = _body._position[2] 
-    _mtx[15] = 1#-self._size + 2
-    #
-    ######################################
-    #
-    # save Camera matix before transforming to the Axis' matrix
-    #
-    gl.glPushMatrix()
+
+ 
+  ############################################################################
+  #
+  # WindowLoop Functions
+  #
+
+  cdef void _render(self, soy.bodies.Body _body) :
+    cdef VertPC      _vert[20]     # contains vertex position and color data
+    cdef Line        _elmt[20]     # contains indices to verts to render lines
+    cdef gl.GLfloat  _mtx[16]
+    #
+    ######################################
+    #
+    # get model's matrix
+    #
+    _mtx[0]  = _body._rotation[0]
+    _mtx[1]  = _body._rotation[4]
+    _mtx[2]  = _body._rotation[8]
+    _mtx[3]  = 0.0  
+    _mtx[4]  = _body._rotation[1]
+    _mtx[5]  = _body._rotation[5]
+    _mtx[6]  = _body._rotation[9]
+    _mtx[7]  = 0.0  
+    _mtx[8]  = _body._rotation[2]
+    _mtx[9]  = _body._rotation[6]
+    _mtx[10] = _body._rotation[10]
+    _mtx[11] = 0.0 
+    _mtx[12] = _body._position[0] 
+    _mtx[13] = _body._position[1] 
+    _mtx[14] = _body._position[2] 
+    _mtx[15] = 1 / self._size
+    #
+    ######################################
+    #
+    # save Camera matix before transforming to the Axis' matrix
+    #
+    gl.glPushMatrix()
     gl.glMultMatrixf(_mtx)
-    #gl.glScalef(self._size,self._size,self._size)
-    #
-    ######################################
-    #
-    # Test if we've already setup the axis VBO
-    #
-    if self._vertBuffer :
-      #
-      # Since we already setup the buffers during the first _render, now we
-      # just need to re-bind them to render again
-      #
-      gl.glBindBufferARB(gl.GL_ARRAY_BUFFER_ARB,         self._vertBuffer)
-      gl.glBindBufferARB(gl.GL_ELEMENT_ARRAY_BUFFER_ARB, self._elmtBuffer) 
-      #
-    else:
-      #
-      # This is the first render pass, so we need to setup the VBO
-      #
-      # First we'll populate _vert
+    #gl.glScalef(self._size,self._size,self._size)
+    #
+    ######################################
+    #
+    # Test if we've already setup the axis VBO
+    #
+    if self._vertBuffer :
       #
-      # X Axis.
-      _vert[0].px = 0.00          # \  Vertex 0
-      _vert[0].py = 0.00          #  } (0.0, 0.0, 0.0)
-      _vert[0].pz = 0.00          # /
-      _vert[0].cr = 1.00          # \
-      _vert[0].cg = 0.00          #  } Red
-      _vert[0].cb = 0.00          # /___________________________
-      _vert[1].px = 1.00          # \  Vertex 1
-      _vert[1].py = 0.00          #  } (1.0, 0.0, 0.0)
-      _vert[1].pz = 0.00          # /
-      _vert[1].cr = 1.00          # \
-      _vert[1].cg = 0.00          #  } Red
+      # Since we already setup the buffers during the first _render, now we
+      # just need to re-bind them to render again
+      #
+      gl.glBindBufferARB(gl.GL_ARRAY_BUFFER_ARB,         self._vertBuffer)
+      gl.glBindBufferARB(gl.GL_ELEMENT_ARRAY_BUFFER_ARB, self._elmtBuffer) 
+      #
+    else:
+      #
+      # This is the first render pass, so we need to setup the VBO
+      #
+      # First we'll populate _vert
+      #
+      # X Axis.
+      _vert[0].px = 0.00          # \  Vertex 0
+      _vert[0].py = 0.00          #  } (0.0, 0.0, 0.0)
+      _vert[0].pz = 0.00          # /
+      _vert[0].cr = 1.00          # \
+      _vert[0].cg = 0.00          #  } Red
+      _vert[0].cb = 0.00          # /___________________________
+      _vert[1].px = 1.00          # \  Vertex 1
+      _vert[1].py = 0.00          #  } (1.0, 0.0, 0.0)
+      _vert[1].pz = 0.00          # /
+      _vert[1].cr = 1.00          # \
+      _vert[1].cg = 0.00          #  } Red
       _vert[1].cb = 0.00          # /___________________________
 
-      _vert[2].px = 1.00          # \  Vertex 2
-      _vert[2].py = 0.30          #  } (1.0, 0.3, 0.0)
-      _vert[2].pz = 0.00          # /
-      _vert[2].cr = 1.00          # \
-      _vert[2].cg = 0.00          #  } Red
-      _vert[2].cb = 0.00          # /___________________________
-      _vert[3].px = 1.30          # \  Vertex 3
-      _vert[3].py = 0.00          #  } (1.3, 0.0, 0.0)
-      _vert[3].pz = 0.00          # /
-      _vert[3].cr = 1.00          # \
-      _vert[3].cg = 0.00          #  } Red
+      _vert[2].px = 1.00          # \  Vertex 2
+      _vert[2].py = 0.30          #  } (1.0, 0.3, 0.0)
+      _vert[2].pz = 0.00          # /
+      _vert[2].cr = 1.00          # \
+      _vert[2].cg = 0.00          #  } Red
+      _vert[2].cb = 0.00          # /___________________________
+      _vert[3].px = 1.30          # \  Vertex 3
+      _vert[3].py = 0.00          #  } (1.3, 0.0, 0.0)
+      _vert[3].pz = 0.00          # /
+      _vert[3].cr = 1.00          # \
+      _vert[3].cg = 0.00          #  } Red
       _vert[3].cb = 0.00          # /___________________________
 
-      _vert[4].px = 1.00          # \  Vertex 4
-      _vert[4].py = -.30          #  } (1.0, -0.3, 0.0)
-      _vert[4].pz = 0.00          # /
-      _vert[4].cr = 1.00          # \
-      _vert[4].cg = 0.00          #  } Red
+      _vert[4].px = 1.00          # \  Vertex 4
+      _vert[4].py = -.30          #  } (1.0, -0.3, 0.0)
+      _vert[4].pz = 0.00          # /
+      _vert[4].cr = 1.00          # \
+      _vert[4].cg = 0.00          #  } Red
       _vert[4].cb = 0.00          # /___________________________
 
-      # Y Axis
+      # Y Axis
       _vert[5]= _vert[0]          # Vertex 5 is the same as vertex 0
       _vert[5].cr = 0.0           # Except its not Red.
       _vert[5].cg = 1.0           # Its green.
 
-      _vert[6].px = 0.00          # \  Vertex 6
-      _vert[6].py = 1.00          #  } (0.0, 1.0, 0.0)
-      _vert[6].pz = 0.00          # /
-      _vert[6].cr = 0.00          # \
-      _vert[6].cg = 1.00          #  } Red
-      _vert[6].cb = 0.00          # /___________________________
-      _vert[7].px = 0.30          # \  Vertex 7
-      _vert[7].py = 1.00          #  } (0.3, 1.0, 0.0)
-      _vert[7].pz = 0.00          # /
-      _vert[7].cr = 0.00          # \
-      _vert[7].cg = 1.00          #  } Red
+      _vert[6].px = 0.00          # \  Vertex 6
+      _vert[6].py = 1.00          #  } (0.0, 1.0, 0.0)
+      _vert[6].pz = 0.00          # /
+      _vert[6].cr = 0.00          # \
+      _vert[6].cg = 1.00          #  } Red
+      _vert[6].cb = 0.00          # /___________________________
+      _vert[7].px = 0.30          # \  Vertex 7
+      _vert[7].py = 1.00          #  } (0.3, 1.0, 0.0)
+      _vert[7].pz = 0.00          # /
+      _vert[7].cr = 0.00          # \
+      _vert[7].cg = 1.00          #  } Red
       _vert[7].cb = 0.00          # /___________________________
 
-      _vert[8].px = 0.00          # \  Vertex 8
-      _vert[8].py = 1.30          #  } (0.0, 1.3, 0.0)
-      _vert[8].pz = 0.00          # /
-      _vert[8].cr = 0.00          # \
-      _vert[8].cg = 1.00          #  } Red
-      _vert[8].cb = 0.00          # /___________________________
-      _vert[9].px = -.30          # \  Vertex 9
-      _vert[9].py = 1.00          #  } (-0.3, 1.0, 0.0)
-      _vert[9].pz = 0.00          # /
-      _vert[9].cr = 0.00          # \
-      _vert[9].cg = 1.00          #  } Red
+      _vert[8].px = 0.00          # \  Vertex 8
+      _vert[8].py = 1.30          #  } (0.0, 1.3, 0.0)
+      _vert[8].pz = 0.00          # /
+      _vert[8].cr = 0.00          # \
+      _vert[8].cg = 1.00          #  } Red
+      _vert[8].cb = 0.00          # /___________________________
+      _vert[9].px = -.30          # \  Vertex 9
+      _vert[9].py = 1.00          #  } (-0.3, 1.0, 0.0)
+      _vert[9].pz = 0.00          # /
+      _vert[9].cr = 0.00          # \
+      _vert[9].cg = 1.00          #  } Red
       _vert[9].cb = 0.00          # /___________________________
 
       # Z Axis
-      _vert[10] = _vert[0]
-      _vert[10].cr = 0.00          # \
+      _vert[10] = _vert[0]
+      _vert[10].cr = 0.00          # \
       _vert[10].cb = 1.00          # /___________________________
 
-      _vert[11].px = 0.00          # \  Vertex 11
-      _vert[11].py = 0.00          #  } (0.0, 1.3, 0.0)
-      _vert[11].pz = 1.00          # /
-      _vert[11].cr = 0.00          # \
-      _vert[11].cg = 0.00          #  } Red
+      _vert[11].px = 0.00          # \  Vertex 11
+      _vert[11].py = 0.00          #  } (0.0, 1.3, 0.0)
+      _vert[11].pz = 1.00          # /
+      _vert[11].cr = 0.00          # \
+      _vert[11].cg = 0.00          #  } Red
       _vert[11].cb = 1.00          # /___________________________
-
-      _vert[12].px = 0.30          # \  Vertex 12
-      _vert[12].py = 0.00          #  } (-0.3, 1.0, 0.0)
-      _vert[12].pz = 1.00          # /
-      _vert[12].cr = 0.00          # \
-      _vert[12].cg = 0.00          #  } Red
+
+      _vert[12].px = 0.30          # \  Vertex 12
+      _vert[12].py = 0.00          #  } (-0.3, 1.0, 0.0)
+      _vert[12].pz = 1.00          # /
+      _vert[12].cr = 0.00          # \
+      _vert[12].cg = 0.00          #  } Red
       _vert[12].cb = 1.00          # /___________________________
 
-      _vert[13].px = 0.00          # \  Vertex 13
-      _vert[13].py = 0.00          #  } (0.0, 1.3, 0.0)
-      _vert[13].pz = 1.30          # /
-      _vert[13].cr = 0.00          # \
-      _vert[13].cg = 0.00          #  } Red
-      _vert[13].cb = 1.00          # /___________________________
-      _vert[14].px = -.30          # \  Vertex 14
-      _vert[14].py = 0.00          #  } (-0.3, 1.0, 0.0)
-      _vert[14].pz = 1.00          # /
-      _vert[14].cr = 0.00          # \
-      _vert[14].cg = 0.00          #  } Red
+      _vert[13].px = 0.00          # \  Vertex 13
+      _vert[13].py = 0.00          #  } (0.0, 1.3, 0.0)
+      _vert[13].pz = 1.30          # /
+      _vert[13].cr = 0.00          # \
+      _vert[13].cg = 0.00          #  } Red
+      _vert[13].cb = 1.00          # /___________________________
+      _vert[14].px = -.30          # \  Vertex 14
+      _vert[14].py = 0.00          #  } (-0.3, 1.0, 0.0)
+      _vert[14].pz = 1.00          # /
+      _vert[14].cr = 0.00          # \
+      _vert[14].cg = 0.00          #  } Red
       _vert[14].cb = 1.00          # /___________________________
 
       # TODO optional tags. I left them out because they're not all that useful
       # and take up another 15+ verticies.. maybe when we can define verticies 
more easily.
-      
-
-      #
-      # Next populate _elmt
-      #
-      _elmt[0].a = 0              # Line 0: 0-1
+      
+
+      #
+      # Next populate _elmt
+      #
+      _elmt[0].a = 0              # Line 0: 0-1
       _elmt[0].b = 1              # ____________________________
 
-      _elmt[1].a = 2              # Line 1: 2-4
+      _elmt[1].a = 2              # Line 1: 2-4
       _elmt[1].b = 4              # ____________________________
 
-      _elmt[2].a = 2              # Line 2: 2-3
+      _elmt[2].a = 2              # Line 2: 2-3
       _elmt[2].b = 3              # ____________________________
 
-      _elmt[3].a = 3              # Line 3: 3-4
+      _elmt[3].a = 3              # Line 3: 3-4
       _elmt[3].b = 4              # ____________________________
 
-      _elmt[4].a = 5              # Line 4: 5-6
+      _elmt[4].a = 5              # Line 4: 5-6
       _elmt[4].b = 6              # ____________________________
 
-      _elmt[5].a = 7              # Line 5: 7-9
+      _elmt[5].a = 7              # Line 5: 7-9
       _elmt[5].b = 9              # ____________________________
 
-      _elmt[6].a = 8              # Line 6: 8-9
+      _elmt[6].a = 8              # Line 6: 8-9
       _elmt[6].b = 9              # ____________________________
 
-      _elmt[7].a = 8              # Line 7: 8-7
+      _elmt[7].a = 8              # Line 7: 8-7
       _elmt[7].b = 7              # ____________________________
 
-      _elmt[8].a = 10             # Line 8: 10-11
+      _elmt[8].a = 10             # Line 8: 10-11
       _elmt[8].b = 11             # ____________________________
 
-      _elmt[9].a = 14             # Line 9: 14-12
+      _elmt[9].a = 14             # Line 9: 14-12
       _elmt[9].b = 12             # ____________________________
 
-      _elmt[10].a = 13            # Line 10: 13-12
+      _elmt[10].a = 13            # Line 10: 13-12
       _elmt[10].b = 12            # ____________________________
 
-      _elmt[11].a = 13            # Line 11: 13-14
+      _elmt[11].a = 13            # Line 11: 13-14
       _elmt[11].b = 14            # ____________________________
-
-      #
-      # Create new vertex buffer and send _vert
-      #
-      gl.glGenBuffersARB(1, &self._vertBuffer)
-      gl.glBindBufferARB(gl.GL_ARRAY_BUFFER_ARB, self._vertBuffer)
-      gl.glBufferDataARB(gl.GL_ARRAY_BUFFER_ARB, sizeof(_vert), _vert, 
-                         gl.GL_STATIC_DRAW_ARB)
-      #
-      # Do the same for the element buffer
-      #
-      gl.glGenBuffersARB(1, &self._elmtBuffer)
-      gl.glBindBufferARB(gl.GL_ELEMENT_ARRAY_BUFFER_ARB, self._elmtBuffer)
-      gl.glBufferDataARB(gl.GL_ELEMENT_ARRAY_BUFFER_ARB, sizeof(_elmt), _elmt,
+
+      #
+      # Create new vertex buffer and send _vert
+      #
+      gl.glGenBuffersARB(1, &self._vertBuffer)
+      gl.glBindBufferARB(gl.GL_ARRAY_BUFFER_ARB, self._vertBuffer)
+      gl.glBufferDataARB(gl.GL_ARRAY_BUFFER_ARB, sizeof(_vert), _vert, 
                          gl.GL_STATIC_DRAW_ARB)
-
-    #
-    ######################################
-    #
-    # Disable unused pointers
-    #
-    #   Unlike Mesh and most other models, Axis doesn't use normals or textures
-    #   so we need to turn these off while rendering an Axis
-    #
-    gl.glDisableClientState(gl.GL_NORMAL_ARRAY)         # No Normals
-    gl.glDisableClientState(gl.GL_TEXTURE_COORD_ARRAY)  # No Texture Coords
-    #
-    ######################################
-    #
-    # Enable color pointer
-    #
-    #   To get color data into the vertices without making three separate
-    #   rendering calls we turn on the color array while rendering
-    #
-    gl.glEnableClientState(gl.GL_COLOR_ARRAY) # We need to render with color 
arrays
-    #
+      #
+      # Do the same for the element buffer
+      #
+      gl.glGenBuffersARB(1, &self._elmtBuffer)
+      gl.glBindBufferARB(gl.GL_ELEMENT_ARRAY_BUFFER_ARB, self._elmtBuffer)
+      gl.glBufferDataARB(gl.GL_ELEMENT_ARRAY_BUFFER_ARB, sizeof(_elmt), _elmt,
+                         gl.GL_STATIC_DRAW_ARB)
+
+    #
+    ######################################
+    #
+    # Disable unused pointers
+    #
+    #   Unlike Mesh and most other models, Axis doesn't use normals or textures
+    #   so we need to turn these off while rendering an Axis
+    #
+    gl.glDisableClientState(gl.GL_NORMAL_ARRAY)         # No Normals
+    gl.glDisableClientState(gl.GL_TEXTURE_COORD_ARRAY)  # No Texture Coords
+    #
+    ######################################
+    #
+    # Enable color pointer
+    #
+    #   To get color data into the vertices without making three separate
+    #   rendering calls we turn on the color array while rendering
+    #
+    gl.glEnableClientState(gl.GL_COLOR_ARRAY) # We need to render with color 
arrays
+    #
     gl.glVertexPointer(3, gl.GL_FLOAT, sizeof(VertPC),  <gl.GLvoid *> 0)
-    gl.glColorPointer (3, gl.GL_FLOAT, sizeof(VertPC), <gl.GLvoid *> 0+12)
-    gl.glDisable(gl.GL_CULL_FACE)
-    gl.glDisable(gl.GL_DEPTH_TEST)
-    gl.glDisable(gl.GL_LIGHTING)
-    gl.glDrawElements(gl.GL_LINES, 24, gl.GL_UNSIGNED_BYTE, <gl.GLvoid *> 0)
-    gl.glEnable(gl.GL_LIGHTING)
-    gl.glEnable(gl.GL_DEPTH_TEST)
-    gl.glEnable(gl.GL_CULL_FACE) 
-    gl.glDisableClientState(gl.GL_COLOR_ARRAY)
-    gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY)
-    gl.glEnableClientState(gl.GL_NORMAL_ARRAY)
-    #
-    ######################################
-    #
-    # return to camera matrix
-    #
-    gl.glPopMatrix()
-    #
-    ######################################
-
+    gl.glColorPointer (3, gl.GL_FLOAT, sizeof(VertPC), <gl.GLvoid *> 0+12)
+    gl.glDisable(gl.GL_CULL_FACE)
+    gl.glDisable(gl.GL_DEPTH_TEST)
+    gl.glDisable(gl.GL_LIGHTING)
+    gl.glDrawElements(gl.GL_LINES, 24, gl.GL_UNSIGNED_BYTE, <gl.GLvoid *> 0)
+    gl.glEnable(gl.GL_LIGHTING)
+    gl.glEnable(gl.GL_DEPTH_TEST)
+    gl.glEnable(gl.GL_CULL_FACE) 
+    gl.glDisableClientState(gl.GL_COLOR_ARRAY)
+    gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY)
+    gl.glEnableClientState(gl.GL_NORMAL_ARRAY)
+    #
+    ######################################
+    #
+    # return to camera matrix
+    #
+    gl.glPopMatrix()
+    #
+    ######################################
+

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

Reply via email to