}   // end of c'tor

        public static void AddSmokeParticle(ref SharedSmokeEmitter.SmokeParticle p)
        {
            // Get the index formn the lifetime.
            int i = 0;

            while (p.lifetime > smokeMaxLife[i])
            {
                ++i;
            }
            Debug.Assert(i < kNumSmokes);

            smoke[i].AddParticle(ref p);
        }   // end of AddSmokeParticle()
示例#2
0
        public void AddSplashes(int numSplashes, Vector3 pos, Vector3 vel, float radius, Vector4 tint)
        {
            Vector3 ax0   = new Vector3(-vel.Y, vel.X, 0.0f);
            float   lenSq = ax0.LengthSquared();

            if (lenSq > 0)
            {
                ax0 *= (float)(1.0 / Math.Sqrt(lenSq));
            }
            else
            {
                ax0 = Vector3.UnitY;
            }
            Vector3 ax1   = Vector3.Normalize(Vector3.Cross(vel, ax0));
            float   speed = vel.Length();
            Vector3 ax2   = vel / speed;

            Random rnd = BokuGame.bokuGame.rnd;

            for (int i = 0; i < numSplashes; ++i)
            {
                SharedSmokeEmitter.SmokeParticle party = new SharedSmokeEmitter.SmokeParticle();

                float rnd0 = (float)(rnd.NextDouble() * 2.0 - 1.0);
                float rnd1 = (float)(rnd.NextDouble() * 2.0 - 1.0);
                float rnd2 = (float)(rnd.NextDouble() * 2.0 - 1.0) * 0.2f + 1.0f;

                Vector3 deviate = (ax0 * rnd0 + ax1 * rnd1);

                Vector3 pPos = pos + deviate * radius * 0.2f;

                Vector3 pVel = vel * rnd2 + deviate * speed * 0.2f;

                party.position     = pPos;
                party.velocity     = pVel;
                party.acceleration = gravity;
                party.startRadius  = radius * 0.2f;
                party.endRadius    = radius;
                party.rotationRate = 0.0f;
                party.lifetime     = maxAge;
                party.color        = tint;

                SharedEmitterManager.Splashes.AddParticle(ref party);
            }
        }
        }   // end of SparkEmitter AddSparks()

        /// <summary>
        /// Add in some explicit sparks.
        /// </summary>
        /// <param name="numSparks">How many</param>
        /// <param name="sparks">List of positions</param>
        /// <param name="vels">List of velocities (including speed)</param>
        /// <param name="minRadius">Starting size</param>
        /// <param name="maxRadius">Ending size</param>
        public void AddSparks(int numSparks, Vector3[] pos, Vector3[] vel, float minRadius, float maxRadius)
        {
            for (int i = 0; i < numSparks; i++)
            {
                Vector4 color = Vector4.One;

                SharedSmokeEmitter.SmokeParticle party = new SharedSmokeEmitter.SmokeParticle();
                party.position     = pos[i];
                party.velocity     = vel[i];
                party.acceleration = gravity;
                party.startRadius  = minRadius;
                party.endRadius    = maxRadius;
                party.rotationRate = 0.0f;
                party.lifetime     = maxAge;
                party.color        = color;

                SharedEmitterManager.Sparks.AddParticle(ref party);
            }
        }
示例#4
0
        }   // end of c'tor

        /// <summary>
        /// Create a new burst of Splashes.
        /// </summary>
        /// <param name="numSplashes">How many to create.</param>
        /// <param name="origin">Where the Splashes should originate from.</param>
        /// <param name="minRadius">Starting size.</param>
        /// <param name="maxRadius">Ending size.</param>
        /// <param name="speed">Initial speed of particles.  If this is bigger, a more spread burst is created.</param>
        /// <param name="color">Color used to tint the particles.  Generaly this should just be Vector4.One.</param>
        public void AddSplashes(int numSplashes, Vector3 origin, float minRadius, float maxRadius, float speed, Vector4 color)
        {
            Random rnd = BokuGame.bokuGame.rnd;

            for (int i = 0; i < numSplashes; i++)
            {
                Vector3 velocity = new Vector3((float)rnd.NextDouble() - (float)rnd.NextDouble(), (float)rnd.NextDouble() - (float)rnd.NextDouble(), (float)rnd.NextDouble() - (float)rnd.NextDouble());
                velocity *= speed;

                SharedSmokeEmitter.SmokeParticle party = new SharedSmokeEmitter.SmokeParticle();
                party.position     = origin;
                party.velocity     = velocity;
                party.acceleration = gravity;
                party.startRadius  = minRadius;
                party.endRadius    = maxRadius;
                party.rotationRate = 0.0f;
                party.lifetime     = maxAge;
                party.color        = color;

                SharedEmitterManager.Splashes.AddParticle(ref party);
            }
        }
        }   // end of AddSmokeParticle()

        public static void AddDistortedSmokeParticle(ref SharedSmokeEmitter.SmokeParticle p)
        {
            distortedSmoke.AddParticle(ref p);
        }   // end of AddDistortedSmokeParticle()
示例#6
0
        protected float partial = 0.0f; // Number of particles that need to be emitted.
        public override void Update()
        {
            // See if we've died.
            if (Dying)
            {
                // We don't need to wait for any particles to
                // go away since the shared emitter owns them.
                Active = false;
                RemoveFromManager();
            }

            if (emitting)
            {
                float  dt  = Time.GameTimeFrameSeconds;
                Random rnd = BokuGame.bokuGame.rnd;

                if (LinearEmission)
                {
                    Vector3 deltaPosition = position - PreviousPosition;
                    float   dist          = deltaPosition.Length();

                    partial += dist * EmissionRate / Scale;
                }
                else
                {
                    partial += dt * EmissionRate;
                }

                // Emit as many particles as needed this
                // frame to keep up with the emission rate.
                SharedSmokeEmitter.SmokeParticle particle = new SharedSmokeEmitter.SmokeParticle();
                while (partial >= 1.0f)
                {
                    // Pick a random position somewhere along the path covered this frame.
                    Vector3 pos = position - (position - PreviousPosition) * (float)rnd.NextDouble();
                    if (PositionJitter > 0.0f)
                    {
                        pos += PositionJitter * new Vector3((float)rnd.NextDouble() - (float)rnd.NextDouble(), (float)rnd.NextDouble() - (float)rnd.NextDouble(), (float)rnd.NextDouble() - (float)rnd.NextDouble());
                    }
                    float lifetime = MinLifetime + (float)rnd.NextDouble() * (MaxLifetime - MinLifetime);

                    // Fill in the particle data.
                    particle.position     = pos;
                    particle.velocity     = velocity;
                    particle.acceleration = Vector3.Zero;
                    particle.color        = Color;
                    particle.startRadius  = StartRadius * Scale;
                    particle.endRadius    = EndRadius * Scale;
                    float rotationRate = MaxRotationRate * (float)(rnd.NextDouble() - rnd.NextDouble());
                    particle.rotationRate = rotationRate;
                    particle.lifetime     = lifetime;
                    particle.flash        = Vector3.Zero;

                    if ((usage & Use.Regular) != 0)
                    {
                        SharedEmitterManager.AddSmokeParticle(ref particle);
                    }

                    partial -= 1.0f;
                }
            }

            PreviousPosition = position;
        }   // end of Update()