Example usage for com.badlogic.gdx.math Vector2 set

List of usage examples for com.badlogic.gdx.math Vector2 set

Introduction

In this page you can find the example usage for com.badlogic.gdx.math Vector2 set.

Prototype

public Vector2 set(float x, float y) 

Source Link

Document

Sets the components of this vector

Usage

From source file:com.stercore.code.net.dermetfan.utils.libgdx.maps.MapUtils.java

License:Apache License

/** sets the given Vector2 to the max width and height of all {@link TiledMapTileLayer tile layers} of the given map
 *  @param map the map to measure//from w  w  w  .  j a  va  2s.c  o m
 *  @param output the Vector2 to set to the map size
 *  @return the given Vector2 representing the map size */
public static Vector2 size(TiledMap map, Vector2 output) {
    Array<TiledMapTileLayer> layers = map.getLayers().getByType(TiledMapTileLayer.class);
    float maxWidth = 0, maxTileWidth = 0, maxHeight = 0, maxTileHeight = 0;
    for (TiledMapTileLayer layer : layers) {
        int layerWidth = layer.getWidth(), layerHeight = layer.getHeight();
        float layerTileWidth = layer.getTileWidth(), layerTileHeight = layer.getTileHeight();
        if (layerWidth > maxWidth)
            maxWidth = layerWidth;
        if (layerTileWidth > maxTileWidth)
            maxTileWidth = layerTileWidth;
        if (layerHeight > maxHeight)
            maxHeight = layerHeight;
        if (layerTileHeight > maxTileHeight)
            maxTileHeight = layerTileHeight;
    }
    return output.set(maxWidth * maxTileWidth, maxHeight * maxTileHeight);
}

From source file:com.stercore.code.net.dermetfan.utils.libgdx.math.GeometryUtils.java

License:Apache License

/** @return a Vector2 representing the size of a rectangle containing all given vertices */
public static Vector2 size(Vector2[] vertices, Vector2 output) {
    return output.set(width(vertices), height(vertices));
}

From source file:com.stercore.code.net.dermetfan.utils.libgdx.math.GeometryUtils.java

License:Apache License

/** @param a the first point of the segment
 *  @param b the second point of the segment
 *  @param polygon the polygon, assumed to be convex
 *  @param intersection1 the first intersection point
 *  @param intersection2 the second intersection point
 *  @return the number of intersection points
 *  @see #intersectSegments(Vector2, Vector2, float[], boolean, Array)*/
public static int intersectSegments(Vector2 a, Vector2 b, float[] polygon, Vector2 intersection1,
        Vector2 intersection2) {/*from   w w w.ja va2 s .  c  o  m*/
    FloatArray intersections = Pools.obtain(FloatArray.class);
    intersectSegments(a.x, a.y, b.x, b.y, polygon, true, intersections);
    int size = intersections.size;
    if (size >= 2) {
        intersection1.set(intersections.get(0), intersections.get(1));
        if (size == 4)
            intersection2.set(intersections.get(2), intersections.get(3));
        else if (size > 4)
            assert false : "more intersection points with a convex polygon found than possible: " + size;
    }
    Pools.free(intersections);
    return size / 2;
}

From source file:com.strategames.catchdastars.screens.editor.LevelEditorScreen.java

License:Open Source License

@Override
public boolean touchDown(float x, float y, int pointer, int button) {
    //      Gdx.app.log("LevelEditorScreen", "touchDown float: (x,y)="+x+","+y+")");

    this.dragDirection.x = x;
    this.dragDirection.y = y;
    this.initialTouchPosition.x = x;
    this.initialTouchPosition.y = y;

    this.previousZoomDistance = 0f; // reset zoom distance
    this.state = States.NONE;

    Vector2 touchPosition = new Vector2(x, y);

    Stage stageUIActors = getStageUIActors();
    Stage stageActors = getStageActors();

    stageUIActors.screenToStageCoordinates(touchPosition);
    this.uiElementHit = stageUIActors.hit(touchPosition.x, touchPosition.y, false);
    touchPosition.set(x, y); //reset vector as we use different metrics for actor stage
    stageActors.screenToStageCoordinates(touchPosition);
    Actor actor = stageActors.hit(touchPosition.x, touchPosition.y, false);
    //      Gdx.app.log("LevelEditorScreen", "touchDown touchPosition="+touchPosition);

    if ((actor instanceof Wall) && (((Wall) actor).isBorder())) {
        return true;
    }/*from   www . ja  v  a  2  s. c  om*/

    this.actorTouched = actor;

    if (actor != null) { // actor selected
        //         deselectAllGameObjects();
        selectGameObject((GameObject) this.actorTouched);
    } else if (this.uiElementHit == null) { // empty space selected
        //         deselectAllGameObjects();
    }

    return true;
}

From source file:com.strategames.engine.scenes.scene2d.Stage.java

License:Open Source License

public Array<Actor> getActorsAt(float x, float y) {
    Array<Actor> actors = getActors();
    Array<Actor> actorsHit = new Array<Actor>();
    Vector2 point = new Vector2();
    for (int i = 0; i < actors.size; i++) {
        Actor actor = actors.get(i);//w  w  w  .  j  a v a2s  .  c o m
        actor.parentToLocalCoordinates(point.set(x, y));
        if (actor.hit(point.x, point.y, false) != null) {
            actorsHit.add(actor);
        }
    }
    return actorsHit;
}

From source file:com.tnf.ptm.common.PtmMath.java

License:Apache License

/**
 * Modifies the given vector so it has the given angle and length. If not {@code precice}, the resulting vector angle may slightly differ from a given one, in the cost of performance.
 *//*  w ww .  j  av  a2  s .  c  o  m*/
public static void fromAl(Vector2 vec, float angle, float len, boolean precise) {
    vec.set(len, 0);
    rotate(vec, angle, precise);
}

From source file:com.tnf.ptm.common.PtmMath.java

License:Apache License

/**
 * @return a new bound vector// w  w w .  ja v a 2  s  . co  m
 */
@Bound
public static Vector2 getVec(float x, float y) {
    VECTORS_TAKEN++;
    Vector2 v = vs.obtain();
    v.set(x, y);
    return v;
}

From source file:com.tnf.ptm.entities.planet.PlanetManager.java

License:Apache License

private boolean recoverObj(PtmObject obj, float toNp, float npMinH) {
    if (npMinH < toNp) {
        return false;
    }//from  ww w  .j a va 2s .  co m
    if (!(obj instanceof PtmShip)) {
        return false;
    }
    PtmShip ship = (PtmShip) obj;
    Hull hull = ship.getHull();
    if (hull.config.getType() == HullConfig.Type.STATION) {
        return false;
    }
    float fh = myNearestPlanet.getFullHeight();
    Vector2 npPos = myNearestPlanet.getPos();
    Vector2 toShip = PtmMath.distVec(npPos, ship.getPosition());
    float len = toShip.len();
    if (len == 0) {
        toShip.set(0, fh);
    } else {
        toShip.scl(fh / len);
    }
    toShip.add(npPos);
    Body body = hull.getBody();
    body.setTransform(toShip, 0);
    body.setLinearVelocity(Vector2.Zero);
    PtmMath.free(toShip);
    return true;
}

From source file:com.trgk.touchwave.gamescene.HitCircle.java

License:Open Source License

public void updateTouchStatus() {
    Vector2 touchCoord = new Vector2();
    int processedTouchNum = 0;
    for (int pointer = 0; pointer < 20; pointer++) {
        if (Gdx.input.isTouched(pointer))
            processedTouchNum++;//from  w ww. j  a v a2 s . c  o  m
        if (touchedSet.contains(pointer)) {
            boolean currentlyTouching = false;
            if (Gdx.input.isTouched(pointer)) {
                float touchX = Gdx.input.getX(pointer);
                float touchY = Gdx.input.getY(pointer);
                mainStage.screenToStageCoordinates(touchCoord.set(touchX, touchY));
                this.stageToLocalCoordinates(touchCoord);
                touchX = touchCoord.x;
                touchY = touchCoord.y;
                if (this.hit(touchX, touchY, true) == this)
                    currentlyTouching = true;
            }
            if (!currentlyTouching) {
                touchedSet.remove(pointer);
            }
        }

        // Allow only up to 5 touches
        if (processedTouchNum == 5)
            break;
    }
}

From source file:com.trgk.touchwave.gamescene.HitFrame.java

License:Open Source License

@Override
public Actor hit(float x, float y, boolean touchable) {
    if (touchable && getTouchable() != Touchable.enabled)
        return null;

    Vector2 point = new Vector2();
    for (HitCircle circle : circles) {
        circle.parentToLocalCoordinates(point.set(x, y));
        Actor hit = circle.hit(point.x, point.y, touchable);
        if (hit != null)
            return hit;
    }/*from  w w w  .jav a 2  s  .  c  om*/
    return null;
}