public void updateForce(MyParticle particle, float duration) { // Calculate spring vector MyVector3 force; force = particle.getPosition(); force.SubtractVectorFromThisVector(other.getPosition()); //Check is the bungie is compressed // if bungie is compressed break out of the method without adding a force float magnitude = force.magnitude(); if (magnitude < restLength) { return; } else if (magnitude > restLength) { //Everything after this comment will happen if the if condition isn't true //Calculate the magnitude of the force magnitude = springConstant * (restLength - magnitude); //magnitude = springConstant * (magnitude-restLength); //Calculate the final force and apply it force.normalize(); force.multiplyVectorByScalar(magnitude); particle.addForce(force); } else { return; } }
public void updateForce(MyParticle particle, float duration) { //checking if particle has infinite mass if (!particle.hasFiniteMass()) { return; } //calculates position of the particle relative to the anchor MyVector3 position; position = particle.getPosition(); position.SubtractVectorFromThisVector(this.anchor); //Calculate constants and check whether they are in bounds float gamma = 0.5f * Mathf.Sqrt(4 * springConstant - damping * damping); if (gamma == 0.0f) { return; } MyVector3 c = position.multiplyVectorByScalarVR(damping / (2.0f * gamma)).returnAddVectorToThisVector(particle.getVelocity().multiplyVectorByScalarVR(1.0f / gamma)); //Calculate the target position MyVector3 target = position.multiplyVectorByScalarVR(Mathf.Cos(gamma * duration)).returnAddVectorToThisVector(c.multiplyVectorByScalarVR(Mathf.Sin(gamma * duration))); target.multiplyVectorByScalar(Mathf.Exp(-0.5f * duration * damping)); //Calculate resulting acceration and force MyVector3 accel = (target.returnSubtractVectorFromThisVector(position)).multiplyVectorByScalarVR(1.0f / (duration * duration)).returnSubtractVectorFromThisVector(particle.getVelocity().multiplyVectorByScalarVR(duration)); particle.addForce(accel.multiplyVectorByScalarVR(particle.getMass())); }
/*Updates force*/ /* * void ParticleForceGenerator.updateForce (MyParticle particle, float duration){ * * //check we don't have infinite mass * if (!particle.hasFiniteMass()) * return; * //app mass-scaled force to the particle * particle.addForce(gravity.multiplyVectorByScalarVR(particle.getMass ())); * } */ public void updateForce(MyParticle particle, float duration) { //ParticleForceGenerator.updateForce (particle, duration); //check we don't have infinite mass if (!particle.hasFiniteMass()) { return; } //app mass-scaled force to the particle particle.addForce(gravity.multiplyVectorByScalarVR(particle.getMass())); }
//I might come back and add some get and set methods to modify volume and waterHeight public void updateForce(MyParticle particle, float duration) { float depth = particle.getPosition().getComponentY(); //check is object is out of water // if (depth >= waterHeight + maxDepth) { return; } MyVector3 force = new MyVector3(0f, 0f, 0f); //check if we're at max depth if (depth <= waterHeight - maxDepth) { force.y = liquidDensity * volume; particle.addForce(force); return; } //if the other 2 aren't true we're partially submerged force.y = liquidDensity * volume * (depth - maxDepth - waterHeight); particle.addForce(force); }
public void updateForce(MyParticle particle, float duration) { MyVector3 force; force = particle.getVelocity(); //Calculate Total Drag coefficient float dragCoeff = force.magnitude(); dragCoeff = k1 * dragCoeff + k2 * dragCoeff * dragCoeff; //Calculate and apply the final force force.normalize(); force.multiplyVectorByScalar(-dragCoeff); particle.addForce(force); }
public void updateForce(MyParticle particle, float duration) { // Calculate spring vector MyVector3 force; force = particle.getPosition(); force.SubtractVectorFromThisVector(anchor); //Calculate the magnitude of the force float magnitude = force.magnitude(); magnitude = absValue(magnitude - this.restLength); magnitude *= springConstant; //Calculate the final force and apply it force.normalize(); force.multiplyVectorByScalar(-1 * magnitude); particle.addForce(force); }
/* * public Move(MyVector3 force) * { * this.force = force; * } */ public void updateForce(MyParticle particle, float duration) { particle.addForce(this.force.multiplyVectorByScalarVR(particle.getMass())); }