use of com.badlogic.gdx.physics.box2d.Fixture in project libgdx by libgdx.
the class ContactListenerTest method endContact.
@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.");
}
}
use of com.badlogic.gdx.physics.box2d.Fixture in project libgdx by libgdx.
the class ConveyorBelt method preSolve.
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);
}
}
use of com.badlogic.gdx.physics.box2d.Fixture in project RubeLoader by tescott.
the class BodySerializer method read.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public Body read(Json json, JsonValue jsonData, Class type) {
if (world == null)
return null;
BodyDef defaults = RubeDefaults.Body.definition;
int bodyType = json.readValue("type", int.class, defaults.type.getValue(), jsonData);
if (bodyType == BodyType.DynamicBody.getValue())
def.type = BodyType.DynamicBody;
else if (bodyType == BodyType.KinematicBody.getValue())
def.type = BodyType.KinematicBody;
else
def.type = BodyType.StaticBody;
def.position.set(json.readValue("position", Vector2.class, defaults.position, jsonData));
def.linearVelocity.set(json.readValue("linearVelocity", Vector2.class, defaults.linearVelocity, jsonData));
def.angle = json.readValue("angle", float.class, defaults.angle, jsonData);
def.angularVelocity = json.readValue("angularVelocity", float.class, defaults.angularVelocity, jsonData);
def.linearDamping = json.readValue("linearDamping", float.class, defaults.linearDamping, jsonData);
def.angularDamping = json.readValue("angularDamping", float.class, defaults.angularDamping, jsonData);
def.gravityScale = json.readValue("gravityScale", float.class, defaults.gravityScale, jsonData);
def.allowSleep = json.readValue("allowSleep", boolean.class, defaults.allowSleep, jsonData);
def.awake = json.readValue("awake", boolean.class, defaults.awake, jsonData);
def.fixedRotation = json.readValue("fixedRotation", boolean.class, defaults.fixedRotation, jsonData);
def.bullet = json.readValue("bullet", boolean.class, defaults.bullet, jsonData);
def.active = json.readValue("active", boolean.class, defaults.active, jsonData);
Body body = world.createBody(def);
if (def.type == BodyType.DynamicBody) {
Vector2 center = json.readValue("massData-center", Vector2.class, jsonData);
float mass = json.readValue("massData-mass", float.class, 0.0f, jsonData);
float I = json.readValue("massData-I", float.class, 0.0f, jsonData);
if (center != null) {
MassData massData = new MassData();
massData.center.set(center);
massData.mass = mass;
massData.I = I;
if (massData.mass != 0.0f || massData.I != 0.0f || massData.center.x != 0.0f || massData.center.y != 0.0f)
body.setMassData(massData);
}
}
scene.parseCustomProperties(json, body, jsonData);
String name = json.readValue("name", String.class, jsonData);
if (name != null) {
scene.putNamed(name, body);
}
fixtureSerializer.setBody(body);
scene.addFixtures(json.readValue("fixture", Array.class, Fixture.class, jsonData));
return body;
}
use of com.badlogic.gdx.physics.box2d.Fixture in project RubeLoader by tescott.
the class FixtureSerializer method read.
@SuppressWarnings("rawtypes")
@Override
public Fixture read(Json json, JsonValue jsonData, Class type) {
if (body == null)
return null;
json.setIgnoreUnknownFields(true);
FixtureDef defaults = RubeDefaults.Fixture.definition;
FixtureDef def = new FixtureDef();
json.readFields(def, jsonData);
def.friction = json.readValue("friction", float.class, defaults.friction, jsonData);
def.density = json.readValue("density", float.class, defaults.density, jsonData);
def.restitution = json.readValue("restitution", float.class, defaults.restitution, jsonData);
def.isSensor = json.readValue("sensor", boolean.class, defaults.isSensor, jsonData);
def.filter.maskBits = json.readValue("filter-maskBits", short.class, defaults.filter.maskBits, jsonData);
def.filter.categoryBits = json.readValue("filter-categoryBits", short.class, defaults.filter.categoryBits, jsonData);
def.filter.groupIndex = json.readValue("filter-groupIndex", short.class, defaults.filter.groupIndex, jsonData);
CircleShape circle = json.readValue("circle", CircleShape.class, jsonData);
if (circle != null) {
def.shape = circle;
} else {
EdgeShape edge = json.readValue("edge", EdgeShape.class, jsonData);
if (edge != null) {
def.shape = edge;
} else {
chainShapeSerializer.setReadLoop(false);
ChainShape chain = json.readValue("chain", ChainShape.class, jsonData);
if (chain != null) {
def.shape = chain;
} else {
chainShapeSerializer.setReadLoop(true);
chain = json.readValue("loop", ChainShape.class, jsonData);
if (chain != null) {
def.shape = chain;
} else {
PolygonShape polygon = json.readValue("polygon", PolygonShape.class, jsonData);
if (polygon != null) {
def.shape = polygon;
} else {
edge = json.readValue("polygon", EdgeShape.class, jsonData);
if (edge != null) {
def.shape = edge;
}
}
}
}
}
}
Fixture fixture = body.createFixture(def);
def.shape.dispose();
scene.parseCustomProperties(json, fixture, jsonData);
String name = json.readValue("name", String.class, jsonData);
if (name != null) {
scene.putNamed(name, fixture);
}
return fixture;
}
use of com.badlogic.gdx.physics.box2d.Fixture in project commons-gdx by gemserk.
the class Box2dUtils method getFixture.
/**
* Returns a Fixture from a Body given the fixtureUserData.
*
* @param body
* The Body to get the Fixture from.
* @param fixtureUserData
* The Fixture userData to identify the Fixture.
*/
public static Fixture getFixture(Body body, Object fixtureUserData) {
ArrayList<Fixture> fixtureList = body.getFixtureList();
for (int i = 0; i < fixtureList.size(); i++) {
Fixture fixture = fixtureList.get(i);
Object userData = fixture.getUserData();
if (userData == fixtureUserData || fixtureUserData.equals(userData))
return fixture;
}
return null;
}
Aggregations