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(Vector2 v) 

Source Link

Document

Constructs a vector from the given vector

Usage

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();/* w  ww .  j  a  v a 2 s.co  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.jmolina.orb.elements.LinearMagnetic.java

License:Open Source License

/**
 * Indica si el punto se encuentra en la cara frontal del elemento. La cara frontal es la que
 * queda a la izquierda del vector segmento (Start-End).
 *
 * @param point Punto en coordenadas del mundo
 *//*ww  w.  j ava2 s .  c  o  m*/
private boolean atFrontSide(Vector2 point) {
    Vector2 vectorStartPoint = new Vector2(point);
    vectorStartPoint.sub(getStart());

    return getSegment().angle(vectorStartPoint) >= 0;
}

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

License:Apache License

public static Vector2[][] polygonize(Polygonizer polygonizer, Vector2[] points) {
    Vector2[][] polygons = null;//from   w ww. java 2s  .c o m

    if (PolygonUtils.isPolygonCCW(points))
        ArrayUtils.reverse(points);

    switch (polygonizer) {
    case EWJORDAN:
        polygons = EwjordanDecomposer.decompose(points);
        break;

    case BAYAZIT:
        Array<Vector2> tmpPoints = new Array<Vector2>(points.length);
        tmpPoints.addAll(points);

        Array<Array<Vector2>> tmpPolygons;

        try {
            tmpPolygons = BayazitDecomposer.ConvexPartition(tmpPoints);
        } catch (Exception ex) {
            tmpPolygons = null;
        }

        if (tmpPolygons != null) {
            polygons = new Vector2[tmpPolygons.size][];
            for (int i = 0; i < tmpPolygons.size; i++) {
                polygons[i] = new Vector2[tmpPolygons.get(i).size];
                for (int ii = 0; ii < tmpPolygons.get(i).size; ii++)
                    polygons[i][ii] = new Vector2(tmpPolygons.get(i).get(ii));
            }
        }
        break;
    }

    if (polygons != null)
        polygons = sliceForMax8Vertices(polygons);
    return polygons;
}

From source file:com.kotcrab.vis.editor.module.scene.action.ChangePolygonAction.java

License:Apache License

private Array<Vector2> copyArray(Array<Vector2> orig) {
    Array<Vector2> copy = new Array<>(orig.size);

    for (Vector2 v : orig) {
        copy.add(new Vector2(v));
    }/*from  w  ww  . j a  v  a  2s .  c  om*/

    return copy;
}

From source file:com.laex.cg2d.render.impl.ScreenManagerImpl.java

License:Open Source License

@Override
public Body switchAnimation(final String id, final String animationName) {
    Body switchedBody = null;/*from www .j av a2s  . com*/
    Array<Body> bodies = new Array<Body>();
    world.getBodies(bodies);

    for (Body bod : bodies) {
        CGShape shape = (CGShape) bod.getUserData();

        if (id.equals(shape.getId())) {
            try {
                Vector2 positionToCopy = new Vector2(bod.getTransform().getPosition());
                float rotation = bod.getTransform().getRotation();

                world.destroyBody(bod);
                entityManager.removeEntity(shape);

                switchedBody = entityManager.createEntity(shape, animationName);

                if (switchedBody != null) {
                    switchedBody.setTransform(positionToCopy, rotation);
                }

            } catch (IOException e) {
                AppExceptionUtil.handle(e);
            }
        }

    }

    return switchedBody;
}

From source file:com.me.mygdxgame.MoveableActor.java

License:Apache License

public Vector2 getWorldCenter() {
    return new Vector2(body.getWorldCenter().sub(size.cpy().div(2f)));
}