use of com.badlogic.gdx.physics.box2d.MassData 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.MassData 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.MassData in project commons-gdx by gemserk.
the class BodyBuilder method build.
public Body build(boolean disposeShapes) {
Body body = world.createBody(bodyDef);
for (int i = 0; i < fixtureDefs.size(); i++) {
FixtureDef fixtureDef = fixtureDefs.get(i);
Fixture fixture = body.createFixture(fixtureDef);
fixture.setUserData(fixtureUserDatas.get(i));
}
if (massSet) {
MassData bodyMassData = body.getMassData();
// massData.center.set(position);
massData.center.set(bodyMassData.center);
// massData.I = bodyMassData.I;
body.setMassData(massData);
}
// MassData massData = body.getMassData();
// massData.mass = mass;
// massData.I = 1f;
body.setUserData(userData);
body.setTransform(position, angle);
reset(disposeShapes);
return body;
}
Aggregations