Example #1
0
        public void Render()
        {
            if (!isRunning)
            {
                return;
            }

            Device device = this.Host.Device;

            if (device == null)
            {
                return;
            }

            device.InputAssembler.InputLayout       = this.ParticleLayout;
            device.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleStrip;

            ParticlePass.Apply();

            device.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(this.Particles, 32, 0));
            ParticleProjection.Set(new Vector2(Host.Width, Host.Height));
            ParticleCamera.Set(new Vector2(0, -PlayerShip.Instance.Position.Y));
            device.Draw(ParticleManager.particleList.Count, 0);

            device.InputAssembler.InputLayout       = this.ShapeLayout;
            device.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleStrip;

            ShapeCamera.Set(new Vector2(0, -PlayerShip.Instance.Position.Y));
            ShapeProjection.Set(new Vector2(Host.Width, Host.Height));

            foreach (Entity entity in EntityManager.Entities)
            {
                device.InputAssembler.SetVertexBuffers(0, entity.Shape.Buffer);

                ShapeColor.Set(entity.Color);
                ShapePosition.Set(new Vector3(entity.Position, entity.Orientation));

                ShapePass.Apply();
                device.Draw(entity.Shape.Vertices.Length * 2 + 2, 0);
            }

            if (Math.Abs(Profiles.Current.State.LinesPosition - PlayerShip.Instance.Position.Y) < Height)
            {
                device.InputAssembler.InputLayout       = this.LineLayout;
                device.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.PointList;

                device.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(LineBuffer, 8, 0));

                LineEffect.GetVariableByName("Step").AsScalar().Set(0.1f);
                LineEffect.GetVariableByName("Width").AsScalar().Set(2.0f / Width);
                LineEffect.GetVariableByName("Height").AsScalar().Set(1.0f - Math.Abs(Profiles.Current.State.LinesPosition - PlayerShip.Instance.Position.Y) / Height);
                LineEffect.GetVariableByName("Color").AsVector().Set(Color.Yellow);

                Vector4[] disturb = new Vector4[16];
                float     maxX = 0.05f, maxY = 0.02f;

                for (int i = 0; i < linesCount; i++)
                {
                    for (int k = 0; k < 16; k++)
                    {
                        disturb[k] = new Vector4(Rand.NextFloat(-maxX, maxX), Rand.NextFloat(-maxY, maxY), Rand.NextFloat(-maxX, maxX), Rand.NextFloat(-maxY, maxY));
                    }
                    LineEffect.GetVariableByName("Disturb").AsVector().Set(disturb);
                    LineEffect.GetTechniqueByIndex(0).GetPassByIndex(0).Apply();

                    device.Draw(1, i);
                }
            }
        }