Пример #1
0
        /// <summary>
        /// Example of how to create a Particle Initialization Function
        /// </summary>
        /// <param name="cParticle">The Particle to be Initialized</param>
        public void InitializeParticleProperties(DefaultTexturedQuadParticle cParticle)
        {
            //-----------------------------------------------------------
            // TODO: Initialize all of the Particle's properties here.
            // If you plan on simply using the default InitializeParticleUsingInitialProperties
            // Particle Initialization Function (see the LoadParticleSystem() function above),
            // then you may delete this function all together.
            //-----------------------------------------------------------

            // Set the Particle's Lifetime (how long it should exist for)
            cParticle.Lifetime = 2.0f;

            // Set the Particle's initial Position to be wherever the Emitter is
            cParticle.Position = Emitter.PositionData.Position;

            // Set the Particle's Velocity
            Vector3 sVelocityMin = new Vector3(-50, 50, -50);
            Vector3 sVelocityMax = new Vector3(50, 100, 50);

            cParticle.Velocity = DPSFHelper.RandomVectorBetweenTwoVectors(sVelocityMin, sVelocityMax);

            // Adjust the Particle's Velocity direction according to the Emitter's Orientation
            cParticle.Velocity = Vector3.Transform(cParticle.Velocity, Emitter.OrientationData.Orientation);

            // Give the Particle a random Size
            // Since we have Size Lerp enabled we must also set the Start and End Size
            cParticle.Width      = cParticle.StartWidth = cParticle.EndWidth =
                cParticle.Height = cParticle.StartHeight = cParticle.EndHeight = RandomNumber.Next(10, 50);

            // Give the Particle a random Color
            // Since we have Color Lerp enabled we must also set the Start and End Color
            cParticle.Color = cParticle.StartColor = cParticle.EndColor = DPSFHelper.RandomColor();
        }
Пример #2
0
        //===========================================================
        // Particle Update Functions
        //===========================================================

        //-----------------------------------------------------------
        // TODO: Place your Particle Update functions here, using the
        // same function prototype as below (i.e. public void FunctionName(DPSFParticle, float))
        //-----------------------------------------------------------

        /// <summary>
        /// Example of how to create a Particle Event Function
        /// </summary>
        /// <param name="cParticle">The Particle to update</param>
        /// <param name="fElapsedTimeInSeconds">How long it has been since the last update</param>
        protected void UpdateParticleFunctionExample(DefaultTexturedQuadParticle cParticle, float fElapsedTimeInSeconds)
        {
            // Place code to update the Particle here
            // Example: cParticle.Position += cParticle.Velocity * fElapsedTimeInSeconds;
            //cParticle.Position += cParticle.Velocity * fElapsedTimeInSeconds;
            // Effects expect a premultiplied color, so get the actual color to use.
        }
 public void SwipeParticle(DefaultTexturedQuadParticle particle, float elapsedTimeInSecconds)
 {
     if (!this.swipedParticles.Contains(particle))
     {
         this.swipedParticles.Add(particle);
         particle.Velocity = particle.Velocity + new Vector3((particle.ElapsedTime * 1.5f / particle.Lifetime) * 5 * this.LastSwipeDeltaX, 0, 0);
     }
 }
Пример #4
0
 //===========================================================
 // Particle Update Functions
 //===========================================================
 protected void UpdateParticleDieOnceGroundIsHit(DefaultTexturedQuadParticle cParticle, float fElapsedTimeInSeconds)
 {
     // If the Particle hits the ground
     if (cParticle.Position.Y < -5)
     {
         // Kill it
         cParticle.Lifetime = 1.0f;
     }
 }
Пример #5
0
 protected void UpdateParticleChangeVelocityAndRotation(DefaultTexturedQuadParticle cParticle, float fElapsedTimeInSeconds)
 {
     if (RandomNumber.Next(0, 100) == 50)
     {
         Vector3 sChange = new Vector3(RandomNumber.Next(-3, 3), RandomNumber.Next(-3, 3), RandomNumber.Next(-3, 3));
         cParticle.Velocity             += sChange;
         cParticle.RotationalVelocity.Z += RandomNumber.Between(-MathHelper.PiOver4, MathHelper.PiOver4);
     }
 }
 public void InitializeParticleProperties(DefaultTexturedQuadParticle cParticle)
 {
     cParticle.Lifetime = 2.0f;
     cParticle.Position = Emitter.PositionData.Position;
     Vector3 sVelocityMin = new Vector3(-50, 50, -50);
     Vector3 sVelocityMax = new Vector3(50, 100, 50);
     cParticle.Velocity = DPSFHelper.RandomVectorBetweenTwoVectors(sVelocityMin, sVelocityMax);
     cParticle.Velocity = Vector3.Transform(cParticle.Velocity, Emitter.OrientationData.Orientation);
     cParticle.Width = cParticle.StartWidth = cParticle.EndWidth =
     cParticle.Height = cParticle.StartHeight = cParticle.EndHeight = RandomNumber.Next(10, 50);
     cParticle.Color = cParticle.StartColor = cParticle.EndColor = DPSFHelper.RandomColor();
 }
Пример #7
0
        /// <summary>
        /// Initialize the properties of a particle.
        /// </summary>
        /// <param name="particle">Reference to the particle to be initialized.</param>
        public void InitializeParticleProperties(DefaultTexturedQuadParticle particle)
        {
            // Set the Particle's Lifetime (how long it should exist for) and initial Position
            particle.Lifetime = 5;
            particle.Position = Emitter.PositionData.Position;

            // Give the Particle a random velocity direction to start with
            particle.Velocity = DPSFHelper.RandomNormalizedVector() * 0.5f;

            particle.Size  = 0.2f;
            particle.Color = Color.Red;
        }
Пример #8
0
        protected void AttractParticleToExternalObject(DefaultTexturedQuadParticle cParticle, float fElapsedTimeInSeconds)
        {
            // Calculate Direction towards the Object and how far the Particle is from the Object
            Vector3 sDirectionTowardsObject = mcExternalObjectPosition - cParticle.Position;
            float   fDistance = sDirectionTowardsObject.Length();

            // If the Particle is close enough to the Object to be affected by it
            if (fDistance < mfAttractRepelRange)
            {
                // Attract the Particle to the Object
                sDirectionTowardsObject.Normalize();
                cParticle.Velocity = sDirectionTowardsObject * (mfAttractRepelRange - fDistance) * mfAttractRepelForce;
            }
        }
Пример #9
0
        // Used to generate smoke coming off the ring of fire
        public void InitializeSmokeRingParticle(DefaultTexturedQuadParticle cParticle)
        {
            cParticle.Lifetime = RandomNumber.Between(1.0f, 5.0f);

            cParticle.Position = new Vector3(0, 10, 0);
            cParticle.StartSize = RandomNumber.Next(10, 40);
            cParticle.EndSize = RandomNumber.Next(20, 60);
            cParticle.Size = cParticle.StartSize;
            cParticle.Color = Color.AliceBlue;
            cParticle.Orientation = Orientation3D.Rotate(Matrix.CreateRotationZ(RandomNumber.Between(0, MathHelper.TwoPi)), cParticle.Orientation);

            cParticle.Velocity = new Vector3(RandomNumber.Next(0, 30), RandomNumber.Next(10, 30), RandomNumber.Next(-20, 10));
            cParticle.Acceleration = Vector3.Zero;
            cParticle.RotationalVelocity.Z = RandomNumber.Between(-MathHelper.Pi, MathHelper.Pi);
        }
Пример #10
0
        public void InitializeParticleTrail(DefaultTexturedQuadParticle cParticle)
        {
            cParticle.Lifetime = 4.0f;

            cParticle.Position = Emitter.PositionData.Position;
            cParticle.StartSize = cParticle.Size = TrailStartSize;
            cParticle.EndSize = TrailEndSize;
            cParticle.StartColor = cParticle.Color = TrailStartColor;
            cParticle.EndColor = TrailEndColor;

            cParticle.Velocity = Vector3.Zero;
            cParticle.Acceleration = Vector3.Zero;
            cParticle.Orientation = Emitter.OrientationData.Orientation;
            cParticle.RotationalVelocity = new Vector3(0, 0, (float)Math.PI);
        }
Пример #11
0
        protected void RepelParticleFromExternalObject(DefaultTexturedQuadParticle cParticle, float fElapsedTimeInSeconds)
        {
            // Calculate Direction away from the Object and how far the Particle is from the Object
            Vector3 sDirectionAwayFromObject = cParticle.Position - mcExternalObjectPosition;
            float   fDistance = sDirectionAwayFromObject.Length();

            // If the Particle is close enough to the Object to be affected by it
            if (fDistance < mfAttractRepelRange)
            {
                // Repel the Particle from the Object
                sDirectionAwayFromObject.Normalize();
                cParticle.Velocity             += sDirectionAwayFromObject * (mfAttractRepelRange - fDistance) * mfAttractRepelForce;
                cParticle.RotationalVelocity.Z += 0.005f;
            }
        }
Пример #12
0
		// Used to generate a single smoke plume
		public void InitializeParticleRisingSmoke(DefaultTexturedQuadParticle cParticle)
		{
			cParticle.Lifetime = RandomNumber.Between(1.0f, 7.0f);

			cParticle.Position = Emitter.PositionData.Position;
			cParticle.Position += new Vector3(0, 10, 0);
			cParticle.Size = RandomNumber.Next(10, 25);
			cParticle.Color = msaColors[miCurrentColor];
			cParticle.Orientation = DPSF.Orientation3D.Rotate(Matrix.CreateRotationZ(RandomNumber.Between(0, MathHelper.TwoPi)), cParticle.Orientation);

			cParticle.Velocity = new Vector3(RandomNumber.Next(-15, 15), RandomNumber.Next(10, 30), RandomNumber.Next(-15, 15));
			cParticle.Acceleration = Vector3.Zero;
			cParticle.RotationalVelocity.Z = RandomNumber.Between(-MathHelper.Pi, MathHelper.Pi);

			cParticle.StartSize = cParticle.Size;

			mfColorBlendAmount = 0.5f;
		}
Пример #13
0
        // Used to generate random smoke particles around the floor
        public void InitializeParticleFoggySmoke(DefaultTexturedQuadParticle cParticle)
        {
            cParticle.Lifetime = RandomNumber.Between(1.0f, 3.0f);

            cParticle.Position    = Emitter.PositionData.Position;
            cParticle.Position   += new Vector3(RandomNumber.Next(-500, 500), 0, RandomNumber.Next(-500, 500));
            cParticle.Size        = RandomNumber.Next(10, 25);
            cParticle.Color       = msaColors[miCurrentColor];
            cParticle.Orientation = DPSF.Orientation3D.Rotate(Matrix.CreateRotationZ(RandomNumber.Between(0, MathHelper.TwoPi)), cParticle.Orientation);

            cParticle.Velocity             = new Vector3(RandomNumber.Next(-30, 30), RandomNumber.Next(0, 10), RandomNumber.Next(-30, 30));
            cParticle.Acceleration         = Vector3.Zero;
            cParticle.RotationalVelocity.Z = RandomNumber.Between(-MathHelper.Pi, MathHelper.Pi);

            cParticle.StartSize = cParticle.Size;

            mfColorBlendAmount = 0.5f;
        }
Пример #14
0
		public void InitializeParticleSnow(DefaultTexturedQuadParticle cParticle)
		{
			// Position the Snow within 500 units of the emitter
			Vector3 sPosition = Emitter.PositionData.Position;
			sPosition.Y = 200;
			sPosition.X += RandomNumber.Next(-500, 500);
			sPosition.Z += RandomNumber.Next(-500, 500);

			cParticle.Lifetime = 0.0f;

			cParticle.Position = sPosition;
			cParticle.Size = RandomNumber.Next(2, 5);
			cParticle.Color = DPSFHelper.LerpColor(new Color(255, 255, 255, 50), new Color(255, 255, 255, 255), RandomNumber.NextFloat());
			cParticle.Orientation = Orientation3D.Rotate(Matrix.CreateRotationZ(RandomNumber.Between(0, MathHelper.TwoPi)), cParticle.Orientation);

			cParticle.Velocity = new Vector3(RandomNumber.Next(-10, 3), RandomNumber.Next(-15, -5), RandomNumber.Next(-10, 10));
			cParticle.Acceleration = Vector3.Zero;
			cParticle.RotationalVelocity.Z = RandomNumber.Between(-MathHelper.PiOver2, MathHelper.PiOver2);
		}
Пример #15
0
        public void InitializeParticleSnow(DefaultTexturedQuadParticle cParticle)
        {
            // Position the Snow within 500 units of the emitter
            Vector3 sPosition = Emitter.PositionData.Position;

            sPosition.Y  = 200;
            sPosition.X += RandomNumber.Next(-500, 500);
            sPosition.Z += RandomNumber.Next(-500, 500);

            cParticle.Lifetime = 0.0f;

            cParticle.Position    = sPosition;
            cParticle.Size        = RandomNumber.Next(2, 5);
            cParticle.Color       = DPSFHelper.LerpColor(new Color(255, 255, 255, 50), new Color(255, 255, 255, 255), RandomNumber.NextFloat());
            cParticle.Orientation = Orientation3D.Rotate(Matrix.CreateRotationZ(RandomNumber.Between(0, MathHelper.TwoPi)), cParticle.Orientation);

            cParticle.Velocity             = new Vector3(RandomNumber.Next(-10, 3), RandomNumber.Next(-15, -5), RandomNumber.Next(-10, 10));
            cParticle.Acceleration         = Vector3.Zero;
            cParticle.RotationalVelocity.Z = RandomNumber.Between(-MathHelper.PiOver2, MathHelper.PiOver2);
        }
Пример #16
0
        // Change the Particle's Rotational Velocity
		public void UpdateParticleToUseRotationalVelocity(DefaultTexturedQuadParticle cParticle, float fElapsedTimeInSeconds)
        {
            cParticle.RotationalVelocity.Z = RandomNumber.Between(-MathHelper.TwoPi, MathHelper.TwoPi);
        }
Пример #17
0
		protected void AttractParticleToExternalObject(DefaultTexturedQuadParticle cParticle, float fElapsedTimeInSeconds)
		{
			// Calculate Direction towards the Object and how far the Particle is from the Object
			Vector3 sDirectionTowardsObject = mcExternalObjectPosition - cParticle.Position;
			float fDistance = sDirectionTowardsObject.Length();

			// If the Particle is close enough to the Object to be affected by it
			if (fDistance < mfAttractRepelRange)
			{
				// Attract the Particle to the Object
				sDirectionTowardsObject.Normalize();
				cParticle.Velocity = sDirectionTowardsObject * (mfAttractRepelRange - fDistance) * mfAttractRepelForce;
			}
		}
Пример #18
0
		protected void UpdateColor(DefaultTexturedQuadParticle cParticle, float fElapsedTimeInSeconds)
		{
			cParticle.Color = msaColors[miCurrentColor];
		}
		/// <summary>
		/// Example of how to create a Particle Initialization Function
		/// </summary>
		/// <param name="cParticle">The Particle to be Initialized</param>
		public void InitializeParticleProperties(DefaultTexturedQuadParticle cParticle)
		{
			//-----------------------------------------------------------
			// TODO: Initialize all of the Particle's properties here.
			// If you plan on simply using the default InitializeParticleUsingInitialProperties
			// Particle Initialization Function (see the LoadParticleSystem() function above), 
			// then you may delete this function all together.
			//-----------------------------------------------------------

			// Set the Particle's Lifetime (how long it should exist for)
			cParticle.Lifetime = 2.0f;

			// Set the Particle's initial Position to be wherever the Emitter is
			cParticle.Position = Emitter.PositionData.Position;

			// Set the Particle's Velocity
			Vector3 sVelocityMin = new Vector3(-50, 50, -50);
			Vector3 sVelocityMax = new Vector3(50, 100, 50);
			cParticle.Velocity = DPSFHelper.RandomVectorBetweenTwoVectors(sVelocityMin, sVelocityMax);

			// Adjust the Particle's Velocity direction according to the Emitter's Orientation
			cParticle.Velocity = Vector3.Transform(cParticle.Velocity, Emitter.OrientationData.Orientation);

			// Give the Particle a random Size
			// Since we have Size Lerp enabled we must also set the Start and End Size
			cParticle.Width = cParticle.StartWidth = cParticle.EndWidth =
				cParticle.Height = cParticle.StartHeight = cParticle.EndHeight = RandomNumber.Next(10, 50);

			// Give the Particle a random Color
			// Since we have Color Lerp enabled we must also set the Start and End Color
			cParticle.Color = cParticle.StartColor = cParticle.EndColor = DPSFHelper.RandomColor();
		}
Пример #20
0
        //===========================================================
        // Particle Update Functions
        //===========================================================

        //-----------------------------------------------------------
        // TODO: Place your Particle Update functions here, using the
        // same function prototype as below (i.e. public void FunctionName(DPSFParticle, float))
        //-----------------------------------------------------------

        /// <summary>
        /// Example of how to create a Particle Event Function
        /// </summary>
        /// <param name="cParticle">The Particle to update</param>
        /// <param name="fElapsedTimeInSeconds">How long it has been since the last update</param>
        protected void UpdateParticleFunctionExample(DefaultTexturedQuadParticle cParticle, float fElapsedTimeInSeconds)
        {
            // Place code to update the Particle here
            // Example: cParticle.Position += cParticle.Velocity * fElapsedTimeInSeconds;
        }
Пример #21
0
 protected void UpdateParticleRemoveWindForce(DefaultTexturedQuadParticle cParticle, float fElapsedTimeInSeconds)
 {
     cParticle.ExternalForce = Vector3.Zero;
 }
Пример #22
0
        /// <summary>
        /// Another example of how to create a Particle Initialization Function
        /// </summary>
        /// <param name="cParticle">The Particle to be Initialized</param>
		public void InitializeParticleProperties2(DefaultTexturedQuadParticle cParticle)
        {
            // Set the Particle's Lifetime (how long it should exist for)
            cParticle.Lifetime = 1.0f;

            // Set the Particle's initial Position to be wherever the Emitter is
            cParticle.Position = Emitter.PositionData.Position;

            // Set the Particle's Velocity
            cParticle.Velocity = new Vector3(0, 200, 0);

            // Adjust the Particle's Velocity direction according to the Emitter's Orientation
            cParticle.Velocity = Vector3.Transform(cParticle.Velocity, Emitter.OrientationData.Orientation);

            // If the Particles should be Increasing in Size
            if (mbSizeIncreasing)
            {
                miCurrentSize++;
            }
            // Else they should be Decreasing in Size
            else
            {
                miCurrentSize--;
            }

            // If the Particle Size is too small or too large, negate the size scaling
            if (miCurrentSize <= 10 || miCurrentSize >= 60)
            {
                mbSizeIncreasing = !mbSizeIncreasing;
            }

            // Set the Particle's Size to our CurrentSize value
            // Since we have Size Lerp enabled we must also set the Start and End Size
            cParticle.Size = cParticle.StartSize = cParticle.EndSize = miCurrentSize;

            // Give the Particle a random Color
            // Since we have Color Lerp enabled we must also set the Start and End Color
            cParticle.Color = cParticle.StartColor = cParticle.EndColor = DPSFHelper.RandomColor();
        }
Пример #23
0
		//===========================================================
		// Particle Update Functions
		//===========================================================
		protected void UpdateParticleToFaceCenter(DefaultTexturedQuadParticle cParticle, float fElapsedTimeInSeconds)
		{
			cParticle.Normal = Vector3.Lerp(InitialProperties.PositionMin, InitialProperties.PositionMax, 0.5f) - cParticle.Position;
		}
Пример #24
0
		public void InitializeParticleRotatingQuad(DefaultTexturedQuadParticle cParticle)
		{            
			// Set the type of Rotation this Particle should do
			switch (RandomNumber.Next(0, 5))
			{
				case 0:
					InitialProperties.RotationalVelocityMin = new Vector3(MathHelper.PiOver4, 0, 0);
					InitialProperties.RotationalVelocityMax = new Vector3(MathHelper.TwoPi, 0, 0);
				break;

				case 1:
					InitialProperties.RotationalVelocityMin = new Vector3(0, MathHelper.PiOver4, 0);
					InitialProperties.RotationalVelocityMax = new Vector3(0, MathHelper.TwoPi, 0);
				break;

				case 2:
					InitialProperties.RotationalVelocityMin = new Vector3(0, 0, MathHelper.PiOver4);
					InitialProperties.RotationalVelocityMax = new Vector3(0, 0, MathHelper.TwoPi);
				break;

				default:
				case 3:
					InitialProperties.RotationalVelocityMin = Vector3.Zero;
					InitialProperties.RotationalVelocityMax = new Vector3(MathHelper.TwoPi, MathHelper.TwoPi, MathHelper.TwoPi);
					InitialProperties.InterpolateBetweenMinAndMaxRotationalVelocity = false;
				break;
			}

			InitializeParticleUsingInitialProperties(cParticle);
		}
Пример #25
0
        // Make the Particle InVisible
		public void UpdateParticleVisibleOff(DefaultTexturedQuadParticle cParticle, float fElapsedTimeInSeconds)
        {
            cParticle.Visible = false;
        }
Пример #26
0
        // Change the Particle Size
		public void UpdateParticleSizeTo20(DefaultTexturedQuadParticle cParticle, float fElapsedTimeInSeconds)
        {
            cParticle.Size = 20;
        }
Пример #27
0
 //===========================================================
 // Particle Update Functions
 //===========================================================
 protected void IncreaseSizeBasedOnLifetime(DefaultTexturedQuadParticle cParticle, float fElapsedTimeInSeconds)
 {
     cParticle.Size = ((1.0f + cParticle.NormalizedElapsedTime) / 1.0f) * cParticle.StartSize;
 }
Пример #28
0
 protected void UpdateColor(DefaultTexturedQuadParticle cParticle, float fElapsedTimeInSeconds)
 {
     cParticle.Color = msaColors[miCurrentColor];
 }
Пример #29
0
		/// <summary>
		/// Example of how to create a Particle Initialization Function
		/// </summary>
		/// <param name="cParticle">The Particle to be Initialized</param>
		public void InitializeParticleProperties(DefaultTexturedQuadParticle cParticle)
		{
			//-----------------------------------------------------------
			// TODO: Initialize all of the Particle's properties here.
			// If you plan on simply using the default InitializeParticleUsingInitialProperties
			// Particle Initialization Function (see the LoadParticleSystem() function above), 
			// then you may delete this function all together.
			//-----------------------------------------------------------
			cParticle.Lifetime = 1.0f;

			int iTotalWidth = miNumberOfColumns * miSpaceBetweenParticles;
			int iTotalHeight = miNumberOfRows * miSpaceBetweenParticles;
			int iTotalDepth = miNumberOfLayers * miSpaceBetweenParticles;

			// Get which Particle this is being added
			int iParticleNumber = ActiveParticles.Count;

			// Calculate where in the Grid this Particle should be
			int iLayer = iParticleNumber / (miNumberOfRows * miNumberOfColumns);
			int iRow = (iParticleNumber / miNumberOfColumns) % miNumberOfRows;
			int iColumn = iParticleNumber % miNumberOfColumns;

			// Calculate the Particles absolute position
			Vector3 sPosition = new Vector3(iColumn * miSpaceBetweenParticles, iRow * miSpaceBetweenParticles, iLayer * miSpaceBetweenParticles);

			// Center the Grid around the origin
			sPosition.X -= (iTotalWidth / 2.0f);
			sPosition.Y -= (iTotalHeight / 2.0f);
			sPosition.Z -= (iTotalDepth / 2.0f);

			// Set the Particle's initial Position
			cParticle.Position = sPosition;

			cParticle.Width = cParticle.Height = cParticle.StartWidth = cParticle.StartHeight = miStartSize;
			cParticle.EndWidth = cParticle.EndHeight = miEndSize;

			cParticle.Color = cParticle.StartColor = msStartColor;
			cParticle.EndColor = msEndColor;
		}
Пример #30
0
 protected void UpdateParticleAddWindForce(DefaultTexturedQuadParticle cParticle, float fElapsedTimeInSeconds)
 {
     cParticle.ExternalForce = Vector3.Lerp(Vector3.Zero, mcMaxWindForce, RandomNumber.Between(0.1f, 1.0f));
 }
Пример #31
0
		/// <summary>
		/// Example of how to create a Particle Initialization Function
		/// </summary>
		/// <param name="cParticle">The Particle to be Initialized</param>
		public void InitializeParticleProperties(DefaultTexturedQuadParticle cParticle)
		{
			// Set the Particle's Lifetime (how long it should exist for)
			cParticle.Lifetime = 2.0f;

			// Set the Particle's initial Position to be wherever the Emitter is
			cParticle.Position = Emitter.PositionData.Position;

			// Set the Particle's Velocity
			Vector3 sVelocityMin = new Vector3(-50, 50, -50);
			Vector3 sVelocityMax = new Vector3(50, 100, 50);
			cParticle.Velocity = DPSFHelper.RandomVectorBetweenTwoVectors(sVelocityMin, sVelocityMax);

			// Adjust the Particle's Velocity direction according to the Emitter's Orientation
			cParticle.Velocity = Vector3.Transform(cParticle.Velocity, Emitter.OrientationData.Orientation);

			// Give the Particle a random Size
			// Since we have Size Lerp enabled we must also set the Start and End Size
			cParticle.Size = cParticle.StartSize = cParticle.EndSize = RandomNumber.Next(10, 50);

			// Give the Particle a random Color
			// Since we have Color Lerp enabled we must also set the Start and End Color
			cParticle.Color = cParticle.StartColor = cParticle.EndColor = DPSFHelper.RandomColor();
		}
Пример #32
0
        //===========================================================
        // Structures and Variables
        //===========================================================

        //===========================================================
        // Vertex Update and Overridden Particle System Functions
        //===========================================================

        /// <summary>
        /// Function to update the Vertex properties according to the Particle properties
        /// </summary>
        /// <param name="sVertexBuffer">The array containing the Vertices to be drawn</param>
        /// <param name="iIndex">The Index in the array where the Particle's Vertex info should be placed</param>
        /// <param name="Particle">The Particle to copy the information from</param>
        protected virtual void UpdateVertexProperties(ref DefaultTexturedQuadParticleVertex[] sVertexBuffer, int iIndex, DPSFParticle Particle)
        {
            // Cast the Particle to the type it really is
            DefaultTexturedQuadParticle cParticle = (DefaultTexturedQuadParticle)Particle;

            // Calculate what half of the Quads Width and Height are
            float fHalfWidth  = cParticle.Width / 2.0f;
            float fHalfHeight = cParticle.Height / 2.0f;

            // Calculate the Positions of the Quads corners around the origin
            Vector3 sTopLeft     = new Vector3(-fHalfWidth, -fHalfHeight, 0);
            Vector3 sTopRight    = new Vector3(fHalfWidth, -fHalfHeight, 0);
            Vector3 sBottomLeft  = new Vector3(-fHalfWidth, fHalfHeight, 0);
            Vector3 sBottomRight = new Vector3(fHalfWidth, fHalfHeight, 0);

            // Rotate the Quad corners around the origin according to its Orientation,
            // then calculate their final Positions
            sTopLeft     = Vector3.Transform(sTopLeft, cParticle.Orientation) + cParticle.Position;
            sTopRight    = Vector3.Transform(sTopRight, cParticle.Orientation) + cParticle.Position;
            sBottomLeft  = Vector3.Transform(sBottomLeft, cParticle.Orientation) + cParticle.Position;
            sBottomRight = Vector3.Transform(sBottomRight, cParticle.Orientation) + cParticle.Position;

            // Copy this Particle's renderable Properties to the Vertex Buffer
            // This is a Quad so we must copy all 4 Vertices over
            sVertexBuffer[iIndex].Position          = sBottomLeft;
            sVertexBuffer[iIndex].TextureCoordinate = new Vector2(0, 1);
            sVertexBuffer[iIndex].Color             = cParticle.Color;

            sVertexBuffer[iIndex + 1].Position          = sTopLeft;
            sVertexBuffer[iIndex + 1].TextureCoordinate = new Vector2(0, 0);
            sVertexBuffer[iIndex + 1].Color             = cParticle.Color;

            sVertexBuffer[iIndex + 2].Position          = sBottomRight;
            sVertexBuffer[iIndex + 2].TextureCoordinate = new Vector2(1, 1);
            sVertexBuffer[iIndex + 2].Color             = cParticle.Color;

            sVertexBuffer[iIndex + 3].Position          = sTopRight;
            sVertexBuffer[iIndex + 3].TextureCoordinate = new Vector2(1, 0);
            sVertexBuffer[iIndex + 3].Color             = cParticle.Color;

            // Fill in the Index Buffer for the newly added Vertices.
            // Specify the Vertices in Clockwise order.
            // It takes 6 Indices to represent a quad (2 triangles = 6 corners).
            // If we're using the HiDef profile, fill in the regular Index Buffer.
            if (this.GraphicsDevice.GraphicsProfile == GraphicsProfile.HiDef)
            {
                IndexBuffer[IndexBufferIndex++] = iIndex + 1;
                IndexBuffer[IndexBufferIndex++] = iIndex + 2;
                IndexBuffer[IndexBufferIndex++] = iIndex;
                IndexBuffer[IndexBufferIndex++] = iIndex + 1;
                IndexBuffer[IndexBufferIndex++] = iIndex + 3;
                IndexBuffer[IndexBufferIndex++] = iIndex + 2;
            }
            // Else we're using the Reach profile, so fill the Reach Index Buffer instead.
            else
            {
                IndexBufferReach[IndexBufferIndex++] = (short)(iIndex + 1);
                IndexBufferReach[IndexBufferIndex++] = (short)(iIndex + 2);
                IndexBufferReach[IndexBufferIndex++] = (short)(iIndex);
                IndexBufferReach[IndexBufferIndex++] = (short)(iIndex + 1);
                IndexBufferReach[IndexBufferIndex++] = (short)(iIndex + 3);
                IndexBufferReach[IndexBufferIndex++] = (short)(iIndex + 2);
            }
        }
Пример #33
0
        //===========================================================
        // Particle Update Functions
        //===========================================================

        /// <summary>
        /// Example of how to create a Particle Event Function
        /// </summary>
        /// <param name="cParticle">The Particle to update</param>
        /// <param name="fElapsedTimeInSeconds">How long it has been since the last update</param>
		public void UpdateParticleFunctionExample(DefaultTexturedQuadParticle cParticle, float fElapsedTimeInSeconds)
        {
            // Place code to update the Particle here
            // Example: cParticle.Position += cParticle.Velocity * fElapsedTimeInSeconds;
        }
 private void UpdateParticleCleanupAtEndOfLifecycle(DefaultTexturedQuadParticle particle, float elapsedTimeInSeconds)
 {
     this.swipedParticles.Remove(particle);
 }
Пример #35
0
 public void StopDirtTrail(DefaultTexturedQuadParticle cParticle, float fElapsedTimeInSeconds)
 {
 }
Пример #36
0
		//===========================================================
		// Particle Update Functions
		//===========================================================
		protected void IncreaseSizeBasedOnLifetime(DefaultTexturedQuadParticle cParticle, float fElapsedTimeInSeconds)
		{
			cParticle.Size = ((1.0f + cParticle.NormalizedElapsedTime) / 1.0f) * cParticle.StartSize;
		}
Пример #37
0
        public void InitializeParticleFireOnHorizontalRing(DefaultTexturedQuadParticle cParticle)
        {
            Quaternion cBackup = Emitter.OrientationData.Orientation;
            Emitter.OrientationData.Orientation = Quaternion.Identity;
            InitializeParticleUsingInitialProperties(cParticle);
            Emitter.OrientationData.Orientation = cBackup;

            cParticle.Position = DPSFHelper.PointOnSphere(RandomNumber.Between(0, MathHelper.TwoPi), 0, 100);
            cParticle.Position = Vector3.Transform(cParticle.Position, Emitter.OrientationData.Orientation);
            cParticle.Position += Emitter.PositionData.Position;
        }
Пример #38
0
		protected void RepelParticleFromExternalObject(DefaultTexturedQuadParticle cParticle, float fElapsedTimeInSeconds)
		{
			// Calculate Direction away from the Object and how far the Particle is from the Object
			Vector3 sDirectionAwayFromObject = cParticle.Position - mcExternalObjectPosition;
			float fDistance = sDirectionAwayFromObject.Length();

			// If the Particle is close enough to the Object to be affected by it
			if (fDistance < mfAttractRepelRange)
			{
				// Repel the Particle from the Object
				sDirectionAwayFromObject.Normalize();
				cParticle.Velocity += sDirectionAwayFromObject * (mfAttractRepelRange - fDistance) * mfAttractRepelForce;
				cParticle.RotationalVelocity.Z += 0.005f;
			}
		}
Пример #39
0
        protected void GenerateSmokeParticle(DefaultTexturedQuadParticle cParticle, float fElapsedTimeInSeconds)
        {
            // If the Smoke Particle System is initialized
            if (mcSmokeParticleSystem != null && mcSmokeParticleSystem.IsInitialized)
            {
                // Only create a Smoke Particles some of the time
                if (RandomNumber.NextFloat() < mfAmountOfSmokeToRelease)
                {
                    // Create a new Smoke Particle at the same Position as this Fire Particle
                    DefaultTexturedQuadParticle cSmokeParticle = new DefaultTexturedQuadParticle();
                    mcSmokeParticleSystem.InitializeParticle(cSmokeParticle);
                    cSmokeParticle.Position = cParticle.Position;

                    // Add the Particle to the Smoke Particle System
                    mcSmokeParticleSystem.AddParticle(cSmokeParticle);
                }
            }
        }
Пример #40
0
		//===========================================================
		// Particle Update Functions
		//===========================================================
		protected void CreateExplosionParticles(DefaultTexturedQuadParticle cParticle, float fElapsedTimeInSeconds)
		{
			// If the Fireworks Explosion Particle Systems are Initialized
			if (mcFireworksExplosionParticleSystem1.IsInitialized &&
				mcFireworksExplosionParticleSystem2.IsInitialized &&
				mcFireworksExplosionParticleSystem3.IsInitialized &&
				mcFireworksExplosionParticleSystem4.IsInitialized)
			{
				// Randomly choose which Particle System to use for the Explosion
				int iPSToUse = RandomNumber.Next(1, 5);
				DPSFDefaultTexturedQuadParticleSystem<DefaultTexturedQuadParticle, DefaultTexturedQuadParticleVertex> cExplosionPS;
				switch (iPSToUse)
				{
					default:
					case 1:
						cExplosionPS = mcFireworksExplosionParticleSystem1;
					break;

					case 2:
						cExplosionPS = mcFireworksExplosionParticleSystem2;
					break;

					case 3:
						cExplosionPS = mcFireworksExplosionParticleSystem3;
					break;

					case 4:
						cExplosionPS = mcFireworksExplosionParticleSystem4;
					break;
				}

				// Randomly select how many particles should be in this explosion
				int iNumberOfExplosionParticles = RandomNumber.Next(5, 100);

				// Randomly select the size of the Explosion Particles
				int iParticleSize = RandomNumber.Next(0, (int)cExplosionPS.InitialProperties.StartSizeMax);

				// Initialize the Explosion Particles Color variable
				Color sParticleColor = Color.White;

				// If all of the Explosion Particles should be the same Color
				if (RandomNumber.Next(0, 5) != 2)
				{
					// Randomly select the color of the Explosion Particles
					sParticleColor = DPSFHelper.LerpColor(Color.Black, Color.White, RandomNumber.NextFloat(), RandomNumber.NextFloat(), RandomNumber.NextFloat(), RandomNumber.NextFloat());
				}
				
				// Create the explosion particles
				for (int iIndex = 0; iIndex < iNumberOfExplosionParticles; iIndex++)
				{
					DefaultTexturedQuadParticle cExplosionParticle = new DefaultTexturedQuadParticle();
					cExplosionPS.InitializeParticle(cExplosionParticle);
					
					// Start the Explosion Particles where the fireworks Particle died
					cExplosionParticle.Position = cParticle.Position;

					// If the random Particle Size is big enough
					if (iParticleSize > cExplosionPS.InitialProperties.StartSizeMin)
					{
						// Make all Explosion Particles this Size
						cExplosionParticle.Size = iParticleSize;
					}
					// Else each Particle will be a random Size

					// If the Explosion Particles should all be the same Color
					if (sParticleColor != Color.White)
					{
						cExplosionParticle.Color = sParticleColor;
					}

					// Add the Explosion Particle to the Explosion Particle System
					cExplosionPS.AddParticle(cExplosionParticle);
				}

				// If the Explosion Smoke Particle System is initialized
				if (mcFireworksExplosionSmokeParticleSystem.IsInitialized)
				{
					// Create some Smoke at the position where the Particle died
					mcFireworksExplosionSmokeParticleSystem.Emitter.PositionData.Position = cParticle.Position;

					// Choose how much Smoke to create based on how big the Explosion was
					int iNumberOfSmokeParticles = iNumberOfExplosionParticles / 2;

					// Create the Smoke Particles
					for (int iIndex = 0; iIndex < iNumberOfSmokeParticles; iIndex++)
					{
						mcFireworksExplosionSmokeParticleSystem.AddParticle();
					}
				}
			}
		}
Пример #41
0
        // Change the Particle's Velocity
		public void UpdateParticleVelocityToTravelRight(DefaultTexturedQuadParticle cParticle, float fElapsedTimeInSeconds)
        {
            cParticle.Velocity = new Vector3(RandomNumber.Next(50, 100), 0, 0);
        }
Пример #42
0
		//===========================================================
		// Particle Update Functions
		//===========================================================

		//-----------------------------------------------------------
		// TODO: Place your Particle Update functions here, using the 
		// same function prototype as below (i.e. public void FunctionName(DPSFParticle, float))
		//-----------------------------------------------------------

		/// <summary>
		/// Updates the Particle's Start and End Colors
		/// </summary>
		/// <param name="cParticle">The Particle to update</param>
		/// <param name="fElapsedTimeInSeconds">How long it has been since the last update</param>
		protected void UpdateParticleResetProperties(DefaultTexturedQuadParticle cParticle, float fElapsedTimeInSeconds)
		{
			cParticle.ElapsedTime = 0.0f;

			// If this is the first particle that was added to the list
			if (cParticle == ActiveParticles.Last.Value)
			{
				// Choose a new Random Color to use
				msStartColor = msEndColor;
				msEndColor = DPSFHelper.RandomColor();

				int iTempSize = miStartSize;
				miStartSize = miEndSize;
				miEndSize = iTempSize;
			}

			cParticle.StartColor = msStartColor;
			cParticle.EndColor = msEndColor;

			cParticle.StartWidth = cParticle.StartHeight = miStartSize;
			cParticle.EndWidth = cParticle.EndHeight = miEndSize;
		}
Пример #43
0
			public void InitializeParticleFireworksExplosion(DefaultTexturedQuadParticle cParticle)
			{
				InitializeParticleUsingInitialProperties(cParticle);
			}
Пример #44
0
        /// <summary>
        /// Example of how to create a Particle Initialization Function
        /// </summary>
        /// <param name="cParticle">The Particle to be Initialized</param>
		public void InitializeParticleProperties(DefaultTexturedQuadParticle cParticle)
        {
            // Set the Particle's Lifetime (how long it should exist for) and initial Position
			cParticle.Lifetime = 5;
			cParticle.Position = Emitter.PositionData.Position;

			// If the Particles should travel in random directions
			if (mbInitializeParticlesWithRandomDirection)
			{
				// Give the Particle a random velocity direction to start with
				cParticle.Velocity = DPSFHelper.RandomNormalizedVector() * 50;
			}
			else
			{
				// Emit all of the Particles in the same direction
				cParticle.Velocity = Vector3.Right * 50;

				// Adjust the Particle's starting velocity direction according to the Emitter's Orientation
				cParticle.Velocity = Vector3.Transform(cParticle.Velocity, Emitter.OrientationData.Orientation);
			}

			cParticle.RotationalVelocity.Z = RandomNumber.Between(-MathHelper.Pi, MathHelper.Pi);
			cParticle.Size = 10;
			cParticle.StartColor = cParticle.EndColor = cParticle.Color = DPSFHelper.RandomColor();
        }
Пример #45
0
			public void InitializeParticleFireworksExplosionSmoke(DefaultTexturedQuadParticle cParticle)
			{
				InitializeParticleUsingInitialProperties(cParticle);

				// Make it so all Smoke doesn't start from the same spot
				cParticle.Position += new Vector3(RandomNumber.Next(-20, 20), RandomNumber.Next(-20, 20), RandomNumber.Next(-20, 20));
			}
Пример #46
0
        //===========================================================
        // Structures and Variables
        //===========================================================

        //===========================================================
        // Vertex Update and Overridden Particle System Functions
        //===========================================================

        /// <summary>
        /// Function to update the Vertex properties according to the Particle properties
        /// </summary>
        /// <param name="sVertexBuffer">The array containing the Vertices to be drawn</param>
        /// <param name="iIndex">The Index in the array where the Particle's Vertex info should be placed</param>
        /// <param name="Particle">The Particle to copy the information from</param>
        protected virtual void UpdateVertexProperties(ref DefaultTexturedQuadParticleVertex[] sVertexBuffer, int iIndex, DPSFParticle Particle)
        {
            // Cast the Particle to the type it really is
            DefaultTexturedQuadParticle cParticle = (DefaultTexturedQuadParticle)Particle;

            // Calculate what half of the Quads Width and Height are
            float fHalfWidth  = cParticle.Width / 2.0f;
            float fHalfHeight = cParticle.Height / 2.0f;

            // Calculate the Positions of the Quads corners around the origin
            Vector3 sTopLeft     = new Vector3(-fHalfWidth, -fHalfHeight, 0);
            Vector3 sTopRight    = new Vector3(fHalfWidth, -fHalfHeight, 0);
            Vector3 sBottomLeft  = new Vector3(-fHalfWidth, fHalfHeight, 0);
            Vector3 sBottomRight = new Vector3(fHalfWidth, fHalfHeight, 0);

            // Rotate the Quad corners around the origin according to its Orientation,
            // then calculate their final Positions
            sTopLeft     = Vector3.Transform(sTopLeft, cParticle.Orientation) + cParticle.Position;
            sTopRight    = Vector3.Transform(sTopRight, cParticle.Orientation) + cParticle.Position;
            sBottomLeft  = Vector3.Transform(sBottomLeft, cParticle.Orientation) + cParticle.Position;
            sBottomRight = Vector3.Transform(sBottomRight, cParticle.Orientation) + cParticle.Position;

            // Effects expect a premultiplied color, so get the actual color to use.
            Color premultipliedColor = cParticle.ColorAsPremultiplied;

            // Copy this Particle's renderable Properties to the Vertex Buffer
            // This is a Quad so we must copy all 4 Vertices over
            sVertexBuffer[iIndex].Position          = sBottomLeft;
            sVertexBuffer[iIndex].TextureCoordinate = new Vector2(0, 1);
            sVertexBuffer[iIndex].Color             = premultipliedColor;

            sVertexBuffer[iIndex + 1].Position          = sTopLeft;
            sVertexBuffer[iIndex + 1].TextureCoordinate = new Vector2(0, 0);
            sVertexBuffer[iIndex + 1].Color             = premultipliedColor;

            sVertexBuffer[iIndex + 2].Position          = sBottomRight;
            sVertexBuffer[iIndex + 2].TextureCoordinate = new Vector2(1, 1);
            sVertexBuffer[iIndex + 2].Color             = premultipliedColor;

            sVertexBuffer[iIndex + 3].Position          = sTopRight;
            sVertexBuffer[iIndex + 3].TextureCoordinate = new Vector2(1, 0);
            sVertexBuffer[iIndex + 3].Color             = premultipliedColor;

            // Fill in the Index Buffer for the newly added Vertices.
            // Specify the Vertices in Clockwise order.
            // It takes 6 Indices to represent a quad (2 triangles = 6 corners).
            // If we should be using the 32-bit Integer Index Buffer, fill it.
            if (this.IsUsingIntegerIndexBuffer)
            {
                IndexBuffer[IndexBufferIndex++] = iIndex + 1;
                IndexBuffer[IndexBufferIndex++] = iIndex + 2;
                IndexBuffer[IndexBufferIndex++] = iIndex;
                IndexBuffer[IndexBufferIndex++] = iIndex + 1;
                IndexBuffer[IndexBufferIndex++] = iIndex + 3;
                IndexBuffer[IndexBufferIndex++] = iIndex + 2;
            }
            // Else we should be using the 16-bit Short Index Buffer.
            else
            {
                IndexBufferShort[IndexBufferIndex++] = (short)(iIndex + 1);
                IndexBufferShort[IndexBufferIndex++] = (short)(iIndex + 2);
                IndexBufferShort[IndexBufferIndex++] = (short)(iIndex);
                IndexBufferShort[IndexBufferIndex++] = (short)(iIndex + 1);
                IndexBufferShort[IndexBufferIndex++] = (short)(iIndex + 3);
                IndexBufferShort[IndexBufferIndex++] = (short)(iIndex + 2);
            }
        }
Пример #47
0
			protected void RandomlyToggleVisiblity(DefaultTexturedQuadParticle cParticle, float fElapsedTimeInSeconds)
			{
				if (RandomNumber.NextFloat() < 0.1f)
				{
					cParticle.Visible = !cParticle.Visible;
				}
			}