Exemple #1
0
        private void SetupTerrainVertexBuffer()
        {
            VertexTerrain[] verticesArray = new VertexTerrain[vertexList.Count];

            this.vertexList.CopyTo(verticesArray);

            this.vertexBuffer = new VertexBuffer(MapViewer.graphics.GraphicsDevice, VertexTerrain.SizeInBytes * vertexList.Count, BufferUsage.WriteOnly);
            this.vertexBuffer.SetData(verticesArray);
        }
Exemple #2
0
        public void SetupTerrainVertice(int x, int z)
        {
            VertexTerrain tempVert     = new VertexTerrain();
            float         offsetXtotal = (float)x;
            float         offsetZtotal = (float)z;

            tempVert.Position = new Vector3(offsetXtotal * scale,
                                            heightData[x, z],
                                            offsetZtotal * scale);

            tempVert.Normal = normals[x, z];

            this.vertexList[x * size + z] = tempVert;
        }
Exemple #3
0
        private void SetupTerrainVertices()
        {
            vertexList.Clear();

            // Texture the level
            for (int x = 0; x < size; x++)
            {
                for (int z = 0; z < size; z++)
                {
                    VertexTerrain tempVert     = new VertexTerrain();
                    float         offsetXtotal = (float)x;
                    float         offsetZtotal = (float)z;
                    tempVert.Position = new Vector3(offsetXtotal * scale,
                                                    heightData[x, z],
                                                    offsetZtotal * scale);

                    tempVert.Normal = normals[x, z];

                    this.vertexList.Add(tempVert);
                }
            }
        }
Exemple #4
0
        private void SetupNormals()
        {
            VertexTerrain[] terrainVertices = new VertexTerrain[this.size * this.size];
            this.normals = new Vector3[this.size, this.size];

            // Determine vertex positions so we can figure out normals in section below.
            for (int x = 0; x < this.size; ++x)
            {
                for (int z = 0; z < this.size; ++z)
                {
                    terrainVertices[x + z * this.size].Position = new Vector3(x * this.scale, this.heightData[x, z], z * this.scale);
                }
            }

            // Setup normals for lighting and physics (Credit: Riemer's method)
            int sizeMinusOne = this.size - 1;

            for (int x = 1; x < sizeMinusOne; ++x)
            {
                for (int z = 1; z < sizeMinusOne; ++z)
                {
                    int     ZTimesSize = (z * this.size);
                    Vector3 normX      = new Vector3((terrainVertices[x - 1 + ZTimesSize].Position.Y - terrainVertices[x + 1 + ZTimesSize].Position.Y) / 2, 1, 0);
                    Vector3 normZ      = new Vector3(0, 1, (terrainVertices[x + (z - 1) * this.size].Position.Y - terrainVertices[x + (z + 1) * this.size].Position.Y) / 2);

                    // We inline the normalize method here since it is used alot, this is faster than calling Vector3.Normalize()
                    Vector3 normal = normX + normZ;
                    float   length = (float)Math.Sqrt((float)((normal.X * normal.X) + (normal.Y * normal.Y) + (normal.Z * normal.Z)));
                    float   num    = 1f / length;
                    normal.X *= num;
                    normal.Y *= num;
                    normal.Z *= num;

                    this.normals[x, z] = terrainVertices[x + ZTimesSize].Normal = normal;    // Stored for use in physics and for the
                    // quad-tree component to reference.
                }
            }
        }
Exemple #5
0
        private void SetupTerrainVertices()
        {
            vertexList.Clear();

            // Texture the level
            Vector3 refPoint = new Vector3((float)size / 2f, 0f, (float)size / 2f);

            for (int x = 0; x < size; ++x)
            {
                for (int z = 0; z < size; ++z)
                {
                    VertexTerrain tempVert     = new VertexTerrain();
                    float         offsetXtotal = (float)x - refPoint.X;
                    float         offsetZtotal = (float)z - refPoint.Z;
                    tempVert.Position = new Vector3(offsetXtotal,
                                                    heightData[x, z],
                                                    offsetZtotal);

                    tempVert.Normal = normals[x, z];

                    this.vertexList.Add(tempVert);
                }
            }
        }
Exemple #6
0
        private void SetupTerrainVertices()
        {
            vertexList.Clear();

            // Texture the level
            for (int x = 0; x < size; x++)
                for (int z = 0; z < size; z++)
                {
                    VertexTerrain tempVert = new VertexTerrain();
                    float offsetXtotal = (float)x;
                    float offsetZtotal = (float)z;
                    tempVert.Position = new Vector3(offsetXtotal * scale,
                                                    heightData[x, z],
                                                    offsetZtotal * scale);

                    tempVert.Normal = normals[x, z];

                    this.vertexList.Add(tempVert);
                }
        }
Exemple #7
0
        private void SetupNormals()
        {
            VertexTerrain[] terrainVertices = new VertexTerrain[this.size * this.size];
            this.normals = new Vector3[this.size, this.size];

            // Determine vertex positions so we can figure out normals in section below.
            for (int x = 0; x < this.size; ++x)
                for (int z = 0; z < this.size; ++z)
                {
                    terrainVertices[x + z * this.size].Position = new Vector3(x * this.scale, this.heightData[x, z], z * this.scale);
                }

            // Setup normals for lighting and physics (Credit: Riemer's method)
            int sizeMinusOne = this.size - 1;
            for (int x = 1; x < sizeMinusOne; ++x)
                for (int z = 1; z < sizeMinusOne; ++z)
                {
                    int ZTimesSize = (z * this.size);
                    Vector3 normX = new Vector3((terrainVertices[x - 1 + ZTimesSize].Position.Y - terrainVertices[x + 1 + ZTimesSize].Position.Y) / 2, 1, 0);
                    Vector3 normZ = new Vector3(0, 1, (terrainVertices[x + (z - 1) * this.size].Position.Y - terrainVertices[x + (z + 1) * this.size].Position.Y) / 2);

                    // We inline the normalize method here since it is used alot, this is faster than calling Vector3.Normalize()
                    Vector3 normal = normX + normZ;
                    float length = (float)Math.Sqrt((float)((normal.X * normal.X) + (normal.Y * normal.Y) + (normal.Z * normal.Z)));
                    float num = 1f / length;
                    normal.X *= num;
                    normal.Y *= num;
                    normal.Z *= num;

                    this.normals[x, z] = terrainVertices[x + ZTimesSize].Normal = normal;    // Stored for use in physics and for the
                    // quad-tree component to reference.
                }
        }
Exemple #8
0
        public void SetupTerrainVertice(int x, int z)
        {
            VertexTerrain tempVert = new VertexTerrain();
            float offsetXtotal = (float)x;
            float offsetZtotal = (float)z;
            tempVert.Position = new Vector3(offsetXtotal * scale,
                                            heightData[x, z],
                                            offsetZtotal * scale);

            tempVert.Normal = normals[x, z];

            this.vertexList[x * size + z] = tempVert;
        }
Exemple #9
0
        public void SetupTerrainVertexBuffer()
        {
            VertexTerrain[] verticesArray = new VertexTerrain[vertexList.Count];

            this.vertexList.CopyTo(verticesArray);

            this.vertexBuffer = new VertexBuffer(MapViewer.graphics.GraphicsDevice, VertexTerrain.SizeInBytes * vertexList.Count, BufferUsage.WriteOnly);
            this.vertexBuffer.SetData(verticesArray);
        }
Exemple #10
0
        private void SetupTerrainVertices()
        {
            vertexList.Clear();

            // Texture the level
            Vector3 refPoint = new Vector3((float)size / 2f, 0f, (float)size / 2f);
            for (int x = 0; x < size; ++x)
                for (int z = 0; z < size; ++z)
                {
                    VertexTerrain tempVert = new VertexTerrain();
                    float offsetXtotal = (float)x - refPoint.X;
                    float offsetZtotal = (float)z - refPoint.Z;
                    tempVert.Position = new Vector3(offsetXtotal,
                                                    heightData[x, z],
                                                    offsetZtotal);

                    tempVert.Normal = normals[x, z];

                    this.vertexList.Add(tempVert);
                }
        }