com.badlogic.gdx.physics.box2d.CircleShape Java Examples
The following examples show how to use
com.badlogic.gdx.physics.box2d.CircleShape.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Box2DFactory.java From homescreenarcade with GNU General Public License v3.0 | 6 votes |
/** 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; }
Example #2
Source File: Box2dLightTest.java From box2dlights with Apache License 2.0 | 6 votes |
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(); }
Example #3
Source File: Box2dSteeringTest.java From gdx-ai with Apache License 2.0 | 6 votes |
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)); }
Example #4
Source File: Ball.java From homescreenarcade with GNU General Public License v3.0 | 5 votes |
public void draw(IFieldRenderer renderer) { CircleShape shape = (CircleShape)body.getFixtureList().get(0).getShape(); Vector2 center = body.getPosition(); float radius = shape.getRadius(); renderer.fillCircle(center.x, center.y, radius, primaryColor); // Draw a smaller circle to show the ball's rotation. float angle = body.getAngle(); float smallCenterX = center.x + (radius / 2) * MathUtils.cos(angle); float smallCenterY = center.y + (radius / 2) * MathUtils.sin(angle); renderer.fillCircle(smallCenterX, smallCenterY, radius / 4, secondaryColor); }
Example #5
Source File: RenderOfCircleFixture.java From tilt-game-android with MIT License | 5 votes |
public RenderOfCircleFixture(Fixture fixture, VertexBufferObjectManager pVBO) { super(fixture); CircleShape fixtureShape = (CircleShape) fixture.getShape(); Vector2 position = fixtureShape.getPosition(); float radius = fixtureShape.getRadius() * PhysicsConnector.PIXEL_TO_METER_RATIO_DEFAULT; mEntity = new Ellipse(position.x * PhysicsConnector.PIXEL_TO_METER_RATIO_DEFAULT, position.y * PhysicsConnector.PIXEL_TO_METER_RATIO_DEFAULT, radius, radius, pVBO); }
Example #6
Source File: Piece.java From fluid-simulator-v2 with Apache License 2.0 | 5 votes |
/** Circle Shape */ public Piece (float radius, BodyType type) { this.shape = new CircleShape(); ((CircleShape)this.shape).setRadius(radius); this.pos = new Vector2(); this.type = type; this.radius = radius; }
Example #7
Source File: PhysicsFactory.java From tilt-game-android with MIT License | 4 votes |
public static Body createCircleBody(final PhysicsWorld pPhysicsWorld, final float pCenterX, final float pCenterY, final float pRadius, final float pRotation, final BodyType pBodyType, final FixtureDef pFixtureDef, final float pPixelToMeterRatio) { final BodyDef circleBodyDef = new BodyDef(); circleBodyDef.type = pBodyType; circleBodyDef.position.x = pCenterX / pPixelToMeterRatio; circleBodyDef.position.y = pCenterY / pPixelToMeterRatio; circleBodyDef.angle = MathUtils.degToRad(pRotation); final Body circleBody = pPhysicsWorld.createBody(circleBodyDef); final CircleShape circlePoly = new CircleShape(); pFixtureDef.shape = circlePoly; final float radius = pRadius / pPixelToMeterRatio; circlePoly.setRadius(radius); circleBody.createFixture(pFixtureDef); circlePoly.dispose(); return circleBody; }
Example #8
Source File: Box2DFactory.java From Codelabs with MIT License | 4 votes |
public static Shape createCircleShape(float radius) { CircleShape circleShape = new CircleShape(); circleShape.setRadius(radius); return circleShape; }