List of usage examples for com.badlogic.gdx.math Rectangle getCenter
public Vector2 getCenter(Vector2 vector)
From source file:com.redtoorange.game.gameobject.GameMap.java
License:Open Source License
/** * Strip the rectangle objects from the TMX file and resize them to the correct scale for the game world. * * @param source The collection of source rectangles from the TMX file. * @param destination The collection to place the resized rectangles. *//*from w w w. ja v a2 s . c o m*/ private void pullAndAddRectangles(Array<RectangleMapObject> source, Array<Rectangle> destination) { for (RectangleMapObject r : source) { Rectangle rectangle = r.getRectangle(); Vector2 size = new Vector2(); Vector2 center = new Vector2(); rectangle.getSize(size); rectangle.getCenter(center); size.scl(mapScale); center.scl(mapScale); rectangle.setSize(size.x, size.y); rectangle.setCenter(center.x, center.y); destination.add(rectangle); } }
From source file:org.ams.prettypaint.TextureAligner.java
License:Open Source License
private Vector2 getOrigin(Array<TexturePolygon> texturePolygons, int origin) { Rectangle boundingRectangle = new Rectangle(); boolean initialized = false; for (TexturePolygon texturePolygon : texturePolygons) { if (!initialized) { initialized = true;/*from w w w . j a va 2s. co m*/ boundingRectangle.set(texturePolygon.getBoundingRectangle()); } else boundingRectangle.merge(texturePolygon.getBoundingRectangle()); } Vector2 v = boundingRectangle.getCenter(new Vector2()); v.scl(texturePolygons.first().getTextureScale()); TextureRegion firstRegion = texturePolygons.first().getTextureRegion(); float firstTextureScale = texturePolygons.first().getTextureScale(); v.add(firstRegion.getRegionWidth() * firstTextureScale * 0.5f, firstRegion.getRegionHeight() * firstTextureScale * 0.5f); return v; }
From source file:org.ams.testapps.paintandphysics.physicspuzzle.PhysicsPuzzle.java
License:Open Source License
/** Finds vertices that form an (almost complete) outline of the walls and floor. */ private Array<Vector2> computeChainVerticesForFloorAndWalls() { Array<Vector2> vertices = new Array<Vector2>(); {//from w w w. ja v a 2 s . c o m Rectangle boundingRectangle = ((Polygon) rightWall.getPhysicsThing()).getPhysicsBoundingBox(); float halfWidth = boundingRectangle.width * 0.5f; float halfHeight = boundingRectangle.height * 0.5f; Vector2 center = boundingRectangle.getCenter(new Vector2()); vertices.add(new Vector2(center).add(-halfWidth, halfHeight)); vertices.add(new Vector2(center).add(halfWidth, halfHeight)); } { Rectangle boundingRectangle = ((Polygon) floor.getPhysicsThing()).getPhysicsBoundingBox(); float halfWidth = boundingRectangle.width * 0.5f; float halfHeight = boundingRectangle.height * 0.5f; Vector2 center = boundingRectangle.getCenter(new Vector2()); vertices.add(new Vector2(center).add(halfWidth, -halfHeight)); vertices.add(new Vector2(center).add(-halfWidth, -halfHeight)); } { Rectangle boundingRectangle = ((Polygon) leftWall.getPhysicsThing()).getPhysicsBoundingBox(); float halfWidth = boundingRectangle.width * 0.5f; float halfHeight = boundingRectangle.height * 0.5f; Vector2 center = boundingRectangle.getCenter(new Vector2()); vertices.add(new Vector2(center).add(-halfWidth, halfHeight)); vertices.add(new Vector2(center).add(halfWidth, halfHeight)); } return vertices; }
From source file:org.ams.testapps.paintandphysics.physicspuzzle.PhysicsPuzzle.java
License:Open Source License
private void lookAtPuzzle() { // find puzzle bounding box Rectangle boundingBox = new Rectangle(); boundingBox.set(leftWall.getTexturePolygon().getBoundingRectangle()); boundingBox.merge(rightWall.getTexturePolygon().getBoundingRectangle()); boundingBox.merge(floor.getTexturePolygon().getBoundingRectangle()); // adjust the bounding box for zooming float differenceY = boundingBox.height * (1f / zoom - 1); float differenceX = boundingBox.width * (1f / zoom - 1); boundingBox.height += differenceY;// w w w . j a v a2s .c om boundingBox.width += differenceX; boundingBox.y -= differenceY * 0.5f; boundingBox.x -= differenceX * 0.5f; boundingBox.x += 0.5f * position.x * differenceX; boundingBox.y += 0.5f * position.y * differenceY; // look at the entire bounding box Vector2 center = boundingBox.getCenter(new Vector2()); camera.position.x = center.x; camera.position.y = center.y; float horizontalZoom = boundingBox.width / camera.viewportWidth; float verticalZoom = boundingBox.height / camera.viewportHeight; camera.zoom = Math.max(horizontalZoom, verticalZoom); camera.update(); }
From source file:rosthouse.rosty.loader.MapLoader.java
private void createRectangle(RectangleMapObject rectangleObject, PhysicsSystem physicsSystem, Entity mapObjectEntity, boolean isSensor) { Rectangle rectangle = rectangleObject.getRectangle(); RectangleComponent rectComponent = new RectangleComponent(rectangle); PolygonShape polygonShape = new PolygonShape(); polygonShape.setAsBox(rectangle.width * 0.5f, rectangle.height * 0.5f); FixtureDef fixtureDef = new FixtureDef(); fixtureDef.density = 0;// w w w.j a v a2 s .co m fixtureDef.friction = 1; fixtureDef.restitution = 0.2f; PhysicsComponent<PolygonShape> cmpPhys; if (isSensor) { cmpPhys = physicsSystem.createSensorComponent(BodyDef.BodyType.StaticBody, polygonShape, rectangle.getCenter(Vector2.Zero), fixtureDef); } else { cmpPhys = physicsSystem.createPhysicsComponent(BodyDef.BodyType.StaticBody, polygonShape, rectangle.getCenter(Vector2.Zero), fixtureDef); } mapObjectEntity.add(rectComponent); mapObjectEntity.add(cmpPhys); cmpPhys.fixture.setUserData(mapObjectEntity.getId()); }