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

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

Introduction

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

Prototype

@Override
    public boolean equals(Object obj) 

Source Link

Usage

From source file:com.codefiddler.libgdx.tetris.domain.SettledPlayBoard.java

License:Apache License

public boolean containsBlockAt(Vector2 point) {
    for (Tetrimino block : getBlocks()) {
        for (Vector2 blockPoint : block.getCurrentPosition()) {
            if (blockPoint.equals(point)) {
                return true;
            }//www  . ja v a  2  s . co m
        }
    }
    return false;
}

From source file:com.github.unluckyninja.defenseofhuman.model.entity.Rope.java

License:Open Source License

public Rope(GameWorld gameWorld, Body body, Vector2 direction) {
    this.gameWorld = gameWorld;
    world = body.getWorld();//from ww  w.j  a va  2s. c o  m
    bodyA = body;

    // ???
    Vector2 oriPosition = new Vector2(body.getPosition());
    if (direction.equals(Vector2.Zero)) {
        direction = Vector2.X;
    }
    Vector2 dir = new Vector2(direction);
    dir.nor();
    Vector2 distance = dir.scl(width / 2 * 1.25f); // ,?1/4,?

    // ?body
    bodyDef.angle = (float) Math.toRadians(dir.angle());
    bodyDef.position.set(distance.add(oriPosition));
    bodyDef.linearDamping = 0.3f;
    bodyDef.type = BodyDef.BodyType.DynamicBody;

    Body piece = body.getWorld().createBody(bodyDef);
    piece.setGravityScale(0.1f);

    // ?
    // ??,????
    fixtureDef.isSensor = true;
    fixtureDef.density = 0.001f;

    polygonShape.setAsBox(width / 2, height / 2);

    fixtureDef.shape = polygonShape;

    piece.createFixture(fixtureDef);

    // ?
    RevoluteJointDef rjDef = new RevoluteJointDef();
    rjDef.bodyA = body;
    rjDef.bodyB = piece;

    rjDef.localAnchorA.x = 0;
    rjDef.localAnchorA.y = 0;
    rjDef.localAnchorB.x = -width / 2 * 1.25f;
    rjDef.localAnchorB.y = 0;

    joints.add(body.getWorld().createJoint(rjDef));
    pieces.add(piece);

    piece.setUserData(this);

}

From source file:com.github.unluckyninja.defenseofhuman.model.entity.Rope.java

License:Open Source License

private Rope append(Vector2 direction) {
    //TODO /*from  w w  w . j  av a2s.c om*/
    Body body = pieces.get(pieces.size - 1);

    // ???
    oriPosition.set(body.getWorldPoint(temp1.set(width / 2 * 1.25f, 0)));
    if (direction.equals(Vector2.Zero)) {
        direction = Vector2.X;
    }
    dir.set(direction);
    dir.nor();
    dir.scl(width / 2 * 1.25f);

    // ?body
    bodyDef.angle = (float) Math.toRadians(dir.angle());
    bodyDef.position.set(dir.add(oriPosition));

    Body piece = body.getWorld().createBody(bodyDef);
    piece.setGravityScale(0.1f);

    // ?
    fixtureDef.isSensor = true;
    fixtureDef.density = 0.001f;

    polygonShape.setAsBox(width / 2, height / 2);

    fixtureDef.shape = polygonShape;

    piece.createFixture(fixtureDef);

    // ??
    RevoluteJointDef rjDef = new RevoluteJointDef();
    rjDef.bodyA = body;
    rjDef.bodyB = piece;

    rjDef.localAnchorA.x = width / 2 * 1.25f;
    rjDef.localAnchorA.y = 0;
    rjDef.localAnchorB.x = -width / 2 * 1.25f;
    rjDef.localAnchorB.y = 0;

    joints.add(body.getWorld().createJoint(rjDef));
    pieces.add(piece);

    body.setUserData(this);

    return this;
}

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

License:Apache License

public static Array<Vector2> MergeIdenticalPoints(Array<Vector2> vertices) {
    Array<Vector2> results = new Array<Vector2>();
    for (int i = 0; i < vertices.size; i++) {
        Vector2 vOriginal = vertices.get(i);

        boolean alreadyExists = false;
        for (int j = 0; j < results.size; j++) {
            Vector2 v = results.get(j);
            if (vOriginal.equals(v)) {
                alreadyExists = true;/* www. j av  a  2s .  c  om*/
                break;
            }
        }
        if (!alreadyExists)
            results.add(vertices.get(i));
    }
    return results;
}

From source file:com.o2d.pkayjava.editor.view.stage.tools.PolygonTool.java

License:Apache License

private boolean isSamePoint(Vector2 point1, Vector2 point2) {
    int pixelsPerWU = Sandbox.getInstance().getPixelPerWU();
    int precision = 10000 * pixelsPerWU;
    Vector2 pointA = new Vector2(point1);
    Vector2 pointB = new Vector2(point2);
    pointA.x = Math.round(point1.x * precision) / (float) precision;
    pointA.y = Math.round(point1.y * precision) / (float) precision;
    pointB.x = Math.round(point2.x * precision) / (float) precision;
    pointB.y = Math.round(point2.y * precision) / (float) precision;

    return pointA.equals(pointB);
}

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

License:Apache License

/** rotates a {@code point} around {@code center}
 *  @param point the point to rotate//from   w w w  .  j a va2s.c o  m
 *  @param origin the point around which to rotate {@code point}
 *  @param radians the rotation
 *  @return the given {@code point} rotated around {@code center} by {@code radians} */
public static Vector2 rotate(Vector2 point, Vector2 origin, float radians) {
    if (point.equals(origin))
        return point;
    return point.add(origin).rotateRad(radians).sub(origin);
}

From source file:com.torrosoft.sopistan.gui.graphics.DrawResolver.java

License:Open Source License

/**
 * Simple distance-based simplification. TODO doc simplify
 * //from ww w  .  j  av a2 s  .c  om
 * @param points
 * @param sqTolerance
 * @param out
 */
private static void simplify(Array<Vector2> points, float sqTolerance, Array<Vector2> out) {
    int len = points.size;
    Vector2 point = new Vector2();
    Vector2 prevPoint = points.get(0);

    out.clear();
    out.add(prevPoint);

    for (int i = 1; i < len; i++) {
        point = points.get(i);

        if (distSq(point, prevPoint) > sqTolerance) {
            out.add(point);
            prevPoint = point;
        }
    }

    if (!prevPoint.equals(point))
        out.add(point);
}

From source file:es.eucm.ead.engine.collision.BoundingAreaBuilder.java

License:Open Source License

private static Polygon getBoundingPolygon(EngineEntity entity, Group sceneContentGroup, Group group) {
    SnapshotArray<Vector2> allPoints = new SnapshotArray<Vector2>();

    for (Polygon polygon : getColliders(entity)) {
        for (int i = 0; i < polygon.getVertices().length; i += 2) {
            Vector2 tmp = Pools.obtain(Vector2.class);
            tmp.set(polygon.getVertices()[i], polygon.getVertices()[i + 1]);
            group.localToAscendantCoordinates(sceneContentGroup, tmp);
            allPoints.add(tmp);/*  w  ww .  j  a v  a 2 s. c  o  m*/
        }
    }

    if (allPoints.size == 0) {
        return null;
    }

    // Remove duplicates, if any. Algorithm works better this way
    Object[] pointsToIterate = allPoints.begin();
    int size = allPoints.size;
    for (int i = 0; i < size; i++) {
        Vector2 pointA = (Vector2) pointsToIterate[i];
        for (int j = 0; j < size; j++) {
            Vector2 pointB = (Vector2) pointsToIterate[j];
            if (j != i && pointA.equals(pointB)) {
                allPoints.removeValue(pointB, true);
            }
        }
    }
    allPoints.end();

    // To array
    float[] points = toSimpleArray(allPoints);
    FloatArray floatArray = convexHull.computePolygon(points, false);
    // Remove the last point, since its the first one (duplicate)
    floatArray.removeRange(floatArray.size - 2, floatArray.size - 1);
    Polygon polygon = new Polygon();
    polygon.setVertices(floatArray.toArray());
    return polygon;
}

From source file:es.eucm.ead.engine.paths.PathFinder.java

License:Open Source License

/**
 * Finds a path from start to finish. The path is guaranteed to be minimal
 * and to fall entirely within the original path polygon. If either start or
 * finish are outside the polygon, the closest inside points will be chosen
 * instead.//from   ww w .  ja v a2 s .c o  m
 * 
 * @param start
 *            starting point, in original view coordinates
 * @param finish
 *            end point, in original view coordinates
 */
Array<PathPoint> findPath(Vector2 start, Vector2 finish) {

    if (start.equals(finish)) {
        Array<PathPoint> empty = new Array<PathPoint>();
        empty.add(new PathPoint(0, start, null, finish));
        return empty;
    }

    // transform to world-coordinates
    start = new Vector2(start);
    finish = new Vector2(finish);
    PathUtils.transformPoints(viewToWorld, start, finish);

    if (!pathBoundary.contains(start.x, start.y)) {
        start = PathUtils.closestInternalPoint(start, pathBoundary);
    }
    if (!pathBoundary.contains(finish.x, finish.y)) {
        finish = PathUtils.closestInternalPoint(finish, pathBoundary);
    }

    // set once goal is reached
    PathPoint goal = null;

    // A*
    PriorityQueue<PathPoint> pathPoints = new PriorityQueue<PathPoint>();
    HashMap<Vector2, PathPoint> expanded = new HashMap<Vector2, PathPoint>();
    pathPoints.add(new PathPoint(pathPoints.size(), start, null, finish));
    while (!pathPoints.isEmpty() && goal == null) {
        PathPoint current = pathPoints.poll();
        PathPoint prevExpanded = expanded.get(current.pos);
        if (prevExpanded != null && prevExpanded.dist <= current.dist) {
            // if already expanded, ignore
            continue;
        } else {
            expanded.put(current.pos, current);
        }
        Vector2[] endpoints = lineEndpoints(current.pos, finish, true);
        if (endpoints.length == 1) {
            goal = new PathPoint(pathPoints.size(), finish, current, finish);
        } else {
            for (Vector2 v : endpoints) {
                pathPoints.add(new PathPoint(pathPoints.size(), v, current, finish));
            }
        }
    }

    // check "did not reach"
    if (goal == null) {
        return null;
    }

    // reverse path & return
    Array<PathPoint> best = new Array<PathPoint>();
    do {
        best.add(goal);
        goal = goal.parent;
    } while (goal != null);
    best.reverse();
    return best;
}

From source file:org.csproduction.descendant.entities.Player.java

@Override
public boolean update(float dt) {
    if (!alive)//from w w  w .  j a  va 2s.  co  m
        return false;

    Vector2 v = body.getLinearVelocity();
    if (facesRight && v.x < 0 || !facesRight && v.x > 0)
        turn();

    super.update(dt);
    if (v.equals(new Vector2(0, 0))) {
        if (wasIdle && currentAnim != idleAnim)
            currentAnim = idleAnim;
        wasIdle = true;
    } else {
        wasIdle = false;
    }

    prevVelocity = new Vector2(v.x, v.y);

    return true;
}