Java 类com.badlogic.gdx.math.Polygon 实例源码

项目:feup-lpoo-armadillo    文件:B2DFactory.java   
/**
 * Creates polygon ground from the given object, at the given world.
 *
 * @param world  The world were the ground will be.
 * @param object The object used to initialize the ground.
 * @return The body of the created ground.
 */
static Body makePolygonGround(World world, PolygonMapObject object) {
    Polygon polygon = object.getPolygon();

    // Body and Fixture variables
    BodyDef bdef = new BodyDef();
    FixtureDef fdef = new FixtureDef();
    PolygonShape shape = new PolygonShape();

    bdef.type = BodyDef.BodyType.StaticBody;
    bdef.position.set(PIXEL_TO_METER * polygon.getX(), PIXEL_TO_METER * polygon.getY());

    Body body = world.createBody(bdef);

    float[] new_vertices = polygon.getVertices().clone();
    for (int i = 0; i < new_vertices.length; i++)
        new_vertices[i] *= PIXEL_TO_METER;

    shape.set(new_vertices);
    fdef.shape = shape;
    fdef.filter.categoryBits = GROUND_BIT;
    body.createFixture(fdef);

    return body;
}
项目:Onyx    文件:PolygonLoader.java   
/**
 * Retrieves a polygon from the polygon cache, with a specified width and height
 *
 * @param name the polygon to retrieve
 * @param width the width of the polygon
 * @param height the height of the polygon
 *
 * @return the loaded polygon
 */
public static Polygon getPolygon(String name, float width, float height) {
    if(! polygons.containsKey(name))
        loadPolygon(name);
    Polygon temp = polygons.get(name);
    float[] tempVertices = temp.getVertices();
    float[] returnVertices = new float[tempVertices.length];
    for(int i = 0; i < tempVertices.length; i++)
    {
        if(i % 2 == 0)
            returnVertices[i] = tempVertices[i] * width;
        else returnVertices[i] = tempVertices[i] * height;
    }
    Polygon ret = new Polygon(returnVertices);
    ret.setOrigin(width/2, height/2);
    return ret;
    //NOTE: Origin might need to be revisited
}
项目:jewelthief    文件:Bat.java   
@Override
public Polygon getPolygon() {
    float x = getPosition().x;
    float y = getPosition().y;
    float[] vertices = {
            x + 16, y - 5,
            x + 16, y + 1,
            x + 8, y + 9,
            x, y + 8,
            x - 8, y + 9,
            x - 16, y + 1,
            x - 16, y - 5,
            x, y - 9
    };
    return new Polygon(vertices);
}
项目:jewelthief    文件:Wizard.java   
@Override
public Polygon getPolygon() {
    float x = getPosition().x;
    float y = getPosition().y;
    float[] vertices = {
            x + 6, y - 15,
            x + 6, y,
            x + 8, y,
            x + 8, y + 3,
            x + 12, y + 15,
            x + 9, y + 15,
            x + 5, y + 4,
            x - 2, y + 14,
            x - 3, y + 14,
            x - 3, y + 7,
            x - 7, y + 7,
            x - 11, y + 3,
            x - 8, y - 1,
            x - 12, y - 15,
    };
    return new Polygon(vertices);
}
项目:jewelthief    文件:Spider.java   
@Override
public Polygon getPolygon() {
    float x = getPosition().x;
    float y = getPosition().y;
    float[] vertices = {
            x, y - 3,
            x + 3, y - 5,
            x + 6, y,
            x + 4, y + 5,
            x, y + 2,
            x - 4, y + 5,
            x - 6, y,
            x - 3, y - 5,
    };
    return new Polygon(vertices);
}
项目:jewelthief    文件:Camel.java   
@Override
public Polygon getPolygon() {
    float x = getPosition().x;
    float y = getPosition().y;
    float[] vertices = {
            x + 6, y - 10,
            x + 9, y - 5,
            x + 6, y - 2,
            x + 10, y + 3,
            x + 10, y + 7,
            x + 13, y + 7,
            x + 13, y + 10,
            x + 7, y + 10,
            x + 7, y + 4,
            x + 3, y + 4,
            x + 1, y + 10,
            x - 4, y + 8,
            x - 9, y + 10,
            x - 13, y - 2,
            x - 13, y - 10,
            x - 7, y - 10,
            x - 3, y - 4,
            x + 1, y - 10
    };
    return new Polygon(vertices);
}
项目:jewelthief    文件:Cloud.java   
@Override
public Polygon getPolygon() {
    float x = getPosition().x;
    float y = getPosition().y;
    float[] vertices = {
            x + 36, y - 1,
            x + 18, y + 11,
            x + 5, y + 8,
            x - 5, y + 12,
            x - 25, y + 10,
            x - 36, y + 2,
            x - 32, y - 10,
            x - 15, y - 8,
            x + 2, y - 12,
            x + 18, y - 12,
            x + 34, y - 7,
    };
    return new Polygon(vertices);
}
项目:jewelthief    文件:Bandit.java   
@Override
public Polygon getPolygon() {
    float x = getPosition().x;
    float y = getPosition().y;
    float[] vertices = {
            x + 5, y - 10,
            x + 13, y + 2,
            x + 13, y + 7,
            x + 10, y + 10,
            x + 7, y,
            x, y + 10,
            x - 4, y + 10,
            x - 14, y + 5,
            x - 14, y - 1,
            x - 12, y - 8,
            x - 14, y - 8,
            x - 14, y - 11,
            x - 9, y - 11,
            x - 5, y - 5,
            x, y - 10
    };
    return new Polygon(vertices);
}
项目:jewelthief    文件:Battlecopter.java   
@Override
public Polygon getPolygon() {
    float x = getPosition().x;
    float y = getPosition().y;
    float[] vertices = {
            x + 13, y,
            x + 14, y + 3,
            x + 10, y + 7,
            x + 6, y,
            x + 3, y,
            x - 5, y + 6,
            x + 3, y + 8,
            x - 15, y + 6,
            x - 7, y + 4,
            x - 14, y - 1,
            x - 14, y - 8,
            x - 9, y - 6,
            x - 9, y - 8,
            x - 4, y - 8,
            x - 2, y - 5,
    };
    return new Polygon(vertices);
}
项目:jewelthief    文件:BigBandit.java   
@Override
public Polygon getPolygon() {
    float x = getPosition().x;
    float y = getPosition().y;
    float[] vertices = {
            x, y - 16,
            x + 2, y - 8,
            x + 16, y + 2,
            x + 16, y + 12,
            x, y + 12,
            x - 1, y + 15,
            x - 5, y + 15,
            x - 8, y + 10,
            x - 11, y + 16,
            x - 14, y + 12,
            x - 11, y + 1,
            x - 16, y,
            x - 16, y - 3,
            x - 8, y - 8,
            x - 7, y - 15
    };
    return new Polygon(vertices);
}
项目:jewelthief    文件:Helicopter.java   
@Override
public Polygon getPolygon() {
    float x = getPosition().x;
    float y = getPosition().y;
    float[] vertices = {
            x + 16, y - 3,
            x + 8, y + 3,
            x + 13, y + 5,
            x + 13, y + 6,
            x - 4, y + 6,
            x - 16, y + 7,
            x - 11, y + 4,
            x - 16, y - 1,
            x - 6, y - 1,
            x - 3, y - 7,
            x + 11, y - 7,
    };
    return new Polygon(vertices);
}
项目:jewelthief    文件:Battleship.java   
@Override
public Polygon getPolygon() {
    float x = getPosition().x;
    float y = getPosition().y;
    float[] vertices = {
            x + 16, y - 5,
            x + 16, y + 3,
            x + 2, y + 5,
            x + 2, y + 12,
            x - 4, y + 12,
            x - 6, y,
            x - 16, y,
            x - 16, y - 9,
            x - 14, y - 12,
            x + 11, y - 12
    };
    return new Polygon(vertices);
}
项目:jewelthief    文件:Sailboat.java   
@Override
public Polygon getPolygon() {
    float x = getPosition().x;
    float y = getPosition().y;
    float[] vertices = {
            x + 16, y - 5,
            x + 6, y + 10,
            x + 3, y + 8,
            x - 3, y + 14,
            x - 9, y + 11,
            x - 6, y + 7,
            x - 15, y + 5,
            x - 15, y - 13,
            x + 10, y - 13
    };
    return new Polygon(vertices);
}
项目:jewelthief    文件:Soldier.java   
@Override
public Polygon getPolygon() {
    float x = getPosition().x;
    float y = getPosition().y;
    float[] vertices = {
            x + 5, y - 2,
            x + 5, y + 4,
            x + 1, y + 15,
            x - 5, y + 16,
            x - 5, y - 4,
            x - 3, y - 4,
            x - 3, y - 16,
            x + 3, y - 16,
            x + 3, y - 4,
            x + 5, y - 4,
    };
    return new Polygon(vertices);
}
项目:jewelthief    文件:Sphinx.java   
@Override
public Polygon getPolygon() {
    float x = getPosition().x;
    float y = getPosition().y;
    float[] vertices = {
            x + 10, y - 5,
            x + 14, y + 3,
            x + 8, y + 13,
            x - 8, y + 13,
            x - 14, y + 3,
            x - 10, y - 5,
            x - 3, y - 13,
            x + 3, y - 13
    };
    return new Polygon(vertices);
}
项目:jewelthief    文件:Emerald.java   
@Override
public Polygon getPolygon() {
    float x = getPosition().x;
    float y = getPosition().y;
    float[] vertices = {
            x + 6, y - 5,
            x + 6, y + 5,
            x + 3, y + 8,
            x - 3, y + 8,
            x - 6, y + 5,
            x - 6, y - 5,
            x - 3, y - 8,
            x + 3, y - 8
    };
    return new Polygon(vertices);
}
项目:jewelthief    文件:Sapphire.java   
@Override
public Polygon getPolygon() {
    float x = getPosition().x;
    float y = getPosition().y;
    float[] vertices = {
            x + 6, y - 5,
            x + 6, y + 5,
            x + 3, y + 8,
            x - 3, y + 8,
            x - 6, y + 5,
            x - 6, y - 5,
            x - 3, y - 8,
            x + 3, y - 8
    };
    return new Polygon(vertices);
}
项目:jewelthief    文件:Topaz.java   
@Override
public Polygon getPolygon() {
    float x = getPosition().x;
    float y = getPosition().y;
    float[] vertices = {
            x + 3, y + 8,
            x - 3, y + 8,
            x - 8, y + 3,
            x - 8, y - 3,
            x - 3, y - 8,
            x + 3, y - 8,
            x + 8, y - 3,
            x + 8, y + 3
    };
    return new Polygon(vertices);
}
项目:Fruit-Destroyer    文件:Bullet.java   
public Bullet(Sprite sprite)
{
    this.sprite = sprite;

    weapon = new Weapon(START_DAMAGE, START_ROF, START_MAGSIZE, START_RECOIL, START_KNOCKBACKPOWER);

    velocity = new Vector2();

    vertices = new float[]{
            0, 0,
            0, sprite.getHeight(),
            sprite.getWidth(), sprite.getHeight(),
            sprite.getWidth(), 0 };

    bounds = new Polygon(vertices);
    bounds.setOrigin(this.sprite.getWidth() / 2, this.sprite.getHeight() / 2);
    isOutOfScreen = false;
    isUsed = false;
}
项目:fabulae    文件:FilledPolygonRenderer.java   
public void setPolygon(Polygon polygon, GameMap map) {
    TextureRegion mapSolidTile = Assets.getTextureRegion(Configuration.getFileOrthogonalMapSolidWhiteTileTexture());
    // create a new region of size 1x1 in the middle of the solid tile texture
    TextureRegion pixel = new TextureRegion(mapSolidTile);
    float[] vertices = MathUtil.transformVerticesFromTileToScreen(
            polygon.getTransformedVertices(), map);
    polyReg = createdPolygonRegion(pixel, vertices);
    Rectangle rec = polygon.getBoundingRectangle();
    int width = (int) rec.getWidth();
    int height = (int) rec.getHeight();
    int x = (int) rec.getX();
    int y = (int) rec.getY();
    boundingRectangleTiles = new int[width * height * 2];

    int index = 0;
    for (int i = x; i < x + width; ++i) {
        for (int j = y; j < y + height; ++j) {
            boundingRectangleTiles[index++] = i;
            boundingRectangleTiles[index++] = j;
        }
    }
}
项目:fabulae    文件:GameMapLoader.java   
private void loadTransitions() {
    MapLayer locationsLayer = map.getLayers().get(LAYER_TRANSITIONS);
    if (locationsLayer == null) {
        return;
    }
    Array<Transition> transitions = new Array<Transition>();
    MapObjects locations = locationsLayer.getObjects();
    for (MapObject location : locations) {
        MapObject mapObject = (MapObject) location;
        String[] coords = ((String) mapObject.getProperties().get(PROPERTY_TARGET)).split(",");
        Tile target = new Tile(Integer.parseInt(coords[0].trim()), Integer.parseInt(coords[1].trim()));

        Polygon polygon = getPolygonFromMapObject(mapObject);
        Transition newTransition = new Transition(gameMap, mapObject.getName(), target.getX(), target.getY(),
                transformTiledPolygon(gameMap, polygon));
        transitions.add(newTransition);
    }
    buildTransitionTiles(transitions);
}
项目:fabulae    文件:GameMapLoader.java   
private Vector2 getPositionFromMapObject(MapObject mapObject) {
    if (mapObject instanceof PolygonMapObject) {
        Polygon polygon = ((PolygonMapObject) mapObject).getPolygon();
        return new Vector2(polygon.getX(), polygon.getY());
    } else if (mapObject instanceof RectangleMapObject) {
        Rectangle rectangle = ((RectangleMapObject) mapObject).getRectangle();
        return new Vector2(rectangle.getX(), rectangle.getY());
    } else if (mapObject instanceof EllipseMapObject) {
        Ellipse ellipse = ((EllipseMapObject) mapObject).getEllipse();
        return new Vector2(ellipse.x, ellipse.y);
    } else if (mapObject instanceof CircleMapObject) {
        Circle circle = ((CircleMapObject) mapObject).getCircle();
        return new Vector2(circle.x, circle.y);
    }
    throw new GdxRuntimeException("Only Polygons, Rectangles, Ellipses and Circles are supported!");
}
项目:fabulae    文件:GameMapLoader.java   
private IntArray getTilesFromPolygon(Polygon polygon) {
    IntArray tiles = new IntArray();
    Polygon transformedPolygon = transformTiledPolygon(gameMap, polygon);
    Rectangle rectangle = transformedPolygon.getBoundingRectangle();
    int startX = (int) rectangle.getX();
    int startY = (int) rectangle.getY();
    int endX = startX + (int) rectangle.getWidth();
    int endY = startY + (int) rectangle.getHeight();
    for (int x = startX; x <= endX; ++x) {
        for (int y = startY; y <= endY; ++y) {
            if (transformedPolygon.contains(x, y)) {
                tiles.add(x);
                tiles.add(y);
            }
        }
    }
    return tiles;
}
项目:fabulae    文件:Transition.java   
public Transition(GameMap parentMap, String targetMap, int targetX, int targetY, Polygon polygon) {
    this.targetMap = targetMap.toLowerCase(Locale.ENGLISH);
    this.targetX = targetX;
    this.targetY = targetY;
    this.polygon = polygon;
    cameraVertices = Arrays.copyOf(polygon.getTransformedVertices(), polygon.getTransformedVertices().length);
    if (parentMap.isIsometric()) {
        Vector2 tempVector = MathUtil.getVector2();
        for (int i = 0; i < cameraVertices.length; i += 2) {
            tempVector.set(cameraVertices[i], cameraVertices[i+1]);
            parentMap.projectFromTiles(tempVector);
            cameraVertices[i] = tempVector.x;
            cameraVertices[i+1] = tempVector.y;
        }
        MathUtil.freeVector2(tempVector);
    }
}
项目:fabulae    文件:LineOfSight.java   
LineOfSight(RayHandler rayHandler, int rays,
        int distance, float x, float y, GameMap map) {
    start.x = x;
    start.y = y;
    sin = new float[rays];
    cos = new float[rays];
    endX = new float[rays];
    endY = new float[rays];

    visibleShapePolygons = new ObjectSet<Polygon>();

    this.rayHandler = rayHandler;
    setRayNum(rays);
    this.distance = distance < 1 ? 1 : distance;
    tileVertices = new TileSet((distance+1)*2);
    this.map = map;
}
项目:Mario-Libgdx    文件:CastleFirebar.java   
public CastleFirebar(MapObject mapObject) {
    super(mapObject, new Vector2());        
    setRenderingSize(3, 0.5f);
    setOrigin(0, 0.25f);
    bounds=new Rectangle(getX() + offset.x, getY(), getWidth(), getHeight());
    polygon = new Polygon(new float[]{getX() + offset.x,getY(),
            getX() + offset.x, getY()+getHeight()-offset.y, 
            getX() + offset.x + getWidth(), getY()+getHeight()-offset.y,
            getX() + offset.x + getWidth(), getY()
            });     
    polygon.setOrigin(getX() + offset.x, getY() + 0.25f);
    moveable = false;
    collidableWithTilemap = false;
    gravitating = false;
    killableByPlayer = false;
    killableByFireball = false;
    explodeFireball = false;

    float rotation = Float.parseFloat((String)mapObject.getProperties().get("angle"));      
    rotateBy(rotation);             
    polygon.setRotation(getRotation());
}
项目:Aftamath    文件:Barrier.java   
public Barrier(Polygon polygon, String ID){
        this.polygon = polygon;
        this.ID = "barrier"+ID;
        isAttackable = false;

//      polygon.setScale(.5f, .5f);
        setDimensions(polygon.getBoundingRectangle().width, 
                polygon.getBoundingRectangle().height);
        this.x = polygon.getX() + width;
        this.y = polygon.getY() + height;

//      System.out.println("polyX: "+polygon.getX());

        loadSprite();
        followers = new HashMap<>();
    }
项目:codeday-spring2014    文件:Engine.java   
public Entity addPlayer(Position pos, Velocity vel, Health health, Invincibility invisible)
{
    Entity player = new Entity();
    player.add(pos);
    player.add(vel);
    player.add(health);
    player.add(invisible);

    float[] playerCoords = {
         25.0f,   0.0f,
         50.0f,  25.0f,
         25.0f,  50.0f,
          0.0f,  25.0f
    };
    Polygon poly = new Polygon(playerCoords);
    poly.setOrigin(25.0f, 25.0f);
    CollisionBox box = new CollisionBox(poly);
    player.add(box);

    player.add(new Graphics(playerSprite));

    return player;
}
项目:bladecoder-adventure-engine    文件:PolygonUtils.java   
public static void addPoint(Polygon poly, float x, float y, int index) {
    float verts[] = poly.getVertices();

    x -= poly.getX();
    y -= poly.getY();

    int length = verts.length;
    float destination[] = new float[length + 2];

    System.arraycopy(verts, 0, destination, 0, index);
    destination[index] = x;
    destination[index + 1] = y;
    System.arraycopy(verts, index, destination, index + 2, length - index);

    poly.setVertices(destination);
}
项目:bladecoder-adventure-engine    文件:PolygonUtils.java   
public static boolean isVertexConcave(Polygon poly, int index) {
    float verts[] = poly.getTransformedVertices();

    float currentX = verts[index];
    float currentY = verts[index + 1];
    float nextX = verts[(index + 2) % verts.length];
    float nextY = verts[(index + 3) % verts.length];
    float previousX = verts[index == 0 ? verts.length - 2 : index - 2];
    float previousY = verts[index == 0 ? verts.length - 1 : index - 1];

    float leftX = currentX - previousX;
    float leftY = currentY - previousY;
    float rightX = nextX - currentX;
    float rightY = nextY - currentY;

    float cross = (leftX * rightY) - (leftY * rightX);

    return cross < 0;
}
项目:bladecoder-adventure-engine    文件:PolygonUtils.java   
public static boolean inLineOfSight(Vector2 p1, Vector2 p2, Polygon polygon, boolean obstacle) {
    tmp.set(p1);
    tmp2.set(p2);

    float verts[] = polygon.getTransformedVertices();

    for (int i = 0; i < verts.length; i += 2) {
        if (lineSegmentsCross(tmp.x, tmp.y, tmp2.x, tmp2.y, verts[i],
                verts[i + 1], verts[(i + 2) % verts.length], verts[(i + 3)
                        % verts.length]))
            return false;
    }

    tmp.add(tmp2);
    tmp.x /= 2;
    tmp.y /= 2;

    boolean result = PolygonUtils.isPointInside(polygon, tmp.x, tmp.y, !obstacle);

    return obstacle?!result:result;
}
项目:bladecoder-adventure-engine    文件:PolygonalNavGraph.java   
private boolean inLineOfSight(float p1X, float p1Y, float p2X, float p2Y) {

        tmp.set(p1X, p1Y);
        tmp2.set(p2X, p2Y);

        if (!PolygonUtils.inLineOfSight(tmp, tmp2, walkZone, false)) {
            return false;
        }

        for (Polygon o : obstacles) {
            if (!PolygonUtils.inLineOfSight(tmp, tmp2, o, true)) {
                return false;
            }
        }

        return true;
    }
项目:bladecoder-adventure-engine    文件:PolygonalNavGraph.java   
private void addObstacleToGrapth(Polygon poly) {
    float verts[] = poly.getTransformedVertices();
    for (int i = 0; i < verts.length; i += 2) {
        if (PolygonUtils.isVertexConcave(poly, i)
                && PolygonUtils.isPointInside(walkZone, verts[i], verts[i + 1], false)) {
            NavNodePolygonal n1 = new NavNodePolygonal(verts[i], verts[i + 1]);

            for (int j = 0; j < graphNodes.size(); j++) {
                NavNodePolygonal n2 = graphNodes.get(j);

                if (inLineOfSight(n1.x, n1.y, n2.x, n2.y)) {
                    n1.neighbors.add(n2);
                    n2.neighbors.add(n1);
                }
            }

            graphNodes.add(n1);
        }
    }
}
项目:SMC-Android    文件:Sprite.java   
/**
 * @param originX , originY, rotation point relative to self
 */
private void rotate2(Rectangle sourceRect, Rectangle destRect, float originX, float originY, float rotate)
{
    float x = sourceRect.x;
    float y = sourceRect.y;
    float centerX = sourceRect.x + originX;
    float centerY = sourceRect.y + originY;
    float w = sourceRect.width;
    float h = sourceRect.height;

    Polygon polygon = new Polygon(new float[]{
            x, y,
            x, y + h,
            x + w, y + h,
            x + w, y
    });

    polygon.setOrigin(centerX, centerY);
    polygon.setRotation(rotate);
    destRect.set(polygon.getBoundingRectangle());
}
项目:Horses-in-Space    文件:Horse.java   
public Horse(TextureRegion horse, int width, int height, float weight,
        float posX, float posY) {
    super(horse, width, height, weight, posX, posY, AssetLoader.polyHorse);
    this.polyMap = new HashMap<TextureRegion, Polygon>();
    this.polyMap.put(AssetLoader.horse, AssetLoader.polyHorse);
    this.polyMap.put(AssetLoader.horse2, AssetLoader.polyHorse2);
    this.polyMap.put(AssetLoader.horse3, AssetLoader.polyHorse3);
    this.polyMap.put(AssetLoader.horseJump, AssetLoader.polyHorseJump);
    this.polyMap.put(AssetLoader.horseSlide, AssetLoader.polyHorseSlide);

    for (Polygon polygon : this.polyMap.values()) {
        polygon.setScale(0.15f, 0.16f);
        polygon.setPosition(posX, posY + 50);
    }
    this.polyMap.get(AssetLoader.horseSlide).setScale(0.15f, 0.12f);
}
项目:Horses-in-Space    文件:Physics.java   
/**
 * Constructor for class Physics
 *
 * @param width
 *            width of the object
 * @param height
 *            height of the object
 * @param weight
 *            weight of the object, used to offset jump height
 * @param posX
 *            position on screen, X axis
 * @param posY
 *            position on screen, Y axis
 */
public Physics(int width, int height, float weight, float posX, float posY,
        Polygon poly) {
    this.weight = weight;

    // Rectangle is used as an easier way to detect collisions in physEngine
    this.rect = new Rectangle(posX, posY + height, width, height);

    this.poly = poly;
    if (this.poly == null) {
        setPoly(Utilities.rectangleToPolygon(this.rect));
    }
    this.poly.setPosition(this.rect.x, this.rect.y);
    this.platform = false;

    this.position = new Vector2(posX, posY);
    this.velocity = new Vector2(0, 0);
    this.acceleration = new Vector2(0, this.weight);

}
项目:ead    文件:BoundingAreaBuilder.java   
private static boolean processRenderer(EngineEntity entity,
        Group sceneContentGroup, Group group, Vector2 x, Vector2 y) {
    boolean hasRenderer = false;
    Vector2 tmp = Pools.obtain(Vector2.class);
    for (Polygon polygon : getColliders(entity)) {
        for (int i = 0; i < polygon.getVertices().length; i += 2) {
            tmp.set(polygon.getVertices()[i], polygon.getVertices()[i + 1]);
            group.localToAscendantCoordinates(sceneContentGroup, tmp);
            x.set(Math.min(tmp.x, x.x), Math.max(tmp.x, x.y));
            y.set(Math.min(tmp.y, y.x), Math.max(tmp.y, y.y));
            hasRenderer = true;
        }
    }
    Pools.free(tmp);
    return hasRenderer;
}
项目:ead    文件:ImageProcessor.java   
protected void createCollider(Image image, ImageActor component) {
    Array<es.eucm.ead.schema.data.shape.Polygon> schemaCollider = image
            .getCollider();
    if (schemaCollider != null && schemaCollider.size > 0) {
        Array<Polygon> collider = new Array<Polygon>(schemaCollider.size);
        for (es.eucm.ead.schema.data.shape.Polygon polygon : schemaCollider) {
            Array<Float> pointsArray = polygon.getPoints();
            float[] points = new float[pointsArray.size];
            for (int i = 0; i < pointsArray.size; i++) {
                points[i] = pointsArray.get(i);
            }
            Polygon contour = new Polygon(points);
            collider.add(contour);
        }
        component.setCollider(collider);
    }
}
项目:ead    文件:GeometryUtils.java   
/**
 * Creates an n-sided regular polygon with the requested radius and location
 * 
 * @param sides
 *            count
 * @param radius
 *            distance from center to each vertex
 * @param location
 *            of center
 * @return resulting polygon
 */
public static Polygon createPoly(int sides, float radius, Vector2 location) {
    if (sides < 3 || radius <= 0) {
        throw new IllegalArgumentException(
                "negative radius or <3 sides not supported");
    }

    float[] vs = new float[sides * 2];
    double angle = 0;
    double angleDelta = Math.PI * 2 / (double) sides;
    for (int i = 0, j = 0; i < sides; i++, j += 2) {
        vs[j] = (float) (Math.cos(angle) * radius + location.x);
        vs[j + 1] = (float) (Math.sin(angle) * radius + location.y);
        angle += angleDelta;
    }

    return new Polygon(vs);
}
项目:ead    文件:GeometryUtils.java   
/**
 * Creates an n-sided star with the selected inner and outer radius and
 * location.
 * 
 * @param sides
 *            count
 * @param innerRadius
 *            distance from center to each inner vertex
 * @param outerRadius
 *            distance from center to each exterior vertex
 * @param location
 *            of center
 * @return resulting polygon
 */
public static Polygon createStar(int sides, float innerRadius,
        float outerRadius, Vector2 location) {
    if (sides < 3 || innerRadius <= 0 || outerRadius <= 0) {
        throw new IllegalArgumentException(
                "negative radius or <3 sides not supported");
    } else if (innerRadius > outerRadius) {
        throw new IllegalArgumentException(
                "inner radius should be <= outer radius");
    }
    float[] vs = new float[sides * 4];
    double angle = 0;
    double angleDelta = Math.PI / (double) sides;
    for (int i = 0, j = 0; i < sides; i++, j += 4) {
        vs[j] = (float) (Math.cos(angle) * innerRadius + location.x);
        vs[j + 1] = (float) (Math.sin(angle) * innerRadius + location.y);
        angle += angleDelta;
        vs[j + 2] = (float) (Math.cos(angle) * outerRadius + location.x);
        vs[j + 3] = (float) (Math.sin(angle) * outerRadius + location.y);
        angle += angleDelta;
    }

    return new Polygon(vs);
}