Beispiel #1
0
        public void Draw(Graphics graphics, RectangleD cameraBounds)
        {
            var particleBounds = new List <RectangleF>();

            foreach (Particle particle in _particles)
            {
                if (particle.IsActive)
                {
                    if (cameraBounds.Contains(particle.Position))
                    {
                        PointF localPoint = RenderUtils.WorldToScreen(particle.Position, cameraBounds);

                        particleBounds.Add(new RectangleF(localPoint.X, localPoint.Y, 1.5f, 1.5f));
                    }
                }
            }

            RenderUtils.DrawRectangles(graphics, particleBounds, Color.FromArgb(200, 255, 255, 0));
        }
Beispiel #2
0
        public Bitmap GenerateTexture(double sootRatio)
        {
            // Simple case for soot texture
            if (sootRatio > 0.99)
            {
                return(_sootTexture);
            }

            // Simple case for base texture
            if (sootRatio < 0.01)
            {
                return(_baseTexture);
            }

            // Otherwise blend
            // Build the main texture (a combination of base and soot)
            using (Graphics graphics = RenderUtils.GetContext(false, _sootBuffer))
            {
                graphics.DrawImage(_baseTexture, new Rectangle(0, 0, _sootBuffer.Width, _sootBuffer.Height));

                float[][] matrixAlpha =
                {
                    new float[] { 1, 0, 0,                0, 0 },
                    new float[] { 0, 1, 0,                0, 0 },
                    new float[] { 0, 0, 1,                0, 0 },
                    new float[] { 0, 0, 0, (float)sootRatio, 0 },
                    new float[] { 0, 0, 0,                0, 1 }
                };

                ColorMatrix colorMatrix = new ColorMatrix(matrixAlpha);

                ImageAttributes iaAlphaBlend = new ImageAttributes();
                iaAlphaBlend.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);

                graphics.DrawImage(_sootTexture, new Rectangle(0, 0, _sootBuffer.Width, _sootBuffer.Height), 0, 0,
                                   _sootBuffer.Width, _sootBuffer.Height, GraphicsUnit.Pixel, iaAlphaBlend);
            }

            return(_sootBuffer);
        }