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

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


  @Override
  public PanicEnvironment[] generateRunnables(final ParCollection params) {
    final PanicEnvironment world = new PanicEnvironment(
        0,
        params,
        new Vector2f(0, 0),
        1);
    final PanicEnvironment worldWithColumn = new PanicEnvironment(
        0,
        params,
        new Vector2f(0, 0),
        1);

    final PanicScene panicScene = new PanicScene("Scene of Panic", params);
    final PanicSceneWithColumn panicSceneWC = new PanicSceneWithColumn("Scene of Panic", params);
View Full Code Here


        dead = true;
      }
    }

    if (forceNormal == null) {
      forceNormal = new Vector2f();
    }
    if (forceGetAwayFromFire == null) {
      forceGetAwayFromFire = new Vector2f();
    }
    if (forceGetTowardsExit == null) {
      forceGetTowardsExit = new Vector2f();
    }

    final double distanceFire = ((AbstractEnvironment2D) getEnvironment()).getAgentPosition(id()).distance(new Vector2D(fireLocation.x, fireLocation.y));
    final double distanceExit = ((AbstractEnvironment2D) getEnvironment()).getAgentPosition(id()).distance(new Vector2D(exitLocation.x, exitLocation.y));

    if ((Boolean) this.sense("IsInPanic?")) {
      forceNormal.x = 0;
      forceNormal.y = 0;

      forceGetAwayFromFire.x = (float) ((AbstractEnvironment2D) getEnvironment()).getAgentPosition(id()).x - fireLocation.x;
      forceGetAwayFromFire.y = (float) ((AbstractEnvironment2D) getEnvironment()).getAgentPosition(id()).y - fireLocation.y;

      forceGetAwayFromFire.scale(100 / (float) distanceFire);
      forceGetTowardsExit.scale(100 / (float) distanceExit);

      forceGetTowardsExit.x = exitLocation.x - (float) ((AbstractEnvironment2D) getEnvironment()).getAgentPosition(id()).x;
      forceGetTowardsExit.y = exitLocation.y - (float) ((AbstractEnvironment2D) getEnvironment()).getAgentPosition(id()).y;
    } else {
      forceNormal.x = rand.nextFloat() * 50 - 25f;
      forceNormal.y = rand.nextFloat() * 50 - 25f;
    }

    if (!dead) {
      addForce(forceNormal);
      addForce(forceGetAwayFromFire);
      addForce(forceGetTowardsExit);
      addForce(new Vector2f((float) (rand.nextDouble() * mult - mult / 2), (float) (rand.nextDouble() * mult - mult / 2)));
    } else {
      // setForce(0, 0);
      // setDamping(0.85f);
    }
  }
View Full Code Here

   */
  @Override
    public void preStep(float invDT) {
    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);
    Vector2f dp = new Vector2f(p2);
    dp.sub(p1);
    float length = dp.length();
    // dp.scale(1.0f/length);
    Vector2f V = new Vector2f((float) Math.cos(originalAngle
        + body1.getRotation()), (float) Math.sin(originalAngle
        + body1.getRotation()));
    Vector2f ndp = new Vector2f(dp);
    ndp.normalise();
    float torq = (float) Math.asin(MathUtil.cross(ndp, V))
        * compressConstant / invDT;
    float P = torq / length;
    Vector2f n = new Vector2f(ndp.y, -ndp.x);
    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(dp,
          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

    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.getBodyShape();
   
    // 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

            }
            if (b.isResting() && restingBodyDetection) {
                continue;
            }

            Vector2f temp = new Vector2f(b.getForce());
            temp.scale(b.getInvMass());
            if (b.getGravityEffected()) {
                temp.add(gravity);
            }
            temp.scale(dt);
           
            b.adjustVelocity(temp);
           
            Vector2f damping = new Vector2f(b.getVelocity());
            damping.scale(-b.getDamping() * b.getInvMass());
            b.adjustVelocity(damping);
           
            b.adjustAngularVelocity(dt * b.getInvI() * b.getTorque());
            b.adjustAngularVelocity(-b.getAngularVelocity() * b.getInvI() * b.getRotDamping());
        }
View Full Code Here

   * @param endA End point of the line
   * @param point The point to get a closes point on the line for
   * @return the closest point on the line or null if the lines are parallel
   */
  public static Vector2f getClosestPoint(Vector2f startA, Vector2f endA, Vector2f point) {
    Vector2f startB = point;
    Vector2f endB = new Vector2f(endA);
    endB.sub(startA);
    endB.set(endB.y, -endB.x);

    float d = endB.y * (endA.x - startA.x);
    d -= endB.x * (endA.y - startA.y);
   
    if ( d == 0 )
      return null;
   
    float uA = endB.x * (startA.y - startB.getY());
    uA -= endB.y * (startA.x - startB.getX());
    uA /= d;
   
    return new Vector2f(
      startA.x + uA * (endA.x - startA.x),
      startA.y + uA * (endA.y - startA.y));
  }
View Full Code Here

    public int collide(Contact[] contacts, PhysicsAgent2D<?> bodyA, PhysicsAgent2D<?> bodyB) {
    int count = collider.collide(contacts, bodyB, bodyA);
   
    // reverse the collision results by inverting normals
    for ( int i = 0; i < count; i++ ) {
      Vector2f vec = MathUtil.scale(contacts[i].getNormal(),-1);
      contacts[i].setNormal(vec);
    }
   
    return count;
  }
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(anchor);
    a1.sub(body1.getPosition());
    localAnchor1 = MathUtil.mul(rot1T,a1);
    Vector2f a2 = new Vector2f(anchor);
    a2.sub(body2.getPosition());
    localAnchor2 = MathUtil.mul(rot2T,a2);

    accumulatedImpulse.set(0.0f, 0.0f);
    relaxation = 1.0f;
  }
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.