Exemplo n.º 1
0
 /// <summary>
 /// A fire particle system
 /// </summary>
 /// <returns></returns>
 public static ParticleSystem3D CreateFireParticleSystem3D()
 {
     ParticleSystem3D pSystem = new ParticleSystem3D()
     {
         NumParticles = 500,
         MinColor = Color.Black,
         MaxColor = Color.Black,
         MinLife = TimeSpan.FromSeconds(3),
         MaxLife = TimeSpan.FromSeconds(5),
         LocalVelocity = new Vector3(0.0f, 3.0f, 0.0f),
         RandomVelocity = new Vector3(0.2f, 1.0f, 0.2f),
         MinSize = 40,
         MaxSize = 70,
         EndDeltaScale = 3f,
         EmitterSize = new Vector2(500),
         EmitterShape = ParticleSystem3D.Shape.Circle,
         InterpolationColors = new List<Color>() { Color.Red, Color.Orange },
         LinearColorEnabled = true,
         AlphaEnabled = true,
     };
     return pSystem;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Set the current settings to the particle system attached
        /// </summary>
        private void LoadParticleSystem()
        {
            this.random = WaveServices.Random;

            if (this.indexBuffer != null)
            {
                this.GraphicsDevice.DestroyIndexBuffer(this.indexBuffer);
            }

            if (this.vertexBuffer != null)
            {
                this.GraphicsDevice.DestroyVertexBuffer(this.vertexBuffer);
            }

            this.settings = this.System;
            this.numParticles = this.System.NumParticles;
            this.numPrimitives = this.numParticles * 2;
            this.numVertices = this.numParticles * 4;
            this.numIndices = this.numParticles * 6;
            this.particles = new Particle[this.numParticles];

            // Create Indexbuffer
            ushort[] indices = new ushort[this.numIndices];

            for (int i = 0; i < this.numParticles; i++)
            {
                indices[(i * 6) + 0] = (ushort)((i * 4) + 0);
                indices[(i * 6) + 1] = (ushort)((i * 4) + 2);
                indices[(i * 6) + 2] = (ushort)((i * 4) + 1);

                indices[(i * 6) + 3] = (ushort)((i * 4) + 0);
                indices[(i * 6) + 4] = (ushort)((i * 4) + 3);
                indices[(i * 6) + 5] = (ushort)((i * 4) + 2);
            }

            this.indexBuffer = new IndexBuffer(indices);
            this.GraphicsDevice.BindIndexBuffer(this.indexBuffer);

            // Initialize Particles
            for (int i = 0; i < this.numParticles; i++)
            {
                this.particles[i] = new Particle()
                {
                    Alive = true,
                    Life = TimeSpan.FromMilliseconds(this.random.NextDouble() * (this.numParticles * InitTimeMultipler)).TotalMilliseconds
                };
            }

            this.vertices = new VertexPositionColorTexture[this.numVertices];
            this.vertexBuffer = new DynamicVertexBuffer(VertexPositionColorTexture.VertexFormat);
            this.vertexBuffer.SetData(this.vertices, this.numVertices);
            this.GraphicsDevice.BindVertexBuffer(this.vertexBuffer);
        }
Exemplo n.º 3
0
 /// <summary>
 /// A fog particle system
 /// </summary>
 /// <returns></returns>
 public static ParticleSystem3D CreateFogParticleSystem3D()
 {
     ParticleSystem3D pSystem = new ParticleSystem3D()
        {
        NumParticles = 100,
        MinColor = Color.Black,
        MaxColor = Color.Black,
        MinLife = TimeSpan.FromSeconds(3),
        MaxLife = TimeSpan.FromSeconds(4),
        LocalVelocity = new Vector3(0.0f, 3.0f, 0.0f),
        RandomVelocity = new Vector3(0.2f, 1.0f, 0.2f),
        MinSize = 40,
        MaxSize = 70,
        EndDeltaScale = 3f,
        EmitterSize = new Vector2(500),
        EmitterShape = ParticleSystem3D.Shape.FillCircle,
        InterpolationColors = new List<Color>() { new Color(226, 207, 190), new Color(200, 153, 109), Color.Transparent },
        LinearColorEnabled = true,
        AlphaEnabled = true,
        };
     return pSystem;
 }
Exemplo n.º 4
0
 /// <summary>
 /// A vapor particle system
 /// </summary>
 /// <returns></returns>
 public static ParticleSystem3D CreateVaporParticleSystem3D()
 {
     ParticleSystem3D pSystem = new ParticleSystem3D()
     {
         NumParticles = 100,
         MinColor = Color.Black,
         MaxColor = Color.Black,
         MinLife = TimeSpan.FromSeconds(2),
         MaxLife = TimeSpan.FromSeconds(4),
         LocalVelocity = new Vector3(0.0f, 3.0f, 0.0f),
         RandomVelocity = new Vector3(10f, 10f, 10f),
         MinSize = 40,
         MaxSize = 50,
         EndDeltaScale = 10f,
         EmitterSize = new Vector2(100),
         EmitterShape = ParticleSystem3D.Shape.Rectangle,
         InterpolationColors = new List<Color>() { Color.White },
         LinearColorEnabled = true,
         AlphaEnabled = true,
     };
     return pSystem;
 }
Exemplo n.º 5
0
 /// <summary>
 /// A sparks particle system
 /// </summary>
 /// <returns></returns>
 public static ParticleSystem3D CreateSparksParticleSystem3D()
 {
     ParticleSystem3D pSystem = new ParticleSystem3D()
     {
         NumParticles = 800,
         MinColor = Color.White,
         MaxColor = Color.Yellow,
         LocalVelocity = new Vector3(10f, 10f, 10f),
         RandomVelocity = new Vector3(5f, 10f, 5f),
         MinLife = TimeSpan.FromSeconds(3),
         MaxLife = TimeSpan.FromSeconds(9),
         InitialAngle = 0.5f,
         MinRotateSpeed = 0.01f,
         MaxRotateSpeed = 0.05f,
         MinSize = 20,
         MaxSize = 80,
         EmitterSize = new Vector2(50, 0),
         Gravity = new Vector3(0f, -0.3f, 0f),
         InterpolationColors = new List<Color>() { Color.White, Color.Gray },
         LinearColorEnabled = true,
         AlphaEnabled = false,
     };
     return pSystem;
 }
Exemplo n.º 6
0
 /// <summary>
 /// A snow particle system
 /// </summary>
 /// <returns></returns>
 public static ParticleSystem3D CreateSnowParticleSystem3D()
 {
     ParticleSystem3D pSystem = new ParticleSystem3D()
       {
       NumParticles = 700,
       MinColor = Color.White,
       MaxColor = Color.Gray,
       LocalVelocity = new Vector3(0f, 0.1f, 0f),
       RandomVelocity = new Vector3(1f, 0.2f, 1f),
       MinLife = TimeSpan.FromSeconds(3),
       MaxLife = TimeSpan.FromSeconds(6),
       InitialAngle = 0.5f,
       MinRotateSpeed = 0.01f,
       MaxRotateSpeed = 0.05f,
       MinSize = 1,
       MaxSize = 4,
       EmitterShape = ParticleSystem3D.Shape.FillRectangle,
       EmitterSize = new Vector2(1200, 200),
       Gravity = new Vector3(0f, -0.1f, 0f),
       InterpolationColors = new List<Color>() { Color.White, Color.Gray },
       LinearColorEnabled = true,
       AlphaEnabled = false,
       CollisionBehavior = ParticleSystem3D.ParticleCollisionBehavior.Bounce,
       CollisionType = ParticleSystem3D.ParticleCollisionFlags.MinY,
       CollisionMinY = 0,
       Bounciness = 0.0f
       };
     return pSystem;
 }
        /// <summary>
        /// Set the current settings to the particle system attached
        /// </summary>
        private void LoadParticleSystem()
        {
            this.random = WaveServices.Random;

            if (this.mesh != null)
            {
                if (this.mesh.IndexBuffer != null)
                {
                    this.GraphicsDevice.DestroyIndexBuffer(this.mesh.IndexBuffer);
                }

                if (this.mesh.VertexBuffer != null)
                {
                    this.GraphicsDevice.DestroyVertexBuffer(this.mesh.VertexBuffer);
                }

                this.mesh = null;
            }

            this.settings = this.System;
            this.numParticles = this.System.NumParticles;
            this.numPrimitives = this.numParticles * 2;
            this.numVertices = this.numParticles * 4;
            this.numIndices = this.numParticles * 6;
            this.particles = new Particle[this.numParticles];

            // Create Indexbuffer
            ushort[] indices = new ushort[this.numIndices];

            for (int i = 0; i < this.numParticles; i++)
            {
                indices[(i * 6) + 0] = (ushort)((i * 4) + 0);
                indices[(i * 6) + 1] = (ushort)((i * 4) + 2);
                indices[(i * 6) + 2] = (ushort)((i * 4) + 1);

                indices[(i * 6) + 3] = (ushort)((i * 4) + 0);
                indices[(i * 6) + 4] = (ushort)((i * 4) + 3);
                indices[(i * 6) + 5] = (ushort)((i * 4) + 2);
            }

            IndexBuffer indexBuffer = new IndexBuffer(indices);

            // Initialize Particles
            for (int i = 0; i < this.numParticles; i++)
            {
                double life = (this.settings.EmitRate > 0) ? -1 : TimeSpan.FromSeconds(this.random.NextDouble() * (this.numParticles * InitTimeMultipler)).TotalSeconds;

                this.particles[i] = new Particle()
                {
                    Alive = true,
                    Life = life
                };
            }

            this.vertices = new VertexPositionNormalColorTexture[this.numVertices];
            DynamicVertexBuffer vertexBuffer = new DynamicVertexBuffer(VertexPositionNormalColorTexture.VertexFormat);
            vertexBuffer.SetData(this.vertices, this.numVertices);

            this.mesh = new Mesh(0, vertexBuffer.VertexCount, 0, indexBuffer.IndexCount / 3, vertexBuffer, indexBuffer, PrimitiveType.TriangleList)
            {
                DisableBatch = true
            };
        }
Exemplo n.º 8
0
        /// <summary>
        /// Creates a new explosion decorator
        /// </summary>
        /// <param name="name">The entity name</param>
        /// <param name="frame">The explosion frame </param>
        public ExplosionDecorator(string name, int frame)
        {
            this.particleSystems = new List<ParticleSystem3D>();

            this.entity = new Entity(name)
            .AddComponent(this.cachedTransform = new Transform3D())
            ;

            ParticleSystem3D particleSystem;
            var emitter1 = new Entity()
            .AddComponent(new Transform3D())
            .AddComponent(emitter = new Sound3DEmitter())
            .AddComponent(particleSystem = new ParticleSystem3D()
            {
                NumParticles = 25,
                EmitRate = 300000,
                MinLife = TimeSpan.FromSeconds(1),
                MaxLife = TimeSpan.FromSeconds(1.5),
                LocalVelocity = Vector3.Zero,
                RandomVelocity = Vector3.One * 0.7f,
                MinSize = 20,
                MaxSize = 25,
                MaxRotateSpeed = 0.025f,
                MinRotateSpeed = -0.055f,
                InitialAngle = MathHelper.TwoPi,
                EndDeltaScale = 2f,
                EmitterSize = new Vector2(4),
                EmitterShape = ParticleSystem3D.Shape.FillRectangle,
                InterpolationColors = new List<Color>() { Color.White, Color.White, Color.Black },
                LinearColorEnabled = true,
                Gravity = Vector3.Zero,
                Emit = false
            })
            .AddComponent(new ParticleSystemRenderer3D())
            .AddComponent(new MaterialsMap(new BasicMaterial("Content/Textures/Explosion/Explosion_1.png", DefaultLayers.Additive) { VertexColorEnabled = true }))
            ;

            this.particleSystems.Add(particleSystem);

            var emitter2 = new Entity()
            .AddComponent(new Transform3D())
            .AddComponent(particleSystem = new ParticleSystem3D()
            {
                NumParticles = 4,
                EmitRate = 300000,
                MinLife = TimeSpan.FromSeconds(0.2),
                MaxLife = TimeSpan.FromSeconds(0.3),
                LocalVelocity = Vector3.Zero,
                RandomVelocity = Vector3.One * 0.01f,
                MinSize = 30,
                MaxSize = 40,
                InitialAngle = MathHelper.TwoPi,
                MaxRotateSpeed = 0.1f,
                MinRotateSpeed = -0.1f,
                EndDeltaScale = 0.3f,
                EmitterSize = new Vector2(1),
                EmitterShape = ParticleSystem3D.Shape.FillRectangle,
                InterpolationColors = new List<Color>() { Color.White, Color.Black },
                LinearColorEnabled = true,
                Gravity = Vector3.Zero,
                Emit = false
            })
            .AddComponent(new ParticleSystemRenderer3D())
            .AddComponent(new MaterialsMap(new BasicMaterial("Content/Textures/Explosion/Explosion_3.png", DefaultLayers.Additive) { VertexColorEnabled = true }))
            ;

            this.particleSystems.Add(particleSystem);

            var emitter3 = new Entity()
            .AddComponent(new Transform3D())
            .AddComponent(particleSystem = new ParticleSystem3D()
            {
                NumParticles = 60,
                EmitRate = 300000,
                MinLife = TimeSpan.FromSeconds(2),
                MaxLife = TimeSpan.FromSeconds(2.4),
                LocalVelocity = Vector3.Zero,
                RandomVelocity = Vector3.One * 1f,
                MinSize = 0.7f,
                MaxSize = 0.7f,
                InitialAngle = MathHelper.TwoPi,
                Gravity = Vector3.Zero,
                EndDeltaScale = 1,
                EmitterSize = new Vector2(1),
                EmitterShape = ParticleSystem3D.Shape.FillRectangle,
                InterpolationColors = new List<Color>() { Color.White, Color.Black },
                LinearColorEnabled = true,
                Emit = false
            })
            .AddComponent(new ParticleSystemRenderer3D())
            .AddComponent(new MaterialsMap(new BasicMaterial("Content/Textures/Blaster.png", DefaultLayers.Additive) { VertexColorEnabled = true }))
            ;

            this.particleSystems.Add(particleSystem);

            var emitter4 = new Entity()
            .AddComponent(new Transform3D())
            .AddComponent(particleSystem = new ParticleSystem3D()
            {
                NumParticles = 15,
                EmitRate = 300000,
                MinLife = TimeSpan.FromSeconds(1.5),
                MaxLife = TimeSpan.FromSeconds(4),
                LocalVelocity = Vector3.Zero,
                RandomVelocity = Vector3.One * 0.2f,
                MinSize = 15,
                MaxSize = 20,
                MaxRotateSpeed = 0.015f,
                MinRotateSpeed = -0.015f,
                InitialAngle = MathHelper.TwoPi,
                EndDeltaScale = 2f,
                EmitterSize = new Vector2(4),
                EmitterShape = ParticleSystem3D.Shape.FillRectangle,
                AlphaEnabled = true,
                InterpolationColors = new List<Color>() { Color.White * 0.5f, Color.Black },

                LinearColorEnabled = true,

                Gravity = Vector3.Zero,
                Emit = false
            })
            .AddComponent(new ParticleSystemRenderer3D())
            .AddComponent(new MaterialsMap(new BasicMaterial("Content/Textures/Explosion/Explosion_5.png", DefaultLayers.Alpha) { VertexColorEnabled = true }))
            ;

            this.particleSystems.Add(particleSystem);

            Entity shockwave = new Entity("shockwave")
            .AddComponent(new Transform3D() { Rotation = new Vector3(0.3f, -0.2f, -0.4f)})
            .AddComponent(new Model("Content/Models/Plane.FBX"))
            .AddComponent(new ModelRenderer())
            .AddComponent(this.shockwave = new ShockwaveBehavior())
            .AddComponent(new MaterialsMap(new BasicMaterial("Content/Textures/Explosion/Explosion_4.png", DefaultLayers.Additive)))
            ;

            this.entity.AddChild(emitter1);
            this.entity.AddChild(emitter2);
            this.entity.AddChild(emitter3);
            this.entity.AddChild(emitter4);
            this.entity.AddChild(shockwave);

            this.entity.EntityInitialized += (s, e) =>
                {
                    var screenplay = this.entity.Scene.EntityManager.Find("ScreenplayManager").FindComponent<ScreenplayManager>();
                    screenplay.FrameEvent(frame, this.BayExplosion);
                };
        }