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

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

Introduction

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

Prototype

public Vector2(float x, float y) 

Source Link

Document

Constructs a vector with the given components

Usage

From source file:com.jumpbuttonstudios.vikingdodge.ui.popup.HighscoresPopup.java

License:Apache License

@Override
public void create() {
    setScreenPositions(0, 1000, 0, 0);/*from ww w  .j a v a2s.c o m*/
    personal = new Table();
    global = new Table();
    friends = new Table();
    globalScores = new Table();
    setFillParent(true);
    backButtonPos = new Vector2(background.getWidth() / 2, 75);
    back = new Button(Assets.skin.get("backButton", ButtonStyle.class));
    notLoggedIn = new Label("LOGIN TO SEE FRIENDS HIGHSCORES", Assets.skin.get("label", LabelStyle.class));
    scrollPane = new ScrollPane(globalScores);

}

From source file:com.kotcrab.vis.editor.module.physicseditor.PCameraModule.java

License:Apache License

public Vector2 screenToWorld(float x, float y) {
    Vector3 v3 = new Vector3(x, y, 0);
    camera.unproject(v3);// w  w  w  .j  a  v  a2  s  .c  o m
    return new Vector2(v3.x, v3.y);
}

From source file:com.kotcrab.vis.editor.module.physicseditor.PRigidBodiesScreen.java

License:Apache License

public void insertPointsBetweenSelected() {
    if (!isInsertEnabled())
        return;/*from  w w w .jav  a2  s .  co m*/

    List<Vector2> toAdd = new ArrayList<Vector2>();

    for (ShapeModel shape : selectedModel.getShapes()) {
        if (shape.getType() != ShapeModel.Type.POLYGON)
            continue;

        Array<Vector2> vs = shape.getVertices();

        for (int i = 0; i < vs.size; i++) {
            Vector2 p1 = vs.get(i);
            Vector2 p2 = i != vs.size - 1 ? vs.get(i + 1) : vs.get(0);

            if (selectedPoints.contains(p1) && selectedPoints.contains(p2)) {
                Vector2 p = new Vector2((p1.x + p2.x) / 2, (p1.y + p2.y) / 2);
                vs.insert(i + 1, p);
                toAdd.add(p);
            }
        }
    }

    selectedPoints.addAll(toAdd);
    selectedModel.computePhysics(settings.polygonizer);
}

From source file:com.kotcrab.vis.editor.module.physicseditor.util.earclipping.bayazit.BayazitDecomposer.java

License:Apache License

public static Vector2 Cross(Vector2 a, float s) {
    return new Vector2(s * a.y, -s * a.x);
}

From source file:com.kotcrab.vis.editor.module.physicseditor.util.earclipping.bayazit.BayazitDecomposer.java

License:Apache License

public static Array<Vector2> ReduceByDistance(Array<Vector2> vertices, float distance) {
    // We can't simplify polygons under 3 vertices
    if (vertices.size < 3)
        return vertices;
    Array<Vector2> simplified = new Array<Vector2>();
    for (int i = 0; i < vertices.size; i++) {
        Vector2 current = vertices.get(i);
        int ii = i + 1;
        if (ii >= vertices.size)
            ii = 0;/*  w w w  .  j ava  2  s  .c om*/
        Vector2 next = vertices.get(ii);
        Vector2 diff = new Vector2(next.x - current.x, next.y - current.y);
        // If they are closer than the distance, continue
        if (diff.len2() <= distance)
            continue;
        simplified.add(current);
    }
    return simplified;
}

From source file:com.kotcrab.vis.editor.module.physicseditor.util.earclipping.ewjordan.EwjordanDecomposer.java

License:Apache License

public static Vector2[][] decompose(Vector2[] points) {
    int vNum = points.length;
    float[] xv = new float[vNum];
    float[] yv = new float[vNum];

    for (int i = 0; i < vNum; i++) {
        xv[i] = points[i].x;/*w w  w.j a v  a2s. c o  m*/
        yv[i] = points[i].y;
    }

    Triangle[] tempTriangles = triangulatePolygon(xv, yv, vNum);
    Polygon[] tempPolygons = polygonizeTriangles(tempTriangles);

    if (tempPolygons == null)
        return null;

    Vector2[][] polygons = new Vector2[tempPolygons.length][];
    for (int i = 0; i < tempPolygons.length; i++) {
        polygons[i] = new Vector2[tempPolygons[i].nVertices];
        for (int ii = 0; ii < tempPolygons[i].nVertices; ii++)
            polygons[i][ii] = new Vector2(tempPolygons[i].x[ii], tempPolygons[i].y[ii]);
    }

    return polygons;
}

From source file:com.kotcrab.vis.editor.module.physicseditor.util.trace.TextureConverter.java

License:Apache License

private static Vector2 GetHoleHullEntrance(PolygonCreationAssistance pca, Array<Vector2> polygon,
        Vector2 startVertex) throws Exception {
    Array<CrossingEdgeInfo> edges = new Array<CrossingEdgeInfo>();
    Vector2 entrance;//w w w.  j  av  a  2  s .  com
    int startLine;
    int endLine;
    int lastSolid = 0;
    boolean foundSolid;
    boolean foundTransparent;
    if (polygon != null && polygon.size > 0) {
        if (startVertex != null) {
            startLine = (int) startVertex.y;
        } else {
            startLine = (int) GetTopMostCoord(polygon);
        }
        endLine = (int) GetBottomMostCoord(polygon);
        if (startLine > 0 && startLine < pca.Height && endLine > 0 && endLine < pca.Height) {
            // go from top to bottom of the polygon
            for (int y = startLine; y <= endLine; y += pca.getHoleDetectionLineStepSize()) {
                // get x-coord of every polygon edge which crosses y
                edges = GetCrossingEdges(polygon, EdgeAlignment.Vertical, y);
                // we need an even number of crossing edges
                if (edges.size > 1 && edges.size % 2 == 0) {
                    for (int i = 0; i < edges.size; i += 2) {
                        foundSolid = false;
                        foundTransparent = false;
                        for (int x = (int) edges.get(i).CrossingPoint.x; x <= (int) edges
                                .get(i + 1).CrossingPoint.x; x++) {
                            if (pca.IsSolid(x, y)) {
                                if (!foundTransparent) {
                                    foundSolid = true;
                                    lastSolid = x;
                                }
                                if (foundSolid && foundTransparent) {
                                    entrance = new Vector2(lastSolid, y);
                                    if (DistanceToHullAcceptable(pca, polygon, entrance, true)) {
                                        return entrance;
                                    }
                                    entrance = null;
                                    break;
                                }
                            } else {
                                if (foundSolid) {
                                    foundTransparent = true;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return null;
}

From source file:com.kotcrab.vis.editor.module.physicseditor.util.trace.TextureConverter.java

License:Apache License

public static Vector2 vectorSub(Vector2 v1, Vector2 v2) {
    return new Vector2(v1.x - v2.x, v1.y - v2.y);
}

From source file:com.kotcrab.vis.editor.module.physicseditor.util.trace.TextureConverter.java

License:Apache License

public static Vector2 vectorAdd(Vector2 v1, Vector2 v2) {
    return new Vector2(v1.x + v2.x, v1.y + v2.y);
}

From source file:com.kotcrab.vis.editor.module.physicseditor.util.trace.TextureConverter.java

License:Apache License

public static Vector2 vectorCross(Vector2 v1, float scalar) {
    return new Vector2(scalar * v1.y, -scalar * v1.x);
}