Author: ArcRiley
Date: 2008-09-11 01:50:16 -0400 (Thu, 11 Sep 2008)
New Revision: 1361

Modified:
   trunk/pysoy/src/models/Axis.pym
Log:
Ticket #963 :
  * added proper transformation code
  * more comments


Modified: trunk/pysoy/src/models/Axis.pym
===================================================================
--- trunk/pysoy/src/models/Axis.pym     2008-09-11 05:39:22 UTC (rev 1360)
+++ trunk/pysoy/src/models/Axis.pym     2008-09-11 05:50:16 UTC (rev 1361)
@@ -30,11 +30,42 @@
   #
 
   cdef void _render(self, soy.bodies.Body _body) :
-    cdef VertPC _vert[2]    # contains both vertex position and color data
-    cdef Line   _elmt[1]    # contains indices to verts to render lines
+    cdef VertPC      _vert[2]     # contains vertex position and color data
+    cdef Line        _elmt[1]     # contains indices to verts to render lines
+    cdef gl.GLfloat  _mtx[16]
     #
-    # This should be upgraded to use VBO.  Test for buffer ID here.
+    ######################################
     #
+    # 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.0
+    #
+    ######################################
+    #
+    # save Camera matix before transforming to the Axis' matrix
+    #
+    gl.glPushMatrix()
+    gl.glMultMatrixf(_mtx)
+    #
+    ######################################
+    #
+    # Test if we've already setup the axis VBO
+    #
     if self._vertBuffer :
       #
       # Since we already setup the buffers during the first _render, now we
@@ -81,16 +112,27 @@
       gl.glBufferDataARB(gl.GL_ARRAY_BUFFER_ARB, sizeof(_elmt), _elmt,
                          gl.GL_STATIC_DRAW_ARB)
     #
+    ######################################
+    #
     # Disable unused pointers
-    gl.glDisableClientState(gl.GL_TEXTURE_COORD_ARRAY)  # No Texture Coords..
-    gl.glDisableClientState(gl.GL_NORMAL_ARRAY)         # or Normals either.
     #
+    #   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
-    gl.glEnableClientState(gl.GL_COLOR_ARRAY); # We need to render with color 
arrays
-
+    #
+    #   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, 0,               <gl.GLvoid *> 0)
     gl.glColorPointer (3, gl.GL_FLOAT, sizeof(float)*3, <gl.GLvoid *> 0)
-    #gl.glPushMatrix()
     gl.glDisable(gl.GL_CULL_FACE)
     gl.glDisable(gl.GL_DEPTH_TEST)
     gl.glDisable(gl.GL_LIGHTING)
@@ -98,7 +140,15 @@
     gl.glEnable(gl.GL_LIGHTING)
     gl.glEnable(gl.GL_DEPTH_TEST)
     gl.glEnable(gl.GL_CULL_FACE) 
-    #gl.glPopMatrix()
     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