/** Compute forces and update particles **/
void ParticleSystem::computeForcesAndUpdateParticles(float t)
{
	time = t;
	if (!simulate) return;

	for (int i = 0; i < 20; i++)
	{
		for (int j = 19; j >= 0; j--)
		{
			if (i == 0 && (j == 0 || j == 19)) continue;
			Vec3f force = Vec3f(g);
			Vec3f position = particles[i][j].getPosition();
			
			force += springForce(i - 1, j, position);
			force += springForce(i + 1, j, position);
			force += springForce(i, j - 1, position);
			force += springForce(i, j + 1, position);

			if (force.length() > 10)
			{
				force.normalize();
				force *= 10;
			}

			particles[i][j].applyForce(force);
		}
	}
	
	for (int i = 0; i < 20; i++)
		for (int j = 19; j >= 0; j--)
			particles[i][j].move(t);

	bakeParticles(t);
}
void ForestWindAccumulator::updateWind( const VectorF &windForce, F32 timeDelta )
{
   PROFILE_SCOPE( ForestWindAccumulator_UpdateWind );

   // Update values from datablock... this way we can
   // change settings live and see instant results.
   const F32 tightnessCoefficient = mDataBlock->mTightnessCoefficient;
   const F32 dampingCoefficient = mDataBlock->mDampingCoefficient;
   const F32 mass = mDataBlock->mMass * mScale;
   const F32 rigidity = mDataBlock->mRigidity * mScale;

   // This will be the accumulated
   // target strength for flutter.
   //F32 targetStrength = windForce.len();

   // This will be the accumulated
   // target displacement vector.
   Point2F target( windForce.x, windForce.y );

   // This particle is the spring target.
   // It has a mass of 0, which we count as
   // an infinite mass.
   mParticles[0].position = target;

   Point2F relVel = target * timeDelta;

   Point2F diff( 0, 0 );
   Point2F springForce( 0, 0 );

   // Spring length is the target
   // particle's position minus the
   // current displacement/direction vector.
   diff = mParticles[0].position - mCurrentDir;

   // F = diff * tightness - v * -damping
   diff *= tightnessCoefficient;
   springForce = diff - ( (mParticles[1].position - mParticles[1].lastPosition) * -dampingCoefficient );

   Point2F accel( 0, 0 );
   accel = springForce * (rigidity * 0.001f) / (mass * 0.001f);

   _updateParticle( &mParticles[1], accel, timeDelta );

   mCurrentDir *= 0.989f;
   mCurrentDir += mParticles[1].position;

   mCurrentStrength += windForce.len() * timeDelta;
   mCurrentStrength *= 0.98f;
}
Exemple #3
0
void SimSuspUpdate(tSuspension *susp)
{
	susp->force = (springForce(susp) + damperForce(susp)) * susp->spring.bellcrank;
}