Java Code Examples for com.badlogic.gdx.physics.box2d.Contact#getFixtureB()

The following examples show how to use com.badlogic.gdx.physics.box2d.Contact#getFixtureB() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Field.java    From homescreenarcade with GNU General Public License v3.0 6 votes vote down vote up
@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);
    }
}
 
Example 2
Source File: CarImpactManager.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 3
Source File: GameLevelController.java    From tilt-game-android with MIT License 5 votes vote down vote up
private boolean checkContact(Contact contact) {
    // ignore not touching contacts
    if (!contact.isTouching()) return false;

    Fixture fixtureA = contact.getFixtureA();
    if (fixtureA == null) return false;

    Fixture fixtureB = contact.getFixtureB();
    if (fixtureB == null) return false;

    Body bodyA = fixtureA.getBody();
    Body bodyB = fixtureB.getBody();

    String nameA = (String) bodyA.getUserData();
    String nameB = (String) bodyB.getUserData();

    if (nameA == null || nameB == null) {               // nameless bodies, check if sound needs to be played
        checkCollisionSound(contact, bodyA, bodyB);
        return false;
    } else if (nameA.equals(ObjectName.EDGE_SENSOR_NAME) || nameB.equals(ObjectName.EDGE_SENSOR_NAME)) {    // check edges
        Log.d(TAG, "onUpdate: OFF THE EDGE");

        setBallOut();

        return true;
    } else if (nameA.equals(ObjectName.SINKHOLE_NAME) || nameB.equals(ObjectName.SINKHOLE_NAME)) {  // check sinkhole
        Log.d(TAG, "onUpdate: SINKHOLE");

        setLevelComplete();

        return true;
    }

    return false;
}
 
Example 4
Source File: CollisionsSample.java    From Codelabs with MIT License 5 votes vote down vote up
@Override
public void beginContact(Contact contact) {
	Fixture fixtureA = contact.getFixtureA();
	Fixture fixtureB = contact.getFixtureB();

	/*
	 * If one of the fixture contacting is an static body, and is the wall,
	 * set ballTouchedWall to true.
	 */
	if (fixtureA.getBody().getType() == BodyType.StaticBody) {
		if (fixtureA.getBody().equals(walls)) {
			ballTouchedBox = false;
			ballTouchedWall = true;
		} else {
			ballTouchedBox = true;
			ballTouchedWall = false;
		}
	} else if (fixtureB.getBody().getType() == BodyType.StaticBody) {
		if (fixtureA.getBody().equals(walls)) {
			ballTouchedBox = false;
			ballTouchedWall = true;
		} else {
			ballTouchedBox = true;
			ballTouchedWall = false;
		}
	}
}
 
Example 5
Source File: BuoyancySample.java    From Codelabs with MIT License 5 votes vote down vote up
@Override
public void beginContact(Contact contact) {
	Fixture fixtureA = contact.getFixtureA();
	Fixture fixtureB = contact.getFixtureB();

	if (fixtureA.isSensor()
			&& fixtureB.getBody().getType() == BodyType.DynamicBody) {
		buoyancyController.addBody(fixtureB);
	} else if (fixtureB.isSensor()
			&& fixtureA.getBody().getType() == BodyType.DynamicBody) {
		buoyancyController.addBody(fixtureA);
	}
}
 
Example 6
Source File: BuoyancySample.java    From Codelabs with MIT License 5 votes vote down vote up
@Override
public void endContact(Contact contact) {
	Fixture fixtureA = contact.getFixtureA();
	Fixture fixtureB = contact.getFixtureB();

	if (fixtureA.isSensor()
			&& fixtureB.getBody().getType() == BodyType.DynamicBody) {
		buoyancyController.removeBody(fixtureB);
	} else if (fixtureB.isSensor()
			&& fixtureA.getBody().getType() == BodyType.DynamicBody) {
		if (fixtureA.getBody().getWorldCenter().y > -1) {
			buoyancyController.removeBody(fixtureA);
		}
	}
}
 
Example 7
Source File: CarImpactManager.java    From uracer-kotd with Apache License 2.0 4 votes vote down vote up
private void ifCarThenCollide (Contact contact, Fixture f, Fixture other, ContactImpulse impulse) {
	Body body = f.getBody();
	Object userData = f.getUserData();
	if ((body != null) && (userData == CarType.PlayerCar || userData == CarType.ReplayCar)) {
		Car car = (Car)body.getUserData();
		float[] impulses = impulse.getNormalImpulses();
		tmpVec2.set(impulses[0], impulses[1]);

		// dbg
		Fixture fcar = null;
		if (contact.getFixtureA().getUserData() == CarType.PlayerCar) {
			fcar = contact.getFixtureA();
		} else if (contact.getFixtureB().getUserData() == CarType.PlayerCar) {
			fcar = contact.getFixtureB();
		}

		// assumes perfect side collision
		float front_ratio = 0.5f;

		// compute median front/rear ratio for collision points
		if (fcar != null) {
			front_ratio = 0;
			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]);

				// examine front/rear ratio
				float r = MathUtils.clamp(lp.y + half_ml, 0, ml);
				r /= ml;
				front_ratio += r;
			}

			front_ratio /= (float)num_points;
			// Gdx.app.log("Cntct", "" + front_ratio);
		}
		// dbg

		car.onCollide(other, tmpVec2, front_ratio);
	}
}