public void pre_step() {
    Vector3f ab = mathematik.Util.sub(mParticleA.position(), mParticleB.position());
    Vector3f cb = mathematik.Util.sub(mParticleC.position(), mParticleB.position());
    final float mCurrentAngle = ab.angle(cb);

    if (mCurrentAngle < mMinAngle) {
      final int TINY_FACTOR_MODELL = 0;
      final int TRIG_MODELL = 1;
      final int MAX_DISTANCE_MODELL = 2;

      final int mModell = TRIG_MODELL;

      switch (mModell) {
        case TINY_FACTOR_MODELL:
          {
            final float TINY_FACTOR = 1.1f;
            final float mDistance =
                mParticleA.position().distance(mParticleC.position()) * TINY_FACTOR;
            restlength(mDistance);
          }
          break;
        case TRIG_MODELL:
          {
            // a = sqrt ( b*b + c*c - 2bc*cosA )
            final float b = ab.length();
            final float c = cb.length();
            final float mDistance =
                (float) Math.sqrt(b * b + c * c - 2 * b * c * (float) Math.cos(mMinAngle));
            restlength(mDistance);
          }
          break;
        case MAX_DISTANCE_MODELL:
          {
            final float mDistance =
                mParticleA.position().distance(mParticleB.position())
                    + mParticleC.position().distance(mParticleB.position());
            restlength(mDistance);
          }
          break;
      }
      active(true);
    }
  }
Example #2
0
 public void setRestLengthByPosition() {
   mRestLength = mA.position().distance(mB.position());
 }
Example #3
0
 public Spring(
     Particle theA, Particle theB, final float theSpringConstant, final float theSpringDamping) {
   this(
       theA, theB, theSpringConstant, theSpringDamping, theA.position().distance(theB.position()));
 }
Example #4
0
 public Spring(Particle theA, Particle theB) {
   this(theA, theB, 2.0f, 0.1f, theA.position().distance(theB.position()));
 }
Example #5
0
 public boolean dead() {
   return mA.dead() || mB.dead();
 }
Example #6
0
  public void apply(final float theDeltaTime, final Physics theParticleSystem) {
    //        if (!mA.fixed() || !mB.fixed()) {
    float a2bX = mA.position().x - mB.position().x;
    float a2bY = mA.position().y - mB.position().y;
    float a2bZ = mA.position().z - mB.position().z;
    final float myInversDistance = fastInverseSqrt(a2bX * a2bX + a2bY * a2bY + a2bZ * a2bZ);
    final float myDistance = 1.0F / myInversDistance;

    if (myDistance == 0.0F) {
      a2bX = 0.0F;
      a2bY = 0.0F;
      a2bZ = 0.0F;
    } else {
      a2bX *= myInversDistance;
      a2bY *= myInversDistance;
      a2bZ *= myInversDistance;
    }

    final float mSpringForce = -(myDistance - mRestLength) * mSpringConstant;
    final float Va2bX = mA.velocity().x - mB.velocity().x;
    final float Va2bY = mA.velocity().y - mB.velocity().y;
    final float Va2bZ = mA.velocity().z - mB.velocity().z;
    final float mDampingForce = -mSpringDamping * (a2bX * Va2bX + a2bY * Va2bY + a2bZ * Va2bZ);
    final float r = mSpringForce + mDampingForce;
    a2bX *= r;
    a2bY *= r;
    a2bZ *= r;

    if (mOneWay) {
      if (!mB.fixed()) {
        mB.force().add(-2 * a2bX, -2 * a2bY, -2 * a2bZ);
      }
    } else {
      if (!mA.fixed()) {
        mA.force().add(a2bX, a2bY, a2bZ);
      }
      if (!mB.fixed()) {
        mB.force().add(-a2bX, -a2bY, -a2bZ);
      }
    }
    //        }
  }
Example #7
0
 public final float currentLength() {
   return mA.position().distance(mB.position());
 }