List of usage examples for com.badlogic.gdx.math Vector2 cpy
@Override
public Vector2 cpy()
From source file:com.kotcrab.vis.editor.module.physicseditor.util.trace.TextureConverter.java
License:Apache License
private static Vector2 GetTopMostVertex(Array<Vector2> vertices) { float topMostValue = Float.MAX_VALUE; Vector2 topMost = null; for (int i = 0; i < vertices.size; i++) { if (topMostValue > vertices.get(i).y) { topMostValue = vertices.get(i).y; topMost = vertices.get(i);/* w w w .j a v a 2 s .co m*/ } } return topMost.cpy(); }
From source file:com.kotcrab.vis.editor.module.physicseditor.util.trace.TextureConverter.java
License:Apache License
private static Array<Vector2> CreateSimplePolygon(PolygonCreationAssistance pca, Vector2 entrance, Vector2 last) {// w w w. j a v a 2 s . com boolean entranceFound = false; boolean endOfHull = false; Array<Vector2> polygon = new Array<Vector2>(); Array<Vector2> hullArea = new Array<Vector2>(); Array<Vector2> endOfHullArea = new Array<Vector2>(); Vector2 current = new Vector2(); Vector2 zeroVec = new Vector2(); // Get the entrance point. //todo: alle moglichkeiten testen if (vectorEquals(entrance, zeroVec) || !pca.InBounds(entrance)) { entranceFound = GetHullEntrance(pca, entrance); if (entranceFound) { current.set(entrance.x - 1f, entrance.y); } } else { if (pca.IsSolid(entrance)) { if (IsNearPixel(pca, entrance, last)) { current.set(last); entranceFound = true; } else { Vector2 temp = new Vector2(); if (SearchNearPixels(pca, false, entrance, temp)) { current.set(temp); entranceFound = true; } else { entranceFound = false; } } } } if (entranceFound) { polygon.add(entrance); hullArea.add(entrance); Vector2 next = entrance.cpy(); do { // Search in the pre vision list for an outstanding point. Vector2 outstanding = new Vector2(); if (SearchForOutstandingVertex(hullArea, pca.getHullTolerance(), outstanding)) { if (endOfHull) { // We have found the next pixel, but is it on the last // bit of the // hull? if (vectorListContains(endOfHullArea, outstanding) && !vectorListContains(polygon, outstanding)) { // Indeed. polygon.add(outstanding); } // That's enough, quit. break; } // Add it and remove all vertices that don't matter anymore // (all the vertices before the outstanding). polygon.add(outstanding); int index = vectorListIndexOf(hullArea, outstanding); if (index == -1) { int debug = 1; } if (index >= 0) { // hullArea = hullArea.subList(index + 1, // hullArea.size); // Array<Vector2> newArray = new Array<Vector2> // (hullArea.size - (index + 1)); int counter = 0; for (int i = index + 1; i < hullArea.size; i++) { Vector2 v = hullArea.get(index); // newArray.add(v); hullArea.set(counter, v); counter++; } // hullArea.clear(); // hullArea = newArray; for (int i = 0; i < index + 1; i++) { hullArea.pop(); } } } // Last point gets current and current gets next. Our little // spider is // moving forward on the hull ;). last.set(current); current.set(next); // Get the next point on hull. next = new Vector2(); if (GetNextHullPoint(pca, last, current, next)) { // Add the vertex to a hull pre vision list. hullArea.add(next); } else { // Quit break; } if (vectorEquals(next, entrance) && !endOfHull) { // It's the last bit of the hull, search on and exit at next // found // vertex. endOfHull = true; endOfHullArea.addAll(hullArea); } } while (true); } return polygon; }
From source file:com.kotcrab.vis.editor.module.physicseditor.util.trace.TextureConverter.java
License:Apache License
public CrossingEdgeInfo(Vector2 edgeVertex1, Vector2 edgeVertex2, Vector2 crossingPoint, EdgeAlignment checkLineAlignment) { _egdeVertex1 = edgeVertex1.cpy(); _edgeVertex2 = edgeVertex2.cpy();/*w ww . ja v a 2 s .c o m*/ _alignment = checkLineAlignment; _crossingPoint = crossingPoint; }
From source file:com.me.mygdxgame.MoveableActor.java
License:Apache License
public MoveableActor(GdxTest gdxTest, String textureFilename, Vector2 size) { this.size = size; world = gdxTest.world;/* www .jav a 2s. c o m*/ pixelsPerMeter = gdxTest.getPixelsPerMeter(); texture = new Texture(Gdx.files.internal(textureFilename)); texture.setFilter(TextureFilter.Linear, TextureFilter.Linear); sprite = new Sprite(texture); Vector2 sizePixel = meterToPixel(size.cpy()); sprite.setSize(sizePixel.x, sizePixel.y); sprite.flip(false, true); }
From source file:com.me.mygdxgame.MoveableActor.java
License:Apache License
Vector2 meterToPixel(Vector2 position) { return position.cpy().scl(pixelsPerMeter); }
From source file:com.me.mygdxgame.MoveableActor.java
License:Apache License
Vector2 pixelToMeter(Vector2 pixelVec) { return pixelVec.cpy().div(pixelsPerMeter); }
From source file:com.mygdx.environments.EnvNull.EnvNull.java
public void fallingUpdate() { if (diveFC.complete) { /************************ COMPLETE THE DIVE//from w w w . j a v a 2s .c o m ************************/ //set player to center of section EnvironmentManager.player.getBody() .setTransform(new Vector2((currentSection.getPos().x + currentSection.getWidth() / 2) / PPM, (currentSection.getPos().y + currentSection.getHeight() / 2) / PPM), 0); EnvironmentManager.player.getBody().setLinearVelocity(new Vector2(0, 0)); //zoom out to normal if (fallDown) { currentPlayerZoom = currentPlayerZoom >= PLAYER_LAYER_ZOOM ? PLAYER_LAYER_ZOOM : currentPlayerZoom + 0.065f; } else { //fallUp currentPlayerZoom = currentPlayerZoom <= PLAYER_LAYER_ZOOM ? PLAYER_LAYER_ZOOM : currentPlayerZoom + 0.065f; } //complete current fall, resume play if (currentPlayerZoom == PLAYER_LAYER_ZOOM) { //BUG FIX (4/22/16) Player body movement on dive complete EnvironmentManager.player.getBody().setLinearVelocity(new Vector2(0, 0)); sm.setState(1); currentTopZoom = TOP_LAYER_ZOOM; currentPlayerZoom = PLAYER_LAYER_ZOOM; diveIn = false; diveMovement = 0.1f; } } else { /*************************************** FALL ZOOM INTO CURRENT SECTION ***************************************/ for (LayerManager lm : layerManagers) { lm.updatePitZoom(fallDown); } //move player towards center of pit section Vector2 sectionPos = new Vector2((currentSection.getPos().x + currentSection.getWidth() / 2) / PPM, (currentSection.getPos().y + currentSection.getHeight() / 2) / PPM); //prevSection Vector2 dir = sectionPos.cpy().sub(prevSectionPosition).nor(); float dist = sectionPos.dst(EnvironmentManager.player.getBody().getPosition()); //move player to center of currentSection EnvironmentManager.player.getBody().setTransform(prevSectionPosition.add(dir.scl(diveMovement * dist)), 0); diveMovement = diveMovement >= 1 ? 1 : diveMovement / 0.99f; if (fallDown) { //zoom for sections falling FROM currentTopZoom = currentTopZoom <= 0.03f ? 0.03f : currentTopZoom - 0.055f; //needed for player sprite going out of view at end of dive if (!diveIn) { currentPlayerZoom = currentPlayerZoom <= 0.80f ? 0.80f : currentPlayerZoom - 0.0075f; if (currentPlayerZoom == 0.8f) { diveIn = true; } } else { currentPlayerZoom = currentPlayerZoom >= 1.0f ? 1.0f : currentPlayerZoom + 0.016f; } } else { //fallUp currentTopZoom = currentTopZoom >= 0.03f ? 0.03f : currentTopZoom + 0.055f; //needed for player sprite going out of view at end of dive if (!diveIn) { currentPlayerZoom = currentPlayerZoom >= 0.80f ? 0.80f : currentPlayerZoom + 0.0075f; if (currentPlayerZoom == 0.8f) { diveIn = true; } } else { currentPlayerZoom = currentPlayerZoom <= 1.0f ? 1.0f : currentPlayerZoom - 0.016f; } } } }
From source file:com.ridiculousRPG.movement.auto.MoveArcAdapter.java
License:Apache License
/** * This {@link MovementHandler} tries to move an event by the given origin * and angle. The move waits if a blocking event exists on it's way.<br> * It also supports rotating the texture of the event automatically.<br> * After succeeding the switch finished is set to true. * //ww w . jav a 2 s. co m * @param origin * The origin of the cycle * @param angle * The angle in degrees or +-0 if you want to loop forever. If * the angle is negative, the move will be clockwise. * @param rotateTexture * Should the texture be rotated automatically? * @param fixedSpeed * If this is set to true, the speed will be fixed. (Default * value = false = dynamic speed) * @param stretch * Stretch the curve in x,y direction by the given relative * amount. (Default value = 1f = no stretching) * @param drift * Specifies a drift into direction x,y (positive/negative * allowed).<br> * x-drift will produce a vertical helix. y-drift will produce a * horizontal helix. (Default value = 0f = no drift) * @return */ public MoveArcAdapter(Vector2 origin, float angle, boolean rotateTexture, boolean variableSpeed, Vector2 stretch, Vector2 drift) { this.originReset = origin; this.origin = origin.cpy(); this.angle = angle * MathUtils.degreesToRadians; this.rotateTexture = rotateTexture; this.stretch = stretch; this.fixedSpeed = variableSpeed; this.drift = drift == null ? new Vector2() : drift; }
From source file:com.sixteencolorgames.sandbox.GameScreen.java
public void moveCameraPosition(Vector2 unit) { camera.translate(unit.cpy().scl(camera.zoom)); }
From source file:com.tnf.ptm.entities.StarPort.java
License:Apache License
private static Vector2 adjustDesiredPos(PtmGame game, StarPort myPort, Vector2 desired) { Vector2 newPos = desired;//w ww . j av a 2 s .co m List<PtmObject> objs = game.getObjMan().getObjs(); for (PtmObject o : objs) { if (o instanceof StarPort && o != myPort) { StarPort sp = (StarPort) o; // Check if the positions overlap Vector2 fromPos = sp.getPosition(); Vector2 distVec = PtmMath.distVec(fromPos, desired); float distance = PtmMath.hypotenuse(distVec.x, distVec.y); if (distance <= (float) StarPort.SIZE) { distVec.scl((StarPort.SIZE + .5f) / distance); newPos = fromPos.cpy().add(distVec); Vector2 d2 = PtmMath.distVec(fromPos, newPos); PtmMath.free(d2); } PtmMath.free(distVec); } } return newPos; }