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 preStep(float invDT) {

    // calculate the spring's vector (pointing from body1 to body2) and length
    spring = new Vector2f(body2.getPosition());
    spring.add(r2);
    spring.sub(body1.getPosition());
    spring.sub(r1);
    springLength = spring.length();
   
    // the spring vector needs to be normalized for applyImpulse as well!
    spring.normalise();
   
    // calculate the spring's forces
    // note that although theoretically invDT could never be 0
    // but here it can
    float springConst;
   
    if ( springLength < minSpringSize || springLength > maxSpringSize ) {
      // Pre-compute anchors, mass matrix, and bias.
      Matrix2f rot1 = new Matrix2f(body1.getRotation());
      Matrix2f rot2 = new Matrix2f(body2.getRotation());
 
      r1 = MathUtil.mul(rot1,localAnchor1);
      r2 = MathUtil.mul(rot2,localAnchor2);
     
      // the mass normal or 'k'
      float rn1 = r1.dot(spring);
      float rn2 = r2.dot(spring);
      float kNormal = body1.getInvMass() + body2.getInvMass();
      kNormal += body1.getInvI() * (r1.dot(r1) - rn1 * rn1) + body2.getInvI() * (r2.dot(r2) - rn2 * rn2);
      massNormal = 1 / kNormal;
     
     
      // The spring is broken so apply force to correct it
      // note that we use biased velocities for this
      float springImpulse =
        invDT != 0 ? brokenSpringConst * (springLength - springSize) / invDT : 0;
     
      Vector2f impulse = MathUtil.scale(spring, springImpulse);
      body1.adjustBiasedVelocity(MathUtil.scale(impulse, body1.getInvMass()));
      body1.adjustBiasedAngularVelocity((body1.getInvI() * MathUtil.cross(r1, impulse)));

      body2.adjustBiasedVelocity(MathUtil.scale(impulse, -body2.getInvMass()));
      body2.adjustBiasedAngularVelocity(-(body2.getInvI() * MathUtil.cross(r2, impulse)));
     
      isBroken = true;
      return;
     
    } else if ( springLength < springSize ) {
      springConst = compressedSpringConst;
      isBroken = false;
    } else { // if ( springLength >= springSize )
      springConst = stretchedSpringConst;
      isBroken = false;
    }
   
    float springImpulse =
      invDT != 0 ? springConst * (springLength - springSize) / invDT : 0;

    // apply the spring's forces
    Vector2f impulse = MathUtil.scale(spring, springImpulse);
    body1.adjustVelocity(MathUtil.scale(impulse, body1.getInvMass()));
    body1.adjustAngularVelocity((body1.getInvI() * MathUtil.cross(r1, impulse)));

    body2.adjustVelocity(MathUtil.scale(impulse, -body2.getInvMass()));
    body2.adjustAngularVelocity(-(body2.getInvI() * MathUtil.cross(r2, impulse)));
View Full Code Here


  @Override
    public void applyImpulse() {
    if ( isBroken ) {
      // calculate difference in velocity
      // TODO: share this code with BasicJoint and Arbiter
      Vector2f relativeVelocity =  new Vector2f(body2.getVelocity());
      relativeVelocity.add(MathUtil.cross(body2.getAngularVelocity(), r2));
      relativeVelocity.sub(body1.getVelocity());
      relativeVelocity.sub(MathUtil.cross(body1.getAngularVelocity(), r1));
     
      // project the relative velocity onto the spring vector and apply the mass normal
      float normalImpulse = massNormal * relativeVelocity.dot(spring);
     
//      // TODO: Clamp the accumulated impulse?
//      float oldNormalImpulse = accumulatedNormalImpulse;
//      accumulatedNormalImpulse = Math.max(oldNormalImpulse + normalImpulse, 0.0f);
//      normalImpulse = accumulatedNormalImpulse - oldNormalImpulse;
 
      // only apply the impulse if we are pushing or pulling in the right way
      // i.e. pulling if the string is overstretched and pushing if it is too compressed
      if ( springLength < minSpringSize && normalImpulse < 0
          || springLength > maxSpringSize && normalImpulse > 0 ) {
        // now apply the impulses to the bodies
        Vector2f impulse = MathUtil.scale(spring, normalImpulse);
        body1.adjustVelocity(MathUtil.scale(impulse, body1.getInvMass()));
        body1.adjustAngularVelocity((body1.getInvI() * MathUtil.cross(r1, impulse)));
   
        body2.adjustVelocity(MathUtil.scale(impulse, -body2.getInvMass()));
        body2.adjustAngularVelocity(-(body2.getInvI() * MathUtil.cross(r2, impulse)));
View Full Code Here

      this.geburt = runde;
     
      ROVector2f kraft = this.getForce();
      float x = kraft.getX() * -1;
    float y = kraft.getY() * -1;
    this.addForce(new Vector2f(x,y));
   
    ROVector2f geschwindigkeit = this.getVelocity();
      float x2 = geschwindigkeit.getX() * -1;
    float y2 = geschwindigkeit.getY() * -1;
    this.adjustVelocity(new Vector2f(x2,y2));
   
    float winkelgeschw = this.getAngularVelocity();
    this.adjustAngularVelocity(-1 * winkelgeschw);
   
    //this.setRotation(-1 * this.getRotation());
 
View Full Code Here

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

    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

   * @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

      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

   * 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

    private Joint j1, j2;
   
    @Override
    public Phys3Env[] generateRunnables(ParCollection params) {
        Phys3Env[] envs = new Phys3Env[1];
        final Phys3Env env = new Phys3Env(0, params, new Vector2f(0, 5), 100);
        envs[0] = env;
       
        env.addAgent(new Phys3Agent(0, env, "Agent0", 10, params), new Vector2D(0, -10), 180);
        env.addAgent(new Phys3JetAgent(1, env, "Agent1", 10, params), new Vector2D(-3, 0), 180);
        env.addAgent(new Phys3JetAgent(2, env, "Agent2", 10, params), new Vector2D(3, 0), 180);
        j1 = new DistanceJoint(
                env.getAgent(0),
                env.getAgent(1),
                new Vector2f(4, -5),
                new Vector2f(0, 0.9f),
                0);
        j2 = new DistanceJoint(
                env.getAgent(0),
                env.getAgent(2),
                new Vector2f(-4, -5),
                new Vector2f(0, 0.9f),
                0);
        env.add(j1);
        env.add(j2);
       
        env.addAgent(new StaticObstacleLong(100, env, params), new Vector2D(0, 1), 0);
View Full Code Here

            env.addAgent(new Phys3JetAgent(1, env, "Agent1", 10, params), new Vector2D(-3, 0), 180);
            env.addAgent(new Phys3JetAgent(2, env, "Agent2", 10, params), new Vector2D(3, 0), 180);
            j1 = new DistanceJoint(
                    env.getAgent(0),
                    env.getAgent(1),
                    new Vector2f(4, -5),
                    new Vector2f(0, 0.9f),
                    0);
            j2 = new DistanceJoint(
                    env.getAgent(0),
                    env.getAgent(2),
                    new Vector2f(-4, -5),
                    new Vector2f(0, 0.9f),
                    0);
            env.add(j1);
            env.add(j2);
           
            env.addAgent(new StaticObstacleLong(100, env, params), new Vector2D(0, 1), 0);
View Full Code Here

    private Joint j1, j2;
   
    @Override
    public Phys3Env[] generateRunnables(ParCollection params) {
        Phys3Env[] envs = new Phys3Env[1];
        final Phys3Env env = new Phys3Env(0, params, new Vector2f(0, 5), 1000);
        envs[0] = env;
       
        env.addAgent(new Phys3Agent(0, env, "Agent0", 10, params), new Vector2D(0, -5), 180);
        env.addAgent(new Phys3JetAgent(1, env, "Agent1", 10, params), new Vector2D(-3, 1), 180);
        env.addAgent(new Phys3JetAgent(2, env, "Agent2", 10, params), new Vector2D(3, 1), 180);
        j1 = new DistanceJoint(
                env.getAgent(0),
                env.getAgent(1),
                new Vector2f(4, -5),
                new Vector2f(0, 0.9f),
                0);
        j2 = new DistanceJoint(
                env.getAgent(0),
                env.getAgent(2),
                new Vector2f(-4, -5),
                new Vector2f(0, 0.9f),
                0);
        j1 = new FixedJoint(
                env.getAgent(0),
                 env.getAgent(1));
        j2 = new FixedJoint(
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.