use of org.jbox2d.dynamics.BodyDef in project Bytecoder by mirkosertic.
the class JBox2DTest method testNewWorld.
@Test
public void testNewWorld() {
World world = new World(new Vec2(0, -9.8f));
BodyDef axisDef = new BodyDef();
axisDef.type = BodyType.STATIC;
axisDef.position = new Vec2(3, 3);
Body axis = world.createBody(axisDef);
CircleShape axisShape = new CircleShape();
axisShape.setRadius(0.02f);
axisShape.m_p.set(0, 0);
// FixtureDef axisFixture = new FixtureDef();
// axisFixture.shape = axisShape;
// axis.createFixture(axisFixture);
}
use of org.jbox2d.dynamics.BodyDef in project opennars by opennars.
the class ParticleVelocityQueryCallback method init.
public void init(TestbedState model) {
this.model = model;
Vec2 gravity = new Vec2(0, -10f);
m_world = model.getWorldCreator().createWorld(gravity);
m_world.setParticleGravityScale(0.4f);
m_world.setParticleDensity(1.2f);
bomb = null;
mouseJoint = null;
mouseTracing = false;
mouseTracerPosition.setZero();
mouseTracerVelocity.setZero();
BodyDef bodyDef = new BodyDef();
groundBody = m_world.createBody(bodyDef);
init(m_world, false);
}
use of org.jbox2d.dynamics.BodyDef in project Bytecoder by mirkosertic.
the class JBox2DTest method testSimpleBall.
@Test
public void testSimpleBall() {
World world = new World(new Vec2(0, -9.8f));
float ballRadius = 0.15f;
BodyDef ballDef = new BodyDef();
ballDef.type = BodyType.DYNAMIC;
FixtureDef fixtureDef = new FixtureDef();
fixtureDef.friction = 0.3f;
fixtureDef.restitution = 0.3f;
fixtureDef.density = 0.2f;
CircleShape shape = new CircleShape();
shape.m_radius = ballRadius;
fixtureDef.shape = shape;
int i = 0;
int j = 0;
float x = (j + 0.5f) * (ballRadius * 2 + 0.01f);
float y = (i + 0.5f) * (ballRadius * 2 + 0.01f);
ballDef.position.x = 3 + x;
ballDef.position.y = 3 + y;
Body theBall = world.createBody(ballDef);
theBall.createFixture(fixtureDef);
for (int k = 0; k < 100; k++) {
world.step(0.01f, 20, 40);
}
Vec2 thePosition = theBall.getPosition();
int theX = (int) (thePosition.x * 1000);
int theY = (int) (thePosition.y * 1000);
System.out.println("Finally ended at ");
System.out.println(theX);
System.out.println(theY);
}
use of org.jbox2d.dynamics.BodyDef in project opennars by opennars.
the class ParticleVelocityQueryCallback method launchBomb.
private void launchBomb(Vec2 position, Vec2 velocity) {
if (bomb != null) {
m_world.destroyBody(bomb);
bomb = null;
}
// todo optimize this
BodyDef bd = new BodyDef();
bd.type = BodyType.DYNAMIC;
bd.position.set(position);
bd.bullet = true;
bomb = m_world.createBody(bd);
bomb.setLinearVelocity(velocity);
CircleShape circle = new CircleShape();
circle.m_radius = 0.3f;
FixtureDef fd = new FixtureDef();
fd.shape = circle;
fd.density = 20f;
fd.restitution = 0;
Vec2 minV = new Vec2(position);
Vec2 maxV = new Vec2(position);
minV.subLocal(new Vec2(.3f, .3f));
maxV.addLocal(new Vec2(.3f, .3f));
aabb.lowerBound.set(minV);
aabb.upperBound.set(maxV);
bomb.createFixture(fd);
}
use of org.jbox2d.dynamics.BodyDef in project opennars by opennars.
the class RobotArm method initTest.
@Override
public void initTest(boolean argDeserialized) {
for (int i = 0; i < 10; i++) {
getCamera().zoomToPoint(new Vec2(0, 0), PhysicsCamera.ZoomType.ZOOM_IN);
}
Body ground = null;
{
BodyDef bd = new BodyDef();
ground = getWorld().createBody(bd);
EdgeShape shape = new EdgeShape();
shape.set(new Vec2(-40.0f, 0.0f), new Vec2(40.0f, 0.0f));
ground.createFixture(shape, 0.0f);
}
{
Body prevBody = ground;
// Define upper arm.
{
PolygonShape shape = new PolygonShape();
shape.setAsBox(0.5f, 4.0f);
BodyDef bd = new BodyDef();
bd.type = BodyType.DYNAMIC;
bd.position.set(0.0f, 5.0f);
upperArm = getWorld().createBody(bd);
upperArm.createFixture(shape, 2.0f);
RevoluteJointDef rjd = new RevoluteJointDef();
rjd.initialize(prevBody, upperArm, new Vec2(0.0f, 2.0f));
// 1.0f * MathUtils.PI;
rjd.motorSpeed = 0;
rjd.maxMotorTorque = 10000.0f;
rjd.enableMotor = true;
rjd.lowerAngle = -MathUtils.PI / 2f * 1.5f;
rjd.upperAngle = MathUtils.PI / 2f * 1.5f;
rjd.enableLimit = true;
shoulderJoint = (RevoluteJoint) getWorld().createJoint(rjd);
prevBody = upperArm;
}
// Define lower arm.
{
PolygonShape shape = new PolygonShape();
shape.setAsBox(0.5f, 2.0f);
BodyDef bd = new BodyDef();
bd.type = BodyType.DYNAMIC;
bd.position.set(0.0f, 11.0f);
lowerArm = getWorld().createBody(bd);
lowerArm.createFixture(shape, 1.0f);
RevoluteJointDef rjd = new RevoluteJointDef();
rjd.initialize(prevBody, lowerArm, new Vec2(0.0f, 9.0f));
rjd.enableMotor = true;
rjd.lowerAngle = -MathUtils.PI / 2f * 1.5f;
rjd.upperAngle = MathUtils.PI / 2f * 1.5f;
rjd.enableLimit = true;
elbowJoint = (RevoluteJoint) getWorld().createJoint(rjd);
}
// Finger Right
{
PolygonShape shape = new PolygonShape();
shape.setAsBox(0.1f, 0.75f);
BodyDef bd = new BodyDef();
bd.type = BodyType.DYNAMIC;
bd.position.set(0.5f, 13.5f);
Body body = getWorld().createBody(bd);
body.createFixture(shape, 0.25f);
RevoluteJointDef rjd = new RevoluteJointDef();
rjd.initialize(lowerArm, body, new Vec2(0.5f, 13.0f));
rjd.enableMotor = true;
rjd.upperAngle = MathUtils.PI / 8f * 1.5f;
rjd.lowerAngle = -MathUtils.PI / 4f * 1.5f;
rjd.enableLimit = true;
fingerRightJoint = (RevoluteJoint) getWorld().createJoint(rjd);
prevBody = body;
}
// Finger Left
{
PolygonShape shape = new PolygonShape();
shape.setAsBox(0.1f, 0.75f);
BodyDef bd = new BodyDef();
bd.type = BodyType.DYNAMIC;
bd.position.set(-0.5f, 13.5f);
Body body = getWorld().createBody(bd);
body.createFixture(shape, 0.25f);
RevoluteJointDef rjd = new RevoluteJointDef();
rjd.initialize(lowerArm, body, new Vec2(-0.5f, 13.0f));
rjd.enableMotor = true;
rjd.upperAngle = MathUtils.PI / 4f * 1.5f;
rjd.lowerAngle = -MathUtils.PI / 8f * 1.5f;
rjd.enableLimit = true;
fingerLeftJoint = (RevoluteJoint) getWorld().createJoint(rjd);
}
// // Define piston
// {
// PolygonShape shape = new PolygonShape();
// shape.setAsBox(1.5f, 1.5f);
//
// BodyDef bd = new BodyDef();
// bd.type = BodyType.DYNAMIC;
// bd.fixedRotation = true;
// bd.position.set(0.0f, 17.0f);
// Body body = getWorld().createBody(bd);
// body.createFixture(shape, 2.0f);
//
// RevoluteJointDef rjd = new RevoluteJointDef();
// rjd.initialize(prevBody, body, new Vec2(0.0f, 17.0f));
// getWorld().createJoint(rjd);
//
// PrismaticJointDef pjd = new PrismaticJointDef();
// pjd.initialize(ground, body, new Vec2(0.0f, 17.0f), new Vec2(0.0f, 1.0f));
//
// pjd.maxMotorForce = 1000.0f;
// pjd.enableMotor = false;
//
// m_joint2 = (PrismaticJoint) getWorld().createJoint(pjd);
// }
// // Create a payload
// {
// PolygonShape shape = new PolygonShape();
// shape.setAsBox(1.5f, 1.5f);
//
// BodyDef bd = new BodyDef();
// bd.type = BodyType.DYNAMIC;
// bd.position.set(0.0f, 23.0f);
// Body body = getWorld().createBody(bd);
// body.createFixture(shape, 2.0f);
// }
}
}
Aggregations