Beispiel #1
0
        public Terrain(TerrainInfo heightfield)
        {
            info = heightfield;

            IndicesLength = new int[3];
            indexBuffer   = new Buffer[3];
            vertexBuffer  = new Buffer[3];


            RebuildTerrain(0, 1);

            normals = new Vector3[info.width * info.height];
            Vector3 normal;

            for (int i = 0; i < vertices.Length - info.width; i++)
            {
                Vector3 firstvec  = vertices[i + 1].Position - vertices[i].Position;
                Vector3 secondvec = vertices[i].Position - vertices[i + info.width].Position;

                normal = Vector3.Cross(firstvec, secondvec);
                normal.Normalize();

                normals[i]              += normal;
                normals[i + 1]          += normal;
                normals[i + info.width] += normal;
            }

            for (int i = 0; i < normals.Length; i++)
            {
                normals[i].Normalize();
                int potntialY = (int)Math.Floor((float)i / info.width);
                int potntialX = i - potntialY * info.width;
                info.normalData[potntialX, potntialY] = normals[i];
            }

            RebuildTerrain(1, 4);
            RebuildTerrain(2, 8);

            var buff = new TerrainConstant()
            {
                WaterColor  = info.waterColor,
                WaterHeight = info.waterLevel
            };

            objectBuffer = Buffer.Create(Display.device, ref buff, new BufferDescription(16 * 2, ResourceUsage.Immutable, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0));


            Initialize();
        }
Beispiel #2
0
        public void GenerateCB()
        {
            if (objectBuffer != null)
            {
                objectBuffer.Dispose();
            }

            var buff = new TerrainConstant()
            {
                WaterColor  = info.waterColor,
                WaterHeight = info.waterLevel
            };

            objectBuffer = Buffer.Create(Display.device, ref buff, new BufferDescription(16 * 2, ResourceUsage.Immutable, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0));
        }