Author: JonNeal Date: 2008-03-22 23:04:30 -0400 (Sat, 22 Mar 2008) New Revision: 1208
Modified: trunk/pysoy/src/scenes/Landscape.pxi trunk/pysoy/src/scenes/Planar.pxi trunk/pysoy/src/scenes/soy.scenes.pxd Log: Ticket #950: * Reorder soy.scenes.Plane and soy.scenes.Landscape * Cleaned up soy.scenes.Plane a bit and added some comments * Removed a few gl lines so soy can be imported without error Modified: trunk/pysoy/src/scenes/Landscape.pxi =================================================================== --- trunk/pysoy/src/scenes/Landscape.pxi 2008-03-22 18:43:26 UTC (rev 1207) +++ trunk/pysoy/src/scenes/Landscape.pxi 2008-03-23 03:04:30 UTC (rev 1208) @@ -24,6 +24,12 @@ This is a scene based on a heightmap. Accepts a heightmap and the width, depth, and heigth of it. ''' + + ############################################################################ + # + # Python functions + # + def __cinit__(self, heightmap, scale, width=1024, depth=1024, *args, **kw) : if not isinstance(soy.textures.Texture, heightmap) or heightmap._chans != 1 : raise TypeError('heightmap must be of type soy.textures.Texture and 1 channel.') @@ -39,16 +45,24 @@ self._heightmap = ode.dCreateHeightfield(self._spaceID, self._heightmapID, 1) - def __delalloc__(self) : + def __dealloc__(self) : ode.dGeomHeightfieldDataDestroy(self._heightmapID) + #gl.glDeleteBuffersARB(1, &self._buffer); + ############################################################################ + # + # General C functions + # + + cdef void _createBuffer(self) : + pass + #gl.glGenBuffersARB(1, &self._buffer) + #gl.glBindBufferARB(gl.GL_ARRAY_BUFFER_ARB, self._buffer) + #gl.glBufferDataARB(gl.GL_ARRAY_BUFFER_ARB, (sizeof(Vert)+4+12)*self._bufferAlloc, + # self._heightmap, gl.GL_STATIC_DRAW_ARB) + + cdef void _render(self) : pass - - cdef void _createBuffer(self) : - gl.glGenBuffersARB(1, &self._buffer) - gl.glBindBufferARB(gl.GL_ARRAY_BUFFER_ARB, self._buffer) - gl.glBufferDataARB(gl.GL_ARRAY_BUFFER_ARB, (sizeof(Vert)+4+12)*self._bufferAlloc, - self._heightmap, gl.GL_STATIC_DRAW_ARB) Modified: trunk/pysoy/src/scenes/Planar.pxi =================================================================== --- trunk/pysoy/src/scenes/Planar.pxi 2008-03-22 18:43:26 UTC (rev 1207) +++ trunk/pysoy/src/scenes/Planar.pxi 2008-03-23 03:04:30 UTC (rev 1208) @@ -23,45 +23,48 @@ cimport soy.materials -cdef Vert midpoint(Vert a,Vert b): - X = 0.5*(a.px+b.px) - Y = 0.5*(a.py+b.py) - Z = 0.5*(a.pz+b.pz) - cdef Vert res - res.px=X - res.py=Y - res.pz=Z - return res - cdef class Planar (Scene) : ''' Planar Scene This is a scene based on a collision plane of infinite size facing up in the direction of gravity. ''' - def __cinit__(self,offset=0,step=15, material=None, *args, **kw) : + + ############################################################################ + # + # Python functions + # + + def __cinit__(self, offset=0, step=15, material=None, *args, **kw) : + cdef int _i + cdef Vert _a, _b, _c, _d, _e, _f + self._offset = offset self._planeID = ode.dCreatePlane(self._spaceID, 0.0, 1.0, 0.0, self._offset) ode.dGeomSetCategoryBits(self._planeID,GeomScene) ode.dGeomSetData(self._planeID, <void*> self) - cdef Vert _a, _b, _c, _d, _e, _f - SIZE = 100 - self._verts[0].px = 0.0 ## A Big Triangle - self._verts[0].py = self._offset - self._verts[0].pz = SIZE + (ode.dSin(60)*SIZE)/2 - self._verts[1].px = ode.dCos(60)*SIZE - self._verts[1].py = self._offset - self._verts[1].pz = ode.dSin(60)*SIZE + (ode.dSin(60)*SIZE)/2 - self._verts[2].px = -ode.dCos(60)*SIZE - self._verts[2].py = self._offset - self._verts[2].pz = ode.dSin(60)*SIZE + (ode.dSin(60)*SIZE)/2 - self._faces[0].a = 0 - self._faces[0].b = 2 - self._faces[0].c = 1 - _a = self._verts[0] - _b = self._verts[1] - _c = self._verts[2] + + size = 100 + # + # Create the verts for the first, biggest triangle + self._verts[0].px = 0.0 + self._verts[0].py = self._offset + self._verts[0].pz = size + (ode.dSin(60)*size)/2 + self._verts[1].px = ode.dCos(60)*size + self._verts[1].py = self._offset + self._verts[1].pz = ode.dSin(60)*size + (ode.dSin(60)*size)/2 + self._verts[2].px = ode.dCos(60)*size + self._verts[2].py = self._offset + self._verts[2].pz = ode.dSin(60)*size + (ode.dSin(60)*size)/2 + # + # Provide array indices in order for the triangle face + self._faces[0].a = 0 + self._faces[0].b = 2 + self._faces[0].c = 1 + _a = self._verts[0] + _b = self._verts[1] + _c = self._verts[2] self._verts[0].tx = _a.px - ode.dFabs(_a.px) self._verts[0].ty = _a.pz - ode.dFabs(_a.pz) @@ -70,29 +73,40 @@ self._verts[2].tx = _c.px - ode.dFabs(_c.px) self._verts[2].ty = _c.pz - ode.dFabs(_c.pz) - cdef int _i for _i from 1 <= _i < step : - _d = midpoint(_a,_b) # We get the midpoints from the Big Triangle and create faces from them - _e = midpoint(_b,_c) - _f = midpoint(_c,_a) - _d.py =self._offset - _e.py =self._offset - _f.py =self._offset + # + # We get the midpoints from the smallest (encapsulating) triangle + # and create faces from them + _d = self._midpoint(_a,_b) + _e = self._midpoint(_b,_c) + _f = self._midpoint(_c,_a) + # + # Calculate the verts + _d.py = self._offset + _e.py = self._offset + _f.py = self._offset _d.tx = _d.px - ode.dFabs(_d.px) _d.ty = _d.pz - ode.dFabs(_d.pz) _e.tx = _e.px - ode.dFabs(_e.px) _e.ty = _e.pz - ode.dFabs(_e.pz) _f.tx = _f.px - ode.dFabs(_f.px) _f.ty = _f.pz - ode.dFabs(_f.pz) - self._verts[((_i*3)-2)+2] = _d - self._verts[((_i*3)-1)+2] = _e - self._verts[ (_i*3) +2] = _f - self._faces[_i].a = ((_i*3) -2)+2 # - self._faces[_i].b = ((_i*3)) +2 - self._faces[_i].c = ((_i*3) -1)+2 + # + # Set the verts for this triangle + self._verts[_i*3] = _d + self._verts[_i*3+1] = _e + self._verts[_i*3+2] = _f + # + # Provide array indices in order for the triangle face + self._faces[_i].a = _i*3 + self._faces[_i].b = _i*3+2 + self._faces[_i].c = _i*3+1 _a = _d _b = _e _c = _f + + # + # Set the material of the plane if isinstance(material, soy.materials.Material) : self._material = material elif material == None: @@ -101,31 +115,15 @@ raise TypeError('Must provide an instance of soy.materials.Material') - def __delalloc__(self) : + def __dealloc__(self) : ode.dGeomDestroy(self._planeID) - cdef void _render(self) : - #gl.glDisable(gl.GL_DEPTH_BUFFER) - self._material._coreBind() - - gl.glVertexPointer (3, gl.GL_FLOAT, 48, &self._verts[0].px) - gl.glNormalPointer ( gl.GL_FLOAT, 48, &self._verts[0].nx) - gl.glTexCoordPointer(3, gl.GL_FLOAT, 48, &self._verts[0].tx) - #cdef gl.GLfloat mtx[16] - #self._coreGetModelview(mtx) - #gl.glPushMatrix() - #gl.glMultMatrixf(mtx) - - gl.glDrawElements (gl.GL_TRIANGLES, 60, gl.GL_UNSIGNED_SHORT, - <unsigned short*> self._faces) - - #gl.glPopMatrix() - self._material._coreUnBind() - Scene._render(self) - #gl.glEnable(gl.GL_DEPTH_BUFFER) + ############################################################################ + # + # Properties + # - property material : def __get__(self) : return self._material @@ -146,22 +144,68 @@ An offset for the Y axis may be provided by a fourth value in the tuple. ''' def __get__(self) : - cdef ode.dVector3 grav - ode.dWorldGetGravity(self._worldID, grav) - return (grav[0], grav[1], grav[2]) + cdef ode.dVector3 _grav + ode.dWorldGetGravity(self._worldID, _grav) + return (_grav[0], _grav[1], _grav[2]) + def __set__(self, value) : - cdef ode.dVector3 normal - normal[0] = -(value[0]) - normal[1] = -(value[1]) - normal[2] = -(value[2]) + cdef ode.dVector3 _normal + if type(value) != list or type(value) != tuple : + raise TypeError("A tuple or list must be provided.") + _normal[0] = -(value[0]) + _normal[1] = -(value[1]) + _normal[2] = -(value[2]) + # + # If fourth value is provided, set the offset if len(value) == 4: - stdio.printf("4 Values! using the fourth one as offset") - print value[3] + #stdio.printf("4 Values! using the fourth one as offset") + #print value[3] self._offset = value[3] + # + # Now that we have all of the points set, destroy the old plane and + # make a new one with updated position. ode.dGeomDestroy(self._planeID) - ode.dNormalize3(normal) - self._planeID = ode.dCreatePlane(self._spaceID, normal[0],normal[1],normal[2], self._offset) + ode.dNormalize3(_normal) + self._planeID = ode.dCreatePlane(self._spaceID, _normal[0], _normal[1], _normal[2], self._offset) ode.dGeomSetCategoryBits(self._planeID,GeomScene) ode.dGeomSetData(self._planeID, <void*> self) ode.dWorldSetGravity(self._worldID, value[0], value[1], value[2]) + + ############################################################################ + # + # General C functions + # + + cdef void _render(self) : + #gl.glDisable(gl.GL_DEPTH_BUFFER) + self._material._coreBind() + + gl.glVertexPointer (3, gl.GL_FLOAT, 48, &self._verts[0].px) + gl.glNormalPointer ( gl.GL_FLOAT, 48, &self._verts[0].nx) + gl.glTexCoordPointer(3, gl.GL_FLOAT, 48, &self._verts[0].tx) + #cdef gl.GLfloat mtx[16] + #self._coreGetModelview(mtx) + #gl.glPushMatrix() + #gl.glMultMatrixf(mtx) + + gl.glDrawElements (gl.GL_TRIANGLES, 60, gl.GL_UNSIGNED_SHORT, + <unsigned short*> self._faces) + + #gl.glPopMatrix() + self._material._coreUnBind() + Scene._render(self) + #gl.glEnable(gl.GL_DEPTH_BUFFER) + + + cdef Vert _midpoint(self, Vert a, Vert b): + cdef Vert _res + # + # Get midpoint between two points, (a.x+b.x)/2, etc.. + x = 0.5*(a.px+b.px) + y = 0.5*(a.py+b.py) + z = 0.5*(a.pz+b.pz) + _res.px = x + _res.py = y + _res.pz = z + return _res Modified: trunk/pysoy/src/scenes/soy.scenes.pxd =================================================================== --- trunk/pysoy/src/scenes/soy.scenes.pxd 2008-03-22 18:43:26 UTC (rev 1207) +++ trunk/pysoy/src/scenes/soy.scenes.pxd 2008-03-23 03:04:30 UTC (rev 1208) @@ -78,7 +78,7 @@ cdef int _width cdef int _height cdef gl.GLuint _buffer - cdef void _createBuffer ( self ) + cdef void _createBuffer ( self ) cdef class Planar (Scene) : cdef ode.dGeomID _planeID @@ -86,3 +86,4 @@ cdef soy.materials.Material _material cdef Vert _verts[60] cdef Face _faces[40] + cdef Vert _midpoint(self, Vert, Vert) _______________________________________________ PySoy-SVN mailing list PySoy-SVN@pysoy.org http://www.pysoy.org/mailman/listinfo/pysoy-svn