use of org.jbox2d.collision.shapes.PolygonShape in project HackerHop by nicovank.
the class PlayerTest method playerShapeTest.
@Test
void playerShapeTest() {
World world = new World(new Vec2(0, -50));
Vec2 position = new Vec2(0, 10);
Player p = new Player(world, position);
Shape s = p.getBody().getFixtureList().m_shape;
PolygonShape r = new PolygonShape();
r.setAsBox(3, 3);
assertEquals(s.getType(), r.getType());
}
use of org.jbox2d.collision.shapes.PolygonShape 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