Author: ArcRiley Date: 2008-07-18 23:46:07 -0400 (Fri, 18 Jul 2008) New Revision: 1338
Modified: trunk/pysoy/include/soy.scenes.pxd trunk/pysoy/src/scenes/Landscape.pym Log: Ticket #929 : * renamed _heightmapTex to _pyMap (position y map) * added _tzMap (texcoord Z map, for materials) Modified: trunk/pysoy/include/soy.scenes.pxd =================================================================== --- trunk/pysoy/include/soy.scenes.pxd 2008-07-19 03:33:02 UTC (rev 1337) +++ trunk/pysoy/include/soy.scenes.pxd 2008-07-19 03:46:07 UTC (rev 1338) @@ -86,8 +86,9 @@ cdef float _width cdef float _height cdef float _depth + cdef soy.textures.Texture _pyMap + cdef soy.textures.Texture _tzMap cdef soy.materials.Material _material - cdef soy.textures.Texture _heightmapTex cdef gl.GLuint _buffer cdef gl.GLuint _elementbuffer cdef Vert* _vertArray Modified: trunk/pysoy/src/scenes/Landscape.pym =================================================================== --- trunk/pysoy/src/scenes/Landscape.pym 2008-07-19 03:33:02 UTC (rev 1337) +++ trunk/pysoy/src/scenes/Landscape.pym 2008-07-19 03:46:07 UTC (rev 1338) @@ -47,17 +47,21 @@ self._height = height self._depth = depth self.position = position + self._pyMap = heightmap self._material = mat self._heightfieldDataID = ode.dGeomHeightfieldDataCreate() - self._vertArray = <Vert *> py.PyMem_Malloc(heightmap._width*heightmap._height*16*4) - self._elementArray = <Face *> py.PyMem_Malloc(sizeof(Face)*(heightmap._width-1)*(heightmap._height-1)*2) + self._vertArray = <Vert *> py.PyMem_Malloc(self._pyMap._width * \ + self._pyMap._height * 16 * 4) + self._elementArray = <Face *> py.PyMem_Malloc(sizeof(Face) * + (self._pyMap._width -1) * \ + (self._pyMap._height-1) * 2) ode.dGeomHeightfieldDataBuildByte(self._heightfieldDataID, <unsigned char*> heightmap._texels, 0, # copy? self._width, # width self._depth, # depth - heightmap._width, # dataX - heightmap._height, # dataY + self._pyMap._width, # dataX + self._pyMap._height, # dataY 1.0 / 255.0 * self._height, # scale 0, # offset 4.0, # thick @@ -66,7 +70,6 @@ self._heightfieldDataID, 1) ode.dGeomSetPosition(self._geomID, self._position[0], self._position[1], self._position[2]) - self._heightmapTex = heightmap self._createArrays() def __dealloc__(self) : @@ -116,37 +119,37 @@ # They're used in determining edge collapses in LOD generation below. # _deltaCols = <float*> py.PyMem_Malloc(sizeof(float) * \ - self._heightmapTex._width * \ - self._heightmapTex._height) + self._pyMap._width * \ + self._pyMap._height) _deltaRows = <float*> py.PyMem_Malloc(sizeof(float) * \ - self._heightmapTex._width * \ - self._heightmapTex._height) + self._pyMap._width * \ + self._pyMap._height) # # Calculate positions and texcoords first - for _i from 0 <= _i < self._heightmapTex._height : - for _j from 0 <= _j < self._heightmapTex._width : - _offset = self._heightmapTex._width*_i+_j + 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._heightmapTex._width * self._width - self._vertArray[_offset].py = self._heightmapTex._texels[_offset] \ + self._pyMap._width * self._width + self._vertArray[_offset].py = self._pyMap._texels[_offset] \ / 255.0 * self._height self._vertArray[_offset].pz = <float> _i / \ - self._heightmapTex._height * self._depth + 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._heightmapTex._texels[_offset]/255.0 + self._vertArray[_offset].tz = self._pyMap._texels[_offset] / 255.0 # # Normals and tangents calculated second because they depend on position - for _i from 0 <= _i < self._heightmapTex._height : - for _j from 0 <= _j < self._heightmapTex._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 _normal2[0] = 0 _normal2[1] = 0 _normal2[2] = 0 - _offset = self._heightmapTex._width*_i+_j + _offset = self._pyMap._width * _i + _j # # for code cleanlyness, get the four verticies first as: # @@ -154,12 +157,12 @@ # |\| vector1 (b) = cb # a vector2 (a) = ca # - _a = _offset+self._heightmapTex._width + _a = _offset+self._pyMap._width _b = _offset+1 _c = _offset # # check if we are at either of two sides which only have 3 verts to calc - if _j+1 != self._heightmapTex._width and _i+1 != self._heightmapTex._height : + if _j+1 != self._pyMap._width and _i+1 != self._pyMap._height : # subtract the vertices to get vectors _v1[0] = self._vertArray[_c].px-self._vertArray[_b].px _v2[0] = self._vertArray[_c].px-self._vertArray[_a].px @@ -188,7 +191,7 @@ # |\| vector1 (b) = cb # b c vector2 (a) = ca # - _a = _offset-self._heightmapTex._width + _a = _offset-self._pyMap._width _b = _offset-1 _c = _offset # subtract the vertices to get vectors @@ -215,7 +218,10 @@ _normal[0] /= 2 _normal[1] /= 2 _normal[2] /= 2 - _length = math.sqrt(_normal[0]*_normal[0]+_normal[1]*_normal[1]+_normal[2]*_normal[2]) + _length = math.sqrt(_normal[0] * + _normal[0] + _normal[1] * + _normal[1] + _normal[2] * + _normal[2]) _normal[0] /= _length _normal[1] /= _length _normal[2] /= _length @@ -239,8 +245,8 @@ #and finally, set up the face array to make all of the triangles _currentLoop = 0 #loop through all of the quads in the grid - for _i from 0 <= _i < self._heightmapTex._height-1 : - for _j from 0 <= _j < self._heightmapTex._width-1 : + for _i from 0 <= _i < self._pyMap._height-1 : + for _j from 0 <= _j < self._pyMap._width-1 : # # for code cleanlyness, get the four verticies first as: # @@ -248,10 +254,10 @@ # |\| Tri 1 = abc # b-c Tri 2 = acd # - _a = _j + ( _i * self._heightmapTex._width) - _b = _j + ((_i+1) * self._heightmapTex._width) - _c = _j + ((_i+1) * self._heightmapTex._width) + 1 - _d = _j + ( _i * self._heightmapTex._width) + 1 + _a = _j + ( _i * self._pyMap._width) + _b = _j + ((_i+1) * self._pyMap._width) + _c = _j + ((_i+1) * self._pyMap._width) + 1 + _d = _j + ( _i * self._pyMap._width) + 1 # #create the upper left tri in the quad #verts are in counter clockwise direction @@ -274,12 +280,12 @@ gl.glGenBuffersARB(1, <gl.GLuint*> &self._buffer) # Create the vertex buffers gl.glBindBufferARB(gl.GL_ARRAY_BUFFER_ARB, <gl.GLuint> self._buffer) gl.glBufferDataARB(gl.GL_ARRAY_BUFFER_ARB, (sizeof(Vert)* - self._heightmapTex._width*self._heightmapTex._height), self._vertArray, + self._pyMap._width*self._pyMap._height), self._vertArray, gl.GL_STATIC_DRAW_ARB) gl.glGenBuffersARB(1, &self._elementbuffer) gl.glBindBufferARB(gl.GL_ELEMENT_ARRAY_BUFFER_ARB, self._elementbuffer) # Create the elements buffers gl.glBufferDataARB(gl.GL_ELEMENT_ARRAY_BUFFER_ARB, - sizeof(Face)*(self._heightmapTex._width-1)*(self._heightmapTex._height-1)*2, + sizeof(Face)*(self._pyMap._width-1)*(self._pyMap._height-1)*2, self._elementArray, gl.GL_STATIC_DRAW_ARB) @@ -321,8 +327,8 @@ #stdio.printf("%s","glDrawElements\n") while self._material._render(_pass,<float *>24,<float *>0): gl.glDrawElements (gl.GL_TRIANGLES, - (self._heightmapTex._width-1) * \ - (self._heightmapTex._height-1) * 2 * 3, + (self._pyMap._width-1) * \ + (self._pyMap._height-1) * 2 * 3, gl.GL_UNSIGNED_SHORT, <Face*> 0) _pass+=1 gl.glBindBufferARB(gl.GL_ARRAY_BUFFER_ARB, 0) _______________________________________________ PySoy-SVN mailing list PySoy-SVN@pysoy.org http://www.pysoy.org/mailman/listinfo/pysoy-svn