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: 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

  /** Constructs an EdgeSweep object with the given sweep direction.
   *
   * @param sweepDir The direction in which to sweep
   */
  public EdgeSweep(ROVector2f sweepDir) {
    this.sweepDir = new Vector2f(sweepDir);
  }
View Full Code Here

    touches = circleA.touches(x1,y1,circleB,x2,y2);
    if (!touches) {
      return 0;
    }
   
    Vector2f normal = MathUtil.sub(bodyB.getPosition(),bodyA.getPosition());
    float sep = (circleA.getRadius() + circleB.getRadius()) - normal.length();

    normal.normalise();
    Vector2f pt = MathUtil.scale(normal, circleA.getRadius());
    pt.add(bodyA.getPosition());

    contacts[0].setSeparation(-sep);
    contacts[0].setPosition(pt);
    contacts[0].setNormal(normal);
   
View Full Code Here

    Circle circle = (Circle) bodyB.getShape();
   
    // TODO: this can be optimized using matrix multiplications and moving only the circle
    Vector2f[] vertsA = polyA.getVertices(bodyA.getPosition(), bodyA.getRotation());
   
    Vector2f centroidA = new Vector2f(polyA.getCentroid());
    centroidA.add(bodyA.getPosition());

   
    int[][] collPairs = getCollisionCandidates(vertsA, centroidA, circle.getRadius(), bodyB.getPosition());

    int noContacts = 0;
    for ( int i = 0; i < collPairs.length; i++ ) {
      if ( noContacts >= contacts.length )
        return contacts.length;
     
      Vector2f lineStartA = vertsA[collPairs[i][0]];
      Vector2f lineEndA = vertsA[(collPairs[i][0]+1) % vertsA.length ];
      Line line = new Line(lineStartA, lineEndA);
           
      float dis2 = line.distanceSquared(bodyB.getPosition());
      float r2 = circle.getRadius() * circle.getRadius();

      if ( dis2 < r2 ) {
        Vector2f pt = new Vector2f();
       
        line.getClosestPoint(bodyB.getPosition(), pt);
        Vector2f normal = new Vector2f(bodyB.getPosition());
        normal.sub(pt);
        float sep = circle.getRadius() - normal.length();
        normal.normalise();
       
        contacts[noContacts].setSeparation(-sep);
        contacts[noContacts].setPosition(pt);
        contacts[noContacts].setNormal(normal);
        contacts[noContacts].setFeature(new FeaturePair());
View Full Code Here

   * @param radius The radius of the circle
   * @param circlePos The position (center) of the circle
   * @return The list of edges that can collide with the circle
   */
  protected int[][] getCollisionCandidates(Vector2f[] vertsA, ROVector2f centroid, float radius, ROVector2f circlePos) {
    Vector2f sweepDir = new Vector2f(centroid);
    sweepDir.sub(circlePos);
    sweepDir.normalise(); //TODO: this normalization might not be necessary
   
    EdgeSweep sweep = new EdgeSweep(sweepDir);//vertsA[0], true, true, dist);
   
    sweep.addVerticesToSweep(true, vertsA);
   
View Full Code Here

  void startFrame() {
    if (!canRest()) {
      return;
    }
   
    oldPosition = new Vector2f(getPosition());
    hitByAnother = false;
    hitCount = 0;
    touching.clear();
  }
View Full Code Here

      isResting = false;
      setMass(originalMass);
      touchingStatic = false;
      touchingCount = touching.size();
    } else {
      newPosition = new Vector2f(getPosition());
      if (!hitByAnother) {
        if (true
          && (newPosition.distanceSquared(oldPosition) <= positionTolerance)
          && (velocity.lengthSquared() <= 0.001f)
          && (biasedVelocity.lengthSquared() <= 0.001f)
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.