source: src/models/Axis.pym @ 1327:70ca5f3a2970

Revision 1327:70ca5f3a2970, 5.7 KB checked in by David Czech <davidczech510@…>, 6 years ago (diff)

Ticket #969 : * Convertered most documentation from epydoc format to ReST Sphinx

  • Some Axis VBO debugging
Line 
1# PySoy's models.Axis class
2#
3# Copyright (C) 2006,2007,2008 PySoy Group
4#
5#  This program is free software; you can redistribute it and/or modify
6#  it under the terms of the GNU Affero General Public License as published
7#  by the Free Software Foundation, either version 3 of the License, or
8#  (at your option) any later version.
9#
10#  This program is distributed in the hope that it will be useful,
11#  but WITHOUT ANY WARRANTY; without even the implied warranty of
12#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13#  GNU Affero General Public License for more details.
14#
15#  You should have received a copy of the GNU Affero General Public License
16#  along with this program; if not, see http://www.gnu.org/licenses
17#
18# $Id: Axis.pym 1375 2008-11-11 05:45:21Z DavidCzech $
19
20cdef class Axis (Model) :
21  '''soy.models.Axis
22
23    This :class:`~soy.model.Model` renders a "XYZ axis" oriented to each
24    body it's attached to.  This is useful for debugging.
25  '''
26
27  ############################################################################
28  #
29  # WindowLoop Functions
30  #
31
32  cdef void _render(self, soy.bodies.Body _body) :
33    cdef VertPC      _vert[2]     # contains vertex position and color data
34    cdef Line        _elmt[1]     # contains indices to verts to render lines
35    cdef gl.GLfloat  _mtx[16]
36    cdef int a
37    #
38    ######################################
39    #
40    # get model's matrix
41    #
42    _mtx[0]  = _body._rotation[0]
43    _mtx[1]  = _body._rotation[4]
44    _mtx[2]  = _body._rotation[8]
45    _mtx[3]  = 0.0
46    _mtx[4]  = _body._rotation[1]
47    _mtx[5]  = _body._rotation[5]
48    _mtx[6]  = _body._rotation[9]
49    _mtx[7]  = 0.0
50    _mtx[8]  = _body._rotation[2]
51    _mtx[9]  = _body._rotation[6]
52    _mtx[10] = _body._rotation[10]
53    _mtx[11] = 0.0
54    _mtx[12] = _body._position[0]
55    _mtx[13] = _body._position[1]
56    _mtx[14] = _body._position[2]
57    _mtx[15] = 1.0
58    #
59    ######################################
60    #
61    # save Camera matix before transforming to the Axis' matrix
62    #
63    #gl.glPushMatrix()
64    #gl.glMultMatrixf(_mtx)
65    #
66    ######################################
67    #
68    # Test if we've already setup the axis VBO
69    #
70    if self._vertBuffer :
71      #
72      # Since we already setup the buffers during the first _render, now we
73      # just need to re-bind them to render again
74      #
75      gl.glBindBufferARB(gl.GL_ARRAY_BUFFER_ARB,         self._vertBuffer)
76      gl.glBindBufferARB(gl.GL_ELEMENT_ARRAY_BUFFER_ARB, self._elmtBuffer)
77      #
78    else:
79      #
80      # This is the first render pass, so we need to setup the VBO
81      #
82      # First we'll populate _vert
83      #
84      _vert[0].px = 0.00          # \
85      _vert[0].py = 0.00          #  } (0.0, 0.0, 0.0)
86      _vert[0].pz = 0.00          # /
87      _vert[0].cr = 1.00          # \
88      _vert[0].cg = 0.00          #  } Red
89      _vert[0].cb = 0.00          # /___________________________
90      _vert[1].px = 1.00          # \
91      _vert[1].py = 0.00          #  } (1.0, 0.0, 0.0)
92      _vert[1].pz = 0.00          # /
93      _vert[1].cr = 1.00          # \
94      _vert[1].cg = 0.00          #  } Red
95      _vert[1].cb = 0.00          # /___________________________
96
97      for a from 0 <= a <= 1 :
98        stdio.printf("Index: %d, px %f py %f pz %f cr %f cg %f cb %f\n",a,_vert[a].px,_vert[a].py,_vert[a].pz,_vert[a].cr,_vert[a].cg,_vert[a].cb)
99      #
100      # Next populate _elmt
101      #
102      _elmt[0].a = 0              # Line 0: 0-1
103      _elmt[0].b = 1              # ____________________________
104      #
105      # Create new vertex buffer and send _vert
106      #
107      gl.glGenBuffersARB(1, &self._vertBuffer)
108      gl.glBindBufferARB(gl.GL_ARRAY_BUFFER_ARB, self._vertBuffer)
109      gl.glBufferDataARB(gl.GL_ARRAY_BUFFER_ARB, sizeof(_vert), _vert,
110                         gl.GL_STATIC_DRAW_ARB)
111      #
112      # Do the same for the element buffer
113      #
114      gl.glGenBuffersARB(1, &self._elmtBuffer)
115      gl.glBindBufferARB(gl.GL_ARRAY_BUFFER_ARB, self._elmtBuffer)
116      gl.glBufferDataARB(gl.GL_ARRAY_BUFFER_ARB, sizeof(_elmt), _elmt,
117                         gl.GL_STATIC_DRAW_ARB)
118    #
119    ######################################
120    #
121    # Disable unused pointers
122    #
123    #   Unlike Mesh and most other models, Axis doesn't use normals or textures
124    #   so we need to turn these off while rendering an Axis
125    #
126    #gl.glDisableClientState(gl.GL_NORMAL_ARRAY)         # No Normals
127    #gl.glDisableClientState(gl.GL_TEXTURE_COORD_ARRAY)  # No Texture Coords
128    #
129    ######################################
130    #
131    # Enable color pointer
132    #
133    #   To get color data into the vertices without making three separate
134    #   rendering calls we turn on the color array while rendering
135    #
136    gl.glEnableClientState(gl.GL_COLOR_ARRAY) # We need to render with color arrays
137    #
138    gl.glVertexPointer(3, gl.GL_FLOAT, 0,  <gl.GLvoid *> 0)
139    gl.glNormalPointer  (    gl.GL_FLOAT, 0,<gl.GLvoid *> 0)  # nx ny nz
140    gl.glTexCoordPointer(3, gl.GL_FLOAT, 0,  <gl.GLvoid *> 0) # tx ty tz
141    gl.glColorPointer (3, gl.GL_FLOAT, 0, <gl.GLvoid *> 0)
142    gl.glDisable(gl.GL_CULL_FACE)
143    gl.glDisable(gl.GL_DEPTH_TEST)
144    gl.glDisable(gl.GL_LIGHTING)
145    gl.glDrawElements(gl.GL_LINES, 2, gl.GL_UNSIGNED_BYTE, <gl.GLvoid *> 0)
146    gl.glEnable(gl.GL_LIGHTING)
147    gl.glEnable(gl.GL_DEPTH_TEST)
148    gl.glEnable(gl.GL_CULL_FACE)
149    gl.glDisableClientState(gl.GL_COLOR_ARRAY)
150    #gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY)
151    #gl.glEnableClientState(gl.GL_NORMAL_ARRAY)
152    #
153    ######################################
154    #
155    # return to camera matrix
156    #
157    #gl.glPopMatrix()
158    #
159    ######################################
160
Note: See TracBrowser for help on using the repository browser.