use of com.badlogic.gdx.physics.box2d.FixtureDef in project commons-gdx by gemserk.
the class FixtureDefBuilder method build.
public FixtureDef build() {
FixtureDef fixtureDef = this.fixtureDef;
reset();
return fixtureDef;
}
use of com.badlogic.gdx.physics.box2d.FixtureDef in project Entitas-Java by Rubentxu.
the class CreateNearSensorSystem method execute.
@Override
protected void execute(List<SensorEntity> entities) {
for (SensorEntity e : entities) {
GameEntity gameEntity = Indexed.getInteractiveEntity(e.getLink().ownerEntity);
RigidBody rigidBody = gameEntity.getRigidBody();
NearSensor nearSensor = e.getNearSensor();
if (nearSensor.distance > 0) {
FixtureDef nearFixture = bodyBuilder.fixtureDefBuilder().circleShape(nearSensor.distance).sensor().build();
rigidBody.body.createFixture(nearFixture).setUserData("NearSensor");
if (nearSensor.resetDistance > nearSensor.distance) {
FixtureDef nearResetFixture = bodyBuilder.fixtureDefBuilder().circleShape(nearSensor.resetDistance).sensor().build();
rigidBody.body.createFixture(nearResetFixture).setUserData("ResetNearSensor");
}
}
}
}
use of com.badlogic.gdx.physics.box2d.FixtureDef 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;
}
use of com.badlogic.gdx.physics.box2d.FixtureDef in project libgdx by libgdx.
the class ApplyForce method createWorld.
@Override
protected void createWorld(World world) {
world.setGravity(new Vector2(0, 0));
float k_restitution = 0.4f;
Body ground;
{
BodyDef bd = new BodyDef();
bd.position.set(0, 20);
ground = world.createBody(bd);
EdgeShape shape = new EdgeShape();
FixtureDef sd = new FixtureDef();
sd.shape = shape;
sd.density = 0;
sd.restitution = k_restitution;
shape.set(new Vector2(-20, -20), new Vector2(-20, 20));
ground.createFixture(sd);
shape.set(new Vector2(20, -20), new Vector2(20, 20));
ground.createFixture(sd);
shape.set(new Vector2(-20, 20), new Vector2(20, 20));
ground.createFixture(sd);
shape.set(new Vector2(-20, -20), new Vector2(20, -20));
ground.createFixture(sd);
shape.dispose();
}
{
Transform xf1 = new Transform(new Vector2(), 0.3524f * (float) Math.PI);
xf1.setPosition(xf1.mul(new Vector2(1, 0)));
Vector2[] vertices = new Vector2[3];
vertices[0] = xf1.mul(new Vector2(-1, 0));
vertices[1] = xf1.mul(new Vector2(1, 0));
vertices[2] = xf1.mul(new Vector2(0, 0.5f));
PolygonShape poly1 = new PolygonShape();
poly1.set(vertices);
FixtureDef sd1 = new FixtureDef();
sd1.shape = poly1;
sd1.density = 4.0f;
Transform xf2 = new Transform(new Vector2(), -0.3524f * (float) Math.PI);
xf2.setPosition(xf2.mul(new Vector2(-1, 0)));
vertices[0] = xf2.mul(new Vector2(-1, 0));
vertices[1] = xf2.mul(new Vector2(1, 0));
vertices[2] = xf2.mul(new Vector2(0, 0.5f));
PolygonShape poly2 = new PolygonShape();
poly2.set(vertices);
FixtureDef sd2 = new FixtureDef();
sd2.shape = poly2;
sd2.density = 2.0f;
BodyDef bd = new BodyDef();
bd.type = BodyType.DynamicBody;
bd.angularDamping = 5.0f;
bd.linearDamping = 0.1f;
bd.position.set(0, 2);
bd.angle = (float) Math.PI;
bd.allowSleep = false;
m_body = world.createBody(bd);
m_body.createFixture(sd1);
m_body.createFixture(sd2);
poly1.dispose();
poly2.dispose();
}
{
PolygonShape shape = new PolygonShape();
shape.setAsBox(0.5f, 0.5f);
FixtureDef fd = new FixtureDef();
fd.shape = shape;
fd.density = 1.0f;
fd.friction = 0.3f;
for (int i = 0; i < 10; i++) {
BodyDef bd = new BodyDef();
bd.type = BodyType.DynamicBody;
bd.position.set(0, 5 + 1.54f * i);
Body body = world.createBody(bd);
body.createFixture(fd);
float gravity = 10.0f;
float I = body.getInertia();
float mass = body.getMass();
float radius = (float) Math.sqrt(2 * I / mass);
FrictionJointDef jd = new FrictionJointDef();
jd.localAnchorA.set(0, 0);
jd.localAnchorB.set(0, 0);
jd.bodyA = ground;
jd.bodyB = body;
jd.collideConnected = true;
jd.maxForce = mass * gravity;
jd.maxTorque = mass * radius * gravity;
world.createJoint(jd);
}
shape.dispose();
}
}
use of com.badlogic.gdx.physics.box2d.FixtureDef in project libgdx by libgdx.
the class VerticalStack method keyDown.
@Override
public boolean keyDown(int keyCode) {
if (keyCode == Input.Keys.COMMA) {
if (m_bullet != null) {
world.destroyBody(m_bullet);
m_bullet = null;
}
{
CircleShape shape = new CircleShape();
shape.setRadius(0.25f);
FixtureDef fd = new FixtureDef();
fd.shape = shape;
fd.density = 20.0f;
fd.restitution = 0.05f;
BodyDef bd = new BodyDef();
bd.type = BodyType.DynamicBody;
bd.bullet = true;
bd.position.set(-31, 5);
m_bullet = world.createBody(bd);
m_bullet.createFixture(fd);
m_bullet.setLinearVelocity(new Vector2(400, 0));
}
}
return false;
}
Aggregations