Package org.jbox2d.dynamics.contacts

Examples of org.jbox2d.dynamics.contacts.Contact


          continue;
        }
       
        // Search all contacts connected to this body.
        for (ContactEdge ce = b.m_contactList; ce != null; ce = ce.next) {
          Contact contact = ce.contact;
         
          // Has this contact already been added to an island?
          if ((contact.m_flags & Contact.ISLAND_FLAG) == Contact.ISLAND_FLAG) {
            continue;
          }
         
          // Is this contact solid and touching?
          if (contact.isEnabled() == false || contact.isTouching() == false) {
            continue;
          }
         
          // Skip sensors.
          boolean sensorA = contact.m_fixtureA.m_isSensor;
View Full Code Here


  private Contact[] m_contacts = new Contact[Settings.maxTOIContacts];
 
  private void solveTOI(Body body) {
    // Find the minimum contact.
    Contact toiContact = null;
    float toi = 1.0f;
    Body toiOther = null;
    boolean found;
    int count;
    int iter = 0;
   
    boolean bullet = body.isBullet();
   
    // Iterate until all contacts agree on the minimum TOI. We have
    // to iterate because the TOI algorithm may skip some intermediate
    // collisions when objects rotate through each other.
    do {
      count = 0;
      found = false;
      for (ContactEdge ce = body.m_contactList; ce != null; ce = ce.next) {
        if (ce.contact == toiContact) {
          continue;
        }
       
        Body other = ce.other;
        BodyType type = other.getType();
       
        // Only bullets perform TOI with dynamic bodies.
        if (bullet == true) {
          // Bullets only perform TOI with bodies that have their TOI resolved.
          if ((other.m_flags & Body.e_toiFlag) == 0) {
            continue;
          }
         
          // No repeated hits on non-static bodies
          if (type != BodyType.STATIC && (ce.contact.m_flags & Contact.BULLET_HIT_FLAG) != 0) {
            continue;
          }
        }
        else if (type == BodyType.DYNAMIC) {
          continue;
        }
       
        // Check for a disabled contact.
        Contact contact = ce.contact;
        if (contact.isEnabled() == false) {
          continue;
        }
       
        // Prevent infinite looping.
        if (contact.m_toiCount > 10) {
          continue;
        }
       
        Fixture fixtureA = contact.m_fixtureA;
        Fixture fixtureB = contact.m_fixtureB;
       
        // Cull sensors.
        if (fixtureA.isSensor() || fixtureB.isSensor()) {
          continue;
        }
       
        Body bodyA = fixtureA.m_body;
        Body bodyB = fixtureB.m_body;
       
        // Compute the time of impact in interval [0, minTOI]
        toiInput.proxyA.set(fixtureA.getShape());
        toiInput.proxyB.set(fixtureB.getShape());
        toiInput.sweepA.set(bodyA.m_sweep);
        toiInput.sweepB.set(bodyB.m_sweep);
        toiInput.tMax = toi;
       
        pool.getTimeOfImpact().timeOfImpact(toiOutput, toiInput);
       
        if (toiOutput.state == TOIOutputState.TOUCHING && toiOutput.t < toi) {
          toiContact = contact;
          toi = toiOutput.t;
          toiOther = other;
          found = true;
        }
       
        ++count;
      }
     
      ++iter;
    }
    while (found && count > 1 && iter < 50);
   
    if (toiContact == null) {
      body.advance(1.0f);
      return;
    }
   
    backup.set(body.m_sweep);
    body.advance(toi);
    toiContact.update(m_contactManager.m_contactListener);
    if (toiContact.isEnabled() == false) {
      // Contact disabled. Backup and recurse.
      body.m_sweep.set(backup);
      solveTOI(body);
    }
   
    ++toiContact.m_toiCount;
   
    // Update all the valid contacts on this body and build a contact island.
    if (m_contacts == null || m_contacts.length < Settings.maxTOIContacts){
      m_contacts = new Contact[Settings.maxTOIContacts];
    }
   
    count = 0;
    for (ContactEdge ce = body.m_contactList; ce != null && count < Settings.maxTOIContacts; ce = ce.next) {
      Body other = ce.other;
      BodyType type = other.getType();
     
      // Only perform correction with static bodies, so the
      // body won't get pushed out of the world.
      if (type == BodyType.DYNAMIC) {
        continue;
      }
     
      // Check for a disabled contact.
      Contact contact = ce.contact;
      if (contact.isEnabled() == false) {
        continue;
      }
     
      Fixture fixtureA = contact.m_fixtureA;
      Fixture fixtureB = contact.m_fixtureB;
     
      // Cull sensors.
      if (fixtureA.isSensor() || fixtureB.isSensor()) {
        continue;
      }
     
      // The contact likely has some new contact points. The listener
      // gives the user a chance to disable the contact.
      if (contact != toiContact) {
        contact.update(m_contactManager.m_contactListener);
      }
     
      // Did the user disable the contact?
      if (contact.isEnabled() == false) {
        // Skip this contact.
        continue;
      }
     
      if (contact.isTouching() == false) {
        continue;
      }
     
      m_contacts[count] = contact;
      ++count;
View Full Code Here

    }
   
    // Flag associated contacts for filtering.
    ContactEdge edge = m_body.getContactList();
    while (edge != null){
      Contact contact = edge.contact;
      Fixture fixtureA = contact.getFixtureA();
      Fixture fixtureB = contact.getFixtureB();
      if (fixtureA == this || fixtureB == this){
        contact.flagForFiltering();
      }
      edge = edge.next;
    }
  }
View Full Code Here

    if (m_listener == null) {
      return;
    }

    for (int i = 0; i < m_contactCount; ++i) {
      Contact c = m_contacts[i];

      ContactVelocityConstraint vc = constraints[i];
      impulse.count = vc.pointCount;
      for (int j = 0; j < vc.pointCount; ++j) {
        impulse.normalImpulses[j] = vc.points[j].normalImpulse;
View Full Code Here

    }

    // Flag associated contacts for filtering.
    ContactEdge edge = m_body.getContactList();
    while (edge != null) {
      Contact contact = edge.contact;
      Fixture fixtureA = contact.getFixtureA();
      Fixture fixtureB = contact.getFixtureB();
      if (fixtureA == this || fixtureB == this) {
        contact.flagForFiltering();
      }
      edge = edge.next;
    }

    World world = m_body.getWorld();
View Full Code Here

    if (m_listener == null) {
      return;
    }

    for (int i = 0; i < m_contactCount; ++i) {
      Contact c = m_contacts[i];

      ContactVelocityConstraint vc = constraints[i];
      impulse.count = vc.pointCount;
      for (int j = 0; j < vc.pointCount; ++j) {
        impulse.normalImpulses[j] = vc.points[j].normalImpulse;
View Full Code Here

    }

    // Destroy any contacts associated with the fixture.
    ContactEdge edge = m_contactList;
    while (edge != null) {
      Contact c = edge.contact;
      edge = edge.next;

      Fixture fixtureA = c.getFixtureA();
      Fixture fixtureB = c.getFixtureB();

      if (fixture == fixtureA || fixture == fixtureB) {
        // This destroys the contact and removes it from
        // this body's contact list.
        m_world.m_contactManager.destroy(c);
View Full Code Here

    if (m_contactFilter != null && m_contactFilter.shouldCollide(fixtureA, fixtureB) == false) {
      return;
    }

    // Call the factory.
    Contact c = pool.popContact(fixtureA, indexA, fixtureB, indexB);
    if (c == null) {
      return;
    }

    // Contact creation may swap fixtures.
    fixtureA = c.getFixtureA();
    fixtureB = c.getFixtureB();
    indexA = c.getChildIndexA();
    indexB = c.getChildIndexB();
    bodyA = fixtureA.getBody();
    bodyB = fixtureB.getBody();

    // Insert into the world.
    c.m_prev = null;
View Full Code Here

  /** This is the top level collision call for the time step. Here all the narrow phase collision is processed for the world
   * contact list. */
  public void collide () {
    // Update awake contacts.
    Contact c = m_contactList;
    while (c != null) {
      Fixture fixtureA = c.getFixtureA();
      Fixture fixtureB = c.getFixtureB();
      int indexA = c.getChildIndexA();
      int indexB = c.getChildIndexB();
      Body bodyA = fixtureA.getBody();
      Body bodyB = fixtureB.getBody();

      // is this contact flagged for filtering?
      if ((c.m_flags & Contact.FILTER_FLAG) == Contact.FILTER_FLAG) {
        // Should these bodies collide?
        if (bodyB.shouldCollide(bodyA) == false) {
          Contact cNuke = c;
          c = cNuke.getNext();
          destroy(cNuke);
          continue;
        }

        // Check user filtering.
        if (m_contactFilter != null && m_contactFilter.shouldCollide(fixtureA, fixtureB) == false) {
          Contact cNuke = c;
          c = cNuke.getNext();
          destroy(cNuke);
          continue;
        }

        // Clear the filtering flag.
        c.m_flags &= ~Contact.FILTER_FLAG;
      }

      boolean activeA = bodyA.isAwake() && bodyA.m_type != BodyType.STATIC;
      boolean activeB = bodyB.isAwake() && bodyB.m_type != BodyType.STATIC;

      // At least one body must be awake and it must be dynamic or kinematic.
      if (activeA == false && activeB == false) {
        c = c.getNext();
        continue;
      }

      int proxyIdA = fixtureA.m_proxies[indexA].proxyId;
      int proxyIdB = fixtureB.m_proxies[indexB].proxyId;
      boolean overlap = m_broadPhase.testOverlap(proxyIdA, proxyIdB);

      // Here we destroy contacts that cease to overlap in the broad-phase.
      if (overlap == false) {
        Contact cNuke = c;
        c = cNuke.getNext();
        destroy(cNuke);
        continue;
      }

      // The contact persists.
View Full Code Here

    }

    // Destroy any contacts associated with the fixture.
    ContactEdge edge = m_contactList;
    while (edge != null) {
      Contact c = edge.contact;
      edge = edge.next;

      Fixture fixtureA = c.getFixtureA();
      Fixture fixtureB = c.getFixtureB();

      if (fixture == fixtureA || fixture == fixtureB) {
        // This destroys the contact and removes it from
        // this body's contact list.
        m_world.m_contactManager.destroy(c);
View Full Code Here

TOP

Related Classes of org.jbox2d.dynamics.contacts.Contact

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.