コード例 #1
0
		public void UpdateForce(IParticle particle, double duration)
		{
			if (particle.IsInfiniteMass == true) return;

			// Calculate relative position of the particle from the anchor
			Vector3 positionFromAnchor = particle.Position - Anchor;

			// Calculate the value for Gamma
			var gamma = 0.5 * Math.Sqrt((4 * SpringConstant) - (Damping * Damping));
			
			if (gamma == 0.0) return;

			// Calculate the value for the C constant
			var c = (positionFromAnchor * (Damping / (2.0 * gamma))) + (particle.Velocity * (1.0 / gamma));

			// Calculate the target position (in two parts)
			var tagetPosition = (positionFromAnchor * Math.Cos(gamma * duration)) + (c * Math.Sin(gamma*duration));
			tagetPosition *= Math.Exp(0.5 * duration * Damping);

			// Calculate the acceleration needed (and hence the force)
			var acceleration = ((tagetPosition - positionFromAnchor) * (1.0 / (duration * duration))) -
				(particle.Velocity * duration);

			// Add the force to the particle
			particle.AddForce(acceleration * particle.Mass);
		}
コード例 #2
0
		public void UpdateForce(IParticle particle, double duration)
		{
			if (particle.IsInfiniteMass == false)
			{
				particle.AddForce(Gravity * particle.Mass);
			}
		}
コード例 #3
0
 public void UpdateForce(IParticle particle, double duration)
 {
     if (particle.IsInfiniteMass == false)
     {
         particle.AddForce(Gravity * particle.Mass);
     }
 }
コード例 #4
0
        public void UpdateForce(IParticle particle, double duration)
        {
            if (particle.IsInfiniteMass == true)
            {
                return;
            }

            // Calculate relative position of the particle from the anchor
            Vector3 positionFromAnchor = particle.Position - Anchor;

            // Calculate the value for Gamma
            var gamma = 0.5 * Math.Sqrt((4 * SpringConstant) - (Damping * Damping));

            if (gamma == 0.0)
            {
                return;
            }

            // Calculate the value for the C constant
            var c = (positionFromAnchor * (Damping / (2.0 * gamma))) + (particle.Velocity * (1.0 / gamma));

            // Calculate the target position (in two parts)
            var tagetPosition = (positionFromAnchor * Math.Cos(gamma * duration)) + (c * Math.Sin(gamma * duration));

            tagetPosition *= Math.Exp(0.5 * duration * Damping);

            // Calculate the acceleration needed (and hence the force)
            var acceleration = ((tagetPosition - positionFromAnchor) * (1.0 / (duration * duration))) -
                               (particle.Velocity * duration);

            // Add the force to the particle
            particle.AddForce(acceleration * particle.Mass);
        }
コード例 #5
0
		public void UpdateForce(IParticle particle, double duration)
		{
			var springVector = particle.Position - OtherParticle.Position;
			var springExtension = springVector.Magnitude - RestLength;

			if (((springExtension < 0.0f) && IsBungeeSpring)) return;

			var springForce = (SpringConstant * springExtension) * springVector.Normal.Inverse;
			particle.AddForce(springForce);
		}
コード例 #6
0
        public void UpdateForce(IParticle particle, double duration)
        {
            var speedSquared = particle.Velocity.SquareMagnitude;
            var speed        = Math.Sqrt(speedSquared);

            var dragMagnitude = (K1 * speed) + (K2 * speedSquared);

            var force = new Vector3(particle.Velocity.Normal.Inverse * dragMagnitude);

            particle.AddForce(force);
        }
コード例 #7
0
ファイル: DragForceGenerator.cs プロジェクト: dazpaz/Cyclone
		public void UpdateForce(IParticle particle, double duration)
		{
			var speedSquared = particle.Velocity.SquareMagnitude;
			var speed = Math.Sqrt(speedSquared);

			var dragMagnitude = (K1 * speed) + (K2 * speedSquared);

			var force = new Vector3(particle.Velocity.Normal.Inverse * dragMagnitude);

			particle.AddForce(force);
		}
コード例 #8
0
        public void UpdateForce(IParticle particle, double duration)
        {
            var springVector    = particle.Position - OtherParticle.Position;
            var springExtension = springVector.Magnitude - RestLength;

            if (((springExtension < 0.0f) && IsBungeeSpring))
            {
                return;
            }

            var springForce = (SpringConstant * springExtension) * springVector.Normal.Inverse;

            particle.AddForce(springForce);
        }
コード例 #9
0
		public void UpdateForce(IParticle particle, double duration)
		{
			 var particleHeight = particle.Position.Y;

			// Check if we are out of the water - if so, return as there is no buoyancy force to add
			if (particleHeight >= LiquidHeight + MaximumDepth) return;

			// Fully submerged buoyancy force
			var force = new Vector3 {Y = LiquidDensity * Volume};

			// If partially submerged, adjust the buoyancy force based on how deep the object is
			if (particleHeight > LiquidHeight - MaximumDepth)
			{
				var amountSubmerged = (LiquidHeight - particleHeight) / (MaximumDepth);
				force.Y *= amountSubmerged;
			}
		
			particle.AddForce(force);
		}
コード例 #10
0
        public void UpdateForce(IParticle particle, double duration)
        {
            var particleHeight = particle.Position.Y;

            // Check if we are out of the water - if so, return as there is no buoyancy force to add
            if (particleHeight >= LiquidHeight + MaximumDepth)
            {
                return;
            }

            // Fully submerged buoyancy force
            var force = new Vector3 {
                Y = LiquidDensity * Volume
            };

            // If partially submerged, adjust the buoyancy force based on how deep the object is
            if (particleHeight > LiquidHeight - MaximumDepth)
            {
                var amountSubmerged = (LiquidHeight - particleHeight) / (MaximumDepth);
                force.Y *= amountSubmerged;
            }

            particle.AddForce(force);
        }