Java源码示例:com.badlogic.gdx.physics.box2d.FixtureDef

示例1
/** Creates and applies the fixtures defined in the editor. The name parameter is used to retrieve the shape from the loaded
 * binary file. Therefore, it _HAS_ to be the exact same name as the one that appeared. in the editor. <br/>
 * <br/>
 * 
 * WARNING: The body reference point is supposed to be the bottom left corner. As a result, calling "getPosition()" on the body
 * will return its bottom left corner. This is useful to draw a Sprite directly by setting its position to the body position. <br/>
 * <br/>
 * 
 * Also, saved shapes are normalized. Thus, you need to provide the desired width and height of your body for them to scale
 * according to your needs. <br/>
 * <br/>
 * 
 * Moreover, you can submit a custom FixtureDef object. Its parameters will be applied to every fixture applied to the body by
 * this method.
 * 
 * @param body A box2d Body, previously created.
 * @param name The name of the shape you want to load.
 * @param width The desired width of the body.
 * @param height The desired height of the body.
 * @param params Custom fixture parameters to apply. */
public void createFixtures (Body body, String name, float width, float height, FixtureDef params, Vector2 offset,
	Object userData) {
	BodyModel bm = bodyMap.get(name);
	if (bm == null) {
		Gdx.app.log("FixtureAtlas", name + " does not exist in the fixture list.");
	}

	Vector2[][] polygons = bm.getPolygons(width, height, offset);
	if (polygons == null) {
		Gdx.app.log("FixtureAtlas", name + " does not declare any polygon. "
			+ "Should not happen. Is your shape file corrupted ?");
	}

	for (Vector2[] polygon : polygons) {
		shape.set(polygon);
		FixtureDef fd = params == null ? DEFAULT_FIXTURE : params;
		fd.shape = shape;
		Fixture f = body.createFixture(fd);
		f.setUserData(userData);
	}
}
 
示例2
public NinjaRabbitBodyFactory(final BodyEditorLoader loader) {
	if (loader == null) {
		throw new IllegalArgumentException("'loader' cannot be null");
	}
	this.loader = loader;

	bdef = new BodyDef();
	bdef.type = BodyType.DynamicBody;
	bdef.position.set(INITIAL_POSITION);
	bdef.fixedRotation = true;
	bdef.gravityScale = 2.0f;
	// bdef.bullet = true;

	fdef = new FixtureDef();
	fdef.density = 1.0f;
	fdef.restitution = 0.0f;
	fdef.friction = 0.8f;
}
 
示例3
/**
 * 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;
}
 
示例4
@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");
            }
        }
    }

}
 
示例5
@Override
public void createLevel(PhysicsWorld world, FixtureDef fixtureDef) {
	int boxWidth = 30;
	createBox(world, fixtureDef, 266, 343, boxWidth, 819, 45);
	createBox(world, fixtureDef, 266, 343, boxWidth, 819, -45);

	createBox(world, fixtureDef, 815, 345, boxWidth, 819, 45);
	createBox(world, fixtureDef, 957, 204, boxWidth, 418, -45);
	//--
	int boxHeight = 30;
	createBox(world, fixtureDef, 97, 1010, 191, boxHeight);

	createBox(world, fixtureDef, 541, 1010, boxWidth, 819, 45);
	createBox(world, fixtureDef, 633, 918, boxWidth, 1079, -45);

	createBox(world, fixtureDef, 986, 1010, 191, boxHeight);
	//--
	createBox(world, fixtureDef, 266, 1653, boxWidth, 819, 45);
	createBox(world, fixtureDef, 266, 1653, boxWidth, 819, -45);

	createBox(world, fixtureDef, 958, 1799, boxWidth, 414, 45);
	createBox(world, fixtureDef, 815, 1655, boxWidth, 819, -45);
}
 
示例6
@Override
public void createLevel(PhysicsWorld world, FixtureDef fixtureDef) {
	assertInitialized();

	// lines at an angle
	int boxWidth = 30;
	int rotation = 45;
	createBox(world, fixtureDef, 180, 454, boxWidth, 304, rotation);
	createBox(world, fixtureDef, 492, 675, boxWidth, 403, -rotation);
	createBox(world, fixtureDef, 180, 1058, boxWidth, 304, rotation);
	createBox(world, fixtureDef, 492, 1292, boxWidth, 403, -rotation);
	createBox(world, fixtureDef, 180, 1651, boxWidth, 304, rotation);

	// middle line
	createBox(world, fixtureDef, 635, 842, 30, 1685);

	// lines at the right
	int boxHeight = 30;
	createBox(world, fixtureDef, 1004, 562, 154, boxHeight);
	createBox(world, fixtureDef, 942, 1185, boxWidth, 1248);
}
 
示例7
@Override
public void createLevel(PhysicsWorld world, FixtureDef fixtureDef) {
	int boxWidth = 30;
	createBox(world, fixtureDef, 212, 1081, boxWidth, 1678);

	int boxHeight = 30;
	for(int i = 0; i < 4; i++) {
		if(i == 0) {
			createBox(world, fixtureDef, 370, i * 385 + 257, 336, boxHeight);
		} else {
			createBox(world, fixtureDef, 385, i * 385 + 257, 366, boxHeight);
		}
	}

	for(int i = 0; i < 3; i++) {
		if(i == 0) {
			createBox(world, fixtureDef, 784, 498, 294, boxHeight);
		} else {
			createBox(world, fixtureDef, 694, i * 386 + 448, 456, boxHeight);
		}
	}
	createBox(world, fixtureDef, 652, 409, boxWidth, 177);
	createOpenCircle(world, fixtureDef, 180, 360, 225, 877, 336, 30);
	createBox(world, fixtureDef, 933, 955, boxWidth, 1279);
	createOpenCircle(world, fixtureDef, 0, 180, 225, 870, 1591, 30);
}
 
示例8
@Override
public void createLevel(PhysicsWorld world, FixtureDef fixtureDef) {
	int boxWidth = 30;
	createBox(world, fixtureDef, 534, 370, boxWidth, 742);

	createOpenCircle(world, fixtureDef, -83, 76, 375, 636, 961, 30);

	createOpenCircle(world, fixtureDef, -201, 115, 249, 640, 964, 20);

	createOpenCircle(world, fixtureDef, 180, 398, 113, 647, 964, 20);
	createOpenCircle(world, fixtureDef, 0, 175, 123, 411, 1048, 20);

	createBox(world, fixtureDef, 534, 1309, boxWidth, 698);
	int boxHeight = 30;
	createBox(world, fixtureDef, 411, 1654, 278, boxHeight);

	createBox(world, fixtureDef, 736, 1453, boxWidth, 282);
}
 
示例9
@Override
public void createLevel(PhysicsWorld world, FixtureDef fixtureDef) {
	int boxWidth = 30;
	createBox(world, fixtureDef, 150, 1124, boxWidth, 1352);
	int boxHeight = 30;
	createBox(world, fixtureDef, 354, 463, 403, boxHeight);
	for (int i = 0; i < 3; i++) {
		createBox(world, fixtureDef, 469, i * 358 + 841, 636, boxHeight);
	}
	createBox(world, fixtureDef, 548, 1785, 797, boxHeight);


	for (int i = 0; i < 3; i++) {
		createBox(world, fixtureDef, 605, i * 358 + 662, 636, boxHeight);
	}
	createBox(world, fixtureDef, 930, 947, boxWidth, 1415);
}
 
示例10
@Override
public void createLevel(PhysicsWorld world, FixtureDef fixtureDef) {
	//small circle
	createOpenCircle(world, fixtureDef, 270, 280.5f, 410, -18, 968, 5);
	createOpenCircle(world, fixtureDef, -51.5f, 90, 410, -18, 968, 40);

	//middle circle
	createOpenCircle(world, fixtureDef, -90, 67.5f, 688, -29, 999, 50);
	createOpenCircle(world, fixtureDef, 79, 90, 688, -29, 999, 10);

	//big circle
	createOpenCircle(world, fixtureDef, 270, 309, 904, -20, 999, 20);
	createOpenCircle(world, fixtureDef, -43, 90, 904, -20, 999, 50);

	createBox(world, fixtureDef, 540, 1904, 1080, 30);
}
 
示例11
public Box2dSteeringEntity createSteeringEntity (World world, TextureRegion region, boolean independentFacing, int posX, int posY) {

		CircleShape circleChape = new CircleShape();
		circleChape.setPosition(new Vector2());
		int radiusInPixels = (int)((region.getRegionWidth() + region.getRegionHeight()) / 4f);
		circleChape.setRadius(Box2dSteeringTest.pixelsToMeters(radiusInPixels));

		BodyDef characterBodyDef = new BodyDef();
		characterBodyDef.position.set(Box2dSteeringTest.pixelsToMeters(posX), Box2dSteeringTest.pixelsToMeters(posY));
		characterBodyDef.type = BodyType.DynamicBody;
		Body characterBody = world.createBody(characterBodyDef);

		FixtureDef charFixtureDef = new FixtureDef();
		charFixtureDef.density = 1;
		charFixtureDef.shape = circleChape;
		charFixtureDef.filter.groupIndex = 0;
		characterBody.createFixture(charFixtureDef);

		circleChape.dispose();

		return new Box2dSteeringEntity(region, characterBody, independentFacing, Box2dSteeringTest.pixelsToMeters(radiusInPixels));
	}
 
示例12
private void createRandomWalls (int n) {
	PolygonShape groundPoly = new PolygonShape();

	BodyDef groundBodyDef = new BodyDef();
	groundBodyDef.type = BodyType.StaticBody;

	FixtureDef fixtureDef = new FixtureDef();
	fixtureDef.shape = groundPoly;
	fixtureDef.filter.groupIndex = 0;

	walls = new Body[n];
	walls_hw = new int[n];
	walls_hh = new int[n];
	for (int i = 0; i < n; i++) {
		groundBodyDef.position.set(Box2dSteeringTest.pixelsToMeters(MathUtils.random(50, (int)container.stageWidth - 50)),
			Box2dSteeringTest.pixelsToMeters(MathUtils.random(50, (int)container.stageHeight - 50)));
		walls[i] = world.createBody(groundBodyDef);
		walls_hw[i] = (int)MathUtils.randomTriangular(20, 150);
		walls_hh[i] = (int)MathUtils.randomTriangular(30, 80);
		groundPoly.setAsBox(Box2dSteeringTest.pixelsToMeters(walls_hw[i]), Box2dSteeringTest.pixelsToMeters(walls_hh[i]));
		walls[i].createFixture(fixtureDef);

	}
	groundPoly.dispose();
}
 
示例13
private void createBoxes() {
	CircleShape ballShape = new CircleShape();
	ballShape.setRadius(RADIUS);

	FixtureDef def = new FixtureDef();
	def.restitution = 0.9f;
	def.friction = 0.01f;
	def.shape = ballShape;
	def.density = 1f;
	BodyDef boxBodyDef = new BodyDef();
	boxBodyDef.type = BodyType.DynamicBody;

	for (int i = 0; i < BALLSNUM; i++) {
		// Create the BodyDef, set a random position above the
		// ground and create a new body
		boxBodyDef.position.x = -20 + (float) (Math.random() * 40);
		boxBodyDef.position.y = 10 + (float) (Math.random() * 15);
		Body boxBody = world.createBody(boxBodyDef);
		boxBody.createFixture(def);
		balls.add(boxBody);
	}
	ballShape.dispose();
}
 
示例14
public void createIndestructible(float x, float y, TextureAtlas tileTextureAtlas) {
    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyDef.BodyType.StaticBody;
    bodyDef.position.set(x, y);

    Body body = b2dWorld.createBody(bodyDef);
    PolygonShape polygonShape = new PolygonShape();
    polygonShape.setAsBox(0.5f, 0.5f);
    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.shape = polygonShape;
    fixtureDef.filter.categoryBits = GameManager.INDESTRUCTIIBLE_BIT;
    fixtureDef.filter.maskBits = GameManager.PLAYER_BIT | GameManager.ENEMY_BIT | GameManager.BOMB_BIT;
    body.createFixture(fixtureDef);

    polygonShape.dispose();

    Renderer renderer = new Renderer(new TextureRegion(tileTextureAtlas.findRegion("indestructible"), 0, 0, 16, 16), 16 / GameManager.PPM, 16 / GameManager.PPM);
    renderer.setOrigin(16 / GameManager.PPM / 2, 16 / GameManager.PPM / 2);

    new EntityBuilder(world)
            .with(
                    new Transform(x, y, 1f, 1f, 0),
                    renderer
            )
            .build();
}
 
示例15
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {

	/* Checks whether the max amount of balls were spawned */
	if (spawnedBalls < MAX_SPAWNED_BALLS) {
		spawnedBalls++;

		/* Translate camera point to world point */
		Vector3 unprojectedVector = new Vector3();
		camera.unproject(unprojectedVector.set(screenX, screenY, 0));

		/* Create a new ball */
		Shape shape = Box2DFactory.createCircleShape(1);
		FixtureDef fixtureDef = Box2DFactory.createFixture(shape, 2.5f,
				0.25f, 0.75f, false);
		Box2DFactory.createBody(world, BodyType.DynamicBody, fixtureDef,
				new Vector2(unprojectedVector.x, unprojectedVector.y));
	}

	return true;
}
 
示例16
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {

	/* Checks whether the max amount of balls were spawned */
	if (spawnedBalls < MAX_SPAWNED_BALLS) {
		spawnedBalls++;

		/* Translate camera point to world point */
		Vector3 unprojectedVector = new Vector3();
		camera.unproject(unprojectedVector.set(screenX, screenY, 0));

		/* Create a new ball */
		Shape shape = Box2DFactory.createCircleShape(1);
		FixtureDef fixtureDef = Box2DFactory.createFixture(shape, 2.5f,
				0.25f, 0.75f, false);
		Box2DFactory.createBody(world, BodyType.DynamicBody, fixtureDef,
				new Vector2(unprojectedVector.x, unprojectedVector.y));
	}

	return true;
}
 
示例17
private void createRandomWalls (int n) {
	PolygonShape groundPoly = new PolygonShape();

	BodyDef groundBodyDef = new BodyDef();
	groundBodyDef.type = BodyType.StaticBody;

	FixtureDef fixtureDef = new FixtureDef();
	fixtureDef.shape = groundPoly;
	fixtureDef.filter.groupIndex = 0;

	walls = new Body[n];
	walls_hw = new int[n];
	walls_hh = new int[n];
	for (int i = 0; i < n; i++) {
		groundBodyDef.position.set(MathUtils.random(50, (int)container.stageWidth - 50),
			MathUtils.random(50, (int)container.stageHeight - 50));
		walls[i] = world.createBody(groundBodyDef);
		walls_hw[i] = (int)MathUtils.randomTriangular(20, 150);
		walls_hh[i] = (int)MathUtils.randomTriangular(30, 80);
		groundPoly.setAsBox(walls_hw[i], walls_hh[i]);
		walls[i].createFixture(fixtureDef);

	}
	groundPoly.dispose();
}
 
示例18
@Override
public void createLevel(PhysicsWorld world, FixtureDef fixtureDef) {
	int boxHeight = 30;
	createBox(world, fixtureDef, 225, 1907, 454, boxHeight);

	createBox(world, fixtureDef, 463, 347, 205, boxHeight, 45);
	int boxWidth = 30;
	createBox(world, fixtureDef, 425, 456, boxWidth, 485, 45);

	createBox(world, fixtureDef, 482, 721, boxWidth, 311, -45);
	createBox(world, fixtureDef, 482, 922, boxWidth, 311, 45);

	createBox(world, fixtureDef, 475, 1128, boxWidth, 300, -45);
	createBox(world, fixtureDef, 481, 1325, boxWidth, 311, 45);

	createBox(world, fixtureDef, 490, 1515, boxWidth, 266, -45);
	createBox(world, fixtureDef, 490, 1694, boxWidth, 282, 45);

	createBox(world, fixtureDef, 502, 1860, boxWidth, 249, -45);

	createOpenCircle(world, fixtureDef, -90, 50, 130, 618, 195, 30);

	createBox(world, fixtureDef, 650, 350, 200, boxHeight, 47);

	createBox(world, fixtureDef, 688, 515, boxWidth, 311, 45);
	createBox(world, fixtureDef, 683, 718, boxWidth, 317, -45);

	createBox(world, fixtureDef, 682, 920, boxWidth, 311, 45);
	createBox(world, fixtureDef, 678, 1123, boxWidth, 315, -45);

	createBox(world, fixtureDef, 681, 1328, boxWidth, 289, 45);
	createBox(world, fixtureDef, 702, 1490, boxWidth, 201, -45);

	createBox(world, fixtureDef, 986, 422, 192, boxHeight);
}
 
示例19
@Override
public void createLevel(PhysicsWorld world, FixtureDef fixtureDef) {
	assertInitialized();

	int boxHeight = 30;
	createBox(world, fixtureDef, 633, 495, 615, boxHeight, 45);
	int boxWidth = 30;
	createBox(world, fixtureDef, 767, 1042, boxWidth, 943, 45);

	createBox(world, fixtureDef, 407, 1086, boxWidth, 1209, 45);
	createBox(world, fixtureDef, 372, 1435, 538, boxHeight, 45);
	createBox(world, fixtureDef, 717, 1623, 352, boxHeight, 45);
}
 
示例20
@Override
public void createLevel(PhysicsWorld world, FixtureDef fixtureDef) {
	int boxHeight = 30;
	createBox(world, fixtureDef, 115, 313, 278, boxHeight);
	createBox(world, fixtureDef, 827, 313, 573, boxHeight);

	createBox(world, fixtureDef, 263, 620, 573, boxHeight);
	createBox(world, fixtureDef, 974, 620, 277, boxHeight);

	createBox(world, fixtureDef, 722, 928, 732, boxHeight);

	createBox(world, fixtureDef, 432, 1236, 895, boxHeight);
	createBox(world, fixtureDef, 640, 1543, 906, boxHeight);
}
 
示例21
@Override
public void createLevel(PhysicsWorld world, FixtureDef fixtureDef) {
	createBox(world, fixtureDef, _originalWidth / 2, 14, _originalWidth, 28);
	createBox(world, fixtureDef, _originalWidth / 2, _originalHeight - (20 + (90 * (_density / (_height / _originalHeight)))), _originalWidth, 40);
	createBox(world, fixtureDef, 14, _originalHeight / 2, 28, _originalHeight);
	createBox(world, fixtureDef, _originalWidth - 14, _originalHeight / 2, 28, _originalHeight);
}
 
示例22
@Override
public void createLevel(PhysicsWorld world, FixtureDef fixtureDef) {
	float height = 1680;
	float width = 30;

	createBox(world, fixtureDef, 196, 843, width, height);
	createBox(world, fixtureDef, 420, 1083, width, height);
	createBox(world, fixtureDef, 644, 843, width, height);
	createBox(world, fixtureDef, 858, 1083, width, height);

	drawBox(196, 843, width, height);
	drawBox(420, 1083, width, height);
	drawBox(644, 843, width, height);
	drawBox(858, 1083, width, height);
}
 
示例23
@Override
public void createLevel(PhysicsWorld world, FixtureDef fixtureDef) {
	float scaleY = _height / _originalHeight;
	scaleY = scaleY + ((1 - scaleY) * .5f);
	int barHeight = (int) ((70 + ((_density - 1.5) * 30)) * scaleY);

	createBox(world, fixtureDef, _originalWidth / 2, 12 + (barHeight * (_originalHeight / _height)), _originalWidth, 28);
	createBox(world, fixtureDef, _originalWidth / 2, _originalHeight - (20 + (90 * (_density / (_height / _originalHeight)))), _originalWidth, 40);
	createBox(world, fixtureDef, 410, 701, 820, 28);
	createBox(world, fixtureDef, 937, 902, 290, 28);
	createBox(world, fixtureDef, 688, 1102, 268, 28);
	createBox(world, fixtureDef, 542, 1008, 28, 588);
}
 
示例24
@Override
public void createLevel(PhysicsWorld world, FixtureDef fixtureDef) {
	float rotation = 45;

	int boxHeight = 30;
	createBox(world, fixtureDef, 64, 432, 266, boxHeight, rotation);
	createBox(world, fixtureDef, 183, 858, 624, boxHeight, rotation);
	createBox(world, fixtureDef, 308, 1278, 965, boxHeight, rotation);
	createBox(world, fixtureDef, 543, 1588, 996, boxHeight, rotation);

	createBox(world, fixtureDef, 511, 257, 776, boxHeight, rotation);
	createBox(world, fixtureDef, 810, 502, 813, boxHeight, rotation);
	createBox(world, fixtureDef, 855, 1004, 702, boxHeight, rotation);
}
 
示例25
@Override
public void createLevel(PhysicsWorld world, FixtureDef fixtureDef) {
	createOpenCircle(world, fixtureDef, -90, 90, 580, 0, 878, 35);

	createOpenCircle(world, fixtureDef, 90, 270, 300, 1080, 1299, 30);
	createOpenCircle(world, fixtureDef, 180, 360, 300, 497, 1920, 30);
}
 
示例26
@Override
public void createLevel(PhysicsWorld world, FixtureDef fixtureDef) {
	createBox(world, fixtureDef, _originalWidth / 2, _originalHeight, _originalWidth, 5);
	createBox(world, fixtureDef, _originalWidth / 2, 0, _originalWidth, 5);
	createBox(world, fixtureDef, 0, _originalHeight / 2, 5, _originalHeight);
	createBox(world, fixtureDef, _originalWidth, _originalHeight / 2, 5, _originalHeight);

	_centerSensor = PhysicsFactory.createCircleBody(world, _scale * _originalWidth / 2, _scale * _originalHeight / 2, .1f * _width,
			BodyDef.BodyType.StaticBody, WorldController.SENSOR_FIX_DEF);
	_centerSensor.setUserData(ObjectName.CENTER_SENSOR_NAME);
}
 
示例27
@Override
public void createLevel(PhysicsWorld world, FixtureDef fixtureDef) {
	Vector2 center = Vector2Pool.obtain(541, 942);

	createOpenCircle(world, fixtureDef, -70, 250, 133, center.x, center.y, 20);
	createOpenCircle(world, fixtureDef, 103, 438.5f, 262, center.x, center.y, 30);
	createOpenCircle(world, fixtureDef, -81, 260, 395, center.x, center.y, 40);
}
 
示例28
@Override
public void createLevel(PhysicsWorld world, FixtureDef fixtureDef) {
	createOpenCircle(world, fixtureDef, -57, 88, 890, 173, 1030, 35);
	createOpenCircle(world, fixtureDef, -56, 110, 625, 190, 1004, 30);

	createBox(world, fixtureDef, 15, 1766, 30, 308);
	createBox(world, fixtureDef, 177, 1908, 326, 30);

	createOpenCircle(world, fixtureDef, -60, 78, 458, 110, 989, 20);
	createOpenCircle(world, fixtureDef, 147, 257, 500, 662, 976, 20);
}
 
示例29
protected void createOpenCircleBody(PhysicsWorld world, FixtureDef fixtureDef, float startAngle, float endAngle,
                                    float radius, float innerRadius, float centerX, float centerY, int segmentCount) {
    float angleStep = (endAngle - startAngle) / (float) segmentCount;
    float curAngle = startAngle + angleStep / 2;
    float width = 3;
    float height = (radius - innerRadius);
    float x;
    float y;
    float angleRad;
    float radiusCorrection = (float) Math.cos(angleStep * DEG2RAD / 2);

    while (curAngle < endAngle) {
        float angleLeft = (curAngle - angleStep / 2) * DEG2RAD;
        float xLeft = centerX + radius * (float) Math.cos(angleLeft);
        float yLeft = centerY + radius * (float) Math.sin(angleLeft);

        float angleRight = (curAngle + angleStep / 2) * DEG2RAD;
        float xRight = centerX + radius * (float) Math.cos(angleRight);
        float yRight = centerY + radius * (float) Math.sin(angleRight);

        float dx = xRight - xLeft;
        float dy = yRight - yLeft;
        width = height / segmentCount + (float) (Math.sqrt(dx * dx + dy * dy));

        angleRad = curAngle * DEG2RAD;
        x = centerX + (radius * radiusCorrection) * (float) Math.cos(angleRad);
        y = centerY + (radius * radiusCorrection) * (float) Math.sin(angleRad);
        createBoxBody(world, fixtureDef, x, y, width, height, 90 - curAngle);

        curAngle += angleStep;
    }
}
 
示例30
protected void createWave(PhysicsWorld world, FixtureDef fixtureDef, float amplitude, float frequency,
                          float x, float y, float waveLength, float waveStart) {
    float steps = 100;
    for (int i = 0; i < steps; i++) {
        float angle = 2 * (float) Math.PI * frequency * (i + waveStart) / steps;
        float sin = (float) Math.sin(angle);

        createBox(world, fixtureDef, x + waveLength * (i / steps), y - amplitude * sin, 3, 40);
    }
}