Esempio n. 1
0
 public PatchGeomipmap(LandscapeGeomipmap landscape, Vector3 pos, Matrix rotation, int heightX, int heightZ, int patchSize, int mapSize, int mapDetail)
     : base(landscape.Scene, pos, rotation, Vector3.One)
 {
     this.landscape    = landscape;
     this.patchSize    = patchSize;
     this.mapSize      = mapSize;
     this.mapDetail    = mapDetail;
     this.vertexDetail = 1;
     this.xRatioFull   = 1.0f / (mapSize + 1);
     this.zRatioFull   = 1.0f / (mapSize + 1);
     this.xRatioPatch  = 16.0f / (patchSize + 1);
     this.zRatioPatch  = 16.0f / (patchSize + 1);
     // Store Patch offsets for the heightmap.
     setObject(pos.X, pos.Y, pos.Z);
     // Store pointer to first byte of the height data for this patch.
     this.heightX = heightX;
     this.heightZ = heightZ;
     //this.worldX = worldX;
     //this.worldZ = worldZ;
     maxHeight = landscape.getHeightMap(heightX, heightZ);
     indexX    = (heightX * mapSize) / (mapSize * patchSize);
     indexZ    = (heightZ * mapSize) / (mapSize * patchSize);
     // Initialize flags
     initVertexBuffer();
     drawIndexedPrimitives();
     calculateBoundingSphere();
 }
Esempio n. 2
0
        /// <summary>
        /// draw landscape in local space
        /// (fill vertex array with data)
        /// </summary>
        public override void drawIndexedPrimitives()
        {
            int   vertCount = 0;
            float x         = 0.0f;
            float z         = 0.0f;
            float xTex      = 0.0f;
            float zTex      = 0.0f;
            float xTexFull  = 0.0f;
            float zTexFull  = 0.0f;

            xTex     = 0.0f;
            zTex     = 0.0f;
            xTexFull = heightX * xRatioFull;
            zTexFull = heightZ * zRatioFull;
            for (int zDir = 0; zDir <= patchSize; zDir += vertexDetail)
            {
                for (int xDir = 0; xDir <= patchSize; xDir += vertexDetail)
                {
                    // just draw vertices once, rest does index buffer
                    indexedVerts[vertCount].Position.X = x;
                    indexedVerts[vertCount].Position.Z = z;

                    //save maximum height of patch for bounding box
                    float height = landscape.getHeightMap(heightX + xDir, heightZ + zDir);

                    if (maxHeight < height)
                    {
                        maxHeight = height * scale.Z;
                    }
                    indexedVerts[vertCount].Position.Y = height;

                    // normals for lightning
                    indexedVerts[vertCount].Normal.X = 0.0f;
                    indexedVerts[vertCount].Normal.Y = 1.0f;
                    indexedVerts[vertCount].Normal.Z = 0.0f;

                    //indexedVerts[vertCount].Color = Color.Red;
                    // base texture coords

                    indexedVerts[vertCount].TextureCoordinate.X = xTexFull;
                    indexedVerts[vertCount].TextureCoordinate.Y = zTexFull;

                    // detail texture coords
                    indexedVerts[vertCount].TextureCoordinate1.X = xTex;
                    indexedVerts[vertCount].TextureCoordinate1.Y = zTex;

                    x        += vertexDetail * landscape.Scale.X;
                    xTex     += xRatioPatch;
                    xTexFull += xRatioFull;
                    vertCount++;
                }
                z -= vertexDetail * landscape.Scale.Z;
                //zTex += vertexDetail * landscape.Scale.Z;
                zTex     += zRatioPatch;
                zTexFull += zRatioFull;
                xTex      = 0.0f;
                xTexFull  = heightX * xRatioFull;
                x         = 0.0f;
            }
            //skirt
            x        = 0.0f;
            z        = 0.0f;
            xTex     = 0.0f;
            zTex     = 0.0f;
            xTexFull = heightX * xRatioFull;
            zTexFull = heightZ * zRatioFull;
            for (int xDir = 0; xDir <= patchSize; xDir += vertexDetail)
            {
                indexedVerts[vertCount].Position.X = x;
                indexedVerts[vertCount].Position.Y = -1.0f;
                indexedVerts[vertCount].Position.Z = z;

                // base texture coords
                indexedVerts[vertCount].TextureCoordinate.X = xTexFull;
                indexedVerts[vertCount].TextureCoordinate.Y = zTexFull;
                // detail texture coords
                indexedVerts[vertCount].TextureCoordinate1.X = xTex;
                indexedVerts[vertCount].TextureCoordinate1.Y = zTex;

                x        += vertexDetail * landscape.Scale.X;
                xTex     += xRatioPatch;
                xTexFull += xRatioFull;
                vertCount++;
            }
            x        -= vertexDetail * landscape.Scale.X;
            xTex     -= xRatioPatch;
            xTexFull -= xRatioFull;
            for (int zDir = 0; zDir <= patchSize; zDir += vertexDetail)
            {
                indexedVerts[vertCount].Position.X = x;
                indexedVerts[vertCount].Position.Y = -1.0f;
                indexedVerts[vertCount].Position.Z = z;
                // base texture coords
                indexedVerts[vertCount].TextureCoordinate.X = xTexFull;
                indexedVerts[vertCount].TextureCoordinate.Y = zTexFull;
                // detail texture coords
                indexedVerts[vertCount].TextureCoordinate1.X = xTex;
                indexedVerts[vertCount].TextureCoordinate1.Y = zTex;

                z        -= vertexDetail * landscape.Scale.Z;
                zTex     += zRatioPatch;
                zTexFull += zRatioFull;
                vertCount++;
            }
            z        += vertexDetail * landscape.Scale.Z;
            zTex     -= zRatioPatch;
            zTexFull -= zRatioFull;
            for (int xDir = patchSize; xDir >= 0; xDir -= vertexDetail)
            {
                indexedVerts[vertCount].Position.X = x;
                indexedVerts[vertCount].Position.Y = -1.0f;
                indexedVerts[vertCount].Position.Z = z;
                // base texture coords
                indexedVerts[vertCount].TextureCoordinate.X = xTexFull;
                indexedVerts[vertCount].TextureCoordinate.Y = zTexFull;
                // detail texture coords
                indexedVerts[vertCount].TextureCoordinate1.X = xTex;
                indexedVerts[vertCount].TextureCoordinate1.Y = zTex;
                x        -= vertexDetail * landscape.Scale.X;
                xTex     -= xRatioPatch;
                xTexFull -= xRatioFull;
                vertCount++;
            }
            x        += vertexDetail * landscape.Scale.X;
            xTex     -= xRatioPatch;
            xTexFull -= xRatioFull;
            for (int zDir = patchSize; zDir >= 0; zDir -= vertexDetail)
            {
                indexedVerts[vertCount].Position.X = x;
                indexedVerts[vertCount].Position.Y = -1.0f;
                indexedVerts[vertCount].Position.Z = z;
                // base texture coords
                indexedVerts[vertCount].TextureCoordinate.X = xTexFull;
                indexedVerts[vertCount].TextureCoordinate.Y = zTexFull;
                // detail texture coords
                indexedVerts[vertCount].TextureCoordinate1.X = xTex;
                indexedVerts[vertCount].TextureCoordinate1.Y = zTex;
                z        += vertexDetail * landscape.Scale.Z;
                zTex     -= zRatioPatch;
                zTexFull -= zRatioFull;
                vertCount++;
            }
            //calculateNormals();
            vbIndexed.SetData <PositionNormalMultiTexture>(indexedVerts);
        }