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.cyphercove.doublehelix.FilmGrain.java

License:Apache License

static void swapVector2(Vector2 vector) {
    vector.set(vector.y, vector.x);
}

From source file:com.esotericsoftware.spine.TransformConstraint.java

License:Open Source License

public void update() {
    float rotateMix = this.rotateMix, translateMix = this.translateMix, scaleMix = this.scaleMix,
            shearMix = this.shearMix;
    Bone target = this.target;
    float ta = target.a, tb = target.b, tc = target.c, td = target.d;
    float degRadReflect = ta * td - tb * tc > 0 ? degRad : -degRad;
    float offsetRotation = data.offsetRotation * degRadReflect,
            offsetShearY = data.offsetShearY * degRadReflect;
    Array<Bone> bones = this.bones;
    for (int i = 0, n = bones.size; i < n; i++) {
        Bone bone = bones.get(i);//  w w w  .  j  a v a  2s .  c  o  m
        boolean modified = false;

        if (rotateMix != 0) {
            float a = bone.a, b = bone.b, c = bone.c, d = bone.d;
            float r = atan2(tc, ta) - atan2(c, a) + offsetRotation;
            if (r > PI)
                r -= PI2;
            else if (r < -PI)
                r += PI2;
            r *= rotateMix;
            float cos = cos(r), sin = sin(r);
            bone.a = cos * a - sin * c;
            bone.b = cos * b - sin * d;
            bone.c = sin * a + cos * c;
            bone.d = sin * b + cos * d;
            modified = true;
        }

        if (translateMix != 0) {
            Vector2 temp = this.temp;
            target.localToWorld(temp.set(data.offsetX, data.offsetY));
            bone.worldX += (temp.x - bone.worldX) * translateMix;
            bone.worldY += (temp.y - bone.worldY) * translateMix;
            modified = true;
        }

        if (scaleMix > 0) {
            float s = (float) Math.sqrt(bone.a * bone.a + bone.c * bone.c);
            float ts = (float) Math.sqrt(ta * ta + tc * tc);
            if (s > 0.00001f)
                s = (s + (ts - s + data.offsetScaleX) * scaleMix) / s;
            bone.a *= s;
            bone.c *= s;
            s = (float) Math.sqrt(bone.b * bone.b + bone.d * bone.d);
            ts = (float) Math.sqrt(tb * tb + td * td);
            if (s > 0.00001f)
                s = (s + (ts - s + data.offsetScaleY) * scaleMix) / s;
            bone.b *= s;
            bone.d *= s;
            modified = true;
        }

        if (shearMix > 0) {
            float b = bone.b, d = bone.d;
            float by = atan2(d, b);
            float r = atan2(td, tb) - atan2(tc, ta) - (by - atan2(bone.c, bone.a));
            if (r > PI)
                r -= PI2;
            else if (r < -PI)
                r += PI2;
            r = by + (r + offsetShearY) * shearMix;
            float s = (float) Math.sqrt(b * b + d * d);
            bone.b = cos(r) * s;
            bone.d = sin(r) * s;
            modified = true;
        }

        if (modified)
            bone.appliedValid = false;
    }
}

From source file:com.flatfisk.gnomp.math.GeometryUtils.java

License:Apache License

/**
 * @return a Vector2 representing the size of a rectangle containing all given vertices
 *//*from   w  w w  .ja v a  2s  . com*/
public static Vector2 size(Vector2[] vertices, Vector2 output) {
    return output.set(MathUtils.amplitude(filterX(vertices)), MathUtils.amplitude(filterY(vertices)));
}

From source file:com.flatfisk.gnomp.math.GeometryUtils.java

License:Apache License

/**
 * rotates {@code point} by {@code radians} around [0:0] (local rotation)
 *
 * @param point   the point to rotate//from w  w  w.j  a  v a  2 s  .  c  o  m
 * @param radians the rotation
 * @return the given {@code point} rotated by {@code radians}
 */
public static Vector2 rotate(Vector2 point, float radians) {
    // http://stackoverflow.com/questions/1469149/calculating-vertices-of-a-rotated-rectangle
    float xx = point.x, xy = point.y, yx = point.x, yy = point.y;
    xx = xx * cos(radians) - xy * sin(radians);
    yy = yx * sin(radians) + yy * cos(radians);
    return point.set(xx, yy);
}

From source file:com.github.antag99.chick.component.Position.java

License:Open Source License

/**
 * Sets the value of the given {@link Vector2} to the value of this component.
 *
 * @param out The {@link Vector2} to set the value of.
 * @return The vector passed in.//  w ww . j ava 2  s . c om
 */
public Vector2 v(Vector2 out) {
    return out.set(x, y);
}

From source file:com.indignado.games.smariano.utils.dermetfan.box2d.Box2DUtils.java

License:Apache License

/** @see #size(com.badlogic.gdx.physics.box2d.Shape) */
public static Vector2 size(Shape shape, Vector2 output) {
    if (shape.getType() == Type.Circle) // no call to #vertices(Shape) for performance
        return output.set(shape.getRadius() * 2, shape.getRadius() * 2);
    else if (shapeCache.containsKey(shape))
        return output.set(shapeCache.get(shape).width, shapeCache.get(shape).height);
    return output.set(width(shape), height(shape));
}

From source file:com.indignado.games.smariano.utils.dermetfan.box2d.Box2DUtils.java

License:Apache License

/** @return the relative position of the given Shape to its Body
 *  @param rotation the rotation of the bodyA in radians */
public static Vector2 positionRelative(Shape shape, float rotation, Vector2 output) {
    // get the position without rotation
    if (shapeCache.containsKey(shape)) {
        ShapeCache sc = shapeCache.get(shape);
        output.set(sc.maxX - sc.width / 2, sc.maxY - sc.height / 2);
    } else {//from   w  w w .  j  a  v  a  2  s  .  c  om
        tmpVecArr = vertices(shape); // the shape's vertices will hopefully be put in #shapeCache
        if (shapeCache.containsKey(shape)) // the shape's vertices are now hopefully in #shapeCache, so let's try again
            positionRelative(shape, rotation, output);
        else
            // #autoShapeCache is false or #shapeCache reached #autoShapeCacheSize
            output.set(max(filterX(tmpVecArr)) - amplitude(filterX(tmpVecArr)) / 2,
                    max(filterY(tmpVecArr)) - amplitude(filterY(tmpVecArr)) / 2); // so calculating manually is faster than using the methods because there won't be the containsKey checks
    }

    // transform position according to rotation
    // http://stackoverflow.com/questions/1469149/calculating-vertices-of-a-rotated-rectangle
    float xx = output.x, xy = output.y, yx = output.x, yy = output.y;

    xx = xx * cos(rotation) - xy * sin(rotation);
    yy = yx * sin(rotation) + yy * cos(rotation);

    return output.set(xx, yy);
}

From source file:com.indignado.games.smariano.utils.dermetfan.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(amplitude(filterX(vertices)), amplitude(filterY(vertices)));
}

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) {//from   ww w  . j  a v a  2 s  .  c  om
    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

private static boolean SearchNearPixels(PolygonCreationAssistance pca, boolean searchingForSolidPixel,
        Vector2 current, Vector2 foundPixel) {
    int x;//  ww w . ja v a  2 s. c  om
    int y;
    for (int i = 0; i < 8; i++) {
        x = (int) current.x + ClosePixels[i][0];
        y = (int) current.y + ClosePixels[i][1];
        if (!searchingForSolidPixel ^ pca.IsSolid(x, y)) {
            foundPixel.set(x, y);
            return true;
        }
    }
    // Nothing found.
    foundPixel.set(0, 0);
    return false;
}