Package eas.simulation.spatial.sim2D.physicalSimulation.physicsEngine.net.phys2d.math

Examples of eas.simulation.spatial.sim2D.physicalSimulation.physicsEngine.net.phys2d.math.Vector2f


   * Get the change in position in the last update
   *
   * @return The change in position in the last update
   */
  public ROVector2f getPositionDelta() {
    Vector2f vec = new Vector2f(getPosition());
    vec.sub(getLastPosition());
   
    return vec;
  }
View Full Code Here


   * Get the change in velocity in the last update
   *
   * @return The change in velocity in the last update
   */
  public ROVector2f getVelocityDelta() {
    Vector2f vec = new Vector2f(getVelocity());
    vec.sub(getLastVelocity());
   
    return vec;
  }
View Full Code Here

   *
   * @param maxX The maximum velocity on the X axis
   * @param maxY The maximum veloicty on the Y axis
   */
  public void setMaxVelocity(float maxX, float maxY) {
    maxVelocity = new Vector2f(maxX, maxY);
  }
View Full Code Here

    Matrix2f rot1 = new Matrix2f(body1.getRotation());
    Matrix2f rot2 = new Matrix2f(body2.getRotation());
    Matrix2f rot1T = rot1.transpose();
    Matrix2f rot2T = rot2.transpose();

    Vector2f a1 = new Vector2f(body2.getPosition());
    a1.sub(body1.getPosition());
    localAnchor1 = MathUtil.mul(rot1T,a1);
    Vector2f a2 = new Vector2f(body1.getPosition());
    a2.sub(body2.getPosition());
    localAnchor2 = MathUtil.mul(rot2T,a2);

    accumulatedImpulse.set(0.0f, 0.0f);
    relaxation = 1.0f;
  }
View Full Code Here

    K3.col1.y = -body2.getInvI() * r2.x * r2.y;    K3.col2.y =  body2.getInvI() * r2.x * r2.x;

    Matrix2f K = MathUtil.add(MathUtil.add(K1,K2),K3);
    M = K.invert();

    Vector2f p1 = new Vector2f(body1.getPosition());
    p1.add(r1);
    Vector2f p2 = new Vector2f(body2.getPosition());
    p2.add(r2);
    Vector2f dp = new Vector2f(p2);
    dp.sub(p1);
   
    bias = new Vector2f(dp);
    bias.scale(-0.1f);
    bias.scale(invDT);

    // Apply accumulated impulse.
    accumulatedImpulse.scale(relaxation);
   
    Vector2f accum1 = new Vector2f(accumulatedImpulse);
    accum1.scale(-body1.getInvMass());
    body1.adjustVelocity(accum1);
    body1.adjustAngularVelocity(-(body1.getInvI() * MathUtil.cross(r1, accumulatedImpulse)));

    Vector2f accum2 = new Vector2f(accumulatedImpulse);
    accum2.scale(body2.getInvMass());
    body2.adjustVelocity(accum2);
    body2.adjustAngularVelocity(body2.getInvI() * MathUtil.cross(r2, accumulatedImpulse));
  }
View Full Code Here

  /**
   * Apply the impulse caused by the joint to the bodies attached.
   */
  @Override
    public void applyImpulse() {
    Vector2f dv = new Vector2f(body2.getVelocity());
    dv.add(MathUtil.cross(body2.getAngularVelocity(),r2));
    dv.sub(body1.getVelocity());
    dv.sub(MathUtil.cross(body1.getAngularVelocity(),r1));
      dv.scale(-1);
      dv.add(bias);
     
      if (dv.lengthSquared() == 0) {
        return;
      }
     
    Vector2f impulse = MathUtil.mul(M, dv);

    Vector2f delta1 = new Vector2f(impulse);
    delta1.scale(-body1.getInvMass());
    body1.adjustVelocity(delta1);
    body1.adjustAngularVelocity(-body1.getInvI() * MathUtil.cross(r1,impulse));

    Vector2f delta2 = new Vector2f(impulse);
    delta2.scale(body2.getInvMass());
    body2.adjustVelocity(delta2);
    body2.adjustAngularVelocity(body2.getInvI() * MathUtil.cross(r2,impulse));

    accumulatedImpulse.add(impulse);
  }
 
View Full Code Here

    public void applyImpulse() {
    if (bounceSide == BOUNCE_NONE)
      return;
    Matrix2f rot1 = new Matrix2f(body1.getRotation());
    Matrix2f rot2 = new Matrix2f(body2.getRotation());
    Vector2f r1 = MathUtil.mul(rot1, anchor1);
    Vector2f r2 = MathUtil.mul(rot2, anchor2);

    Vector2f relativeVelocity = new Vector2f(body2.getVelocity());
    relativeVelocity.add(MathUtil.cross(r2, body2.getAngularVelocity()));
    relativeVelocity.sub(body1.getVelocity());
    relativeVelocity.sub(MathUtil.cross(r1, body1.getAngularVelocity()));

    /*
     * Matrix2f tr1 = new Matrix2f(-body1.getRotation()); relativeVelocity =
     * MathUtil.mul(tr1, relativeVelocity);
     * relativeVelocity.add(MathUtil.mul(tr1, dp));
     */

    float rv = MathUtil.cross(dp, relativeVelocity) / dlength2
        - body1.getAngularVelocity();
    rv = restituteAngular - rv;

    float p = rv / K;
    float oldImpulse = accumulateImpulse;
    float newImpulse;

    if (bounceSide == BOUNCE_HIGHER) {
      newImpulse = accumulateImpulse + p > 0.0f ? accumulateImpulse + p
          : 0.0f;
      p = newImpulse - oldImpulse;
    } else {
      newImpulse = accumulateImpulse + p < 0.0f ? accumulateImpulse + p
          : 0.0f;
      p = newImpulse - oldImpulse;
    }
    accumulateImpulse = newImpulse;

    Vector2f impulse = new Vector2f(n);
    impulse.scale(p);
    if (!body1.isStatic()) {
      Vector2f accum1 = new Vector2f(impulse);
      accum1.scale(body1.getInvMass());
      body1.adjustVelocity(accum1);
      body1.adjustAngularVelocity((body1.getInvI() * MathUtil.cross(R,
          impulse)));
    }
    if (!body2.isStatic()) {
      Vector2f accum2 = new Vector2f(impulse);
      accum2.scale(-body2.getInvMass());
      body2.adjustVelocity(accum2);
      body2.adjustAngularVelocity(-(body2.getInvI() * MathUtil.cross(r2,
          impulse)));
    }
  }
 
View Full Code Here

    float biasFactor = 0.005f;
    float biasImpulse = 0.0f;
    float RA = body1.getRotation() + rotateA;
    float RB = body1.getRotation() + rotateB;

    Vector2f VA = new Vector2f((float) Math.cos(RA), (float) Math.sin(RA));
    Vector2f VB = new Vector2f((float) Math.cos(RB), (float) Math.sin(RB));

    Matrix2f rot1 = new Matrix2f(body1.getRotation());
    Matrix2f rot2 = new Matrix2f(body2.getRotation());
    Vector2f r1 = MathUtil.mul(rot1, anchor1);
    Vector2f r2 = MathUtil.mul(rot2, anchor2);

    Vector2f p1 = new Vector2f(body1.getPosition());
    p1.add(r1);
    Vector2f p2 = new Vector2f(body2.getPosition());
    p2.add(r2);
    dp = new Vector2f(p2);
    dp.sub(p1);
    dlength2 = dp.lengthSquared();
    ndp = new Vector2f(dp);
    ndp.normalise();

    R = new Vector2f(r1);
    R.add(dp);
    // System.out.println(accumulateImpulse);
    Vector2f relativeVelocity = new Vector2f(body2.getVelocity());
    relativeVelocity.add(MathUtil.cross(r2, body2.getAngularVelocity()));
    relativeVelocity.sub(body1.getVelocity());
    relativeVelocity.sub(MathUtil.cross(r1, body1.getAngularVelocity()));

    /*
     * Matrix2f tr1 = new Matrix2f(-body1.getRotation()); relativeVelocity =
     * MathUtil.mul(tr1, relativeVelocity);
     * relativeVelocity.add(MathUtil.mul(tr1, dp));
     */
    // relativeVelocity.add(MathUtil.cross(dp,body1.getAngularVelocity()));
    n = new Vector2f(-ndp.y, ndp.x);
    Vector2f v1 = new Vector2f(n);
    v1.scale(-body2.getInvMass() - body1.getInvMass());

    Vector2f v2 = MathUtil.cross(MathUtil.cross(r2, n), r2);
    v2.scale(-body2.getInvI());

    Vector2f v3 = MathUtil.cross(MathUtil.cross(R, n), r1);
    v3.scale(-body1.getInvI());

    Vector2f K1 = new Vector2f(v1);
    K1.add(v2);
    K1.add(v3);

    K = MathUtil.cross(dp, K1) / dlength2 - MathUtil.cross(R, n)
        * body1.getInvI();

    restituteAngular = -restitution
        * (MathUtil.cross(dp, relativeVelocity) / dlength2 - body1
            .getAngularVelocity());

    if (MathUtil.cross(ndp, VA) > 0) {
      // collide on A side
      if (bounceSide != BOUNCE_LOWER)
        accumulateImpulse = 0;
      biasImpulse = biasFactor * MathUtil.cross(ndp, VA) * invDT;
      bounceSide = BOUNCE_LOWER;
      if (restituteAngular < 0) {
        restituteAngular = 0;
      }
    } else if (MathUtil.cross(VB, ndp) > 0) {
      // collide on B side
      if (bounceSide != BOUNCE_HIGHER)
        accumulateImpulse = 0;
      biasImpulse = -biasFactor * MathUtil.cross(VB, ndp) * invDT;
      bounceSide = BOUNCE_HIGHER;
      if (restituteAngular > 0) {
        restituteAngular = 0;
      }
    } else {
      accumulateImpulse = 0;
      biasImpulse = 0.0f;
      bounceSide = BOUNCE_NONE;
    }
    restituteAngular += biasImpulse;

    Vector2f impulse = new Vector2f(n);
    impulse.scale(accumulateImpulse);
    if (!body1.isStatic()) {
      Vector2f accum1 = new Vector2f(impulse);
      accum1.scale(body1.getInvMass());
      body1.adjustVelocity(accum1);
      body1.adjustAngularVelocity((body1.getInvI() * MathUtil.cross(R,
          impulse)));
    }
    if (!body2.isStatic()) {
      Vector2f accum2 = new Vector2f(impulse);
      accum2.scale(-body2.getInvMass());
      body2.adjustVelocity(accum2);
      body2.adjustAngularVelocity(-(body2.getInvI() * MathUtil.cross(r2,
          impulse)));
    }
  }
 
View Full Code Here

   */
  @Override
    public void applyImpulse() {
    Matrix2f rot1 = new Matrix2f(body1.getRotation());
    Matrix2f rot2 = new Matrix2f(body2.getRotation());
    Vector2f r1 = MathUtil.mul(rot1, anchor1);
    Vector2f r2 = MathUtil.mul(rot2, anchor2);

    Vector2f relativeVelocity = new Vector2f(body2.getVelocity());
    relativeVelocity.add(MathUtil.cross(r2, body2.getAngularVelocity()));
    relativeVelocity.sub(body1.getVelocity());
    relativeVelocity.sub(MathUtil.cross(r1, body1.getAngularVelocity()));

    /*
     * Matrix2f tr1 = new Matrix2f(-body1.getRotation()); relativeVelocity =
     * MathUtil.mul(tr1, relativeVelocity);
     * relativeVelocity.add(MathUtil.mul(tr1, dp));
     */

    float rv = MathUtil.cross(dp, relativeVelocity) / dlength2
        - body1.getAngularVelocity();
    rv = 0 - rv;

    float p = rv / K;
    float oldImpulse = accumulateImpulse;
    float newImpulse;

    newImpulse = accumulateImpulse + p;
    p = newImpulse - oldImpulse;

    accumulateImpulse = newImpulse;

    Vector2f impulse = new Vector2f(n);
    impulse.scale(p);
    if (!body1.isStatic()) {
      Vector2f accum1 = new Vector2f(impulse);
      accum1.scale(body1.getInvMass());
      body1.adjustVelocity(accum1);
      body1.adjustAngularVelocity((body1.getInvI() * MathUtil.cross(R,
          impulse)));
    }
    if (!body2.isStatic()) {
      Vector2f accum2 = new Vector2f(impulse);
      accum2.scale(-body2.getInvMass());
      body2.adjustVelocity(accum2);
      body2.adjustAngularVelocity(-(body2.getInvI() * MathUtil.cross(r2,
          impulse)));
    }
  }
 
View Full Code Here

    public void preStep(float invDT) {
    float biasFactor = 0.005f;
    float biasImpulse = 0.0f;
    float RA = body1.getRotation() + rotateA;

    Vector2f VA = new Vector2f((float) Math.cos(RA), (float) Math.sin(RA));

    Matrix2f rot1 = new Matrix2f(body1.getRotation());
    Matrix2f rot2 = new Matrix2f(body2.getRotation());
    Vector2f r1 = MathUtil.mul(rot1, anchor1);
    Vector2f r2 = MathUtil.mul(rot2, anchor2);

    Vector2f p1 = new Vector2f(body1.getPosition());
    p1.add(r1);
    Vector2f p2 = new Vector2f(body2.getPosition());
    p2.add(r2);
    dp = new Vector2f(p2);
    dp.sub(p1);
    dlength2 = dp.lengthSquared();
    ndp = new Vector2f(dp);
    ndp.normalise();

    R = new Vector2f(r1);
    R.add(dp);
    // System.out.println(accumulateImpulse);
    Vector2f relativeVelocity = new Vector2f(body2.getVelocity());
    relativeVelocity.add(MathUtil.cross(r2, body2.getAngularVelocity()));
    relativeVelocity.sub(body1.getVelocity());
    relativeVelocity.sub(MathUtil.cross(r1, body1.getAngularVelocity()));

    /*
     * Matrix2f tr1 = new Matrix2f(-body1.getRotation()); relativeVelocity =
     * MathUtil.mul(tr1, relativeVelocity);
     * relativeVelocity.add(MathUtil.mul(tr1, dp));
     */
    // relativeVelocity.add(MathUtil.cross(dp,body1.getAngularVelocity()));
    n = new Vector2f(-ndp.y, ndp.x);
    Vector2f v1 = new Vector2f(n);
    v1.scale(-body2.getInvMass() - body1.getInvMass());

    Vector2f v2 = MathUtil.cross(MathUtil.cross(r2, n), r2);
    v2.scale(-body2.getInvI());

    Vector2f v3 = MathUtil.cross(MathUtil.cross(R, n), r1);
    v3.scale(-body1.getInvI());

    Vector2f K1 = new Vector2f(v1);
    K1.add(v2);
    K1.add(v3);

    K = MathUtil.cross(dp, K1) / dlength2 - MathUtil.cross(R, n)
        * body1.getInvI();



      biasImpulse = biasFactor * MathUtil.cross(ndp, VA) * invDT;

    Vector2f impulse = new Vector2f(n);
    impulse.scale(accumulateImpulse+biasImpulse);
    if (!body1.isStatic()) {
      Vector2f accum1 = new Vector2f(impulse);
      accum1.scale(body1.getInvMass());
      body1.adjustVelocity(accum1);
      body1.adjustAngularVelocity((body1.getInvI() * MathUtil.cross(R,
          impulse)));
    }
    if (!body2.isStatic()) {
      Vector2f accum2 = new Vector2f(impulse);
      accum2.scale(-body2.getInvMass());
      body2.adjustVelocity(accum2);
      body2.adjustAngularVelocity(-(body2.getInvI() * MathUtil.cross(r2,
          impulse)));
    }
  }
 
View Full Code Here

TOP

Related Classes of eas.simulation.spatial.sim2D.physicalSimulation.physicsEngine.net.phys2d.math.Vector2f

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.