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

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


    K3.col1.y = -body2.getInvI() * r2.x * r2.y;    K3.col2.y =  body2.getInvI() * r2.x * r2.x;

    Matrix2f K = MathUtil.add(MathUtil.add(K1,K2),K3);
    M = K.invert();

    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);
   
    bias = new Vector2f(dp);
    bias.scale(-0.1f);
    bias.scale(invDT);

    // Apply accumulated impulse.
    accumulatedImpulse.scale(relaxation);
   
    Vector2f accum1 = new Vector2f(accumulatedImpulse);
    accum1.scale(-body1.getInvMass());
    body1.adjustVelocity(accum1);
    body1.adjustAngularVelocity(-(body1.getInvI() * MathUtil.cross(r1, accumulatedImpulse)));

    Vector2f accum2 = new Vector2f(accumulatedImpulse);
    accum2.scale(body2.getInvMass());
    body2.adjustVelocity(accum2);
    body2.adjustAngularVelocity(body2.getInvI() * MathUtil.cross(r2, accumulatedImpulse));
  }
View Full Code Here


  /**
   * Apply the impulse caused by the joint to the bodies attached.
   */
  @Override
    public void applyImpulse() {
    Vector2f dv = new Vector2f(body2.getVelocity());
    dv.add(MathUtil.cross(body2.getAngularVelocity(),r2));
    dv.sub(body1.getVelocity());
    dv.sub(MathUtil.cross(body1.getAngularVelocity(),r1));
      dv.scale(-1);
      dv.add(bias);
     
      if (dv.lengthSquared() == 0) {
        return;
      }
     
    Vector2f impulse = MathUtil.mul(M, dv);

    Vector2f delta1 = new Vector2f(impulse);
    delta1.scale(-body1.getInvMass());
    body1.adjustVelocity(delta1);
    body1.adjustAngularVelocity(-body1.getInvI() * MathUtil.cross(r1,impulse));

    Vector2f delta2 = new Vector2f(impulse);
    delta2.scale(body2.getInvMass());
    body2.adjustVelocity(delta2);
    body2.adjustAngularVelocity(body2.getInvI() * MathUtil.cross(r2,impulse));

    accumulatedImpulse.add(impulse);
  }
 
View Full Code Here

   
    Vector2f[] vertsA = line.getVertices(bodyA.getPosition(), bodyA.getRotation());
   
    // compute intersection of the line A and a line parallel to
    // the line A's normal passing through the origin of B
    Vector2f startA = vertsA[0];
    Vector2f endA = vertsA[1];
    ROVector2f startB = bodyB.getPosition();
    Vector2f endB = new Vector2f(endA);
    endB.sub(startA);
    endB.set(endB.y, -endB.x);
//    endB.add(startB);// TODO: inline endB into equations below, this last operation will be useless..
   
    //TODO: reuse mathutil.intersect
//    float d = (endB.y - startB.getY()) * (endA.x - startA.x);
//    d -= (endB.x - startB.getX()) * (endA.y - startA.y);
//   
//    float uA = (endB.x - startB.getX()) * (startA.y - startB.getY());
//    uA -= (endB.y - startB.getY()) * (startA.x - startB.getX());
//    uA /= d;
    float d = endB.y * (endA.x - startA.x);
    d -= endB.x * (endA.y - startA.y);
   
    float uA = endB.x * (startA.y - startB.getY());
    uA -= endB.y * (startA.x - startB.getX());
    uA /= d;
   
    Vector2f position = null;
   
    if ( uA < 0 ) { // the intersection is somewhere before startA
      position = startA;
    } else if ( uA > 1 ) { // the intersection is somewhere after endA
      position = endA;
    } else {
      position = new Vector2f(
          startA.x + uA * (endA.x - startA.x),
          startA.y + uA * (endA.y - startA.y));
    }
   
    Vector2f normal = endB; // reuse of vector object
    normal.set(startB);
    normal.sub(position);
    float distSquared = normal.lengthSquared();
    float radiusSquared = circle.getRadius() * circle.getRadius();
   
    if ( distSquared < radiusSquared ) {
      contacts[0].setPosition(position);
      contacts[0].setFeature(new FeaturePair());
     
      normal.normalise();
      contacts[0].setNormal(normal);
     
      float separation = (float) Math.sqrt(distSquared) - circle.getRadius();
      contacts[0].setSeparation(separation);
     
View Full Code Here

        Polygon2D pol = polygon.getCounterClockwiseOrdered();
       
        ROVector2f[] vecs = new ROVector2f[pol.nPoints()];
       
        for (int i = 0; i < pol.nPoints(); i++) {
            vecs[i] = new Vector2f((float) pol.get(i).x, (float) pol.get(i).y);
        }
       
        Polygon p = new Polygon(vecs);
        return p;
    }
View Full Code Here

    public synchronized 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

     * Get the change in position in the last update
     *
     * @return The change in position in the last update
     */
    public ROVector2f getPositionDelta() {
        Vector2f vec = new Vector2f(getPosition());
        vec.sub(getLastPosition());
       
        return vec;
    }
View Full Code Here

     * Get the change in velocity in the last update
     *
     * @return The change in velocity in the last update
     */
    public ROVector2f getVelocityDelta() {
        Vector2f vec = new Vector2f(getVelocity());
        vec.sub(getLastVelocity());
       
        return vec;
    }
View Full Code Here

     *
     * @param maxX The maximum velocity on the X axis
     * @param maxY The maximum veloicty on the Y axis
     */
    public synchronized void setMaxVelocity(float maxX, float maxY) {
        maxVelocity = new Vector2f(maxX, maxY);
    }
View Full Code Here

    @Override
  public DomPhysEnv[] generateRunnables(ParCollection params) {
   
    /* Gravitation mit Vector2f einstellbar*/
    DomPhysEnv env
    = new DomPhysEnv(0, params, new Vector2f(0, 0), 100);
   
    return new DomPhysEnv[] {env};
  }
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.