Java 类com.badlogic.gdx.physics.box2d.FixtureDef 实例源码

项目:homescreenarcade    文件:Box2DFactory.java   
/** Creates a circle object with the given position and radius. Resitution defaults to 0.6. */
public static Body createCircle(World world, float x, float y, float radius, boolean isStatic) {
    CircleShape sd = new CircleShape();
    sd.setRadius(radius);

    FixtureDef fdef = new FixtureDef();
    fdef.shape = sd;
    fdef.density = 1.0f;
    fdef.friction = 0.3f;
    fdef.restitution = 0.6f;

    BodyDef bd = new BodyDef();
    bd.allowSleep = true;
    bd.position.set(x, y);
    Body body = world.createBody(bd);
    body.createFixture(fdef);
    if (isStatic) {
        body.setType(BodyDef.BodyType.StaticBody);
    }
    else {
        body.setType(BodyDef.BodyType.DynamicBody);
    }
    return body;
}
项目:homescreenarcade    文件:Box2DFactory.java   
/**
 * Creates a wall by constructing a rectangle whose corners are (xmin,ymin) and (xmax,ymax),
 * and rotating the box counterclockwise through the given angle, with specified restitution.
 */
public static Body createWall(World world, float xmin, float ymin, float xmax, float ymax,
        float angle, float restitution) {
    float cx = (xmin + xmax) / 2;
    float cy = (ymin + ymax) / 2;
    float hx = Math.abs((xmax - xmin) / 2);
    float hy = Math.abs((ymax - ymin) / 2);
    PolygonShape wallshape = new PolygonShape();
    // Don't set the angle here; instead call setTransform on the body below. This allows future
    // calls to setTransform to adjust the rotation as expected.
    wallshape.setAsBox(hx, hy, new Vector2(0f, 0f), 0f);

    FixtureDef fdef = new FixtureDef();
    fdef.shape = wallshape;
    fdef.density = 1.0f;
    if (restitution>0) fdef.restitution = restitution;

    BodyDef bd = new BodyDef();
    bd.position.set(cx, cy);
    Body wall = world.createBody(bd);
    wall.createFixture(fdef);
    wall.setType(BodyDef.BodyType.StaticBody);
    wall.setTransform(cx, cy, angle);
    return wall;
}
项目:feup-lpoo-armadillo    文件:B2DFactory.java   
/**
 * Creates polygon ground from the given object, at the given world.
 *
 * @param world  The world were the ground will be.
 * @param object The object used to initialize the ground.
 * @return The body of the created ground.
 */
static Body makePolygonGround(World world, PolygonMapObject object) {
    Polygon polygon = object.getPolygon();

    // Body and Fixture variables
    BodyDef bdef = new BodyDef();
    FixtureDef fdef = new FixtureDef();
    PolygonShape shape = new PolygonShape();

    bdef.type = BodyDef.BodyType.StaticBody;
    bdef.position.set(PIXEL_TO_METER * polygon.getX(), PIXEL_TO_METER * polygon.getY());

    Body body = world.createBody(bdef);

    float[] new_vertices = polygon.getVertices().clone();
    for (int i = 0; i < new_vertices.length; i++)
        new_vertices[i] *= PIXEL_TO_METER;

    shape.set(new_vertices);
    fdef.shape = shape;
    fdef.filter.categoryBits = GROUND_BIT;
    body.createFixture(fdef);

    return body;
}
项目:feup-lpoo-armadillo    文件:B2DFactory.java   
/**
 * Creates rectangular ground from the given object, at the given world.
 *
 * @param world  The world were the ground will be.
 * @param object The object used to initialize the ground.
 * @return The body of the created ground.
 */
static Body makeRectGround(World world, RectangleMapObject object) {
    Rectangle rect = object.getRectangle();

    // Body and Fixture variables
    BodyDef bdef = new BodyDef();
    FixtureDef fdef = new FixtureDef();
    PolygonShape shape = new PolygonShape();

    bdef.type = BodyDef.BodyType.StaticBody;
    bdef.position.set(PIXEL_TO_METER * (rect.getX() + rect.getWidth() / 2), PIXEL_TO_METER * (rect.getY() + rect.getHeight() / 2));

    Body body = world.createBody(bdef);

    shape.setAsBox((rect.getWidth() / 2) * PIXEL_TO_METER, (rect.getHeight() / 2) * PIXEL_TO_METER);
    fdef.shape = shape;
    fdef.filter.categoryBits = GROUND_BIT;
    body.createFixture(fdef);

    return body;
}
项目:feup-lpoo-armadillo    文件:WaterModel.java   
/**
 * Water Model's constructor.
 * Creates a water model from the given object, into the given world.
 *
 * @param world The world the water model will be in.
 * @param rect  The rectangle to create the water model with.
 */
public WaterModel(World world, Rectangle rect) {
    // Body and Fixture variables
    BodyDef bdef = new BodyDef();
    FixtureDef fdef = new FixtureDef();
    PolygonShape shape = new PolygonShape();

    bdef.type = BodyDef.BodyType.StaticBody;
    bdef.position.set(PIXEL_TO_METER * (rect.getX() + rect.getWidth() / 2), PIXEL_TO_METER * (rect.getY() + rect.getHeight() / 2));

    this.body = world.createBody(bdef);

    shape.setAsBox((rect.getWidth() / 2) * PIXEL_TO_METER, (rect.getHeight() / 2) * PIXEL_TO_METER);
    fdef.shape = shape;
    fdef.filter.categoryBits = FLUID_BIT;
    fdef.isSensor = true;
    fdef.density = 1f;
    fdef.friction = 0.1f;
    fdef.restitution = 0f;
    body.createFixture(fdef);

    body.setUserData(new BuoyancyController(world, body.getFixtureList().first()));

}
项目:feup-lpoo-armadillo    文件:EntityModel.java   
/**
 * Creates a Fixture with the given Fixture Properties.
 *
 * @param fixtureProperties Fixture properties used to generate the fixture
 */
final void createFixture(FixtureProperties fixtureProperties) {
    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.shape = fixtureProperties.getShape();

    fixtureDef.density = fixtureProperties.getDensity();
    fixtureDef.friction = fixtureProperties.getFriction();
    fixtureDef.restitution = fixtureProperties.getRestitution();
    fixtureDef.filter.categoryBits = fixtureProperties.getCategory();
    fixtureDef.filter.maskBits = fixtureProperties.getMask();
    fixtureDef.isSensor = fixtureProperties.isSensor();

    body.createFixture(fixtureDef);

    fixtureProperties.getShape().dispose();
}
项目:GDX-Engine    文件:PhysicsManager.java   
public Body createTempBodyDistanceJoint(Body bodyA, Body bodyB,
    Vector2 localA, Vector2 localB, int length) {
DistanceJointDef dJoint = new DistanceJointDef();
FixtureDef fixtureDef = createFixtureDef(1f, 0.5f, 0.2f, (short) 0x0004);
IPhysicsObject sprite = (IPhysicsObject) bodyA.getUserData();
Body temp = createTempBody(sprite.getX(), sprite.getY(), fixtureDef);
createRevoluteJoint(bodyA, temp, localA, Vector2.Zero);
dJoint.bodyA = temp;
dJoint.bodyB = bodyB;
dJoint.localAnchorA.set(localA.x * WORLD_TO_BOX, localA.y
    * WORLD_TO_BOX);
dJoint.localAnchorB.set(localB.x * WORLD_TO_BOX, localB.y
    * WORLD_TO_BOX);
dJoint.length = length * WORLD_TO_BOX;
world.createJoint(dJoint);
return temp;
   }
项目:GDX-Engine    文件:PhysicsManager.java   
public Body createTempBody(float x, float y, FixtureDef fixtureDef) {
// Dynamic Body
BodyDef bodyDef = new BodyDef();
if (box2dDebug)
    bodyDef.type = BodyType.StaticBody;
else
    bodyDef.type = BodyType.DynamicBody;

// transform into box2d
x = x * WORLD_TO_BOX;
y = y * WORLD_TO_BOX;

bodyDef.position.set(x, y);

Body body = world.createBody(bodyDef);

Shape shape = new CircleShape();
((CircleShape) shape).setRadius(1 * WORLD_TO_BOX);

if (fixtureDef == null)
    throw new GdxRuntimeException("fixtureDef cannot be null!");
fixtureDef.shape = shape;
body.createFixture(fixtureDef);
return body;
   }
项目:GDX-Engine    文件:Rope.java   
private Body createRopeTipBody()
{
    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyType.DynamicBody;
    bodyDef.linearDamping = 0.5f;
    Body body = world.createBody(bodyDef);

    FixtureDef circleDef = new FixtureDef();
    CircleShape circle = new CircleShape();
    circle.setRadius(1.0f/PTM_RATIO);
    circleDef.shape = circle;
    circleDef.density = 10.0f;

    // Since these tips don't have to collide with anything
    // set the mask bits to zero
    circleDef.filter.maskBits = 0x01; //0;
    body.createFixture(circleDef);

    return body;
}
项目:GDX-Engine    文件:PhysicsTiledScene.java   
public Body createTempBodyDistanceJoint(Body bodyA, Body bodyB,
        Vector2 localA, Vector2 localB, int length) {
    DistanceJointDef dJoint = new DistanceJointDef();
    FixtureDef fixtureDef = createFixtureDef(1f, 0.5f, 0.2f, (short) 0x0004);
    IPhysicsObject sprite = (IPhysicsObject) bodyA.getUserData();
    Body temp = createTempBody(sprite.getX(), sprite.getY(), fixtureDef);
    createRevoluteJoint(bodyA, temp, localA, Vector2.Zero);
    dJoint.bodyA = temp;
    dJoint.bodyB = bodyB;
    dJoint.localAnchorA.set(localA.x * WORLD_TO_BOX, localA.y
            * WORLD_TO_BOX);
    dJoint.localAnchorB.set(localB.x * WORLD_TO_BOX, localB.y
            * WORLD_TO_BOX);
    dJoint.length = length * WORLD_TO_BOX;
    world.createJoint(dJoint);
    return temp;
}
项目:GDX-Engine    文件:PhysicsTiledScene.java   
public Body createTempBody(float x, float y, FixtureDef fixtureDef) {
    // Dynamic Body
    BodyDef bodyDef = new BodyDef();
    if (box2dDebug)
        bodyDef.type = BodyType.StaticBody;
    else
        bodyDef.type = BodyType.DynamicBody;

    // transform into box2d
    x = x * WORLD_TO_BOX;
    y = y * WORLD_TO_BOX;

    bodyDef.position.set(x, y);

    Body body = world.createBody(bodyDef);

    Shape shape = new CircleShape();
    ((CircleShape) shape).setRadius(1 * WORLD_TO_BOX);

    if (fixtureDef == null)
        throw new GdxRuntimeException("fixtureDef cannot be null!");
    fixtureDef.shape = shape;
    body.createFixture(fixtureDef);
    return body;
}
项目:water2d-libgdx    文件:GameMain.java   
private void createBody() {
    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyType.DynamicBody;

    // Set our body's starting position in the world
    bodyDef.position.set(Gdx.input.getX() / 100f, camera.viewportHeight - Gdx.input.getY() / 100f);

    // Create our body in the world using our body definition
    Body body = world.createBody(bodyDef);

    // Create a circle shape and set its radius to 6
    PolygonShape square = new PolygonShape();
    square.setAsBox(0.3f, 0.3f);

    // Create a fixture definition to apply our shape to
    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.shape = square;
    fixtureDef.density = 0.5f;
    fixtureDef.friction = 0.5f;
    fixtureDef.restitution = 0.5f;

    // Create our fixture and attach it to the body
    body.createFixture(fixtureDef);

    square.dispose();
}
项目:summer17-android    文件:InteractiveTileObject.java   
public InteractiveTileObject(World world, TiledMap map, Rectangle bounds){
    this.world = world;
    this.map = map;
    this.bounds = bounds;

    BodyDef bdef = new BodyDef();
    FixtureDef fdef = new FixtureDef();
    PolygonShape shape = new PolygonShape();

    bdef.type = BodyDef.BodyType.StaticBody;
    bdef.position.set((bounds.getX() + bounds.getWidth() / 2) / NoObjectionGame.PPM, (bounds.getY() + bounds.getHeight() / 2 )/ NoObjectionGame.PPM);

    body = world.createBody(bdef);
    shape.setAsBox(bounds.getWidth() / 2 / NoObjectionGame.PPM, bounds.getHeight() / 2 / NoObjectionGame.PPM);
    fdef.shape = shape;
    fixture = body.createFixture(fdef);
}
项目:FlappySpinner    文件:WorldUtils.java   
public static Body createSpinner(World world) {
    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyDef.BodyType.DynamicBody;
    bodyDef.position.set(Constants.SPINNER_POSITIONS);
    Body body = world.createBody(bodyDef);
    CircleShape circle = new CircleShape();
    circle.setRadius(Constants.SPINNER_SIZE);
    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.shape = circle;
    fixtureDef.density = Constants.SPENNER_DENSITY;
    fixtureDef.friction = 0f;
    fixtureDef.restitution = 0.45f;
    body.createFixture(fixtureDef);
    circle.dispose();
    return body;
}
项目:school-game    文件:BaseEntity.java   
/**
 * Erlaubt es den Unterklassen möglichst einfach einen beliebigen Box2D Körper zu erstellen.
 *
 * @param position die Startposition des Body
 * @param shape die Form, die für dne Body verwendet werden soll
 * @param type der Typ des Körpers
 * @return ein Box2D Körper
 */
protected Body createEntityBody(Vector2 position, Shape shape, BodyDef.BodyType type)
{
    position.scl(Physics.MPP);

    BodyDef bodyDef = new BodyDef();
    bodyDef.type = type;
    bodyDef.position.set(position);
    bodyDef.fixedRotation = true;

    Body body = worldObjectManager.getPhysicalWorld().createBody(bodyDef);
    body.setUserData(this);

    FixtureDef fixture = new FixtureDef();
    fixture.shape = shape;
    fixture.filter.categoryBits = Physics.CATEGORY_ENTITIES;
    fixture.filter.maskBits = Physics.MASK_ENTITIES;

    body.createFixture(fixture).setUserData(this);

    shape.dispose();

    return body;
}
项目:libGdx-xiyou    文件:Tao.java   
private void init() {
    mRegion = MyGdxGame.assetManager.getTextureAtlas(Constant.PLAY_BLOOD).findRegion("hp");

    mBodyDef = new BodyDef();
    mFixtureDef = new FixtureDef();
    PolygonShape shape = new PolygonShape();

    //初始化刚体形状
    mBodyDef.type = BodyDef.BodyType.StaticBody;
    mBodyDef.position.set(x, y);

    shape.setAsBox(30 / Constant.RATE, 30 / Constant.RATE);
    mFixtureDef.shape = shape;
    mFixtureDef.isSensor = true;
    mFixtureDef.filter.categoryBits = Constant.TAO;
    mFixtureDef.filter.maskBits = Constant.PLAYER;

    mBody = mWorld.createBody(mBodyDef);
    mBody.createFixture(mFixtureDef).setUserData("tao");
}
项目:libGdx-xiyou    文件:Monkey.java   
/**
 * 创建攻击夹具
 */
public void createStick() {
    if (mAttackFixture != null) {
        return;
    }
    //创建攻击传感器 stick
    PolygonShape shape = new PolygonShape();
    if (STATE == State.STATE_RIGHT_ATTACK) {
        shape.setAsBox(45 / Constant.RATE, 5 / Constant.RATE
                , new Vector2(60 / Constant.RATE, 0), 0);
    } else {
        shape.setAsBox(45 / Constant.RATE, 5 / Constant.RATE
                , new Vector2(-60 / Constant.RATE, 0), 0);
    }
    FixtureDef attackFixDef = new FixtureDef();
    attackFixDef.shape = shape;
    attackFixDef.filter.categoryBits = Constant.PLAYER;
    attackFixDef.filter.maskBits = Constant.ENEMY_DAO | Constant.BOSS;
    attackFixDef.isSensor = true;
    mAttackFixture = mBody.createFixture(attackFixDef);
    mAttackFixture.setUserData("stick");
}
项目:libGdx-xiyou    文件:Monkey.java   
/**
 * 创建升龙斩攻击夹具
 */
public void createJumpStick() {
    if (mJumpAtkFix != null) {
        return;
    }
    //创建攻击传感器 stick
    PolygonShape shape = new PolygonShape();
    if (STATE == State.STATE_RIGHT_JUMP_ATTACK) {
        shape.setAsBox(10 / Constant.RATE, 40 / Constant.RATE
                , new Vector2(100 / Constant.RATE, 20 / Constant.RATE), 0);
    } else {
        shape.setAsBox(10 / Constant.RATE, 45 / Constant.RATE
                , new Vector2(-100 / Constant.RATE, 20 / Constant.RATE), 0);
    }
    FixtureDef attackFixDef = new FixtureDef();
    attackFixDef.shape = shape;
    attackFixDef.filter.categoryBits = Constant.PLAYER;
    attackFixDef.filter.maskBits = Constant.ENEMY_DAO | Constant.BOSS;
    attackFixDef.isSensor = true;
    mJumpAtkFix = mBody.createFixture(attackFixDef);
    mJumpAtkFix.setUserData("ball");
}
项目:libGdx-xiyou    文件:Blue.java   
private void init() {
    mRegion = MyGdxGame.assetManager.getTextureAtlas(Constant.PLAY_BLOOD).findRegion("mp");

    mBodyDef = new BodyDef();
    mFixtureDef = new FixtureDef();
    PolygonShape shape = new PolygonShape();

    //初始化刚体形状
    mBodyDef.type = BodyDef.BodyType.StaticBody;
    mBodyDef.position.set(x, y);

    shape.setAsBox(30 / Constant.RATE, 30 / Constant.RATE);
    mFixtureDef.shape = shape;
    mFixtureDef.isSensor = true;
    mFixtureDef.filter.categoryBits = Constant.BLUE;
    mFixtureDef.filter.maskBits = Constant.PLAYER;

    mBody = mWorld.createBody(mBodyDef);
    mBody.createFixture(mFixtureDef).setUserData("blue");
}
项目:QuackHack    文件:Player.java   
public void definePlayer(){
    BodyDef bdef = new BodyDef();
    bdef.position.set(100 / QuackHack.PPM, 1500 / QuackHack.PPM); // Mario start position
    bdef.type = BodyDef.BodyType.DynamicBody;
    b2body = world.createBody(bdef);

    FixtureDef fdef = new FixtureDef();
    CircleShape shape = new CircleShape();
    shape.setRadius(64 / QuackHack.PPM);

    fdef.filter.categoryBits = QuackHack.MARIO_BIT;
    fdef.filter.maskBits = QuackHack.DEFAULT_BIT;
    fdef.friction = 0;
    fdef.density = 0.1f;

    fdef.shape = shape;
    b2body.createFixture(fdef);
    b2body.createFixture(fdef).setUserData(this);
}
项目:joe    文件:Player.java   
@Override
protected Body createBody(EntityDefinition definition) {
    BodyDef bodyDef = definition.getBodyDef();
    bodyDef.position.set(definition.getCenter());
    Body body = Level.getInstance().getPhysicsWorld().createBody(bodyDef);

    FixtureDef fixtureDef = createFixtureDef();
    body.createFixture(fixtureDef);
    fixtureDef.shape.dispose();

    body.setBullet(true);
    attachFootSensor(body, definition.getSize().x);

    Filter filter = new Filter();
    filter.categoryBits = 0x0001;
    filter.maskBits = ~Player.COLLISION_MASK;
    body.getFixtureList().get(0).setFilterData(filter);

    return body;
}
项目:joe    文件:Player.java   
private FixtureDef createFixtureDef() {
        PolygonShape shape = new PolygonShape();
//        shape.set(new Vector2[]{
//                new Vector2(1.3f, -1.29f),
//                new Vector2(1f, -1.3f),
//                new Vector2(-1f, -1.3f),
//                new Vector2(-1.3f, -1.29f),
//                new Vector2(-1.3f, 1.29f),
//                new Vector2(-1f, 1.3f),
//                new Vector2(1f, 1.3f),
//                new Vector2(1.3f, 1.29f)
//        });
        shape.setAsBox(getWidth() * 0.49f, getHeight() * 0.459375f);

        FixtureDef fixtureDef = new FixtureDef();
        fixtureDef.shape = shape;
        fixtureDef.density = 0.71f;
        fixtureDef.friction = 0f;
        fixtureDef.restitution = 0;

        return fixtureDef;
    }
项目:joe    文件:TiledUtils.java   
public static FixtureDef getFixtureDefFromBodySkeleton(MapObject object) {
    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.density = 1;
    fixtureDef.friction = 0;
    fixtureDef.restitution = 0;

    Shape shape = null;
    if (object instanceof TextureMapObject) {
        shape = getTextureMapShape(object);
    } else if (object instanceof RectangleMapObject) {
        shape = getRectangleShape(object);
    } else if (object instanceof CircleMapObject) {
        shape = getCircleShape(object);
    } else if (object instanceof EllipseMapObject) {
        shape = getEllipseShape(object);
    } else if (object instanceof PolygonMapObject) {
        shape = getPolygonShape(object);
    } else if (object instanceof PolylineMapObject) {
        shape = getPolylineShape(object);
    }

    fixtureDef.shape = shape;

    return fixtureDef;
}
项目:M-M    文件:Bonus.java   
@Override
protected Body createBody(final Box2DService box2d) {
    final BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyType.StaticBody;
    bodyDef.fixedRotation = true;

    final PolygonShape shape = new PolygonShape();
    shape.setAsBox(Block.HALF_SIZE, Block.HALF_SIZE);
    final FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.isSensor = true;
    fixtureDef.shape = shape;
    fixtureDef.filter.categoryBits = Box2DUtil.CAT_BLOCK;
    fixtureDef.filter.maskBits = Box2DUtil.MASK_BLOCK;
    final Body body = box2d.getWorld().createBody(bodyDef);
    body.createFixture(fixtureDef);
    shape.dispose();
    return body;
}
项目:M-M    文件:Block.java   
@Override
protected Body createBody(final Box2DService box2d) {
    final BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyType.StaticBody;
    bodyDef.fixedRotation = true;

    final PolygonShape shape = new PolygonShape();
    shape.setAsBox(HALF_SIZE, HALF_SIZE);
    final FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.restitution = 1f;
    fixtureDef.friction = 0f;
    fixtureDef.shape = shape;
    fixtureDef.filter.categoryBits = Box2DUtil.CAT_BLOCK;
    fixtureDef.filter.maskBits = Box2DUtil.MASK_BLOCK;
    final Body body = box2d.getWorld().createBody(bodyDef);
    body.createFixture(fixtureDef);
    shape.dispose();
    return body;
}
项目:M-M    文件:BoundsEntity.java   
@Override
protected Body createBody(final Box2DService box2d) {
    final BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyType.StaticBody;
    bodyDef.fixedRotation = true;

    final ChainShape shape = new ChainShape();
    final float w = Box2DUtil.WIDTH * 2f / 5f, h = Box2DUtil.HEIGHT * 2f / 5f;
    shape.createLoop(new float[] { -w, -h, -w, h, w, h, w, -h });
    final FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.restitution = 0.9f;
    fixtureDef.friction = 0.2f;
    fixtureDef.shape = shape;
    fixtureDef.filter.categoryBits = Box2DUtil.CAT_BOUNDS;
    fixtureDef.filter.maskBits = Box2DUtil.MASK_BLOCK;
    final Body body = box2d.getWorld().createBody(bodyDef);
    body.createFixture(fixtureDef);
    return body;
}
项目:advio    文件:Food.java   
public Food(World world, float x, float y, int size, float toGive) {
    super(x, y);
    color = new Color((float) Math.random(), (float) Math.random(), (float) Math.random(), 1);
    outline = Advio.instance.darker(color);
    BodyDef bd = new BodyDef();
    bd.type = BodyType.KinematicBody;
    bd.position.set(x, y);
    CircleShape shape = new CircleShape();
    shape.setRadius(size);
    FixtureDef fd = new FixtureDef();
    fd.density = 0.1f;
    fd.shape = shape;
    fd.friction = 0.1f;
    // fd.filter.groupIndex = Advio.GROUP_BEINGS;
    body = world.createBody(bd);
    body.createFixture(fd).setUserData(new UserData("food").add("toGive", toGive));
    shape.dispose();
}
项目:advio    文件:Block.java   
public Block(World world, float x, float f, BodyType type, boolean invisible) {
    BodyDef bd = new BodyDef();
    bd.type = type;
    bd.position.set(x, f);
    PolygonShape shape = new PolygonShape();
    shape.setAsBox(size / 2, size / 2);
    FixtureDef fd = new FixtureDef();
    fd.density = 0.1f;
    fd.shape = shape;
    fd.friction = 0.1f;
    fd.filter.groupIndex = Advio.GROUP_DONT_COLLIDE_WITH_PLAYER;
    // fd.filter.groupIndex = Advio.GROUP_SCENERY;
    body = world.createBody(bd);
    body.createFixture(fd).setUserData(new UserData("block"));
    this.invisible = invisible;
    shape.dispose();
}
项目:advio    文件:PressurePlate.java   
public PressurePlate(Level l, World world, float x, float y, float weight, Block[] blocks) {
    super(x, y);
    this.level = l;
    BodyDef bd = new BodyDef();
    bd.type = BodyType.KinematicBody;
    bd.position.set(x, y);
    PolygonShape shape = new PolygonShape();
    shape.setAsBox(Block.size / 2, Block.size / 2);
    FixtureDef fd = new FixtureDef();
    fd.density = 0.0f;
    fd.shape = shape;
    fd.friction = 0.1f;
    fd.isSensor = true;
    this.blocks = new ArrayList<Block>(Arrays.asList(blocks));
    body = world.createBody(bd);
    body.createFixture(fd).setUserData(new UserData("plate").add("pressed", false).add("weight", weight));
    shape.dispose();
    this.world = world;
}
项目:advio    文件:Player.java   
public Player(World world, float x, float y) {
    super(x, y);
    this.world = world;
    this.graphicsSize = 10;
    color = new Color((float) Math.random(), (float) Math.random(), (float) Math.random(), 1);
    outline = Advio.instance.darker(color);
    BodyDef bd = new BodyDef();
    bd.type = BodyType.DynamicBody;
    bd.position.set(x, y);
    CircleShape shape = new CircleShape();
    shape.setRadius(50);
    FixtureDef fd = new FixtureDef();
    fd.density = 0.0f;
    fd.shape = shape;
    fd.friction = 0.1f;
    body = world.createBody(bd);
    body.createFixture(fd).setUserData(new UserData("player"));
    shape.dispose();
    // size * 2.25f
}
项目:advio    文件:AgarLogic.java   
public AgarLogic(Level l, World world, float x, float y) {
    super(x, y);
    this.level = l;
    BodyDef bd = new BodyDef();
    bd.type = BodyType.KinematicBody;
    bd.position.set(x, y);
    PolygonShape shape = new PolygonShape();
    shape.setAsBox(Block.size / 2, Block.size / 2);
    FixtureDef fd = new FixtureDef();
    fd.density = 0.0f;
    fd.shape = shape;
    fd.friction = 0.1f;
    fd.isSensor = true;
    body = world.createBody(bd);
    body.createFixture(fd).setUserData(new UserData("agariologic"));
    shape.dispose();
    this.world = world;
}
项目:advio    文件:Enemy.java   
public Enemy(World world, float x, float y, int size) {
    super(x, y);
    this.world = world;
    this.graphicsSize = 0.1f;
    color = new Color((float) Math.random(), (float) Math.random(), (float) Math.random(), 1);
    outline = Advio.instance.darker(color);
    BodyDef bd = new BodyDef();
    bd.type = BodyType.DynamicBody;
    bd.position.set(x, y);
    CircleShape shape = new CircleShape();
    shape.setRadius(size);
    FixtureDef fd = new FixtureDef();
    fd.density = 0.0f;
    fd.shape = shape;
    fd.friction = 0.1f;
    body = world.createBody(bd);
    body.createFixture(fd).setUserData(new UserData("enemy").add("body", body));
    shape.dispose();
}
项目:advio    文件:Goal.java   
public Goal(World world, float x, float y) {
    super(x, y);
    BodyDef bd = new BodyDef();
    bd.type = BodyType.KinematicBody;
    bd.position.set(x, y);
    PolygonShape shape = new PolygonShape();
    shape.setAsBox(Block.size / 2, Block.size / 2);
    FixtureDef fd = new FixtureDef();
    fd.density = 0.1f;
    fd.shape = shape;
    fd.friction = 0.1f;
    fd.isSensor = true;
    // fd.filter.groupIndex = Advio.GROUP_SCENERY;
    body = world.createBody(bd);
    body.createFixture(fd).setUserData(new UserData("goal"));
    shape.dispose();
}
项目:RavTech    文件:BoxCollider.java   
@Override
public void apply () {
    Body body = ((Rigidbody)getParent().getComponentByType(ComponentType.Rigidbody)).getBody();
    FixtureDef fixtureDef = new FixtureDef();
    PolygonShape shape = new PolygonShape();
    shape.setAsBox(width / 2, height / 2, new Vector2(x, y), (float)Math.toRadians(angle));
    fixtureDef.density = density;
    fixtureDef.friction = friction;
    fixtureDef.isSensor = isSensor;
    fixtureDef.restitution = restitution;
    fixtureDef.shape = shape;
    if (fixture != null) {
        dispose();
        fixture = null;
        ((Rigidbody)getParent().getComponentByType(ComponentType.Rigidbody)).apply();
        rebuildAll();
        return;
    }
    fixture = body.createFixture(fixtureDef);
    fixture.setFilterData(filter);
    UserData userdata = new UserData();
    userdata.component = (Rigidbody)getParent().getComponentByType(ComponentType.Rigidbody);
    fixture.setUserData(userdata);
}
项目:RavTech    文件:CircleCollider.java   
@Override
public void apply () {
    Body body = ((Rigidbody)getParent().getComponentByType(ComponentType.Rigidbody)).getBody();
    FixtureDef fixtureDef = new FixtureDef();
    CircleShape shape = new CircleShape();
    shape.setPosition(new Vector2(x, y));
    shape.setRadius(radius);
    fixtureDef.density = density;
    fixtureDef.friction = friction;
    fixtureDef.isSensor = isSensor;
    fixtureDef.restitution = restitution;
    fixtureDef.shape = shape;
    if (fixture != null) {
        dispose();
        fixture = null;
        ((Rigidbody)getParent().getComponentByType(ComponentType.Rigidbody)).apply();
        rebuildAll();
        getParent().transform.setRotation(getParent().transform.getRotation());
        return;
    }
    fixture = body.createFixture(fixtureDef);
    fixture.setFilterData(filter);
    UserData userdata = new UserData();
    userdata.component = (Rigidbody)getParent().getComponentByName("Rigidbody");
    fixture.setUserData(userdata);
}
项目:RavTech    文件:PolygonCollider.java   
@Override
public void apply () {
    Body body = ((Rigidbody)getParent().getComponentByType(ComponentType.Rigidbody)).getBody();
    FixtureDef fixtureDef = new FixtureDef();
    PolygonShape shape = new PolygonShape();
    fixture.setDensity(1);
    fixture.setDensity(density);
    shape.set((Vector2[])vertecies.toArray(Vector2.class));
    fixtureDef.density = 4;
    fixtureDef.friction = friction;
    fixtureDef.isSensor = isSensor;
    fixtureDef.restitution = restitution;
    fixtureDef.shape = shape;
    if (fixtures.size > 0) {
        dispose();
        fixtures.clear();
        ((Rigidbody)getParent().getComponentByType(ComponentType.Rigidbody)).apply();
        rebuildAll();
        return;
    }
    B2DSeparator.separate(body, fixtureDef, (Vector2[])vertecies.toArray(Vector2.class), this);
    fixture = body.createFixture(fixtureDef);
    fixture.setFilterData(filter);
}
项目:libgdxjam    文件:PhysicsDataLoader.java   
private void loadFixtureDefs(JsonValue root) {
    JsonValue fixtures = root.get("fixtures");
    JsonIterator fixturesIt = fixtures.iterator();
    int index = 0;

    while (fixturesIt.hasNext()) {
        JsonValue fixture = fixturesIt.next();

        FixtureDef fixtureDef = new FixtureDef();

        fixtureDef.density = fixture.getFloat("density", 1.0f);
        fixtureDef.restitution = fixture.getFloat("restitution", 0.0f);
        fixtureDef.friction = fixture.getFloat("friction", 1.0f);
        fixtureDef.isSensor = fixture.getBoolean("isSensor", false);
        fixtureDef.shape = loadShape(fixture);
        loadFilter(fixture, fixtureDef.filter);
        String id = fixture.getString("id", "");

        logger.info("loading fixture with id " + id);

        physicsData.fixtureNames.add(id);
        physicsData.fixtureIdx.put(id, index);
        physicsData.fixtureDefs.add(fixtureDef);

        ++index;
    }
}
项目:Entitas-Java    文件:CreateNearSensorSystem.java   
@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");
            }
        }
    }

}
项目:Vector-Pinball-Editor    文件:Box2DFactory.java   
/** Creates a wall by constructing a rectangle whose corners are (xmin,ymin) and (xmax,ymax), and rotating the box counterclockwise
* through the given angle, with specified restitution.
*/
  public static Body createWall(World world, float xmin, float ymin, float xmax, float ymax, float angle, float restitution) {
    float cx = (xmin + xmax) / 2;
    float cy = (ymin + ymax) / 2;
      float hx = Math.abs((xmax - xmin) / 2);
      float hy = Math.abs((ymax - ymin) / 2);
    PolygonShape wallshape = new PolygonShape();
      // Don't set the angle here; instead call setTransform on the body below. This allows future
      // calls to setTransform to adjust the rotation as expected.
      wallshape.setAsBox(hx, hy, new Vector2(0f, 0f), 0f);

FixtureDef fdef = new FixtureDef();
fdef.shape = wallshape;
fdef.density = 1.0f;
if (restitution>0) fdef.restitution = restitution;

    BodyDef bd = new BodyDef();
    bd.position.set(cx, cy);
    Body wall = world.createBody(bd);
    wall.createFixture(fdef);
    wall.setType(BodyDef.BodyType.StaticBody);
      wall.setTransform(cx, cy, angle);
    return wall;
  }
项目:KillTheNerd    文件:BodyFactory.java   
public static Body createRect(final Vector2 position, final Vector2 renderDimension) {
    if (!BodyFactory.initialized) {
        throw new IllegalStateException("You must initialize BodyFactory before using its functions");
    }
    final BodyDef bodyDef = new BodyDef();
    bodyDef.position.set(new Vector2(position.x, position.y));
    bodyDef.type = BodyDef.BodyType.StaticBody;
    final Body b2Body = BodyFactory.world.createBody(bodyDef);

    final PolygonShape shape = new PolygonShape();
    shape.setAsBox(renderDimension.x / 2, renderDimension.y / 2);
    final FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.isSensor = false;
    fixtureDef.density = 0f;
    fixtureDef.friction = 1f;
    fixtureDef.restitution = 0;
    fixtureDef.shape = shape;
    b2Body.createFixture(fixtureDef);

    return b2Body;
}