source: src/models/Axis.pym @ 1313:dd5a9c7d7704

Revision 1313:dd5a9c7d7704, 3.6 KB checked in by David Czech <davidczech510@…>, 6 years ago (diff)
  • No Ticket : Just Commenting
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 1359 2008-09-10 23:36:40Z DavidCzech $
19
20cdef class Axis (Model) :
21  '''soy.models.Axis
22
23    This L{models class<soy.models>} renders a "XYZ axis" oriented to each
24    body it's attached to.  This is useful for debugging.
25  '''
26  def __cinit__( self ) :
27    #self._axis = <gl.GLfloat *> ( 0,0,0,      1,0,0, # format XYZRGB
28    #              1,0,0,      1,0,0 )
29    #              # 1.,0.3,0.   1,0,0
30    self._axis[0] =  0    # Vertex 1 PX
31    self._axis[1] = 0     #py
32    self._axis[2] = 0     #pz
33    self._axis[3] = 1     #Vertex 1 Color R
34    self._axis[4] = 0     #G
35    self._axis[5] = 0     #B
36    self._axis[6] = 1     #Vertex 2 PX
37    self._axis[7] = 0     #PY
38    self._axis[8] = 0     #PZ
39    self._axis[9] = 1     #R
40    self._axis[10] = 0    #G
41    self._axis[11] = 0    #B
42    self._elements[0] = <char>0#Start at vertex 1
43    self._elements[1] = <char>1#End at vertex 2
44    self._vertexBuffer  = 0 # BufferIDs
45    self._elementBuffer = 0
46    # Generate Buffers
47
48  cdef void _createBuffer(self) :
49    gl.glGenBuffersARB(1, <gl.GLuint*> &self._vertexBuffer);
50    gl.glBindBufferARB(gl.GL_ARRAY_BUFFER_ARB, self._vertexBuffer);
51    gl.glBufferDataARB(gl.GL_ARRAY_BUFFER_ARB,sizeof(self._axis) , self._axis, gl.GL_STATIC_DRAW_ARB);
52    gl.glGenBuffersARB(1, <gl.GLuint*> &self._elementBuffer);
53    gl.glBindBufferARB(gl.GL_ARRAY_BUFFER_ARB, self._elementBuffer);
54    gl.glBufferDataARB(gl.GL_ARRAY_BUFFER_ARB, sizeof(self._elements), self._elements, gl.GL_STATIC_DRAW_ARB);
55
56  ############################################################################
57  #
58  # WindowLoop Functions
59  #
60
61  cdef void _render(self, soy.bodies.Body _body) :
62    #
63    # This should be upgraded to use VBO.  Test for buffer ID here.
64    #
65    if self._vertexBuffer :
66      gl.glBindBufferARB(gl.GL_ARRAY_BUFFER_ARB, <gl.GLuint> self._vertexBuffer) # Bind to buffer for rendering below
67      gl.glBindBufferARB(gl.GL_ELEMENT_ARRAY_BUFFER_ARB, self._elementBuffer)
68    else:
69      self._createBuffer() # No buffer, so create it
70    gl.glDisableClientState(gl.GL_TEXTURE_COORD_ARRAY); # No Texture Coords..
71    gl.glDisableClientState(gl.GL_NORMAL_ARRAY);        # or Normals either.
72    gl.glEnableClientState(gl.GL_COLOR_ARRAY); # We need to render with color arrays
73    gl.glVertexPointer(3, gl.GL_FLOAT, 0,<gl.GLvoid *> NULL);
74    gl.glColorPointer(3,gl.GL_FLOAT,3*sizeof(float),<gl.GLvoid *>NULL);
75    #gl.glPushMatrix()
76    gl.glDisable(gl.GL_CULL_FACE)
77    gl.glDisable(gl.GL_DEPTH_TEST)
78    gl.glDisable(gl.GL_LIGHTING)
79    gl.glDrawElements(gl.GL_LINES,2,gl.GL_UNSIGNED_BYTE,<gl.GLvoid *>0)
80    gl.glEnable(gl.GL_LIGHTING)
81    gl.glEnable(gl.GL_DEPTH_TEST)
82    gl.glEnable(gl.GL_CULL_FACE)
83    #gl.glPopMatrix()
84    gl.glDisableClientState(gl.GL_COLOR_ARRAY);
85    gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY);
86    gl.glEnableClientState(gl.GL_NORMAL_ARRAY);
Note: See TracBrowser for help on using the repository browser.