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

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

Introduction

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

Prototype

public Vector2 sub(float x, float y) 

Source Link

Document

Substracts the other vector from this vector.

Usage

From source file:com.flaiker.reaktio.entities.DragSquareEntity.java

License:Open Source License

private float getTravelledDistance() {
    Vector2 tmpVec = new Vector2(startPos);
    return Math.abs(tmpVec.sub(getX(), getY()).len());
}

From source file:com.kotcrab.vis.editor.proxy.EntityProxy.java

License:Apache License

protected void updatePolygon(float x, float y) {
    VisPolygon polygon = polygonCm.get(entity);
    if (polygon != null) {
        float dx = getX() - x;
        float dy = getY() - y;
        for (Vector2 vertex : polygon.vertices) {
            vertex.sub(dx, dy);
        }//  w  w w.j av  a  2 s . c o m

        polygon.faces = Clipper.polygonize(PolygonTool.DEFAULT_POLYGONIZER,
                polygon.vertices.toArray(Vector2.class));
    }
}

From source file:com.uwsoft.editor.view.ui.box.resourcespanel.draggable.DraggableResource.java

License:Apache License

private void drop(DragAndDrop.Payload payload, Vector2 vector2) {
    ResourcePayloadObject resourcePayloadObject = (ResourcePayloadObject) payload.getObject();
    ResourceManager resourceManager = Overlap2DFacade.getInstance().retrieveProxy(ResourceManager.NAME);

    vector2.sub(resourcePayloadObject.xOffset / resourceManager.getProjectVO().pixelToWorld,
            resourcePayloadObject.yOffset / resourceManager.getProjectVO().pixelToWorld);
    factoryFunction.apply(resourcePayloadObject.name, vector2);
}

From source file:org.ams.testapps.paintandphysics.physicspuzzle.PhysicsPuzzle.java

License:Open Source License

/**
 * Finds the vertices for the chain body that is the "ground" for the active blocks.
 * It forms an outline around the walls, floor and locked blocks.
 *//*  ww w .j ava 2s  .  com*/
private Vector2[] computeChainVertices() {

    Array<Vector2> platformVertices = new Array<Vector2>();

    platformVertices.addAll(wallVerticesForGroundBody);

    // first i find all the platforms that the locked blocks form
    Array<Array<Integer>> platforms = new Array<Array<Integer>>();
    {
        Array<Integer> platform = new Array<Integer>();
        platforms.add(platform);

        int row = platformLevels.get(0);
        int previousRow = row;
        platform.add(row);

        for (int i = 1; i < platformLevels.size; i++) {
            row = platformLevels.get(i);
            if (row != previousRow) {
                platform = new Array<Integer>();
                platforms.add(platform);
            }
            platform.add(row);

            previousRow = row;
        }
    }

    // for each platform 2 vertices is added
    // special treatment for platforms with index -1(a platform on the floor)
    // and for platforms touching the left or right wall
    int i = 0;
    int previousPlatformRow = -1;
    for (Array<Integer> platform : platforms) {
        int platformColumnBegin = i; // inclusive
        int platformColumnEnd = i + platform.size - 1; // not inclusive
        int platformRow = platform.first();

        Vector2 beginPos, endPos;

        if (platformRow >= 0) {
            PPPolygon platformBegin = getBlock(platformRow, platformColumnBegin);
            beginPos = new Vector2(platformBegin.getPhysicsThing().getBody().getPosition());
            beginPos.add(-physicsBlockDim * 0.5f, physicsBlockDim * 0.5f);

            PPPolygon platformEnd = getBlock(platformRow, platformColumnEnd);
            endPos = new Vector2(platformEnd.getPhysicsThing().getBody().getPosition());
            endPos.add(physicsBlockDim * 0.5f, physicsBlockDim * 0.5f);
        } else {
            // platform is on the floor
            // we get coordinates for an equally wide platform just
            // one row higher up, then lower height by one block height

            PPPolygon platformBegin = getBlock(0, platformColumnBegin);
            beginPos = new Vector2((Vector2) platformBegin.getUserData());
            beginPos.add(-physicsBlockDim * 0.5f, physicsBlockDim * 0.5f - blockDim);

            PPPolygon platformEnd = getBlock(0, platformColumnEnd);
            endPos = new Vector2((Vector2) platformEnd.getUserData());
            endPos.add(physicsBlockDim * 0.5f, physicsBlockDim * 0.5f - blockDim);

        }

        if (platformRow < previousPlatformRow) {
            beginPos.sub((blockDim - physicsBlockDim), 0);
        } else {
            if (platformVertices.size > 0 && platformColumnBegin != 0) {
                platformVertices.peek().add(blockDim - physicsBlockDim, 0);
            }
        }

        if (platformColumnEnd == columns - 1) {
            // platform touching right wall, adjust slightly
            endPos.add(blockDim - physicsBlockDim, 0);
        }
        if (platformColumnBegin == 0) {
            // platform touching left wall, adjust slightly
            beginPos.sub(blockDim - physicsBlockDim, 0);
        }

        // make sure i don't add vertices that are too close to the previous
        // (this is only an issue for the top row)

        boolean distanceOk = platformVertices.peek().dst(beginPos) > 0.001f;
        distanceOk &= platformVertices.first().dst(beginPos) > 0.001f;

        if (platformVertices.size == 0 || distanceOk)
            platformVertices.add(beginPos);

        distanceOk = platformVertices.peek().dst(endPos) > 0.001f;
        distanceOk &= platformVertices.first().dst(endPos) > 0.001f;

        if (platformVertices.size == 0 || distanceOk)
            platformVertices.add(endPos);

        i += platform.size;
        previousPlatformRow = platformRow;

    }

    return platformVertices.toArray(Vector2.class);
}

From source file:org.bladecoder.bladeengine.model.Sprite3DRenderer.java

License:Apache License

@Override
public void lookat(float x, float y, Vector2 pf) {
    Vector2 tmp = new Vector2(pf);
    float angle = tmp.sub(x, y).angle() + 90;
    lookat(angle);// w  ww .  j a v a2  s .  c o m
}