Java Code Examples for com.badlogic.gdx.physics.box2d.BodyDef.BodyType#StaticBody
The following examples show how to use
com.badlogic.gdx.physics.box2d.BodyDef.BodyType#StaticBody .
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: Box2dLightCustomShaderTest.java From box2dlights with Apache License 2.0 | 6 votes |
private void createPhysicsWorld() { world = new World(new Vector2(0, 0), true); float halfWidth = viewportWidth / 2f; ChainShape chainShape = new ChainShape(); chainShape.createLoop(new Vector2[] { new Vector2(0, 0f), new Vector2(viewportWidth, 0f), new Vector2(viewportWidth, viewportHeight), new Vector2(0, viewportHeight) }); BodyDef chainBodyDef = new BodyDef(); chainBodyDef.type = BodyType.StaticBody; groundBody = world.createBody(chainBodyDef); groundBody.createFixture(chainShape, 0); chainShape.dispose(); createBoxes(); }
Example 2
Source File: Box2dLightTest.java From box2dlights with Apache License 2.0 | 6 votes |
private void createPhysicsWorld() { world = new World(new Vector2(0, 0), true); float halfWidth = viewportWidth / 2f; ChainShape chainShape = new ChainShape(); chainShape.createLoop(new Vector2[] { new Vector2(-halfWidth, 0f), new Vector2(halfWidth, 0f), new Vector2(halfWidth, viewportHeight), new Vector2(-halfWidth, viewportHeight) }); BodyDef chainBodyDef = new BodyDef(); chainBodyDef.type = BodyType.StaticBody; groundBody = world.createBody(chainBodyDef); groundBody.createFixture(chainShape, 0); chainShape.dispose(); createBoxes(); }
Example 3
Source File: Box2dRaycastObstacleAvoidanceTest.java From gdx-ai with Apache License 2.0 | 6 votes |
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(); }
Example 4
Source File: Scene2dRaycastObstacleAvoidanceTest.java From gdx-ai with Apache License 2.0 | 6 votes |
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(); }
Example 5
Source File: Body.java From tilt-game-android with MIT License | 5 votes |
/** * Get the type of this body. */ public BodyType getType () { int type = jniGetType(addr); if (type == 0) return BodyType.StaticBody; if (type == 1) return BodyType.KinematicBody; if (type == 2) return BodyType.DynamicBody; return BodyType.StaticBody; }
Example 6
Source File: CollisionsSample.java From Codelabs with MIT License | 5 votes |
@Override public void beginContact(Contact contact) { Fixture fixtureA = contact.getFixtureA(); Fixture fixtureB = contact.getFixtureB(); /* * If one of the fixture contacting is an static body, and is the wall, * set ballTouchedWall to true. */ if (fixtureA.getBody().getType() == BodyType.StaticBody) { if (fixtureA.getBody().equals(walls)) { ballTouchedBox = false; ballTouchedWall = true; } else { ballTouchedBox = true; ballTouchedWall = false; } } else if (fixtureB.getBody().getType() == BodyType.StaticBody) { if (fixtureA.getBody().equals(walls)) { ballTouchedBox = false; ballTouchedWall = true; } else { ballTouchedBox = true; ballTouchedWall = false; } } }
Example 7
Source File: FluidSimulatorGeneric.java From fluid-simulator-v2 with Apache License 2.0 | 5 votes |
@Override public boolean reportFixture (Fixture fixture) { if (fixture.getBody().getType() != BodyType.StaticBody && !fixture.isSensor() && ((ObjectInfo)fixture.getBody().getUserData()).isPortalAllowed) { // Prevent portal looping if (!((ObjectInfo)fixture.getBody().getUserData()).hasTimePassed(300)) return true; for (int i=0; i<portalIn.size(); i++) { if (portalIn.get(i).fixture.testPoint(fixture.getBody().getPosition().x, fixture.getBody().getPosition().y)) { logicHitBody = fixture.getBody(); if (logicHitBody != null) { logicHitBody.setTransform(portalOut.get(i).getBody().getPosition(), 0); if (portalOut.get(i).normal != null) { // New velocity angle //System.out.println("vel: "+logicHitBody.getLinearVelocity().angle()+" norm: " + portalOut.get(i).normal.angle()+" angle: " + portalOut.get(i).angle); logicHitBody.setLinearVelocity(logicHitBody.getLinearVelocity().rotate(portalOut.get(i).angle - logicHitBody.getLinearVelocity().angle())); // Apply a little more linear force if (allowPortalTransferForce) logicHitBody.applyForceToCenter(portalOut.get(i).transferForce, true); } if (fixture.getBody().getUserData() != null) ((ObjectInfo)fixture.getBody().getUserData()).updateTime(); // handlePortalCallbackRendering(portalIn.get(i).getBody().getPosition(), portalOut.get(i).getBody().getPosition()); } } } } return true; }
Example 8
Source File: FluidSimulatorGeneric.java From fluid-simulator-v2 with Apache License 2.0 | 5 votes |
@Override public boolean reportFixture (Fixture fixture) { if (fixture.getBody().getType() != BodyType.StaticBody && !fixture.isSensor() && ((ObjectInfo)fixture.getBody().getUserData()).isPortalAllowed) { // Prevent portal looping if (!((ObjectInfo)fixture.getBody().getUserData()).hasTimePassed(300)) return true; for (int i=0; i<portalIn.size(); i++) { if (portalOut.get(i).fixture.testPoint(fixture.getBody().getPosition().x, fixture.getBody().getPosition().y)) { logicHitBody = fixture.getBody(); if (logicHitBody != null) { logicHitBody.setTransform(portalIn.get(i).getBody().getPosition(), 0); if (portalIn.get(i).normal != null) { // New velocity angle logicHitBody.setLinearVelocity(logicHitBody.getLinearVelocity().rotate(portalIn.get(i).normal.angle() - logicHitBody.getLinearVelocity().angle())); // Apply a little more linear force if (allowPortalTransferForce) logicHitBody.applyForceToCenter(portalIn.get(i).transferForce, true); } if (fixture.getBody().getUserData() != null) ((ObjectInfo)fixture.getBody().getUserData()).updateTime(); // handlePortalCallbackRendering(portalOut.get(i).getBody().getPosition(), portalIn.get(i).getBody().getPosition()); } } } } return true; }
Example 9
Source File: PhysicsFactory.java From tilt-game-android with MIT License | 4 votes |
public static Body createLineBody(final PhysicsWorld pPhysicsWorld, final float pX1, final float pY1, final float pX2, final float pY2, final FixtureDef pFixtureDef, final float pPixelToMeterRatio) { final BodyDef lineBodyDef = new BodyDef(); lineBodyDef.type = BodyType.StaticBody; final Body boxBody = pPhysicsWorld.createBody(lineBodyDef); final PolygonShape linePoly = new PolygonShape(); linePoly.setAsEdge(new Vector2(pX1 / pPixelToMeterRatio, pY1 / pPixelToMeterRatio), new Vector2(pX2 / pPixelToMeterRatio, pY2 / pPixelToMeterRatio)); pFixtureDef.shape = linePoly; boxBody.createFixture(pFixtureDef); linePoly.dispose(); return boxBody; }
Example 10
Source File: FluidSimulatorLiquid.java From fluid-simulator-v2 with Apache License 2.0 | 4 votes |
@Override public boolean touchDown(int x, int y, int pointer, int button) { touching = true; camera.unproject(testPoint.set(x, y, 0)); testPoint2D.x = testPoint.x; testPoint2D.y = testPoint.y; oldDragPos.set(testPoint2D); if (button == Buttons.LEFT) { // Drag Mode if (isDragging) { for (Piece piece : pieces.values()) { hitBody = null; if (piece.body.getFixtureList().get(0).testPoint(testPoint2D)) { hitBody = piece.body; if (hitBody.getType() == BodyType.KinematicBody || hitBody.getType() == BodyType.StaticBody) continue; MouseJointDef def = new MouseJointDef(); def.bodyA = groundBody; def.bodyB = hitBody; def.collideConnected = true; def.target.set(testPoint2D); def.maxForce = 10.0f * hitBody.getMass(); mouseJoint = (MouseJoint)world.createJoint(def); hitBody.setAwake(true); break; } } if (mouseJoint != null) return false; } if (!IS_DESKTOP) { isRepulsing = true; isAttracting = false; } else { isAttracting = false; isRepulsing = false; } } if (button == Buttons.RIGHT) { isAttracting = true; } if (button == Buttons.MIDDLE) { isRepulsing = true; } return false; }
Example 11
Source File: FluidSimulator.java From fluid-simulator-v2 with Apache License 2.0 | 4 votes |
@Override public boolean touchDown(int x, int y, int pointer, int button) { touching = true; camera.unproject(testPoint.set(x, y, 0)); testPoint2D.x = testPoint.x; testPoint2D.y = testPoint.y; oldDragPos.set(testPoint2D); if (button == Buttons.LEFT) { // Drag Mode if (isDragging) { for (Piece piece : pieces.values()) { hitBody = null; if (piece.body.getFixtureList().get(0).testPoint(testPoint2D)) { hitBody = piece.body; if (hitBody.getType() == BodyType.KinematicBody || hitBody.getType() == BodyType.StaticBody) continue; MouseJointDef def = new MouseJointDef(); def.bodyA = groundBody; def.bodyB = hitBody; def.collideConnected = true; def.target.set(testPoint2D); def.maxForce = 10.0f * hitBody.getMass(); mouseJoint = (MouseJoint)world.createJoint(def); hitBody.setAwake(true); break; } } if (mouseJoint != null) return false; } if (!IS_DESKTOP) { isRepulsing = true; isAttracting = false; } else { isAttracting = false; isRepulsing = false; } } if (button == Buttons.RIGHT) { isAttracting = true; } if (button == Buttons.MIDDLE) { isRepulsing = true; } return false; }
Example 12
Source File: FluidSimulatorMPM.java From fluid-simulator-v2 with Apache License 2.0 | 4 votes |
@Override public boolean touchDown(int x, int y, int pointer, int button) { touching = true; camera.unproject(testPoint.set(x, y, 0)); testPoint2D.x = testPoint.x; testPoint2D.y = testPoint.y; oldDragPos.set(testPoint2D); if (button == Buttons.LEFT) { // MPM mpmSolver.pressed = true; mpmSolver.mx = (int)testPoint2D.x; mpmSolver.my = BOX_HEIGHT - (int)testPoint2D.y; // Drag Mode if (isDragging) { for (Piece piece : pieces.values()) { hitBody = null; if (piece.body.getFixtureList().get(0).testPoint(testPoint2D)) { hitBody = piece.body; if (hitBody.getType() == BodyType.KinematicBody || hitBody.getType() == BodyType.StaticBody) continue; MouseJointDef def = new MouseJointDef(); def.bodyA = groundBody; def.bodyB = hitBody; def.collideConnected = true; def.target.set(testPoint2D); def.maxForce = 10.0f * hitBody.getMass(); mouseJoint = (MouseJoint)world.createJoint(def); hitBody.setAwake(true); break; } } if (mouseJoint != null) return false; } if (!IS_DESKTOP) { isRepulsing = true; isAttracting = false; } else { isAttracting = false; isRepulsing = false; } } if (button == Buttons.RIGHT) { isAttracting = true; } if (button == Buttons.MIDDLE) { isRepulsing = true; } return false; }