List of usage examples for com.badlogic.gdx.math Polygon translate
public void translate(float x, float y)
From source file:com.agateau.pixelwheels.vehicledef.VehicleIO.java
License:Open Source License
private static Shape2D loadShape(XmlReader.Element element, float vehicleWidth, float vehicleHeight) { String type = element.getName(); if (type.equals("octogon")) { float width = element.getFloatAttribute("height"); float height = element.getFloatAttribute("width"); float x = element.getFloatAttribute("y", (vehicleWidth - width) / 2); float y = element.getFloatAttribute("x", (vehicleHeight - height) / 2); float corner = element.getFloatAttribute("corner", 0); Polygon polygon = new Polygon(); polygon.setVertices(new float[] { width / 2 - corner, -height / 2, width / 2, -height / 2 + corner, width / 2, height / 2 - corner, width / 2 - corner, height / 2, -width / 2 + corner, height / 2, -width / 2, height / 2 - corner, -width / 2, -height / 2 + corner, -width / 2 + corner, -height / 2 });/*ww w . ja v a 2 s .c om*/ polygon.translate(x - (vehicleWidth - width) / 2, y - (vehicleHeight - height) / 2); return polygon; } else if (type.equals("trapezoid")) { float bottomHeight = element.getFloatAttribute("bottomWidth"); float topHeight = element.getFloatAttribute("topWidth"); float height = Math.max(bottomHeight, topHeight); float width = element.getFloatAttribute("height"); float x = element.getFloatAttribute("y", (vehicleWidth - width) / 2); float y = element.getFloatAttribute("x", (vehicleHeight - height) / 2); Polygon polygon = new Polygon(); polygon.setVertices(new float[] { width / 2, topHeight / 2, -width / 2, bottomHeight / 2, -width / 2, -bottomHeight / 2, width / 2, -topHeight / 2, }); polygon.translate(x - (vehicleWidth - width) / 2, y - (vehicleHeight - height) / 2); return polygon; } else { throw new RuntimeException("Unknown shape type: " + element); } }
From source file:com.bladecoder.engineeditor.scneditor.ScnWidgetInputListener.java
License:Apache License
@Override public void touchDragged(InputEvent event, float x, float y, int pointer) { // EditorLogger.debug("Touch Dragged - X: " + Gdx.input.getX() + " Y: " // + Gdx.input.getY()); super.touchDragged(event, x, y, pointer); if (Gdx.input.isButtonPressed(Buttons.LEFT)) { Scene scn = scnWidget.getScene(); if (scn == null) return; Vector2 d = new Vector2(Gdx.input.getX(), Gdx.input.getY()); scnWidget.screenToWorldCoords(d); d.sub(org);/*from w w w.j a v a 2s .c o m*/ org.add(d); if (draggingMode == DraggingModes.DRAGGING_ACTOR) { selActor.setPosition(selActor.getX() + d.x, selActor.getY() + d.y); Ctx.project.setModified(this, Project.POSITION_PROPERTY, null, selActor); } else if (draggingMode == DraggingModes.DRAGGING_BBOX_POINT) { Polygon poly = selActor.getBBox(); float verts[] = poly.getVertices(); verts[vertIndex] += d.x; verts[vertIndex + 1] += d.y; poly.dirty(); Ctx.project.setModified(); } else if (draggingMode == DraggingModes.DRAGGING_WALKZONE_POINT) { Polygon poly = scn.getPolygonalNavGraph().getWalkZone(); float verts[] = poly.getVertices(); verts[vertIndex] += d.x; verts[vertIndex + 1] += d.y; poly.dirty(); Ctx.project.setModified(); } else if (draggingMode == DraggingModes.DRAGGING_WALKZONE) { Polygon poly = scn.getPolygonalNavGraph().getWalkZone(); poly.translate(d.x, d.y); } else if (draggingMode == DraggingModes.DRAGGING_MARKER_0) { Vector2 depthVector = scnWidget.getScene().getDepthVector(); depthVector.x += d.y; Ctx.project.setModified(); updateFakeDepth(); } else if (draggingMode == DraggingModes.DRAGGING_MARKER_100) { Vector2 depthVector = scnWidget.getScene().getDepthVector(); depthVector.y += d.y; Ctx.project.setModified(); updateFakeDepth(); } } else if (Gdx.input.isButtonPressed(Buttons.RIGHT) || Gdx.input.isButtonPressed(Buttons.MIDDLE)) { Vector2 p = new Vector2(Gdx.input.getX(), Gdx.input.getY()); scnWidget.screenToWorldCoords(p); p.sub(org); scnWidget.translate(p); } }
From source file:org.catrobat.catroid.content.Look.java
License:Open Source License
public Polygon[] getCurrentCollisionPolygon() { Polygon[] originalPolygons;//from w ww . j a v a2 s . c o m if (getLookData() == null) { originalPolygons = new Polygon[0]; } else { if (getLookData().getCollisionInformation().collisionPolygons == null) { getLookData().getCollisionInformation().loadOrCreateCollisionPolygon(); } originalPolygons = getLookData().getCollisionInformation().collisionPolygons; } Polygon[] transformedPolygons = new Polygon[originalPolygons.length]; for (int p = 0; p < transformedPolygons.length; p++) { Polygon poly = new Polygon(originalPolygons[p].getTransformedVertices()); poly.translate(getX(), getY()); poly.setRotation(getRotation()); poly.setScale(getScaleX(), getScaleY()); poly.setOrigin(getOriginX(), getOriginY()); transformedPolygons[p] = poly; } return transformedPolygons; }