| 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 1358 2008-09-10 19:02:17Z DavidCzech $ |
|---|
| 19 | |
|---|
| 20 | cdef 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 |
|---|
| 31 | self._axis[1] = 0 |
|---|
| 32 | self._axis[2] = 0 |
|---|
| 33 | self._axis[3] = 1 |
|---|
| 34 | self._axis[4] = 0 |
|---|
| 35 | self._axis[5] = 0 |
|---|
| 36 | self._axis[6] = 1 |
|---|
| 37 | self._axis[7] = 0 |
|---|
| 38 | self._axis[8] = 0 |
|---|
| 39 | self._axis[9] = 1 |
|---|
| 40 | self._axis[10] = 0 |
|---|
| 41 | self._axis[11] = 0 |
|---|
| 42 | self._elements[0] = <char>0 |
|---|
| 43 | self._elements[1] = <char>1 |
|---|
| 44 | self._vertexBuffer = 0 |
|---|
| 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() |
|---|
| 70 | gl.glDisableClientState(gl.GL_TEXTURE_COORD_ARRAY); |
|---|
| 71 | gl.glDisableClientState(gl.GL_NORMAL_ARRAY); |
|---|
| 72 | gl.glEnableClientState(gl.GL_COLOR_ARRAY); # We need to render with color arrays |
|---|
| 73 | gl.glVertexPointer(3, gl.GL_FLOAT, 0,<gl.GLvoid *> 0); |
|---|
| 74 | gl.glColorPointer(3,gl.GL_FLOAT,3*sizeof(float),<gl.GLvoid *>0); |
|---|
| 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,1,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); |
|---|