Update() public method

public Update ( ) : void
return void
Exemplo n.º 1
0
        /// <summary>
        /// Updates the Emitter's Position and Orientation according to its Velocities and Accelerations, and returns how many Particles should be emitted this frame.
        /// </summary>
        /// <param name="fElapsedTimeInSeconds">How long (in seconds) it has been since this function was called.</param>
        /// <returns>Returns the number of Particles that should be emitted.</returns>
        public int UpdateAndGetNumberOfParticlesToEmit(float fElapsedTimeInSeconds)
        {
            // Update the Emitter's Positional, Rotational, and Pivotal Data
            PositionData.Update(fElapsedTimeInSeconds);
            OrientationData.Update(fElapsedTimeInSeconds);
            PivotPointData.Update(fElapsedTimeInSeconds);

            // Calculate how many Particles should be generated

            // If Particles should be emitted
            int iNumberOfParticlesToEmit = 0;

            if (_particlesPerSecond > 0.0f && Enabled)
            {
                // If the Emitter is emitting Particles Automatically
                if (EmitParticlesAutomatically)
                {
                    // Get how many Particles should be emitted
                    iNumberOfParticlesToEmit = CalculateHowManyParticlesToEmit(fElapsedTimeInSeconds);
                }
                // Else if Burst Particles should be emitted for a specific amount of Time
                else if (_burstTimeInSeconds > 0.0f)
                {
                    // Make sure we do not emit Particles for too long
                    float fModifiedElapsedTime = fElapsedTimeInSeconds;
                    if (fModifiedElapsedTime > _burstTimeInSeconds)
                    {
                        // Only emit Particles for as long as the Burst lasts
                        fModifiedElapsedTime = _burstTimeInSeconds;
                    }

                    // Get how many Particles should be emitted
                    iNumberOfParticlesToEmit = CalculateHowManyParticlesToEmit(fModifiedElapsedTime);

                    // Subtract the Elapsed Time from the Burst Time
                    BurstTime -= fModifiedElapsedTime;
                }
                // Else if a specific Number Of Burst Particles should be emitted
                else if (_burstNumberOfParticles > 0)
                {
                    // Get how many Particles should be emitted
                    iNumberOfParticlesToEmit = CalculateHowManyParticlesToEmit(fElapsedTimeInSeconds);

                    // If we are emitting too many Particles
                    if (iNumberOfParticlesToEmit > _burstNumberOfParticles)
                    {
                        iNumberOfParticlesToEmit = _burstNumberOfParticles;
                    }

                    // Subtract the Number Of Particles being Emitted from the Number Of Particles that still need to be Emitted
                    BurstParticles -= iNumberOfParticlesToEmit;
                }
            }

            // Return how many Particles should be emitted
            return(iNumberOfParticlesToEmit);
        }