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

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


   
    for (int i = 0; i < numContacts; ++i)
    {
      Contact c = contacts[i];
     
      Vector2f r1 = new Vector2f(c.position);
      r1.sub(b1.getPosition());
      Vector2f r2 = new Vector2f(c.position);
      r2.sub(b2.getPosition());

      // Relative velocity at contact
      Vector2f relativeVelocity =  new Vector2f(b2.getVelocity());
      relativeVelocity.add(MathUtil.cross(b2.getAngularVelocity(), r2));
      relativeVelocity.sub(b1.getVelocity());
      relativeVelocity.sub(MathUtil.cross(b1.getAngularVelocity(), r1));
     
      // Compute normal impulse with bias.
      float vn = relativeVelocity.dot(c.normal);
     
      // bias caculations are now handled seperately hence we only
      // handle the real impulse caculations here
      //float normalImpulse = c.massNormal * ((c.restitution - vn) + c.bias);
      float normalImpulse = c.massNormal * (c.restitution - vn);
     
      // Clamp the accumulated impulse
      float oldNormalImpulse = c.accumulatedNormalImpulse;
      c.accumulatedNormalImpulse = Math.max(oldNormalImpulse + normalImpulse, 0.0f);
      normalImpulse = c.accumulatedNormalImpulse - oldNormalImpulse;
     
      // Apply contact impulse
      Vector2f impulse = MathUtil.scale(c.normal, normalImpulse);
     
      b1.adjustVelocity(MathUtil.scale(impulse, -b1.getInvMass()));
      b1.adjustAngularVelocity(-(b1.getInvI() * MathUtil.cross(r1, impulse)));

      b2.adjustVelocity(MathUtil.scale(impulse, b2.getInvMass()));
      b2.adjustAngularVelocity(b2.getInvI() * MathUtil.cross(r2, impulse));

      // Compute bias impulse
      // NEW STUFF FOR SEPERATING BIAS
      relativeVelocity.set(b2.getBiasedVelocity());
      relativeVelocity.add(MathUtil.cross(b2.getBiasedAngularVelocity(), r2));
      relativeVelocity.sub(b1.getBiasedVelocity());
      relativeVelocity.sub(MathUtil.cross(b1.getBiasedAngularVelocity(), r1));
      float vnb = relativeVelocity.dot(c.normal);

      float biasImpulse = c.massNormal * (-vnb + c.bias);
      float oldBiasImpulse = c.biasImpulse;
      c.biasImpulse = Math.max(oldBiasImpulse + biasImpulse, 0.0f);
      biasImpulse = c.biasImpulse - oldBiasImpulse;

      Vector2f Pb = MathUtil.scale(c.normal, biasImpulse);
     
      b1.adjustBiasedVelocity(MathUtil.scale(Pb, -b1.getInvMass()));
      b1.adjustBiasedAngularVelocity(-(b1.getInvI() * MathUtil.cross(r1, Pb)));

      b2.adjustBiasedVelocity(MathUtil.scale(Pb, b2.getInvMass()));
      b2.adjustBiasedAngularVelocity((b2.getInvI() * MathUtil.cross(r2, Pb)));

      // END NEW STUFF
     
      //
      // Compute friction (tangent) impulse
      //
      float maxTangentImpulse = friction * c.accumulatedNormalImpulse;

      // Relative velocity at contact
      relativeVelocity.set(b2.getVelocity());
      relativeVelocity.add(MathUtil.cross(b2.getAngularVelocity(), r2));
      relativeVelocity.sub(b1.getVelocity());
      relativeVelocity.sub(MathUtil.cross(b1.getAngularVelocity(), r1));
     
      Vector2f tangent = MathUtil.cross(c.normal, 1.0f);
      float vt = relativeVelocity.dot(tangent);
      float tangentImpulse = c.massTangent * (-vt);

      // Clamp friction
      float oldTangentImpulse = c.accumulatedTangentImpulse;
View Full Code Here


   * @param body1 The first body
   * @param body2 The second body
   * @return The energy contained
   */
  protected float getEnergy(AgentType body1, AgentType body2) {
    Vector2f combinedVel = MathUtil.scale(body1.getVelocity(), body1.getMass());
    combinedVel.add(MathUtil.scale(body2.getVelocity(), body2.getMass()));
   
    @SuppressWarnings("unused")
        float combinedInertia = body1.getI() * body1.getAngularVelocity();
    combinedInertia += body2.getI() * body2.getAngularVelocity();
   
 
View Full Code Here

    // TODO: this can be optimized using matrix multiplications and moving only one shape
    // specifically the line, because it has only two vertices
    Vector2f[] vertsA = line.getVertices(bodyA.getPosition(), bodyA.getRotation());
    Vector2f[] vertsB = poly.getVertices(bodyB.getPosition(), bodyB.getRotation());

    Vector2f pos = poly.getCentroid(bodyB.getPosition(), bodyB.getRotation());
   
    // using the z axis of a 3d cross product we determine on what side B is
    boolean isLeftOf = 0 > (pos.x - vertsA[0].x) * (vertsA[1].y - vertsA[0].y) - (vertsA[1].x - vertsA[0].x) * (pos.y - vertsA[0].y);
   
    // to get the proper intersection pairs we make sure
    // the line's normal is pointing towards the polygon
    // TODO: verify that it's not actually pointing in the opposite direction
    if ( isLeftOf ) {
      Vector2f tmp = vertsA[0];
      vertsA[0] = vertsA[1];
      vertsA[1] = tmp;
    }
   
    // we use the line's normal for our sweepline projection
    Vector2f normal = new Vector2f(vertsA[1]);
    normal.sub(vertsA[0]);
    normal.set(normal.y, -normal.x);
    EdgeSweep sweep = new EdgeSweep(normal);
    sweep.insert(0, true, vertsA[0].dot(normal));
    sweep.insert(0, true, vertsA[1].dot(normal));
    sweep.addVerticesToSweep(false, vertsB);
    int[][] collEdgeCands = sweep.getOverlappingEdges();
View Full Code Here

   * @param intersection The intersection where the line enters or exits the polygon
   * @param vertsA The line's vertices
   * @param vertsB The polygon's vertices
   */
  public void setLineEndContact(Contact contact, Intersection intersection, Vector2f[] vertsA, Vector2f[] vertsB) {
    Vector2f separation = new Vector2f(intersection.position);
    if ( intersection.isIngoing )
      separation.sub(vertsA[1]);
    else
      separation.sub(vertsA[0]);
   
    float depthA = 0;//separation.length();
   
    contact.setSeparation(-depthA);
    contact.setNormal(MathUtil.getNormal(vertsB[(intersection.edgeB + 1) % vertsB.length], vertsB[intersection.edgeB]));
View Full Code Here

        this.color = Color.gray;
        if (this.id() == 1 && (
                e.getEventDescription().equals(ConstantsSimulation.KEY_EVENT_ARROW_KEY_ENCODING_RIGHT)
             || e.getEventDescription().equals(ConstantsSimulation.KEY_EVENT_ARROW_KEY_ENCODING_UP))) {
            Vector2D v = ((AbstractEnvironment2D) this.getEnvironment()).getNormalizedLOV(this.id());
            this.addForce(new Vector2f((float) v.x * force, (float) v.y * force));
            this.color = Color.orange;
            this.lastActionTime = lastActionTime.getLastTick();
            this.fuelWasted++;
        }
        if (this.id() == 2 && (
                e.getEventDescription().equals(ConstantsSimulation.KEY_EVENT_ARROW_KEY_ENCODING_LEFT)
                || e.getEventDescription().equals(ConstantsSimulation.KEY_EVENT_ARROW_KEY_ENCODING_UP))) {
            Vector2D v = ((AbstractEnvironment2D) this.getEnvironment()).getNormalizedLOV(this.id());
            this.addForce(new Vector2f((float) v.x * force, (float) v.y * force));
            this.color = Color.orange;
            this.lastActionTime = lastActionTime.getLastTick();
            this.fuelWasted++;
        }
    }
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

        double abstand =  java.lang.Math.sqrt(xAbstand*xAbstand + yAbstand*yAbstand);
        double anziehungskraft = (gravitationsKonstante * agent.getMass()) / (abstand*abstand);
        float anziehungX = (float)(anziehungskraft * xAbstand);
        float anziehungY = (float)(anziehungskraft * yAbstand);
       
        Vector2f anziehung = new Vector2f(anziehungX,anziehungY);
        agent.adjustVelocity(anziehung);
      }
    
  }
View Full Code Here

   
    stretchedSpringConst = 100;
    compressedSpringConst = 100;
    brokenSpringConst = 100;
   
    Vector2f spring = new Vector2f(anchor1);
    spring.sub(anchor2);
    springSize = spring.length();
    minSpringSize = 0;
    maxSpringSize = 2 * springSize;
   
    set(b1,b2,anchor1,anchor2);
  }
 
View Full Code Here

    body1 = b1;
    body2 = b2; 

    Matrix2f rot1 = new Matrix2f(body1.getRotation());
    Matrix2f rot1T = rot1.transpose();
    Vector2f a1 = new Vector2f(anchor1);
    a1.sub(body1.getPosition());
    localAnchor1 = MathUtil.mul(rot1T,a1);
   
    Matrix2f rot2 = new Matrix2f(body2.getRotation());
    Matrix2f rot2T = rot2.transpose();
    Vector2f a2 = new Vector2f(anchor2);
    a2.sub(body2.getPosition());
    localAnchor2 = MathUtil.mul(rot2T,a2);
  }
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.