use of com.badlogic.gdx.physics.box2d.CircleShape 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.CircleShape in project libgdx by libgdx.
the class KinematicBodyTest method create.
public void create() {
cam = new OrthographicCamera(48, 32);
cam.position.set(0, 15, 0);
renderer = new Box2DDebugRenderer();
world = new World(new Vector2(0, -10), true);
Body body = world.createBody(new BodyDef());
CircleShape shape = new CircleShape();
shape.setRadius(1f);
MassData mass = new MassData();
mass.mass = 1f;
body.setMassData(mass);
body.setFixedRotation(true);
body.setType(BodyType.KinematicBody);
body.createFixture(shape, 1);
body.setBullet(true);
body.setTransform(new Vector2(0, 0), body.getAngle());
body.setLinearVelocity(new Vector2(50f, 0));
}
use of com.badlogic.gdx.physics.box2d.CircleShape in project libgdx by libgdx.
the class Box2DCharacterControllerTest method createCircle.
Body createCircle(BodyType type, float radius, float density) {
BodyDef def = new BodyDef();
def.type = type;
Body box = world.createBody(def);
CircleShape poly = new CircleShape();
poly.setRadius(radius);
box.createFixture(poly, density);
poly.dispose();
return box;
}
use of com.badlogic.gdx.physics.box2d.CircleShape in project commons-gdx by gemserk.
the class Box2dUtils method translateFixtures.
/**
* Internally translates all the Body's fixtures the specified translation, without moving the Body's center. For now, it generates garbage so should be used only once.
*
* @param body
* The body to work on.
* @param tx
* The translation in x coordinate.
* @param ty
* The translation in y coordinate.
*/
public static void translateFixtures(ArrayList<Fixture> fixtures, float tx, float ty) {
// TODO: should be in a Box2dUtils
for (int i = 0; i < fixtures.size(); i++) {
Fixture fixture = fixtures.get(i);
Shape shape = fixture.getShape();
if (shape.getType() == Type.Polygon)
ShapeUtils.translatePolygonShape((PolygonShape) shape, tx, ty);
else if (shape.getType() == Type.Circle)
ShapeUtils.translateCircleShape((CircleShape) shape, tx, ty);
}
}
use of com.badlogic.gdx.physics.box2d.CircleShape in project commons-gdx by gemserk.
the class FixtureDefBuilder method circleShape.
public FixtureDefBuilder circleShape(float radius) {
Shape shape = new CircleShape();
shape.setRadius(radius);
fixtureDef.shape = shape;
return this;
}
Aggregations