List of usage examples for com.badlogic.gdx.math Rectangle merge
public Rectangle merge(Vector2[] vecs)
From source file:base.Engine.java
License:Open Source License
public static Set<TreeSet<PatternInstance>> findCollisions(List<PatternInstance> instanceList, int caseThreshold) { Set<TreeSet<PatternInstance>> returnSet = new TreeSet<>(new TreeComparator()); if (instanceList.size() < 2) return returnSet; // Our base case if (instanceList.size() < caseThreshold) { PatternInstance currentInstance = null; for (ListIterator<PatternInstance> i = instanceList.listIterator(); i.hasNext();) { currentInstance = i.next();/*from w ww . j a va 2 s . c o m*/ PatternInstance otherInstance = null; for (ListIterator<PatternInstance> j = instanceList.listIterator(i.nextIndex()); j.hasNext();) { otherInstance = j.next(); if (currentInstance != otherInstance && currentInstance.getRectangle().overlaps(otherInstance.getRectangle())) { returnSet = addPair(returnSet, currentInstance, otherInstance); } } } return returnSet; // Our other base case } Rectangle getRect = instanceList.get(0).getRectangle(); // Create a super-rectangle that encompasses all the objects PatternInstance currentInstance = null; for (ListIterator<PatternInstance> i = instanceList.listIterator(1); i.hasNext();) { currentInstance = i.next(); getRect = getRect.merge(currentInstance.getRectangle()); } List<PatternInstance> listQ1 = new LinkedList<>(); List<PatternInstance> listQ2 = new LinkedList<>(); List<PatternInstance> listQ3 = new LinkedList<>(); List<PatternInstance> listQ4 = new LinkedList<>(); Rectangle rectQ1 = new Rectangle(getRect.getX(), getRect.getY(), getRect.getWidth() / 2 + 1, getRect.getHeight() / 2 + 1); Rectangle rectQ2 = new Rectangle(getRect.getX(), getRect.getY() + getRect.getHeight() / 2 + 1, getRect.getWidth() / 2 + 1, getRect.getHeight() / 2 + 1); Rectangle rectQ3 = new Rectangle(getRect.getX() + getRect.getWidth() / 2 + 1, getRect.getY() + getRect.getHeight() / 2 + 1, getRect.getWidth() / 2 + 1, getRect.getHeight() / 2 + 1); Rectangle rectQ4 = new Rectangle(getRect.getX() + getRect.getWidth() / 2 + 1, getRect.getY(), getRect.getWidth() / 2 + 1, getRect.getHeight() / 2 + 1); for (ListIterator<PatternInstance> iter = instanceList.listIterator(); iter.hasNext();) { currentInstance = iter.next(); if (currentInstance.getRectangle().overlaps(rectQ1)) listQ1.add(currentInstance); if (currentInstance.getRectangle().overlaps(rectQ2)) listQ2.add(currentInstance); if (currentInstance.getRectangle().overlaps(rectQ3)) listQ3.add(currentInstance); if (currentInstance.getRectangle().overlaps(rectQ4)) listQ4.add(currentInstance); } for (TreeSet<PatternInstance> t1 : findCollisions(listQ1, caseThreshold * 2)) resolveTree(returnSet, t1); for (TreeSet<PatternInstance> t2 : findCollisions(listQ2, caseThreshold * 2)) resolveTree(returnSet, t2); for (TreeSet<PatternInstance> t3 : findCollisions(listQ3, caseThreshold * 2)) resolveTree(returnSet, t3); for (TreeSet<PatternInstance> t4 : findCollisions(listQ4, caseThreshold * 2)) resolveTree(returnSet, t4); return returnSet; }
From source file:com.kotcrab.vis.editor.ui.scene.SceneTab.java
License:Apache License
private void centerCameraAroundSelection() { ImmutableArray<SelectionFragment> fragments = entityManipulator.getFragmentedSelection(); if (fragments.size() == 0) return;// w w w. j a v a 2s. c o m Rectangle rect = fragments.first().getBoundingRectangle(); for (SelectionFragment fragment : fragments) { rect.merge(fragment.getBoundingRectangle()); } cameraModule.setPosition(rect.getX() + rect.getWidth() / 2, rect.getY() + rect.getHeight() / 2); }
From source file:com.kotcrab.vis.editor.util.gdx.ParticleUtils.java
License:Apache License
public static Rectangle calculateBoundingRectangle(ParticleEffect effect, Rectangle bounds, boolean additive) { Rectangle tempBounds = new Rectangle(); if (additive == false) bounds.set(0, 0, 0, 0);/* w ww .j a va 2 s . co m*/ for (int i = 0; i < effect.getEmitters().size; i++) { calculateBoundingRectangle(effect.getEmitters().get(i), tempBounds); if (isZero(tempBounds) == false) { if (isZero(bounds)) bounds.set(tempBounds); else bounds.merge(tempBounds); } } return bounds; }
From source file:com.kotcrab.vis.editor.util.gdx.ParticleUtils.java
License:Apache License
/** * Uses reflection (yep) to calculate current bounding rectangle for emitter. Should be uses instead of emitter.getBoundingBox() because * it often returns BoundingBox with Infinity as values making it useless. *///from w w w . ja v a2 s . c om public static Rectangle calculateBoundingRectangle(ParticleEmitter emitter, Rectangle bounds) { try { Field fieldParticles = emitter.getClass().getDeclaredField("particles"); fieldParticles.setAccessible(true); Field fieldActive = emitter.getClass().getDeclaredField("active"); fieldActive.setAccessible(true); Particle[] particles = (Particle[]) fieldParticles.get(emitter); boolean[] active = (boolean[]) fieldActive.get(emitter); if (particles.length == 0) return bounds.set(0, 0, 0, 0); boolean activeFound = false; int startIndex = 0; //find first active particle and set first bounding box for (; startIndex < particles.length; startIndex++) { if (active[startIndex]) { bounds.set(particles[startIndex].getBoundingRectangle()); activeFound = true; break; } } if (activeFound == false) return bounds.set(0, 0, 0, 0); //merge other active particles for (int i = startIndex; i < particles.length; i++) { if (active[i]) { Particle particle = particles[i]; bounds.merge(particle.getBoundingRectangle()); } } return bounds; } catch (NoSuchFieldException | IllegalAccessException e) { throw new IllegalStateException(e); } }
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);/*from w ww.jav a 2 s. c om*/ 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.OutlinePolygon.java
License:Open Source License
/** * Calculates the culling area of the bounding box after it has scaled, rotated and translates. This bounding box * contains a bunch of vertices. This way i don't have to merge hundreds of vertices to get a reasonable culling area, * just the four of the bounding box./*from w ww .j a v a 2s . co m*/ */ private Rectangle getCullingArea(Rectangle cullingArea, Rectangle boundingBox, float rotation, Vector2 translation, float scale) { tmp.set(boundingBox.x, boundingBox.y).scl(scale).rotateRad(rotation).add(translation); cullingArea.set(tmp.x, tmp.y, 0, 0); tmp.set(boundingBox.x + boundingBox.width, boundingBox.y).scl(scale).rotateRad(rotation).add(translation); cullingArea.merge(tmp); tmp.set(boundingBox.x + boundingBox.width, boundingBox.y + boundingBox.height).scl(scale) .rotateRad(rotation).add(translation); cullingArea.merge(tmp); tmp.set(boundingBox.x, boundingBox.y + boundingBox.height).scl(scale).rotateRad(rotation).add(translation); cullingArea.merge(tmp); return cullingArea; }
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;/*ww w . jav a 2s . c om*/ 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 w w w . j a v a 2 s .c om boundingRectangle.set(cullingArea); } else boundingRectangle.merge(cullingArea); } return boundingRectangle; }
From source file:org.ams.prettypaint.TexturePolygon.java
License:Open Source License
/** Computes the culling area of the polygon after scaling, rotating and translating. */ private Rectangle getCullingArea(Rectangle cullingArea, PolygonRegion pr, float rotation, Vector2 translation, float scale) { float[] vertices = pr.getVertices(); tmpVector.set(vertices[0], vertices[1]); tmpVector.scl(scale);/*w ww .ja v a 2 s .c o m*/ tmpVector.rotateRad(rotation); tmpVector.add(translation); cullingArea.set(tmpVector.x, tmpVector.y, 0, 0); tmpVector.set(vertices[2], vertices[3]); tmpVector.scl(scale); tmpVector.rotateRad(rotation); tmpVector.add(translation); cullingArea.merge(tmpVector); tmpVector.set(vertices[4], vertices[5]); tmpVector.scl(scale); tmpVector.rotateRad(rotation); tmpVector.add(translation); cullingArea.merge(tmpVector); return cullingArea; }
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 ww w . j a v a2s. co m*/ 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); }