Author: ArcRiley Date: 2008-07-19 02:11:55 -0400 (Sat, 19 Jul 2008) New Revision: 1341
Modified: trunk/pysoy/src/scenes/Landscape.pym Log: Ticket #929 : * prepping for tiled landscapes with right/bottom tiling edges Modified: trunk/pysoy/src/scenes/Landscape.pym =================================================================== --- trunk/pysoy/src/scenes/Landscape.pym 2008-07-19 05:29:37 UTC (rev 1340) +++ trunk/pysoy/src/scenes/Landscape.pym 2008-07-19 06:11:55 UTC (rev 1341) @@ -100,11 +100,12 @@ py.PyMem_Free(self._faceArray) # # Alloc new arrays - self._vertArray = <Vert *> py.PyMem_Malloc(self._pyMap._width * \ - self._pyMap._height * 16 * 4) + self._vertArray = <Vert *> py.PyMem_Malloc(16 * 4 * + (self._pyMap._width + 1)* + (self._pyMap._height + 1)) self._faceArray = <Quad *> py.PyMem_Malloc(sizeof(Quad) * - (self._pyMap._width -1) * \ - (self._pyMap._height-1)) + (self._pyMap._width) * + (self._pyMap._height)) ode.dGeomHeightfieldDataBuildByte(self._heightfieldDataID, <unsigned char*> self._pyMap._texels, 0, # copy? @@ -133,31 +134,58 @@ # # They're used in determining edge collapses in LOD generation below. # - _deltaCols = <float*> py.PyMem_Malloc(sizeof(float) * \ - self._pyMap._width * \ - self._pyMap._height) - _deltaRows = <float*> py.PyMem_Malloc(sizeof(float) * \ - self._pyMap._width * \ - self._pyMap._height) + _deltaCols = <float*> py.PyMem_Malloc(sizeof(float) * + (self._pyMap._width + 1) * + (self._pyMap._height + 1)) + _deltaRows = <float*> py.PyMem_Malloc(sizeof(float) * + (self._pyMap._width + 1) * + (self._pyMap._height + 1)) # # Calculate positions and texcoords first for _i from 0 <= _i < self._pyMap._height : for _j from 0 <= _j < self._pyMap._width : - _offset = self._pyMap._width*_i+_j - self._vertArray[_offset].px = <float> _j / \ - self._pyMap._width * self._width - self._vertArray[_offset].py = self._pyMap._texels[_offset] \ + _l = (self._pyMap._width + 1) * _i + _j + self._vertArray[_l].px = <float> _j / self._pyMap._width * self._width + self._vertArray[_l].py = self._pyMap._texels[_l] \ / 255.0 * self._height - self._vertArray[_offset].pz = <float> _i / \ - self._pyMap._height * self._depth + self._vertArray[_l].pz = <float> _i /self._pyMap._height * self._depth #all below need to be calculated CORRECTLY! - self._vertArray[_offset].tx = _j # * texture scale - self._vertArray[_offset].ty = _i # * texture scale - self._vertArray[_offset].tz = self._pyMap._texels[_offset] / 255.0 + self._vertArray[_l].tx = _j # * texture scale + self._vertArray[_l].ty = _i # * texture scale + self._vertArray[_l].tz = self._pyMap._texels[_l] / 255.0 # + # The right tiling edge (currently just 0) + for _i from 0 <= _i < self._pyMap._height : + _l = (self._pyMap._width + 1) * _i + self._pyMap._width + self._vertArray[_l].px = <float> self._width + self._vertArray[_l].py = 0.0 + self._vertArray[_l].pz = <float> _i / self._pyMap._height * self._depth + self._vertArray[_l].tx = self._pyMap._width + 1 # * texture scale + self._vertArray[_l].ty = <float> _i # * texture scale + self._vertArray[_l].tz = 0.0 + # + # The bottom tiling edge (currently just 0) + for _i from 0 <= _i < self._pyMap._width : + _l = (self._pyMap._width + 1) * self._pyMap._height + _i + self._vertArray[_l].px = <float> _i / self._pyMap._width * self._width + self._vertArray[_l].py = 0.0 + self._vertArray[_l].pz = <float> self._depth + self._vertArray[_l].tx = <float> _i # * texture scale + self._vertArray[_l].ty = self._pyMap._height + 1 # * texture scale + self._vertArray[_l].tz = 0.0 + # + # bottom-right tiling corner (currently 0) + _l = (self._pyMap._width + 1) * (self._pyMap._height + 1) + self._vertArray[_l].px = <float> self._width + self._vertArray[_l].py = 0.0 + self._vertArray[_l].pz = <float> self._height + self._vertArray[_l].tx = self._pyMap._width + 1 # * texture scale + self._vertArray[_l].ty = self._pyMap._height + 1 # * texture scale + self._vertArray[_l].tz = 0.0 + # # Normals and tangents calculated second because they depend on position - for _i from 0 <= _i < self._pyMap._height : - for _j from 0 <= _j < self._pyMap._width : + for _i from 0 <= _i <= self._pyMap._height : + for _j from 0 <= _j <= self._pyMap._width : _normal[0] = 0 _normal[1] = 0 _normal[2] = 0 @@ -256,22 +284,22 @@ self._vertArray[_offset].ux = _u[0] self._vertArray[_offset].uy = _u[1] self._vertArray[_offset].uz = _u[2] - - #and finally, set up the face array to make all of the triangles + # + # and finally, set up the face array to make all of the quads _l = 0 - #loop through all of the quads in the grid - for _i from 0 <= _i < self._pyMap._height-1 : - for _j from 0 <= _j < self._pyMap._width-1 : + # loop through all of the quads in the grid + for _i from 0 <= _i < self._pyMap._height : + for _j from 0 <= _j < self._pyMap._width : # # CCW winding order: # a--d # | | # b--c # - self._faceArray[_l].a = _j + ( _i * self._pyMap._width) - self._faceArray[_l].b = _j + ((_i+1) * self._pyMap._width) - self._faceArray[_l].c = _j + ((_i+1) * self._pyMap._width) + 1 - self._faceArray[_l].d = _j + ( _i * self._pyMap._width) + 1 + self._faceArray[_l].a = _j + ( _i * (self._pyMap._width+1)) + self._faceArray[_l].b = _j + ((_i+1) * (self._pyMap._width+1)) + self._faceArray[_l].c = _j + ((_i+1) * (self._pyMap._width+1)) + 1 + self._faceArray[_l].d = _j + ( _i * (self._pyMap._width+1)) + 1 _l += 1 # # Free previously alloc'ed delta arrays @@ -282,13 +310,17 @@ cdef void _createBuffer(self) : gl.glGenBuffersARB(1, <gl.GLuint*> &self._vertBuffer) # Create the vertex buffers gl.glBindBufferARB(gl.GL_ARRAY_BUFFER_ARB, <gl.GLuint> self._vertBuffer) - gl.glBufferDataARB(gl.GL_ARRAY_BUFFER_ARB, (sizeof(Vert)* - self._pyMap._width*self._pyMap._height), self._vertArray, - gl.GL_STATIC_DRAW_ARB) + gl.glBufferDataARB(gl.GL_ARRAY_BUFFER_ARB, + sizeof(Vert) * + (self._pyMap._width+1) * (self._pyMap._height+1), + self._vertArray, + gl.GL_STATIC_DRAW_ARB) gl.glGenBuffersARB(1, &self._faceBuffer) - gl.glBindBufferARB(gl.GL_ELEMENT_ARRAY_BUFFER_ARB, self._faceBuffer) # Create the elements buffers + # + # Create the face buffer + gl.glBindBufferARB(gl.GL_ELEMENT_ARRAY_BUFFER_ARB, self._faceBuffer) gl.glBufferDataARB(gl.GL_ELEMENT_ARRAY_BUFFER_ARB, - sizeof(Quad)*(self._pyMap._width-1)*(self._pyMap._height-1), + sizeof(Quad)*(self._pyMap._width)*(self._pyMap._height), self._faceArray, gl.GL_STATIC_DRAW_ARB) @@ -326,11 +358,9 @@ gl.glVertexPointer (3, gl.GL_FLOAT, sizeof(Vert),(<char *>NULL + (0))) #px py pz gl.glNormalPointer ( gl.GL_FLOAT, sizeof(Vert),(<char *>NULL + (12))) # nx ny nz gl.glTexCoordPointer(3, gl.GL_FLOAT, sizeof(Vert), (<char *> NULL + (24))) # tx ty tz - #gl.glDrawArrays(gl.GL_TRIANGLES, 0, self._verts) - #stdio.printf("%s","glDrawElements\n") while self._material._render(_pass, <float*> 24, <float*> 0) : gl.glDrawElements(gl.GL_QUADS, - (self._pyMap._width-1) * (self._pyMap._height-1) * 4, + self._pyMap._width * self._pyMap._height * 4, gl.GL_UNSIGNED_INT, <Quad*> 0) _pass+=1 _______________________________________________ PySoy-SVN mailing list PySoy-SVN@pysoy.org http://www.pysoy.org/mailman/listinfo/pysoy-svn