Beispiel #1
0
        private void BuildTerrainBuffers(IContext context)
        {
            const int pitch = 4;
            int width = _heightMap.Width / pitch;
            int height = _heightMap.Height / pitch;

            int vertexCount = (width + 1) * (height + 1);
            VertexDefinition.PositionTexture[] terrainVertices = new VertexDefinition.PositionTexture[vertexCount];
            for (int i = 0; i < (width + 1); i++)
                for (int j = 0; j < (height + 1); j++)
                    terrainVertices[j * (width + 1) + i] = new VertexDefinition.PositionTexture
                    {
                        position = new Vector3((-(width / 2) + i) * pitch, 0.0f, -(-(height / 2) + j) * pitch),
                        texture = new Vector2(((float)i / width), ((float)j / height))
                    };

            _terrainIndexCount = width * height * 6;
            uint[] terrainIndices = new uint[_terrainIndexCount];
            for (int i = 0; i < (height); i++)
                for (int j = 0; j < (width); j++)
                {
                    terrainIndices[(i * width + j) * 6] = (uint)(i * (width + 1) + j + 1); //Left top
                    terrainIndices[(i * width + j) * 6 + 1] = (uint)((i + 1) * (width + 1) + j); //Right bottom
                    terrainIndices[(i * width + j) * 6 + 2] = (uint)(i * (width + 1) + j); //Left bottom
                    terrainIndices[(i * width + j) * 6 + 3] = (uint)(i * (width + 1) + j + 1); //Left top
                    terrainIndices[(i * width + j) * 6 + 4] = (uint)((i + 1) * (width + 1) + j + 1); //Right top
                    terrainIndices[(i * width + j) * 6 + 5] = (uint)((i + 1) * (width + 1) + j); //Right bottom
                }
            _terrainVertexBuffer = Buffer.Create(context.DirectX.Device, BindFlags.VertexBuffer, terrainVertices);
            _terrainIndexBuffer = Buffer.Create(context.DirectX.Device, BindFlags.IndexBuffer, terrainIndices);
        }
Beispiel #2
0
 public PieChart(IContext context, string id, UniRectangle coordinates, int sliceNumber, Func<List<Tuple<CustomColor, double, string, string>>> valuesGenerator)
     : base(context, id, coordinates)
 {
     _sliceNumber = sliceNumber;
     _valuesGenerator = valuesGenerator;
     _shader = Context.Shaders.Get<Texture1DShader>();
     var vertices = new VertexDefinition.PositionTexture[_sliceNumber * 3];
     for (int i = 0; i < sliceNumber; i++)
     {
         Vector2 texture = new Vector2((0.5f + i)/_sliceNumber, 0.5f);
         vertices[i * 3] = new VertexDefinition.PositionTexture
         {
             texture = texture,
             position = new Vector3(0, 0, 0)
         };
         vertices[i * 3 + 1] = new VertexDefinition.PositionTexture
         {
             texture = texture,
             position = new Vector3((float)Math.Sin(i*(Math.PI * 2) / _sliceNumber), -(float)Math.Cos(i*(Math.PI * 2) / _sliceNumber), 0)
         };
         vertices[i * 3 + 2] = new VertexDefinition.PositionTexture
         {
             texture = texture,
             position = new Vector3((float)Math.Sin((i+1) * (Math.PI * 2) / _sliceNumber), -(float)Math.Cos((i+1) * (Math.PI * 2) / _sliceNumber), 0)
         };
     }
     _vertexBuffer = Buffer.Create(context.DirectX.Device, vertices,
         new BufferDescription
         {
             Usage = ResourceUsage.Dynamic,
             SizeInBytes = Utilities.SizeOf<VertexDefinition.PositionTexture>() * _sliceNumber * 3,
             BindFlags = BindFlags.VertexBuffer,
             CpuAccessFlags = CpuAccessFlags.Write,
             OptionFlags = ResourceOptionFlags.None,
             StructureByteStride = 0
         });
     _data = new List<PieChartInfo>
     {
         new PieChartInfo(_sliceNumber, new CustomColor(0.2f, 0.2f, 0.2f), "NA", "NA")
     };
     _colorTexture = GenerateTexture(Context, _sliceNumber);
 }
        public override void Update()
        {
            float[] xVertexCoordinates = { 0f, _fixedBorderRadius, Size.X - _fixedBorderRadius, Size.X };
            float[] yVertexCoordinates = { 0f, _fixedBorderRadius, Size.Y - _fixedBorderRadius, Size.Y };
            float[] xTextureCoordinates = { 0f, (float)_fixedBorderRadius / _texture.Width, 1f - (float)_fixedBorderRadius / _texture.Width, 1f };
            float[] yTextureCoordinates = { 0f, (float)_fixedBorderRadius / _texture.Height, 1f - (float)_fixedBorderRadius / _texture.Height, 1f };
            for (int x = 0; x < 4; x++)
                for (int y = 0; y < 4; y++)
                    _vertices[x*4+y]  = new VertexDefinition.PositionTexture
                    {
                        position = new Vector3(xVertexCoordinates[x], yVertexCoordinates[y], 0),
                        texture = new Vector2(xTextureCoordinates[x], yTextureCoordinates[y])
                    };

            DataStream mappedResource;
            DeviceContext.MapSubresource(VertexBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None,
                out mappedResource);
            mappedResource.WriteRange(_vertices);
            DeviceContext.UnmapSubresource(VertexBuffer, 0);
        }
Beispiel #4
0
        private void BuildWaterBuffers(IContext context)
        {
            const int waveRepeat = 5;
            const int vertexCount = 4;
            VertexDefinition.PositionTexture[] waterVertices = new VertexDefinition.PositionTexture[vertexCount];
            for (int i = 0; i < 2; i++)
                for (int j = 0; j < 2; j++)
                    waterVertices[j * 2 + i] = new VertexDefinition.PositionTexture
                    {
                        position = new Vector3((-(1 / 2) + i) * _heightMap.Width, 0.0f, -(-(1 / 2) + j) * _heightMap.Height),
                        texture = new Vector2(i, j)
                    };

            _waterIndexCount = 6;
            uint[] waterIndices = { 0, 3, 2, 0, 1, 3 };
            _waterVertexBuffer = Buffer.Create(context.DirectX.Device, BindFlags.VertexBuffer, waterVertices);
            _waterIndexBuffer = Buffer.Create(context.DirectX.Device, BindFlags.IndexBuffer, waterIndices);
        }
Beispiel #5
0
        public override void Update()
        {
            const float left = 0;
            float right = Size.X;
            const float top = 0;
            float bottom = Size.Y;

            _vertices[0] = new VertexDefinition.PositionTexture { position = new Vector3(left, top, 0.0f), texture = new Vector2(0,0)};
            _vertices[1] = new VertexDefinition.PositionTexture { position = new Vector3(right, bottom, 0.0f), texture = new Vector2(_textureRepeat.X, _textureRepeat.Y) };
            _vertices[2] = new VertexDefinition.PositionTexture { position = new Vector3(left, bottom, 0.0f), texture = new Vector2(0, _textureRepeat.Y) };
            _vertices[3] = new VertexDefinition.PositionTexture { position = new Vector3(right, top, 0.0f), texture = new Vector2(_textureRepeat.X, 0) };

            DataStream mappedResource;
                   _deviceContext.MapSubresource(VertexBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None,
                out mappedResource);
            mappedResource.WriteRange(_vertices);
            _deviceContext.UnmapSubresource(VertexBuffer, 0);
        }