Examples of Vector2f


Examples of net.phys2d.math.Vector2f

 
  /**
   * @see net.phys2d.raw.test.AbstractDemo#update()
   */
  protected void update() {
    body2.addForce(new Vector2f(-100,0));
  }
View Full Code Here

Examples of net.phys2d.math.Vector2f

   * @see net.phys2d.raw.test.AbstractDemo#keyHit(char)
   */
  protected void keyHit(char c) {
    if (c == ' ') {
      if (ball.getVelocity().length() == 0) {
        ball.addForce(new Vector2f(-2000000,0));
      }
    }
  }
View Full Code Here

Examples of net.phys2d.math.Vector2f

    world.add(body);
    ball = new Body("Ball",new Box(10.0f, 10.0f), 1000);
    ball.setPosition(70.0f, 170);
    world.add(ball);
   
    j = new BasicJoint(body,ball,new Vector2f(70,110));
    world.add(j);
   
    // dominos
    for (int i=0;i<8;i++) {
      body = new Body("Domino "+i, new Box(10.0f, 40.0f), 10-i);
      body.setPosition(120.0f+(i*30), 170);
      world.add(body);
    }
   
    // ramp
    body = new StaticBody("Ground2",new Box(200.0f, 10.0f));
    body.setPosition(345.0f, 270);
    body.setRotation(-0.6f);
    body.setFriction(0);
    world.add(body);
   
    // teeter
    body = new Body("Teete",new Box(250.0f, 5.0f), 10);
    body.setPosition(250.0f, 360);
    //body.setFriction(3.0f);
    world.add(body);
    j = new BasicJoint(body,base,new Vector2f(250,360));
    world.add(j);
   
    // turner
    body = new Body("Turner", new Box(40.0f, 40.0f), 0.1f);
    body.setPosition(390.0f, 330);
    body.setFriction(0f);
    world.add(body);
    j = new BasicJoint(base,body,new Vector2f(390,335));
    world.add(j);
    Body top = new Body("Top",new Box(40.0f, 5.0f), 0.01f);
    top.setPosition(390.0f, 307.5f);
    top.setFriction(0f);
    world.add(top);
    j = new BasicJoint(top,body,new Vector2f(410,310));
    world.add(j);
  }
View Full Code Here

Examples of net.phys2d.math.Vector2f

    Body body2 = new Body("First", new Box(40.0f, 10.0f), 500);
    body2.setFriction(0.2f);
    body2.setPosition(80.0f, 300);
    world.add(body2);
   
    BasicJoint j = new BasicJoint(body1,body2,new Vector2f(40,300));
    j.setRelaxation(relax);
    world.add(j);
   
    int i;
    for (i=1;i<8;i++) {
      Body body3 = new Body("Teeter",new Box(40.0f, 10.0f), 500);
      body3.setFriction(0.2f);
      body3.setPosition(80.0f+(i*45), 300);
      world.add(body3);
     
      BasicJoint j2 = new BasicJoint(body2,body3,new Vector2f(65+(i*45),300));
      j2.setRelaxation(relax);
      world.add(j2);
      if (i == 4) {
        joint = j2;
      }
     
      body2 = body3;
    }

    BasicJoint j3 = new BasicJoint(body1,body2,new Vector2f(80+(i*45),300));
    j3.setRelaxation(relax);
    world.add(j3);
  }
 
View Full Code Here

Examples of net.phys2d.math.Vector2f

    Polygon polyB = (Polygon) bodyB.getShape();

    Vector2f[] vertsA = polyA.getVertices(bodyA.getPosition(), bodyA.getRotation());
    Vector2f[] vertsB = polyB.getVertices(bodyB.getPosition(), bodyB.getRotation());
   
    Vector2f centroidA = new Vector2f(polyA.getCentroid());
    centroidA.add(bodyA.getPosition());
    Vector2f centroidB = new Vector2f(polyB.getCentroid());
    centroidB.add(bodyB.getPosition());
   
    int[][] collEdgeCands = getCollisionCandidates(vertsA, vertsB, centroidA, centroidB);
    Intersection[][] intersections = getIntersectionPairs(vertsA, vertsB, collEdgeCands);   
    return populateContacts(contacts, vertsA, vertsB, intersections);
  }
View Full Code Here

Examples of net.phys2d.math.Vector2f

   * @param intersection The intection to set the contact information for
   * @param vertsA The vertices of polygon A
   * @param vertsB The vertices of polygon B
   */
  public void setContact(Contact contact, Intersection intersection, Vector2f[] vertsA, Vector2f[] vertsB) {   
    Vector2f startA = vertsA[intersection.edgeA];
    Vector2f endA = vertsA[(intersection.edgeA + 1) % vertsA.length];
    Vector2f startB = vertsB[intersection.edgeB];
    Vector2f endB = vertsB[(intersection.edgeB + 1) % vertsB.length];
   
    Vector2f normal = MathUtil.getNormal(startA, endA);
    normal.sub(MathUtil.getNormal(startB, endB));
    normal.normalise();
   
    contact.setNormal(normal);
    contact.setSeparation(0);
    contact.setFeature(new FeaturePair(intersection.edgeA, intersection.edgeB, 0, 0));
    contact.setPosition(intersection.position);
View Full Code Here

Examples of net.phys2d.math.Vector2f

      Contact contact2,
      Intersection in,
      Intersection out,
      Vector2f[] vertsA,
      Vector2f[] vertsB) {
    Vector2f entryPoint = in.position;
    Vector2f exitPoint = out.position;
   
    Vector2f normal = MathUtil.getNormal(entryPoint, exitPoint);
   
    FeaturePair feature = new FeaturePair(in.edgeA, in.edgeB, out.edgeA, out.edgeB);
   
    float separation = -PenetrationSweep.getPenetrationDepth(in, out, normal, vertsA, vertsB);
    // divided by 2 because there are two contact points
View Full Code Here

Examples of net.phys2d.math.Vector2f

   * For a returned array r
   * the edge between vertsA[r[x][0]] and vertsA[r[x][0] + 1]
   * overlaps with vertsB[r[x][1]] and vertsB[r[x][1] + 1].
   */
  public int[][] getCollisionCandidates(Vector2f[] vertsA, Vector2f[] vertsB, Vector2f sweepDirStart, Vector2f sweepDirEnd) {
    Vector2f sweepDir = new Vector2f(sweepDirEnd);
    sweepDir.sub(sweepDirStart);
   
    return getCollisionCandidates(new EdgeSweep(sweepDir), vertsA, vertsB);
  }
View Full Code Here

Examples of net.phys2d.math.Vector2f

                  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

Examples of net.phys2d.math.Vector2f

//    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
TOP
Copyright © 2018 www.massapi.com. 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.