List of usage examples for com.badlogic.gdx.math Rectangle set
public Rectangle set(Rectangle rect)
From source file:org.ams.prettypaint.OutlinePolygon.java
License:Open Source License
public Rectangle getBoundingRectangle() { Rectangle rectangle = new Rectangle(); boolean initialized = false; for (BoundingBox boundingBox : boundingBoxes) { updateBoxCulling(boundingBox);// w w w.j a v a 2 s.c o m Rectangle cullingArea = getCullingArea(tmpRectangle, boundingBox.rectangle, angleRad, position, scale); if (!initialized) { rectangle.set(cullingArea); initialized = true; } else rectangle.merge(cullingArea); } return 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;/* w w w .ja va 2 s . 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.prettypaint.TexturePolygon.java
License:Open Source License
public Rectangle getBoundingRectangle() { Rectangle boundingRectangle = new Rectangle(); boolean initialized = false; float scale = this.textureScale * this.scale; for (PolygonRegion pr : polygonRegions) { Rectangle cullingArea = getCullingArea(tmpRectangle, pr, angleRad + textureAngle, position, scale); if (!initialized) { initialized = true;//from ww w. j av a2s.c o m boundingRectangle.set(cullingArea); } else boundingRectangle.merge(cullingArea); } return boundingRectangle; }
From source file:org.ams.testapps.paintandphysics.physicspuzzle.PhysicsPuzzle.java
License:Open Source License
/** * Scale so texture fills the entire puzzle. Aligns the TexturePolygons * textures such that they appear to be one when locked in. Also centers * the texture in the middle of the puzzle. *///from w ww. jav a 2 s . c om private void scaleAndAlignTextures() { // find scale so that the texture covers // the entire puzzle with no repetition Rectangle boundingBox = new Rectangle(); boundingBox.set(leftWall.getTexturePolygon().getBoundingRectangle()); boundingBox.merge(rightWall.getTexturePolygon().getBoundingRectangle()); boundingBox.merge(floor.getTexturePolygon().getBoundingRectangle()); float horizontalScale = boundingBox.width / textureRegion.getRegionWidth(); float verticalScale = boundingBox.height / textureRegion.getRegionHeight(); float textureScale = Math.max(horizontalScale, verticalScale); Array<TexturePolygon> toAlign = new Array<TexturePolygon>(); for (PPThing thing : world.things) { TexturePolygon texturePolygon = thing.getTexturePolygon(); if (texturePolygon != null) { // set the scale we found texturePolygon.setTextureScale(textureScale); toAlign.add(texturePolygon); } } // align all the TexturePolygons // the default behaviour centers the texture in the middle of the puzzle TextureAligner textureAligner = new TextureAligner(); textureAligner.alignTextures(toAlign, true); }
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;//from w w w . j a v a 2 s . co m 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(); }