com.badlogic.gdx.math.Vector Java Examples

The following examples show how to use com.badlogic.gdx.math.Vector. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Joiner.java    From shapedrawer with MIT License 6 votes vote down vote up
static float preparePointyJoin(Vector2 A, Vector2 B, Vector2 C, Vector2 D, Vector2 E, float halfLineWidth) {
    AB.set(B).sub(A);
    BC.set(C).sub(B);
    float angle = AB.angleRad(BC);
    if (ShapeUtils.epsilonEquals(angle, 0) || ShapeUtils.epsilonEquals(angle, ShapeUtils.PI2)) {
        prepareStraightJoin(B, D, E, halfLineWidth);
        return angle;
    }
    float len = (float) (halfLineWidth / Math.sin(angle));
    boolean bendsLeft = angle>0;
    AB.setLength(len);
    BC.setLength(len);
    Vector insidePoint = bendsLeft?D:E;
    Vector outsidePoint = bendsLeft?E:D;
    insidePoint.set(B).sub(AB).add(BC);
    outsidePoint.set(B).add(AB).sub(BC);
    return angle;
}
 
Example #2
Source File: Joiner.java    From shapedrawer with MIT License 5 votes vote down vote up
static boolean prepareSmoothJoin(Vector2 A, Vector2 B, Vector2 C, Vector2 D, Vector2 E, float halfLineWidth, boolean startOfEdge) {
    AB.set(B).sub(A);
    BC.set(C).sub(B);
    float angle = AB.angleRad(BC);
    if (ShapeUtils.epsilonEquals(angle, 0) || ShapeUtils.epsilonEquals(angle, ShapeUtils.PI2)) {
        prepareStraightJoin(B, D, E, halfLineWidth);
        return true;
    }
    float len = (float) (halfLineWidth / Math.sin(angle));
    AB.setLength(len);
    BC.setLength(len);
    boolean bendsLeft = angle>0;
    Vector insidePoint = bendsLeft?D:E;
    Vector outsidePoint = bendsLeft?E:D;
    insidePoint.set(B).sub(AB).add(BC);
    //edgeDirection points towards the relevant edge - is this being calculated for the start of BC or the end of AB?
    Vector2 edgeDirection = startOfEdge?BC:AB;
    // rotate edgeDirection PI/2 towards outsidePoint
    if (bendsLeft) {
        v.set(edgeDirection.y, -edgeDirection.x); //rotate PI/2 to the right (clockwise)
    } else {
        v.set(-edgeDirection.y, edgeDirection.x); //rotate PI/2 to the left (anticlockwise)
    }
    v.setLength(halfLineWidth);
    outsidePoint.set(B).add(v);
    return bendsLeft;
}