예제 #1
0
        public void Render(DeviceContext context, VSBuffer cpuBuffer, Buffer vsBuffer)
        {
            if (!Draw)
            {
                return;
            }

            context.UpdateSubresource(ref cpuBuffer, vsBuffer);
            Camera.UpdatePosition();
            var matrix = Camera.InverseViewMatrix;

            for (int i = 0; i < Vertices.Length; i++)
            {
                var vec = Vector4.Transform(baseCubePositions[i], matrix);
                Vertices[i].Position = new Vector3(vec.X, vec.Y, vec.Z);
            }

            var vertexArray = Vertices.Select(x => x.ToVertex).ToArray();

            context.UpdateSubresource(vertexArray, vertexBuffer);

            context.InputAssembler.PrimitiveTopology = PrimitiveTopology.LineList;
            context.InputAssembler.SetIndexBuffer(indexBuffer, Format.R16_UInt, 0);
            context.InputAssembler.SetVertexBuffers(0, vertexBinding);
            context.DrawIndexed(24, 0, 0);
        }
예제 #2
0
        public void Render(DeviceContext context, VSBuffer cpuBuffer, Buffer vsBuffer)
        {
            if (!Draw)
            {
                return;
            }

            context.UpdateSubresource(ref cpuBuffer, vsBuffer);
            context.InputAssembler.PrimitiveTopology = PrimitiveTopology.LineList;
            context.InputAssembler.SetIndexBuffer(indexBuffer, Format.R16_UInt, 0);
            context.InputAssembler.SetVertexBuffers(0, vertexBinding);
            context.DrawIndexed(24, 0, 0);
        }
예제 #3
0
파일: Sphere.cs 프로젝트: Arnyev/SoftBody
        public void Render(DeviceContext context, VSBuffer cpuBuffer, Buffer vsBuffer)
        {
            if (!Draw)
            {
                return;
            }

            context.UpdateSubresource(ref cpuBuffer, vsBuffer);

            context.UpdateSubresource(triangleVertices, vertexBuffer);

            context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
            context.InputAssembler.SetIndexBuffer(triangleIndices, Format.R32_UInt, 0);
            context.InputAssembler.SetVertexBuffers(0, vertexBinding);
            context.DrawIndexed(triangleIndicesArray.Length, 0, 0);
        }
예제 #4
0
        public void Redraw()
        {
            context.ClearDepthStencilView(DepthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0);
            context.ClearRenderTargetView(renderTargetView, Color.White);

            var psBuffer = new PSBuffer();

            psBuffer.SurfaceColor  = new Vector4(0, 0, 1, 1);
            psBuffer.LightPosition = new Vector4(0, 100, 0, 1);
            context.UpdateSubresource(ref psBuffer, this.psBuffer);

            Camera.UpdatePosition();
            var vsBuffer = new VSBuffer();

            vsBuffer.View       = Camera.ViewMatrix;
            vsBuffer.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 3f, viewport.Width / (float)viewport.Height, 0.5f, 100f);
            vsBuffer.InvView    = Camera.InverseViewMatrix;
            vsBuffer.World      = Matrix.Identity;


            var now      = DateTime.Now;
            var timeDiff = now - lastComputeTime;

            lastComputeTime = now;

            for (int i = 0; i < 100; i++)
            {
                bezierCube.Update((float)timeDiff.TotalMilliseconds / 100000);
            }

            //bezierCube.Update((float)timeDiff.TotalMilliseconds / 1000);
            context.VertexShader.Set(_vertexShader);
            cube.Render(context, vsBuffer, this.vsBuffer);

            bezierCube.Render(context, vsBuffer, this.vsBuffer);
            boundingBox.Render(context, vsBuffer, this.vsBuffer);

            mesh.Render(context, vsBuffer, this.vsBuffer);
            sphere.Render(context, vsBuffer, this.vsBuffer);

            swapChain.Present(1, PresentFlags.None);
        }
예제 #5
0
        public void Render(DeviceContext context, VSBuffer cpuBuffer, Buffer vsBuffer)
        {
            context.VertexShader.Set(shader);
            var bezierPointsArray = bezierPoints.Cast <BezierCubeVertex>()
                                    .Select(x => new Vector4(x.Position, 1)).ToArray();

            context.UpdateSubresource(bezierPointsArray, bezierPointsBuffer);

            if (!Draw)
            {
                return;
            }

            context.UpdateSubresource(ref cpuBuffer, vsBuffer);

            context.UpdateSubresource(baseVertices, vertexBuffer);

            context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
            context.InputAssembler.SetIndexBuffer(triangleIndices, Format.R32_UInt, 0);
            context.InputAssembler.SetVertexBuffers(0, vertexBinding);
            context.DrawIndexed(triangleIndicesArray.Length, 0, 0);
        }
예제 #6
0
        public void Render(DeviceContext context, VSBuffer cpuBuffer, Buffer vsBuffer)
        {
            context.UpdateSubresource(ref cpuBuffer, vsBuffer);

            context.UpdateSubresource(GetAllTriangleVertices(), vertexBuffer);
            context.UpdateSubresource(GetBezierVertices(), springBuffer);

            if (DrawCube)
            {
                context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
                context.InputAssembler.SetIndexBuffer(triangleIndices, Format.R32_UInt, 0);
                context.InputAssembler.SetVertexBuffers(0, vertexBinding);
                context.DrawIndexed(triangleIndicesArray.Length, 0, 0);
            }
            if (DrawSprings)
            {
                context.InputAssembler.PrimitiveTopology = PrimitiveTopology.LineList;
                context.InputAssembler.SetIndexBuffer(springIndices, Format.R32_UInt, 0);
                context.InputAssembler.SetVertexBuffers(0, springBinding);
                context.DrawIndexed(springIndicesArray.Length, 0, 0);
            }
        }