@Override public void endContact (Contact contact) { System.out.println(String.format(" endContact() addr=%d", getContactAddr(contact))); System.out.println(String.format(" endContact() addrA=%d, addrB=%d", getFixtureAddrA(contact), getFixtureAddrB(contact))); System.out.println(String.format(" endContact() fixA=%s, fixB=%s", contact.getFixtureA(), contact.getFixtureB())); final Fixture fixtureA = contact.getFixtureA(); final Fixture fixtureB = contact.getFixtureB(); if(fixtureA == null || fixtureB == null) { throw new RuntimeException("No fixture found."); } }
private boolean isPlayerGrounded (float deltaTime) { groundedPlatform = null; Array<Contact> contactList = world.getContactList(); for (int i = 0; i < contactList.size; i++) { Contact contact = contactList.get(i); if (contact.isTouching() && (contact.getFixtureA() == playerSensorFixture || contact.getFixtureB() == playerSensorFixture)) { Vector2 pos = player.getPosition(); WorldManifold manifold = contact.getWorldManifold(); boolean below = true; for (int j = 0; j < manifold.getNumberOfContactPoints(); j++) { below &= (manifold.getPoints()[j].y < pos.y - 1.5f); } if (below) { if (contact.getFixtureA().getUserData() != null && contact.getFixtureA().getUserData().equals("p")) { groundedPlatform = (Platform)contact.getFixtureA().getBody().getUserData(); } if (contact.getFixtureB().getUserData() != null && contact.getFixtureB().getUserData().equals("p")) { groundedPlatform = (Platform)contact.getFixtureB().getBody().getUserData(); } return true; } return false; } } return false; }
public Array<Contact> getContactList () { // FIXME pool contacts org.jbox2d.dynamics.contacts.Contact contactList = world.getContactList(); contacts.clear(); while (contactList != null) { Contact contact = new Contact(this, contactList); contacts.add(contact); contactList = contactList.m_next; } return contacts; }
public void preSolve (Contact contact, Manifold oldManifold) { Fixture fixtureA = contact.getFixtureA(); Fixture fixtureB = contact.getFixtureB(); if (fixtureA == m_platform || fixtureB == m_platform) { contact.setTangentSpeed(5.0f); } }
if (contact.getFixtureA().getUserData() == CarType.PlayerCar) { fcar = contact.getFixtureA(); } else if (contact.getFixtureB().getUserData() == CarType.PlayerCar) { fcar = contact.getFixtureB(); float ml = car.getCarModel().length; float half_ml = ml * 0.5f; Vector2[] pts = contact.getWorldManifold().getPoints(); int num_points = contact.getWorldManifold().getNumberOfContactPoints(); for (int i = 0; i < num_points; i++) { Vector2 lp = fcar.getBody().getLocalPoint(pts[i]);
private void drawContact (Contact contact) { WorldManifold worldManifold = contact.getWorldManifold(); if (worldManifold.getNumberOfContactPoints() == 0) return; Vector2 point = worldManifold.getPoints()[0]; renderer.setColor(getColorByBody(contact.getFixtureA().getBody())); renderer.point(point.x, point.y, 0); }
Contact contact = world.getContactList().get(i); if (contact.isTouching()) { WorldManifold manifold = contact.getWorldManifold(); int numContactPoints = manifold.getNumberOfContactPoints(); for (int j = 0; j < numContactPoints; j++) {
public void beginContact(Contact c) { Body b = c.getFixtureA().getBody(); Image i = (Image) blocks.get(b); if (i != null) { i.remove(); } else if (b == floorBody) { show(); } } public void endContact(Contact c) {}
private void drawContact (Contact contact) { WorldManifold worldManifold = contact.getWorldManifold(); if (worldManifold.getNumberOfContactPoints() == 0) return; Vector2 point = worldManifold.getPoints()[0]; renderer.point(point.x, point.y, 0); }
/** Get the child primitive index for fixture A. */ public int getChildIndexA () { return jniGetChildIndexA(addr); }
private void drawContact (Contact contact) { WorldManifold worldManifold = contact.getWorldManifold(); if (worldManifold.getNumberOfContactPoints() == 0) return; Vector2 point = worldManifold.getPoints()[0]; renderer.setColor(getColorByBody(contact.getFixtureA().getBody())); renderer.point(point.x, point.y, 0); }
/** Get the child primitive index for fixture A. */ public int getChildIndexA () { return jniGetChildIndexA(addr); }
@Override public void beginContact (Contact contact) { System.out.println(String.format("beginContact() addr=%d", getContactAddr(contact))); System.out.println(String.format("beginContact() addrA=%d, addrB=%d", getFixtureAddrA(contact), getFixtureAddrB(contact))); System.out.println(String.format("beginContact() fixA=%s, fixB=%s", contact.getFixtureA(), contact.getFixtureB())); final Body toRemove = contact.getFixtureA().getBody().getType() == BodyType.DynamicBody ? contact.getFixtureA().getBody() : contact.getFixtureB().getBody(); Gdx.app.postRunnable(new Runnable() { @Override public void run () { world.destroyBody(toRemove); } }); }
/** Construct a world object. * @param gravity the world gravity vector. * @param doSleep improve performance by not simulating inactive bodies. */ public World (Vector2 gravity, boolean doSleep) { addr = newWorld(gravity.x, gravity.y, doSleep); contacts.ensureCapacity(contactAddrs.length); freeContacts.ensureCapacity(contactAddrs.length); for (int i = 0; i < contactAddrs.length; i++) freeContacts.add(new Contact(this, 0)); }
@Override public void process (Contact contact, ContactImpulse impulse) { Fixture a = contact.getFixtureA(); Fixture b = contact.getFixtureB(); ifCarThenCollide(contact, a, b, impulse); ifCarThenCollide(contact, b, a, impulse); }
/** Returns the list of {@link Contact} instances produced by the last call to {@link #step(float, int, int)}. Note that the * returned list will have O(1) access times when using indexing. contacts are created and destroyed in the middle of a time * step. Use {@link ContactListener} to avoid missing contacts * @return the contact list */ public Array<Contact> getContactList () { int numContacts = getContactCount(); if (numContacts > contactAddrs.length) { int newSize = 2 * numContacts; contactAddrs = new long[newSize]; contacts.ensureCapacity(newSize); freeContacts.ensureCapacity(newSize); } if (numContacts > freeContacts.size) { int freeConts = freeContacts.size; for (int i = 0; i < numContacts - freeConts; i++) freeContacts.add(new Contact(this, 0)); } jniGetContactList(addr, contactAddrs); contacts.clear(); for (int i = 0; i < numContacts; i++) { Contact contact = freeContacts.get(i); contact.addr = contactAddrs[i]; contacts.add(contact); } return contacts; }
@Override public void endContact(Contact contact) { Fixture fixture = null; Ball ball = ballWithBody(contact.getFixtureA().getBody()); if (ball != null) { fixture = contact.getFixtureB(); } else { ball = ballWithBody(contact.getFixtureB().getBody()); if (ball != null) { fixture = contact.getFixtureA(); } } if (ball != null) { contactedBalls.add(ball); contactedFixtures.add(fixture); } }
/** Construct a world object. * @param gravity the world gravity vector. * @param doSleep improve performance by not simulating inactive bodies. */ public World (Vector2 gravity, boolean doSleep) { addr = newWorld(gravity.x, gravity.y, doSleep); contacts.ensureCapacity(contactAddrs.length); freeContacts.ensureCapacity(contactAddrs.length); for (int i = 0; i < contactAddrs.length; i++) freeContacts.add(new Contact(this, 0)); }
@Override public void beginContact(Contact contact) { // TODO Auto-generated method stub Fixture fixtureA = contact.getFixtureA(); Fixture fixtureB = contact.getFixtureB(); Body bodyA = fixtureA.getBody(); Body bodyB = fixtureB.getBody(); if(bodyA == pointerBody && bodyB != groundBody) bodyB.setUserData(true); else if(bodyB == pointerBody && bodyA != groundBody) bodyA.setUserData(true); }
/** Returns the list of {@link Contact} instances produced by the last call to {@link #step(float, int, int)}. Note that the * returned list will have O(1) access times when using indexing. contacts are created and destroyed in the middle of a time * step. Use {@link ContactListener} to avoid missing contacts * @return the contact list */ public Array<Contact> getContactList () { int numContacts = getContactCount(); if (numContacts > contactAddrs.length) { int newSize = 2 * numContacts; contactAddrs = new long[newSize]; contacts.ensureCapacity(newSize); freeContacts.ensureCapacity(newSize); } if (numContacts > freeContacts.size) { int freeConts = freeContacts.size; for (int i = 0; i < numContacts - freeConts; i++) freeContacts.add(new Contact(this, 0)); } jniGetContactList(addr, contactAddrs); contacts.clear(); for (int i = 0; i < numContacts; i++) { Contact contact = freeContacts.get(i); contact.addr = contactAddrs[i]; contacts.add(contact); } return contacts; }