List of usage examples for com.badlogic.gdx.math Polygon setPosition
public void setPosition(float x, float y)
From source file:com.bladecoder.engine.actions.Param.java
License:Apache License
public static void parsePolygon(Polygon p, String v, String pos) { parsePolygon(p, v);//from www. j ava 2 s.co m Vector2 v2 = parseVector2(pos); p.setPosition(v2.x, v2.y); }
From source file:com.bladecoder.engine.loader.ChapterXMLLoader.java
License:Apache License
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { if (currentVerb != null) { // INSIDE VERB if (!localName.equals(XMLConstants.ACTION_TAG)) { SAXParseException e2 = new SAXParseException("TAG not supported inside VERB: " + localName, locator);/* ww w . j av a 2s.c o m*/ error(e2); throw e2; } parseAction(atts, actor != null ? actor.getId() : null); } else if (currentDialog != null) { // INSIDE DIALOG if (!localName.equals(XMLConstants.OPTION_TAG)) { SAXParseException e2 = new SAXParseException("Only 'option' tag allowed in dialogs", locator); error(e2); throw e2; } parseOption(atts); } else if (localName.equals(XMLConstants.ACTOR_TAG)) { parseActor(atts); } else if (localName.equals(XMLConstants.ANIMATION_TAG)) { parseAnimation(atts); } else if (localName.equals(XMLConstants.VERB_TAG)) { parseVerb(atts, actor != null ? ((InteractiveActor) actor).getVerbManager() : scene.getVerbManager()); } else if (localName.equals(XMLConstants.DIALOG_TAG)) { String id = atts.getValue(XMLConstants.ID_ATTR); currentDialog = new Dialog(); currentDialog.setId(id); currentDialog.setActor(actor.getId()); ((CharacterActor) actor).addDialog(currentDialog); } else if (localName.equals(XMLConstants.SOUND_TAG)) { parseSound(atts, (InteractiveActor) actor); } else if (localName.equals(XMLConstants.CHAPTER_TAG)) { initScene = atts.getValue(XMLConstants.INIT_SCENE_ATTR); } else if (localName.equals(XMLConstants.WALK_ZONE_TAG)) { PolygonalNavGraph polygonalPathFinder = new PolygonalNavGraph(); Polygon poly = new Polygon(); Param.parsePolygon(poly, atts.getValue(XMLConstants.POLYGON_ATTR), atts.getValue(XMLConstants.POS_ATTR)); poly.setScale(scale, scale); poly.setPosition(poly.getX() * scale, poly.getY() * scale); polygonalPathFinder.setWalkZone(poly); scene.setPolygonalNavGraph(polygonalPathFinder); } else if (localName.equals(XMLConstants.SCENE_TAG)) { parseScene(atts); } else if (localName.equals(XMLConstants.LAYER_TAG)) { parseLayer(atts); } else { // SAXParseException e = new SAXParseException("Wrong label '" // + localName + "' loading Scene.", locator); // error(e); // throw e; EngineLogger.error( "TAG not supported in Chapter document: " + localName + " LINE: " + locator.getLineNumber()); } }
From source file:com.bladecoder.engine.polygonalpathfinder.PolygonalNavGraph.java
License:Apache License
@Override public void write(Json json) { Polygon p = new Polygon(walkZone.getVertices()); p.setPosition(walkZone.getX() / walkZone.getScaleX(), walkZone.getY() / walkZone.getScaleY()); json.writeValue("walkZone", p); }
From source file:com.cafeitvn.myballgame.screen.Box2DMapObjectParser.java
License:Apache License
/** * creates a {@link Fixture} from a {@link MapObject} * @param mapObject the {@link MapObject} which to parse * @return the parsed {@link Fixture}/*www . ja v a2 s. c om*/ */ public Fixture createFixture(MapObject mapObject) { MapProperties properties = mapObject.getProperties(); String type = properties.get("type", String.class); Body body = bodies.get( type.equals(aliases.object) ? mapObject.getName() : properties.get(aliases.body, String.class)); if (!type.equals(aliases.fixture) && !type.equals(aliases.object)) throw new IllegalArgumentException("type of " + mapObject + " is \"" + type + "\" instead of \"" + aliases.fixture + "\" or \"" + aliases.object + "\""); FixtureDef fixtureDef = new FixtureDef(); Shape shape = null; if (mapObject instanceof RectangleMapObject) { shape = new PolygonShape(); Rectangle rectangle = ((RectangleMapObject) mapObject).getRectangle(); rectangle.x *= unitScale; rectangle.y *= unitScale; rectangle.width *= unitScale; rectangle.height *= unitScale; ((PolygonShape) shape).setAsBox(rectangle.width / 2, rectangle.height / 2, new Vector2(rectangle.x - body.getPosition().x + rectangle.width / 2, rectangle.y - body.getPosition().y + rectangle.height / 2), body.getAngle()); } else if (mapObject instanceof PolygonMapObject) { shape = new PolygonShape(); Polygon polygon = ((PolygonMapObject) mapObject).getPolygon(); polygon.setPosition(polygon.getX() * unitScale - body.getPosition().x, polygon.getY() * unitScale - body.getPosition().y); polygon.setScale(unitScale, unitScale); ((PolygonShape) shape).set(polygon.getTransformedVertices()); } else if (mapObject instanceof PolylineMapObject) { shape = new ChainShape(); Polyline polyline = ((PolylineMapObject) mapObject).getPolyline(); polyline.setPosition(polyline.getX() * unitScale - body.getPosition().x, polyline.getY() * unitScale - body.getPosition().y); polyline.setScale(unitScale, unitScale); ((ChainShape) shape).createChain(polyline.getTransformedVertices()); } else if (mapObject instanceof CircleMapObject) { shape = new CircleShape(); Circle circle = ((CircleMapObject) mapObject).getCircle(); circle.setPosition(circle.x * unitScale - body.getPosition().x, circle.y * unitScale - body.getPosition().y); circle.radius *= unitScale; ((CircleShape) shape).setPosition(new Vector2(circle.x, circle.y)); ((CircleShape) shape).setRadius(circle.radius); } else if (mapObject instanceof EllipseMapObject) { Ellipse ellipse = ((EllipseMapObject) mapObject).getEllipse(); if (ellipse.width == ellipse.height) { CircleMapObject circleMapObject = new CircleMapObject(ellipse.x, ellipse.y, ellipse.width / 2); circleMapObject.setName(mapObject.getName()); circleMapObject.getProperties().putAll(mapObject.getProperties()); circleMapObject.setColor(mapObject.getColor()); circleMapObject.setVisible(mapObject.isVisible()); circleMapObject.setOpacity(mapObject.getOpacity()); return createFixture(circleMapObject); } IllegalArgumentException exception = new IllegalArgumentException( "Cannot parse " + mapObject.getName() + " because " + mapObject.getClass().getSimpleName() + "s that are not circles are not supported"); Gdx.app.error(getClass().getSimpleName(), exception.getMessage(), exception); throw exception; } else if (mapObject instanceof TextureMapObject) { IllegalArgumentException exception = new IllegalArgumentException("Cannot parse " + mapObject.getName() + " because " + mapObject.getClass().getSimpleName() + "s are not supported"); Gdx.app.error(getClass().getSimpleName(), exception.getMessage(), exception); throw exception; } else assert false : mapObject + " is a not known subclass of " + MapObject.class.getName(); fixtureDef.shape = shape; fixtureDef.density = (Float) getProperty(properties, aliases.density, fixtureDef.density, Float.class); fixtureDef.filter.categoryBits = (Short) getProperty(properties, aliases.categoryBits, fixtureDef.filter.categoryBits, Short.class); fixtureDef.filter.groupIndex = (Short) getProperty(properties, aliases.groupIndex, fixtureDef.filter.groupIndex, Short.class); fixtureDef.filter.maskBits = (Short) getProperty(properties, aliases.maskBits, fixtureDef.filter.maskBits, Short.class); fixtureDef.friction = (Float) getProperty(properties, aliases.friciton, fixtureDef.friction, Float.class); fixtureDef.isSensor = (Boolean) getProperty(properties, aliases.isSensor, fixtureDef.isSensor, Boolean.class); fixtureDef.restitution = (Float) getProperty(properties, aliases.restitution, fixtureDef.restitution, Float.class); Fixture fixture = body.createFixture(fixtureDef); shape.dispose(); String name = mapObject.getName(); if (fixtures.containsKey(name)) { int duplicate = 1; while (fixtures.containsKey(name + duplicate)) duplicate++; name += duplicate; } fixtures.put(name, fixture); return fixture; }
From source file:com.kotcrab.vis.runtime.entity.TextEntity.java
License:Apache License
private void calculateBoundingRectangle() { Polygon polygon = new Polygon(new float[] { 0, 0, textLayout.width, 0, textLayout.width, textLayout.height, 0, textLayout.height });/*from w w w .j a va 2 s .c om*/ polygon.setPosition(x, y); polygon.setRotation(rotation); polygon.setScale(scaleX, scaleY); polygon.setOrigin(originX, originY); boundingRectangle = polygon.getBoundingRectangle(); }
From source file:com.rubentxu.juegos.core.utils.dermetfan.box2d.Box2DMapObjectParser.java
License:Apache License
/** * creates a {@link Fixture} from a {@link MapObject} * * @param mapObject the {@link MapObject} to parse * @return the parsed {@link Fixture}//from w w w.j a v a 2 s .c om */ public Fixture createFixture(MapObject mapObject) { MapProperties properties = mapObject.getProperties(); String type = properties.get("type", String.class); Body body = bodies.get( type.equals(aliases.object) ? mapObject.getName() : properties.get(aliases.body, String.class)); if (!type.equals(aliases.fixture) && !type.equals(aliases.object)) throw new IllegalArgumentException("type of " + mapObject + " is \"" + type + "\" instead of \"" + aliases.fixture + "\" or \"" + aliases.object + "\""); FixtureDef fixtureDef = new FixtureDef(); Shape shape = null; if (mapObject instanceof RectangleMapObject) { shape = new PolygonShape(); Rectangle rectangle = new Rectangle(((RectangleMapObject) mapObject).getRectangle()); rectangle.x *= unitScale; rectangle.y *= unitScale; rectangle.width *= unitScale; rectangle.height *= unitScale; ((PolygonShape) shape).setAsBox(rectangle.width / 2, rectangle.height / 2, new Vector2(rectangle.x - body.getPosition().x + rectangle.width / 2, rectangle.y - body.getPosition().y + rectangle.height / 2), body.getAngle()); } else if (mapObject instanceof PolygonMapObject) { shape = new PolygonShape(); Polygon polygon = ((PolygonMapObject) mapObject).getPolygon(); polygon.setPosition(polygon.getX() * unitScale - body.getPosition().x, polygon.getY() * unitScale - body.getPosition().y); polygon.setScale(unitScale, unitScale); ((PolygonShape) shape).set(polygon.getTransformedVertices()); } else if (mapObject instanceof PolylineMapObject) { shape = new ChainShape(); Polyline polyline = ((PolylineMapObject) mapObject).getPolyline(); polyline.setPosition(polyline.getX() * unitScale - body.getPosition().x, polyline.getY() * unitScale - body.getPosition().y); polyline.setScale(unitScale, unitScale); float[] vertices = polyline.getTransformedVertices(); Vector2[] vectores = new Vector2[vertices.length / 2]; for (int i = 0, j = 0; i < vertices.length; i += 2, j++) { vectores[j].x = vertices[i]; vectores[j].y = vertices[i + 1]; } ((ChainShape) shape).createChain(vectores); } else if (mapObject instanceof CircleMapObject) { shape = new CircleShape(); Circle circle = ((CircleMapObject) mapObject).getCircle(); circle.setPosition(circle.x * unitScale - body.getPosition().x, circle.y * unitScale - body.getPosition().y); circle.radius *= unitScale; ((CircleShape) shape).setPosition(new Vector2(circle.x, circle.y)); ((CircleShape) shape).setRadius(circle.radius); } else if (mapObject instanceof EllipseMapObject) { Ellipse ellipse = ((EllipseMapObject) mapObject).getEllipse(); /* b2ChainShape* chain = (b2ChainShape*)addr; b2Vec2* verticesOut = new b2Vec2[numVertices]; for( int i = 0; i < numVertices; i++ ) verticesOut[i] = b2Vec2(verts[i<<1], verts[(i<<1)+1]); chain->CreateChain( verticesOut, numVertices ); delete verticesOut; */ if (ellipse.width == ellipse.height) { CircleMapObject circleMapObject = new CircleMapObject(ellipse.x, ellipse.y, ellipse.width / 2); circleMapObject.setName(mapObject.getName()); circleMapObject.getProperties().putAll(mapObject.getProperties()); circleMapObject.setColor(mapObject.getColor()); circleMapObject.setVisible(mapObject.isVisible()); circleMapObject.setOpacity(mapObject.getOpacity()); return createFixture(circleMapObject); } IllegalArgumentException exception = new IllegalArgumentException( "Cannot parse " + mapObject.getName() + " because that are not circles are not supported"); Gdx.app.error(getClass().getName(), exception.getMessage(), exception); throw exception; } else if (mapObject instanceof TextureMapObject) { IllegalArgumentException exception = new IllegalArgumentException( "Cannot parse " + mapObject.getName() + " because s are not supported"); Gdx.app.error(getClass().getName(), exception.getMessage(), exception); throw exception; } else assert false : mapObject + " is a not known subclass of " + MapObject.class.getName(); fixtureDef.shape = shape; fixtureDef.density = getProperty(properties, aliases.density, fixtureDef.density); fixtureDef.filter.categoryBits = getProperty(properties, aliases.categoryBits, GRUPO.STATIC.getCategory()); fixtureDef.filter.groupIndex = getProperty(properties, aliases.groupIndex, fixtureDef.filter.groupIndex); fixtureDef.filter.maskBits = getProperty(properties, aliases.maskBits, Box2DPhysicsObject.MASK_STATIC); fixtureDef.friction = getProperty(properties, aliases.friciton, fixtureDef.friction); fixtureDef.isSensor = getProperty(properties, aliases.isSensor, fixtureDef.isSensor); fixtureDef.restitution = getProperty(properties, aliases.restitution, fixtureDef.restitution); Fixture fixture = body.createFixture(fixtureDef); fixture.setUserData(body.getUserData()); shape.dispose(); String name = mapObject.getName(); if (fixtures.containsKey(name)) { int duplicate = 1; while (fixtures.containsKey(name + duplicate)) duplicate++; name += duplicate; } fixtures.put(name, fixture); return fixture; }
From source file:de.bitowl.advent.game2.MyAtlasTmxMapLoader.java
License:Apache License
protected void loadObject(MapLayer layer, Element element) { if (element.getName().equals("object")) { MapObject object = null;//from w w w . j av a 2s .c o m float scaleX = convertObjectToTileSpace ? 1.0f / mapTileWidth : 1.0f; float scaleY = convertObjectToTileSpace ? 1.0f / mapTileHeight : 1.0f; float x = element.getIntAttribute("x", 0) * scaleX; float y = (yUp ? mapHeightInPixels - element.getIntAttribute("y", 0) : element.getIntAttribute("y", 0)) * scaleY; float width = element.getIntAttribute("width", 0) * scaleX; float height = element.getIntAttribute("height", 0) * scaleY; if (element.getChildCount() > 0) { Element child = null; if ((child = element.getChildByName("polygon")) != null) { String[] points = child.getAttribute("points").split(" "); float[] vertices = new float[points.length * 2]; for (int i = 0; i < points.length; i++) { String[] point = points[i].split(","); vertices[i * 2] = Integer.parseInt(point[0]) * scaleX; vertices[i * 2 + 1] = Integer.parseInt(point[1]) * scaleY; if (yUp) { vertices[i * 2 + 1] *= -1; } } Polygon polygon = new Polygon(vertices); polygon.setPosition(x, y); object = new PolygonMapObject(polygon); } else if ((child = element.getChildByName("polyline")) != null) { String[] points = child.getAttribute("points").split(" "); float[] vertices = new float[points.length * 2]; for (int i = 0; i < points.length; i++) { String[] point = points[i].split(","); vertices[i * 2] = Integer.parseInt(point[0]) * scaleX; vertices[i * 2 + 1] = Integer.parseInt(point[1]) * scaleY; if (yUp) { vertices[i * 2 + 1] *= -1; } } Polyline polyline = new Polyline(vertices); polyline.setPosition(x, y); object = new PolylineMapObject(polyline); } else if ((child = element.getChildByName("ellipse")) != null) { object = new EllipseMapObject(x, yUp ? y - height : y, width, height); } } if (object == null) { object = new RectangleMapObject(x, yUp ? y - height : y, width, height); } object.setName(element.getAttribute("name", null)); String type = element.getAttribute("type", null); if (type != null) { object.getProperties().put("type", type); } int gid = element.getIntAttribute("gid", -1); if (gid != -1) { object.getProperties().put("gid", gid); } object.getProperties().put("x", x * scaleX); object.getProperties().put("y", (yUp ? y - height : y) * scaleY); object.setVisible(element.getIntAttribute("visible", 1) == 1); Element properties = element.getChildByName("properties"); if (properties != null) { loadProperties(object.getProperties(), properties); } layer.getObjects().add(object); } }
From source file:de.hasait.tanks.app.common.model.AbstractGameObject.java
License:Apache License
public final Polygon createBounds(final S pState) { final float w2 = _width / 2.0f; final float h2 = _height / 2.0f; final Polygon bounds = new Polygon(new float[] { -w2, h2, w2, h2, w2, -h2, -w2, -h2 }); bounds.setPosition(pState._centerX, pState._centerY); bounds.setRotation(pState._rotation); return bounds; }
From source file:net.dermetfan.utils.libgdx.box2d.Box2DMapObjectParser.java
License:Apache License
/** creates a {@link Fixture} from a {@link MapObject} * @param mapObject the {@link MapObject} to parse * @param body the {@link Body} to create the {@link Fixture Fixtures} on * @return the parsed {@link Fixture} */ public Fixture createFixture(MapObject mapObject, Body body) { MapProperties properties = mapObject.getProperties(); Shape shape = null;/*from ww w . java2s. c om*/ if (mapObject instanceof RectangleMapObject) { shape = new PolygonShape(); Rectangle rectangle = ((RectangleMapObject) mapObject).getRectangle(); float x = rectangle.x * unitScale, y = rectangle.y * unitScale, width = rectangle.width * unitScale, height = rectangle.height * unitScale; ((PolygonShape) shape).setAsBox(width / 2, height / 2, vec2.set(x - body.getPosition().x + width / 2, y - body.getPosition().y + height / 2), body.getAngle()); } else if (mapObject instanceof PolygonMapObject) { shape = new PolygonShape(); Polygon polygon = new Polygon(((PolygonMapObject) mapObject).getPolygon().getTransformedVertices()); polygon.setScale(unitScale, unitScale); polygon.setPosition(-body.getPosition().x, -body.getPosition().y); ((PolygonShape) shape).set(polygon.getTransformedVertices()); } else if (mapObject instanceof PolylineMapObject) { shape = new ChainShape(); Polyline polyline = new Polyline( ((PolylineMapObject) mapObject).getPolyline().getTransformedVertices()); polyline.setPosition(polyline.getX() * unitScale - body.getPosition().x, polyline.getY() * unitScale - body.getPosition().y); polyline.setScale(unitScale, unitScale); ((ChainShape) shape).createChain(polyline.getTransformedVertices()); } else if (mapObject instanceof CircleMapObject) { shape = new CircleShape(); Circle mapObjectCircle = ((CircleMapObject) mapObject).getCircle(); Circle circle = new Circle(mapObjectCircle.x, mapObjectCircle.y, mapObjectCircle.radius); circle.setPosition(circle.x * unitScale - body.getPosition().x, circle.y * unitScale - body.getPosition().y); circle.radius *= unitScale; CircleShape circleShape = (CircleShape) shape; circleShape.setPosition(vec2.set(circle.x, circle.y)); circleShape.setRadius(circle.radius); } else if (mapObject instanceof EllipseMapObject) { Ellipse ellipse = ((EllipseMapObject) mapObject).getEllipse(); if (ellipse.width == ellipse.height) { CircleMapObject circleMapObject = new CircleMapObject(ellipse.x + ellipse.width / 2, ellipse.y + ellipse.height / 2, ellipse.width / 2); circleMapObject.setName(mapObject.getName()); circleMapObject.getProperties().putAll(mapObject.getProperties()); circleMapObject.setColor(mapObject.getColor()); circleMapObject.setVisible(mapObject.isVisible()); circleMapObject.setOpacity(mapObject.getOpacity()); return createFixture(circleMapObject, body); } throw new IllegalArgumentException("Cannot parse " + mapObject.getName() + " because " + mapObject.getClass().getSimpleName() + "s that are not circles are not supported"); } else if (mapObject instanceof TextureMapObject) throw new IllegalArgumentException("Cannot parse " + mapObject.getName() + " because " + mapObject.getClass().getSimpleName() + "s are not supported"); else assert false : mapObject + " is a not known subclass of " + MapObject.class.getName(); FixtureDef fixtureDef = new FixtureDef(); fixtureDef.shape = shape; assignProperties(fixtureDef, heritage); assignProperties(fixtureDef, mapProperties); assignProperties(fixtureDef, layerProperties); assignProperties(fixtureDef, properties); Fixture fixture = body.createFixture(fixtureDef); fixture.setUserData(getProperty(layerProperties, aliases.userData, fixture.getUserData())); fixture.setUserData(getProperty(properties, aliases.userData, fixture.getUserData())); shape.dispose(); fixtures.put(findAvailableName(mapObject.getName(), fixtures), fixture); return fixture; }
From source file:org.bladecoder.bladeengine.actions.Param.java
License:Apache License
public static Polygon parsePolygon(String v, String pos) { Polygon p = parsePolygon(v); Vector2 v2 = parseVector2(pos); p.setPosition(v2.x, v2.y); return p;/*from w ww . j a va 2s . c om*/ }