Example usage for com.badlogic.gdx.physics.box2d Shape getRadius

List of usage examples for com.badlogic.gdx.physics.box2d Shape getRadius

Introduction

In this page you can find the example usage for com.badlogic.gdx.physics.box2d Shape getRadius.

Prototype

public abstract float getRadius();

Source Link

Document

Returns the radius of this shape

Usage

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.stercore.code.net.dermetfan.utils.libgdx.box2d.Box2DUtils.java

License:Apache License

/** @return the minimal x of the vertices of the given Shape */
private static float minX0(Shape shape) {
    if (shape instanceof CircleShape)
        return ((CircleShape) shape).getPosition().x - shape.getRadius();
    return min(filterX(vertices0(shape)));
}

From source file:com.stercore.code.net.dermetfan.utils.libgdx.box2d.Box2DUtils.java

License:Apache License

/** @return the minimal y of the vertices of the given Shape */
private static float minY0(Shape shape) {
    if (shape instanceof CircleShape)
        return ((CircleShape) shape).getPosition().y - shape.getRadius();
    return min(filterY(vertices0(shape)));
}

From source file:com.stercore.code.net.dermetfan.utils.libgdx.box2d.Box2DUtils.java

License:Apache License

/** @return the maximal x of the vertices of the given Shape */
private static float maxX0(Shape shape) {
    if (shape instanceof CircleShape)
        return ((CircleShape) shape).getPosition().x + shape.getRadius();
    return max(filterX(vertices0(shape)));
}

From source file:com.stercore.code.net.dermetfan.utils.libgdx.box2d.Box2DUtils.java

License:Apache License

/** @return the maximal y of the vertices of the given Shape */
private static float maxY0(Shape shape) {
    if (shape instanceof CircleShape)
        return ((CircleShape) shape).getPosition().y + shape.getRadius();
    return max(filterY(vertices0(shape)));
}

From source file:com.stercore.code.net.dermetfan.utils.libgdx.box2d.Box2DUtils.java

License:Apache License

/** @return the width of the given Shape */
private static float width0(Shape shape) {
    if (shape.getType() == Type.Circle)
        return shape.getRadius() * 2;
    return amplitude(filterX(vertices0(shape)));
}

From source file:com.stercore.code.net.dermetfan.utils.libgdx.box2d.Box2DUtils.java

License:Apache License

/** @return the height of the given Shape */
private static float height0(Shape shape) {
    if (shape.getType() == Type.Circle)
        return shape.getRadius() * 2;
    return amplitude(filterY(vertices0(shape)));
}

From source file:net.dermetfan.utils.libgdx.box2d.Box2DUtils.java

License:Apache License

/** @see #size(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 (cache.containsKey(shape))
        return output.set(cache.get(shape).width, cache.get(shape).height);
    return output.set(width(shape), height(shape));
}

From source file:net.dermetfan.utils.libgdx.box2d.Box2DUtils.java

License:Apache License

/** creates a deep copy of a {@link Shape}<br/>
 *  <strong>Note: The {@link ChainShape#setPrevVertex(float, float) previous} and {@link ChainShape#setNextVertex(float, float) next} vertex of a {@link ChainShape} will not be copied since this is not possible due to the API.</strong>
 *  @param shape the {@link Shape} to copy
 *  @return a {@link Shape} exactly like the one passed in */
public static Shape copy(Shape shape) {
    Shape copy;//from   www. j  av a 2s. com
    switch (shape.getType()) {
    case Circle:
        CircleShape circleCopy = (CircleShape) (copy = new CircleShape());
        circleCopy.setPosition(((CircleShape) shape).getPosition());
        break;
    case Polygon:
        PolygonShape polyCopy = (PolygonShape) (copy = new PolygonShape()), poly = (PolygonShape) shape;
        float[] vertices = new float[poly.getVertexCount()];
        for (int i = 0; i < vertices.length; i++) {
            poly.getVertex(i, vec2_0);
            vertices[i++] = vec2_0.x;
            vertices[i] = vec2_0.y;
        }
        polyCopy.set(vertices);
        break;
    case Edge:
        EdgeShape edgeCopy = (EdgeShape) (copy = new EdgeShape()), edge = (EdgeShape) shape;
        edge.getVertex1(vec2_0);
        edge.getVertex2(vec2_1);
        edgeCopy.set(vec2_0, vec2_1);
        break;
    case Chain:
        ChainShape chainCopy = (ChainShape) (copy = new ChainShape()), chain = (ChainShape) shape;
        vertices = new float[chain.getVertexCount()];
        for (int i = 0; i < vertices.length; i++) {
            chain.getVertex(i, vec2_0);
            vertices[i++] = vec2_0.x;
            vertices[i] = vec2_0.y;
        }
        if (chain.isLooped())
            chainCopy.createLoop(GeometryUtils.toVector2Array(vertices));
        else
            chainCopy.createChain(vertices);
        break;
    default:
        return shape;
    }
    copy.setRadius(shape.getRadius());
    return copy;
}