Package org.jbox2d.dynamics

Examples of org.jbox2d.dynamics.Body


    boolean sensorA = m_fixtureA.isSensor();
    boolean sensorB = m_fixtureB.isSensor();
    boolean sensor = sensorA || sensorB;

    Body bodyA = m_fixtureA.getBody();
    Body bodyB = m_fixtureB.getBody();
    Transform xfA = bodyA.getTransform();
    Transform xfB = bodyB.getTransform();
    //log.debug("TransformA: "+xfA);
    //log.debug("TransformB: "+xfB);
   
    if (sensor) {
      Shape shapeA = m_fixtureA.getShape();
      Shape shapeB = m_fixtureB.getShape();
      touching = pool.getCollision().testOverlap(shapeA, shapeB,
          xfA, xfB);

      // Sensors don't generate manifolds.
      m_manifold.pointCount = 0;
    } else {
      evaluate(m_manifold, xfA, xfB);
      touching = m_manifold.pointCount > 0;

      // Match old contact ids to new contact ids and copy the
      // stored impulses to warm start the solver.
      for (int i = 0; i < m_manifold.pointCount; ++i) {
        ManifoldPoint mp2 = m_manifold.points[i];
        mp2.normalImpulse = 0.0f;
        mp2.tangentImpulse = 0.0f;
        ContactID id2 = mp2.id;

        for (int j = 0; j < oldManifold.pointCount; ++j) {
          ManifoldPoint mp1 = oldManifold.points[j];

          if (mp1.id.isEqual(id2)) {
            mp2.normalImpulse = mp1.normalImpulse;
            mp2.tangentImpulse = mp1.tangentImpulse;
            break;
          }
        }
      }

      if (touching != wasTouching) {
        bodyA.setAwake(true);
        bodyB.setAwake(true);
      }
    }

    if (touching) {
      m_flags |= TOUCHING_FLAG;
View Full Code Here


      final Fixture fixtureB = contact.m_fixtureB;
      final Shape shapeA = fixtureA.getShape();
      final Shape shapeB = fixtureB.getShape();
      final float radiusA = shapeA.m_radius;
      final float radiusB = shapeB.m_radius;
      final Body bodyA = fixtureA.getBody();
      final Body bodyB = fixtureB.getBody();
      final Manifold manifold = contact.getManifold();

      final float friction = Settings.mixFriction(fixtureA.getFriction(), fixtureB.getFriction());
      final float restitution = Settings.mixRestitution(fixtureA.getRestitution(), fixtureB.getRestitution());
View Full Code Here

  public void warmStart(){
    // Warm start.
    for (int i = 0; i < m_constraintCount; ++i){
      final ContactConstraint c = m_constraints[i];

      final Body bodyA = c.bodyA;
      final Body bodyB = c.bodyB;
      final float invMassA = bodyA.m_invMass;
      final float invIA = bodyA.m_invI;
      final float invMassB = bodyB.m_invMass;
      final float invIB = bodyB.m_invI;
      final Vec2 normal = c.normal;
View Full Code Here

  private final Vec2 P2 = new Vec2();
 
  public final void solveVelocityConstraints(){
    for (int i = 0; i < m_constraintCount; ++i){
      final ContactConstraint c = m_constraints[i];
      final Body bodyA = c.bodyA;
      final Body bodyB = c.bodyB;
      float wA = bodyA.m_angularVelocity;
      float wB = bodyB.m_angularVelocity;
      final Vec2 vA = bodyA.m_linearVelocity;
      final Vec2 vB = bodyB.m_linearVelocity;
      final float invMassA = bodyA.m_invMass;
View Full Code Here

  public final boolean solvePositionConstraints(float baumgarte){
    float minSeparation = 0.0f;

    for (int i = 0; i < m_constraintCount; ++i){
      final ContactConstraint c = m_constraints[i];
      final Body bodyA = c.bodyA;
      final Body bodyB = c.bodyB;

      final float invMassA = bodyA.m_mass * bodyA.m_invMass;
      final float invIA = bodyA.m_mass * bodyA.m_invI;
      final float invMassB = bodyB.m_mass * bodyB.m_invMass;
      final float invIB = bodyB.m_mass * bodyB.m_invI;

      // Solve normal constraints
      for (int j = 0; j < c.pointCount; ++j){
        final PositionSolverManifold psm = psolver;
        psm.initialize(c, j);
        final Vec2 normal = psm.normal;
       
        final Vec2 point = psm.point;
        final float separation = psm.separation;

        rA.set(point).subLocal(bodyA.m_sweep.c);
        rB.set(point).subLocal(bodyB.m_sweep.c);

        // Track max constraint error.
        minSeparation = MathUtils.min(minSeparation, separation);

        // Prevent large corrections and allow slop.
        final float C = MathUtils.clamp(baumgarte * (separation + Settings.linearSlop), -Settings.maxLinearCorrection, 0.0f);

        // Compute the effective mass.
        final float rnA = Vec2.cross(rA, normal);
        final float rnB = Vec2.cross(rB, normal);
        final float K = invMassA + invMassB + invIA * rnA * rnA + invIB * rnB * rnB;
       
        // Compute normal impulse
        final float impulse = K > 0.0f ? - C / K : 0.0f;

        P.set(normal).mulLocal(impulse);

        temp1.set(P).mulLocal(invMassA);
        bodyA.m_sweep.c.subLocal(temp1);
        bodyA.m_sweep.a -= invIA * Vec2.cross(rA, P);
        bodyA.synchronizeTransform();

        temp1.set(P).mulLocal(invMassB);
        bodyB.m_sweep.c.addLocal(temp1);
        bodyB.m_sweep.a += invIB * Vec2.cross(rB, P);
        bodyB.synchronizeTransform();
      }
    }

    // We can't expect minSpeparation >= -linearSlop because we don't
    // push the separation above -linearSlop.
View Full Code Here

      Fixture fixtureB = contact.getFixtureB();
      Shape shapeA = fixtureA.getShape();
      Shape shapeB = fixtureB.getShape();
      float radiusA = shapeA.m_radius;
      float radiusB = shapeB.m_radius;
      Body bodyA = fixtureA.getBody();
      Body bodyB = fixtureB.getBody();
      Manifold manifold = contact.getManifold();
     
      assert(manifold.pointCount > 0);
     
//      m_constraints[i] = new TOIConstraint();
View Full Code Here

   
    float minSeparation = 0f;
   
    for (int i = 0; i < m_count; ++i){
      TOIConstraint c = m_constraints[i];
      Body bodyA = c.bodyA;
      Body bodyB = c.bodyB;

      float massA = bodyA.m_mass;
      float massB = bodyB.m_mass;

      // Only the TOI body should move.
      if (bodyA == m_toiBody){
        massB = 0.0f;
      }
      else{
        massA = 0.0f;
      }

      float invMassA = massA * bodyA.m_invMass;
      float invIA = massA * bodyA.m_invI;
      float invMassB = massB * bodyB.m_invMass;
      float invIB = massB * bodyB.m_invI;

      // Solve normal constraints
      for (int j = 0; j < c.pointCount; ++j){
        psm.initialize(c, j);
        Vec2 normal = psm.normal;

        Vec2 point = psm.point;
        float separation = psm.separation;

        rA.set(point).subLocal(bodyA.m_sweep.c);
        rB.set(point).subLocal(bodyB.m_sweep.c);

        // Track max constraint error.
        minSeparation = MathUtils.min(minSeparation, separation);

        // Prevent large corrections and allow slop.
        float C = MathUtils.clamp(baumgarte * (separation + Settings.linearSlop), -Settings.maxLinearCorrection, 0.0f);

        // Compute the effective mass.
        float rnA = Vec2.cross(rA, normal);
        float rnB = Vec2.cross(rB, normal);
        float K = invMassA + invMassB + invIA * rnA * rnA + invIB * rnB * rnB;

        // Compute normal impulse
        float impulse = K > 0.0f ? - C / K : 0.0f;

        P.set(normal).mulLocal(impulse);

        temp.set(P).mulLocal(invMassA);
        bodyA.m_sweep.c.subLocal(temp);
        bodyA.m_sweep.a -= invIA * Vec2.cross(rA, P);
        bodyA.synchronizeTransform();

        temp.set(P).mulLocal(invMassB);
        bodyB.m_sweep.c.addLocal(temp);
        bodyB.m_sweep.a += invIB * Vec2.cross(rB, P);
        bodyB.synchronizeTransform();
      }
    }

    // We can't expect minSpeparation >= -_linearSlop because we don't
    // push the separation above -_linearSlop.
View Full Code Here

      final Fixture fixtureB = contact.m_fixtureB;
      final Shape shapeA = fixtureA.getShape();
      final Shape shapeB = fixtureB.getShape();
      final float radiusA = shapeA.m_radius;
      final float radiusB = shapeB.m_radius;
      final Body bodyA = fixtureA.getBody();
      final Body bodyB = fixtureB.getBody();
      final Manifold manifold = contact.getManifold();

      int pointCount = manifold.pointCount;
      assert (pointCount > 0);
View Full Code Here

    return inv_dt * m_impulse.y;
  }

  /** Get the current joint translation, usually in meters. */
  public float getJointSpeed () {
    Body bA = m_bodyA;
    Body bB = m_bodyB;

    Vec2 temp = pool.popVec2();
    Vec2 rA = pool.popVec2();
    Vec2 rB = pool.popVec2();
    Vec2 p1 = pool.popVec2();
View Full Code Here

    return m_manifold;
  }

  /** Get the world manifold. */
  public void getWorldManifold (WorldManifold worldManifold) {
    final Body bodyA = m_fixtureA.getBody();
    final Body bodyB = m_fixtureB.getBody();
    final Shape shapeA = m_fixtureA.getShape();
    final Shape shapeB = m_fixtureB.getShape();

    worldManifold.initialize(m_manifold, bodyA.getTransform(), shapeA.m_radius, bodyB.getTransform(), shapeB.m_radius);
  }
View Full Code Here

TOP

Related Classes of org.jbox2d.dynamics.Body

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.