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

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


  @Override
    public void applyImpulse() {
    if(collideSide==COLLIDE_NONE)
      return;
   
    Vector2f dv = new Vector2f(body2.getVelocity());
    dv.add(MathUtil.cross(body2.getAngularVelocity(),r2));
    dv.sub(body1.getVelocity());
    dv.sub(MathUtil.cross(body1.getAngularVelocity(),r1));
    float reln = dv.dot(ndp);
    reln = restitute-reln;
    float P = reln/K;
    float newImpulse;
    if(collideSide==COLLIDE_MIN){
      newImpulse = accumulateImpulse+P<0.0f?accumulateImpulse+P:0.0f;
    }else{
      newImpulse = accumulateImpulse+P>0.0f?accumulateImpulse+P:0.0f;
    }
    P = newImpulse-accumulateImpulse;
    accumulateImpulse = newImpulse;
   
    Vector2f impulse = new Vector2f(ndp);
    impulse.scale(P);
   
    if (!body1.isStatic()) {
      Vector2f accum1 = new Vector2f(impulse);
      accum1.scale(body1.getInvMass());
      body1.adjustVelocity(accum1);
      body1.adjustAngularVelocity((body1.getInvI() * MathUtil.cross(r1, 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


    Matrix2f rot2 = new Matrix2f(body2.getRotation());

     r1 = MathUtil.mul(rot1,anchor1);
     r2 = MathUtil.mul(rot2,anchor2);
   
    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);
   
    Vector2f dv = new Vector2f(body2.getVelocity());
    dv.add(MathUtil.cross(body2.getAngularVelocity(),r2));
    dv.sub(body1.getVelocity());
    dv.sub(MathUtil.cross(body1.getAngularVelocity(),r1));
     
    ndp = new Vector2f(dp);
    ndp.normalise();
   
    restitute = -restitutionConstant*dv.dot(ndp);
   
    Vector2f v1 = new Vector2f(ndp);
    v1.scale(-body2.getInvMass() - body1.getInvMass());

    Vector2f v2 = MathUtil.cross(MathUtil.cross(r2, ndp), r2);
    v2.scale(-body2.getInvI());
   
    Vector2f v3 = MathUtil.cross(MathUtil.cross(r1, ndp),r1);
    v3.scale(-body1.getInvI());
   
    Vector2f K1 = new Vector2f(v1);
    K1.add(v2);
    K1.add(v3);
   
    K = K1.dot(ndp);
    float length=dp.lengthSquared();
    if(length<minDistance){
      if(collideSide!=COLLIDE_MIN)
        accumulateImpulse=0;
      collideSide=COLLIDE_MIN;     
      biasImpulse=-biasFactor*(length-minDistance);
      if(restitute<0)
        restitute=0;
    }else if(length>maxDistance){
      if(collideSide!=COLLIDE_MAX)
        accumulateImpulse=0;
      collideSide=COLLIDE_MAX;
      biasImpulse=-biasFactor*(length-maxDistance);
      if(restitute>0)
        restitute=0;
    }else{
      collideSide=COLLIDE_NONE;
      accumulateImpulse=0;
    }
    restitute+=biasImpulse;
    Vector2f impulse = new Vector2f(ndp);
    impulse.scale(accumulateImpulse);
   
    if (!body1.isStatic()) {
      Vector2f accum1 = new Vector2f(impulse);
      accum1.scale(body1.getInvMass());
      body1.adjustVelocity(accum1);
      body1.adjustAngularVelocity((body1.getInvI() * MathUtil.cross(r1, 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

    // TODO Auto-generated method stub
   
       
    /* Gravitation mit Vector2f einstellbar*/
    DomPhysEnv env
    = new DomPhysEnv(0, params, new Vector2f(0, 0), 100);
   
    DomPhysBalken balken = new DomPhysBalken (1, env, "balken", 1,params);
    env.addAgent(balken, new Vector2D(-100, -100), 45);
   
    //balken.adjustAngularVelocity(1f);
View Full Code Here

    double Abstand =  java.lang.Math.sqrt(xAbstand*xAbstand + yAbstand*yAbstand);
   
    /* Berechnung der relativen Lage zu Rumpfmittelpunkt und Verstärkung
     * Beachte: Abstand immer 2.5
     */
    Vector2f vKraft; float xKraft; float yKraft;
    xKraft = 40 * ((float) posRumpf.x - pos.getX());
    yKraft = 40 * ((float) posRumpf.y - pos.getY());
    vKraft = new Vector2f (xKraft, yKraft);
   
           
    /*Berechnung der Flugrichtung und Normalisierung des Vektors
    ROVector2f vHilf = this.getLastVelocity();
    Vector2f vRichtung = new Vector2f(vHilf);
View Full Code Here

    double Konstante = 10;
    double xAbstand = posMond.x- pos.x;
    double yAbstand = posMond.y- pos.y;
    double Abstand =  java.lang.Math.sqrt(xAbstand*xAbstand + yAbstand*yAbstand);
    double Anziehungskraft = (Konstante * agent.getMass()) / (Abstand*Abstand);
    Vector2f Anziehung = new Vector2f((float)(Anziehungskraft * xAbstand),(float)(Anziehungskraft * yAbstand));
    agent.adjustVelocity(Anziehung);
  }
 
View Full Code Here

                  ROVector2f pos,
                  Matrix2f rot, Vector2f normal) {
    // The normal is from the reference box. Convert it
    // to the incident boxe's frame and flip sign.
    Matrix2f rotT = rot.transpose();
    Vector2f n = MathUtil.scale(MathUtil.mul(rotT,normal),-1);
    Vector2f nAbs = MathUtil.abs(n);

    if (nAbs.x > nAbs.y)
    {
      if (MathUtil.sign(n.x) > 0.0f)
      {
View Full Code Here

//    Vector2f a1 = rotA.col1;
//    Vector2f a2 = rotA.col2;
//    Vector2f b1 = rotB.col1;
//    Vector2f b2 = rotB.col2;

    Vector2f dp = MathUtil.sub(posB,posA);
    Vector2f dA = MathUtil.mul(RotAT,dp);
    Vector2f dB = MathUtil.mul(RotBT,dp);

    Matrix2f C = MathUtil.mul(RotAT,rotB);
    Matrix2f absC = MathUtil.abs(C);
    Matrix2f absCT = absC.transpose();

    // Box A faces
    Vector2f faceA = MathUtil.abs(dA);
    faceA.sub(hA);
    faceA.sub(MathUtil.mul(absC,hB));
   
    if (faceA.x > 0.0f || faceA.y > 0.0f) {
      return 0;
    }

    // Box B faces
    Vector2f faceB = MathUtil.abs(dB);
    faceB.sub(MathUtil.mul(absCT,hA));
    faceB.sub(hB);
    //MathUtil.sub(MathUtil.sub(MathUtil.abs(dB),MathUtil.mul(absCT,hA)),hB);
    if (faceB.x > 0.0f || faceB.y > 0.0f) {
      return 0;
    }

    // Find best axis
    int axis;
    float separation;
    Vector2f normal;

    // Box A faces
    axis = FACE_A_X;
    separation = faceA.x;
    normal = dA.x > 0.0f ? rotA.col1 : MathUtil.scale(rotA.col1,-1);

    if (faceA.y > 1.05f * separation + 0.01f * hA.y)
    {
      axis = FACE_A_Y;
      separation = faceA.y;
      normal = dA.y > 0.0f ? rotA.col2 : MathUtil.scale(rotA.col2,-1);
    }

    // Box B faces
    if (faceB.x > 1.05f * separation + 0.01f * hB.x)
    {
      axis = FACE_B_X;
      separation = faceB.x;
      normal = dB.x > 0.0f ? rotB.col1 : MathUtil.scale(rotB.col1,-1);
    }

    if (faceB.y > 1.05f * separation + 0.01f * hB.y)
    {
      axis = FACE_B_Y;
      separation = faceB.y;
      normal = dB.y > 0.0f ? rotB.col2 : MathUtil.scale(rotB.col2,-1);
    }

    // Setup clipping plane data based on the separating axis
    Vector2f frontNormal, sideNormal;
    ClipVertex[] incidentEdge = new ClipVertex[] {new ClipVertex(), new ClipVertex()};
    float front, negSide, posSide;
    char negEdge, posEdge;

    // Compute the clipping lines and the line segment to be clipped.
    switch (axis)
    {
    case FACE_A_X:
      {
        frontNormal = normal;
        front = posA.dot(frontNormal) + hA.x;
        sideNormal = rotA.col2;
        float side = posA.dot(sideNormal);
        negSide = -side + hA.y;
        posSide =  side + hA.y;
        negEdge = EDGE3;
        posEdge = EDGE1;
        computeIncidentEdge(incidentEdge, hB, posB, rotB, frontNormal);
      }
      break;

    case FACE_A_Y:
      {
        frontNormal = normal;
        front = posA.dot(frontNormal) + hA.y;
        sideNormal = rotA.col1;
        float side = posA.dot(sideNormal);
        negSide = -side + hA.x;
        posSide =  side + hA.x;
        negEdge = EDGE2;
        posEdge = EDGE4;
        computeIncidentEdge(incidentEdge, hB, posB, rotB, frontNormal);
      }
      break;

    case FACE_B_X:
      {
        frontNormal = MathUtil.scale(normal,-1);
        front = posB.dot(frontNormal) + hB.x;
        sideNormal = rotB.col2;
        float side = posB.dot(sideNormal);
        negSide = -side + hB.y;
        posSide =  side + hB.y;
        negEdge = EDGE3;
        posEdge = EDGE1;
        computeIncidentEdge(incidentEdge, hA, posA, rotA, frontNormal);
      }
      break;

    case FACE_B_Y:
      {
        frontNormal = MathUtil.scale(normal,-1);
        front = posB.dot(frontNormal) + hB.y;
        sideNormal = rotB.col1;
        float side = posB.dot(sideNormal);
        negSide = -side + hB.x;
        posSide =  side + hB.x;
        negEdge = EDGE2;
        posEdge = EDGE4;
        computeIncidentEdge(incidentEdge, hA, posA, rotA, frontNormal);
      }
      break;
    default:
      throw new RuntimeException("Unknown face!");
    }

    // clip other face with 5 box planes (1 face plane, 4 edge planes)

    ClipVertex[] clipPoints1 = new ClipVertex[] {new ClipVertex(), new ClipVertex()};
    ClipVertex[] clipPoints2 = new ClipVertex[] {new ClipVertex(), new ClipVertex()};
    int np;

    // Clip to box side 1
    np = clipSegmentToLine(clipPoints1, incidentEdge, MathUtil.scale(sideNormal,-1), negSide, negEdge);

    if (np < 2)
      return 0;

    // Clip to negative box side 1
    np = clipSegmentToLine(clipPoints2, clipPoints1,  sideNormal, posSide, posEdge);

    if (np < 2)
      return 0;

    // Now clipPoints2 contains the clipping points.
    // Due to roundoff, it is possible that clipping removes all points.

    int numContacts = 0;
    for (int i = 0; i < 2; ++i)
    {
      float separation2 = frontNormal.dot(clipPoints2[i].v) - front;

      if (separation2 <= 0)
      {
        contacts[numContacts].setSeparation(separation2);
        contacts[numContacts].setNormal(normal);
View Full Code Here

    double antriebY = Math.cos(richtungRad) * schub;
   
    //System.out.println("AgentID: " + agent.getID() + " RichtungAntriebX: " + antriebX + " Richtung AntriebY:" + antriebY);
    //System.out.println("Antrieb: " + schub);
       
    Vector2f antrieb = new Vector2f ((float)antriebX, (float) antriebY);
       
    agent.addForce(antrieb);
   
         
   
View Full Code Here

   */
  public void set(PhysicsAgent2D<?> b1, PhysicsAgent2D<?> b2) {
    body1 = b1;
    body2 = b2;

    joint1 = new BasicJoint(b1,b2,new Vector2f(b1.getPosition()));
    joint2 = new BasicJoint(b2,b1,new Vector2f(b2.getPosition()));
  }
View Full Code Here

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

      // Precompute normal mass, tangent mass, and bias.
      float rn1 = r1.dot(c.normal);
      float rn2 = r2.dot(c.normal);
      float kNormal = body1.getInvMass() + body2.getInvMass();
      kNormal += body1.getInvI() * (r1.dot(r1) - rn1 * rn1) + body2.getInvI() * (r2.dot(r2) - rn2 * rn2);
      c.massNormal = damping / kNormal;
     
      Vector2f tangent = MathUtil.cross(c.normal, 1.0f);
      float rt1 = r1.dot(tangent);
      float rt2 = r2.dot(tangent);
      float kTangent = body1.getInvMass() + body2.getInvMass();
      kTangent += body1.getInvI() * (r1.dot(r1) - rt1 * rt1) + body2.getInvI() * (r2.dot(r2) - rt2 * rt2);
      c.massTangent = damping / kTangent;

      // Compute restitution
      // Relative velocity at contact
      Vector2f relativeVelocity =  new Vector2f(body2.getVelocity());
      relativeVelocity.add(MathUtil.cross(r2, body2.getAngularVelocity()));
      relativeVelocity.sub(body1.getVelocity());
      relativeVelocity.sub(MathUtil.cross(r1, body1.getAngularVelocity()));
     
      float combinedRestitution = (body1.getRestitution() * body2.getRestitution());
      float relVel = c.normal.dot(relativeVelocity);
      c.restitution = combinedRestitution * -relVel;
      c.restitution = Math.max(c.restitution, 0);
     
      float penVel = -c.separation / dt;
      if (c.restitution >= penVel) {
        c.bias = 0;
      } else {
        c.bias = -biasFactor * invDT * Math.min(0.0f, c.separation + allowedPenetration);
      }
     
      // apply damping
      c.accumulatedNormalImpulse *= damping;
     
      // Apply normal + friction impulse
      Vector2f impulse = MathUtil.scale(c.normal, c.accumulatedNormalImpulse);
      impulse.add(MathUtil.scale(tangent, c.accumulatedTangentImpulse));
     
      body1.adjustVelocity(MathUtil.scale(impulse, -body1.getInvMass()));
      body1.adjustAngularVelocity(-body1.getInvI() * MathUtil.cross(r1, impulse));

      body2.adjustVelocity(MathUtil.scale(impulse, body2.getInvMass()));
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.