/** Returns whether an x, y pair is contained within the polygon. */ @Override public boolean contains (float x, float y) { final float[] vertices = getTransformedVertices(); final int numFloats = vertices.length; int intersects = 0; for (int i = 0; i < numFloats; i += 2) { float x1 = vertices[i]; float y1 = vertices[i + 1]; float x2 = vertices[(i + 2) % numFloats]; float y2 = vertices[(i + 3) % numFloats]; if (((y1 <= y && y < y2) || (y2 <= y && y < y1)) && x < ((x2 - x1) / (y2 - y1) * (y - y1) + x1)) intersects++; } return (intersects & 1) == 1; }
Polygon polygon = new Polygon(vertices); Polygon tmpPoly = new Polygon(); Polygon intersectionPoly = new Polygon(); EarClippingTriangulator triangulator = new EarClippingTriangulator(); Rectangle boundRect = polygon.getBoundingRectangle(); verts[idx++] = (col+1) * gridWidth; verts[idx] = (row) * gridHeight; tmpPoly.setVertices(verts); verts = intersectionPoly.getVertices(); if(verts.length > 0) { parts.add(snapToGrid(verts));
@Override public boolean contains (Vector2 point) { return contains(point.x, point.y); }
if (p1.getVertices().length == 0 || p2.getVertices().length == 0) { return false; floatArray2.addAll(p1.getTransformedVertices()); for (int i = 0; i < p2.getTransformedVertices().length; i += 2) { ep1.set(p2.getTransformedVertices()[i], p2.getTransformedVertices()[i + 1]); if (i < p2.getTransformedVertices().length - 2) { ep2.set(p2.getTransformedVertices()[i + 2], p2.getTransformedVertices()[i + 3]); } else { ep2.set(p2.getTransformedVertices()[0], p2.getTransformedVertices()[1]); if (overlap.getVertices().length == floatArray2.size) System.arraycopy(floatArray2.items, 0, overlap.getVertices(), 0, floatArray2.size); else overlap.setVertices(floatArray2.toArray());
private void computeBbox() { if (bbox == null) return; if (bbox.getVertices() == null || bbox.getVertices().length != 8) { bbox.setVertices(new float[8]); } float[] verts = bbox.getVertices(); verts[0] = -getWidth() / 2; verts[1] = 0f; verts[2] = -getWidth() / 2; verts[3] = getHeight(); verts[4] = getWidth() / 2; verts[5] = getHeight(); verts[6] = getWidth() / 2; verts[7] = 0f; bbox.dirty(); }
walkZonePol.setScale(worldScale, worldScale); walkZonePol.setPosition(walkZonePol.getX() * worldScale, walkZonePol.getY() * worldScale); wz.bbox.setVertices(walkZonePol.getVertices()); wz.bbox.setScale(walkZonePol.getScaleX(), walkZonePol.getScaleY()); wz.bbox.setPosition(walkZonePol.getX(), walkZonePol.getY()); wz.setScene(this); wz.setInitScene(id);
o.getPolygon().getVertices() ); offsetMt.set(o.getPolygon().getX(), o.getPolygon().getY()); offsetMt.set(Convert.px2mt(offsetMt)); Polygon p = new Polygon(vertices); Rectangle r = p.getBoundingRectangle(); float oX = r.x + r.width / 2; float oY = r.y + r.height / 2; p.setOrigin(oX, oY);
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); }
actor.getBBox().getBoundingRectangle().getCenter(unproject2Tmp);
drawer.polygon(p.getTransformedVertices()); } else if (a instanceof InteractiveActor) { InteractiveActor iActor = (InteractiveActor) a; if (p.getTransformedVertices().length > 2) drawer.polygon(p.getTransformedVertices()); } else if (a instanceof WalkZoneActor) { drawer.setColor(Scene.WALKZONE_COLOR); if (p.getTransformedVertices().length > 2) drawer.polygon(p.getTransformedVertices()); } else if (a instanceof AnchorActor) { drawer.setColor(Scene.ANCHOR_COLOR); drawer.line(p.getX() - Scene.ANCHOR_RADIUS, p.getY(), p.getX() + Scene.ANCHOR_RADIUS, p.getY()); drawer.line(p.getX(), p.getY() - Scene.ANCHOR_RADIUS, p.getX(), p.getY() + Scene.ANCHOR_RADIUS);
@Override public void write(Json json) { BladeJson bjson = (BladeJson) json; if (bjson.getMode() == Mode.MODEL) { PolygonUtils.ensureClockWise(bbox.getVertices(), 0, bbox.getVertices().length); bbox.dirty(); } super.write(json); } }
vertices[i * 2 + 1] = Float.parseFloat(point[1]) * scaleY * (flipY ? -1 : 1); Polygon polygon = new Polygon(vertices); polygon.setPosition(x, y); object = new PolygonMapObject(polygon); } else if ((child = element.getChildByName("polyline")) != null) {
public static void deletePoint(Polygon poly, int index) { float verts[] = poly.getVertices(); if (verts.length < 8) return; int length = verts.length; float destination[] = new float[length - 2]; // index = index * 2; System.arraycopy(verts, 0, destination, 0, index); System.arraycopy(verts, index + 2, destination, index, length - index - 2); poly.setVertices(destination); }
Rectangle rect = p.getBoundingRectangle(); float verts[] = selectedActor.getBBox().getTransformedVertices(); for (int i = 0; i < verts.length; i += 2) drawer.rect(verts[i] - CORNER_DIST / 2, verts[i + 1] - CORNER_DIST / 2, CORNER_DIST, CORNER_DIST);
float verts[] = bbox.getTransformedVertices(); for (int i = 0; i < verts.length; i += 2) { if (p.dst(verts[i], verts[i + 1]) < CanvasDrawer.CORNER_DIST) { vertIndex = i; float v[] = bbox.getVertices(); undoOrg.set(v[i], v[i + 1]); return true;
@Override public void write(Json json) { BladeJson bjson = (BladeJson) json; if (bjson.getMode() == Mode.MODEL) { json.writeValue("id", id); json.writeValue("bbox", bbox.getVertices()); } else { } float worldScale = EngineAssetManager.getInstance().getScale(); Vector2 scaledPos = new Vector2(bbox.getX() / worldScale, bbox.getY() / worldScale); json.writeValue("pos", scaledPos); json.writeValue("visible", visible); }
@Override public void read(Json json, JsonValue jsonData) { BladeJson bjson = (BladeJson) json; if (bjson.getMode() == Mode.MODEL) { id = json.readValue("id", String.class, jsonData); float[] verts = json.readValue("bbox", float[].class, jsonData); if (verts.length > 0) bbox.setVertices(verts); } else { } Vector2 pos = json.readValue("pos", Vector2.class, jsonData); if (pos != null) { float worldScale = EngineAssetManager.getInstance().getScale(); bbox.setPosition(pos.x * worldScale, pos.y * worldScale); bbox.setScale(worldScale, worldScale); visible = json.readValue("visible", boolean.class, visible, jsonData); } } }
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("\nObject: ").append(id); sb.append("\n Visible: ").append(visible); sb.append("\n Pos: ").append(getBBox().getX() + " , " + getBBox().getY()); sb.append("\n Scale: ").append(getBBox().getScaleX()); sb.append("\n"); return sb.toString(); }
public void setPosition(float x, float y) { bbox.setPosition(x, y); }