当前位置: 首页>>代码示例>>Java>>正文


Java Polygon.getVertices方法代码示例

本文整理汇总了Java中com.badlogic.gdx.math.Polygon.getVertices方法的典型用法代码示例。如果您正苦于以下问题:Java Polygon.getVertices方法的具体用法?Java Polygon.getVertices怎么用?Java Polygon.getVertices使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.badlogic.gdx.math.Polygon的用法示例。


在下文中一共展示了Polygon.getVertices方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getPolygon

import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
/**
 * 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
}
 
开发者ID:Benjozork,项目名称:Onyx,代码行数:27,代码来源:PolygonLoader.java

示例2: addPoint

import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
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);
}
 
开发者ID:bladecoder,项目名称:bladecoder-adventure-engine,代码行数:17,代码来源:PolygonUtils.java

示例3: processRenderer

import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
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;
}
 
开发者ID:e-ucm,项目名称:ead,代码行数:17,代码来源:BoundingAreaBuilder.java

示例4: updateWidthAndHeight

import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
private void updateWidthAndHeight() {
	if (getCollider() != null) {
		float minX = Float.MAX_VALUE, maxX = Float.MIN_VALUE, minY = Float.MAX_VALUE, maxY = Float.MIN_VALUE;
		for (Polygon polygon : getCollider()) {
			for (int i = 0; i < polygon.getVertices().length; i++) {
				if (i % 2 == 0) {
					minX = Math.min(minX, polygon.getVertices()[i]);
					maxX = Math.max(maxX, polygon.getVertices()[i]);
				} else {
					minY = Math.min(minY, polygon.getVertices()[i]);
					maxY = Math.max(maxY, polygon.getVertices()[i]);
				}
			}
		}
		setWidth(maxX - minX);
		setHeight(maxY - minY);
	}
}
 
开发者ID:e-ucm,项目名称:ead,代码行数:19,代码来源:EmptyActor.java

示例5: drawCollider

import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
protected void drawCollider(Batch batch) {
	if (getCollider() != null) {
		batch.end();
		Gdx.gl.glEnable(GL20.GL_BLEND);
		Gdx.gl.glBlendFunc(GL20.GL_ONE, GL20.GL_DST_COLOR);
		Gdx.gl.glBlendEquation(GL20.GL_FUNC_SUBTRACT);
		shapeRenderer.setProjectionMatrix(batch.getProjectionMatrix());
		shapeRenderer.setTransformMatrix(batch.getTransformMatrix());
		shapeRenderer.begin(ShapeType.Line);
		shapeRenderer.setColor(Color.WHITE);
		for (Polygon polygon : getCollider()) {
			float[] vertices = polygon.getVertices();
			shapeRenderer.polygon(vertices);
		}
		shapeRenderer.end();
		Gdx.gl.glBlendEquation(GL20.GL_FUNC_ADD);
		Gdx.gl.glDisable(GL20.GL_BLEND);
		batch.begin();
	}
}
 
开发者ID:e-ucm,项目名称:ead,代码行数:21,代码来源:EditorImageActor.java

示例6: setWidth

import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
/**
 * Used to set the width of a rectangular polygon
 *
 * @param p     polygon whose width is to be set
 * @param width new width for the polygon
 */
public static void setWidth(Polygon p, float width) {
    float vals[] = p.getVertices();
    vals[2] = vals[0] + width;
    vals[4] = vals[0] + width;
    p.setVertices(vals);
}
 
开发者ID:Benjozork,项目名称:Onyx,代码行数:13,代码来源:PolygonHelper.java

示例7: setHeight

import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
/**
 * Used to set the height of a rectangular polygon
 *
 * @param p      polygon whose width is to be set
 * @param height new height for the polygonial
 */
public static void setHeight(Polygon p, float height) {
    float vals[] = p.getVertices();
    vals[5] = vals[1] + height;
    vals[7] = vals[1] + height;
    p.setVertices(vals);
}
 
开发者ID:Benjozork,项目名称:Onyx,代码行数:13,代码来源:PolygonHelper.java

示例8: setDimensions

import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
/**
 * Used to set the dimensions of the rectangular polygon
 *
 * @param p      polygon whose dimensions are to be set
 * @param width  the width to be used
 * @param height the height to be used
 */
public static void setDimensions(Polygon p, float width, float height) {
    float vals[] = p.getVertices();
    vals[5] = vals[1] + height;
    vals[7] = vals[1] + height;
    vals[2] = vals[0] + width;
    vals[4] = vals[0] + width;
    p.setVertices(vals);
}
 
开发者ID:Benjozork,项目名称:Onyx,代码行数:16,代码来源:PolygonHelper.java

示例9: drawPolygon

import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
public static void drawPolygon(Polygon polygon, Matrix4 projectionMatrix)
{
	
	Gdx.gl.glLineWidth(2);
	debugRenderer.setProjectionMatrix(projectionMatrix);
	debugRenderer.begin(ShapeRenderer.ShapeType.Line);
	
	debugRenderer.setColor(Color.RED);
	float[] vertices = polygon.getVertices();
    for(int i=0; i<vertices.length; i+=2){
    	debugRenderer.line(vertices[i], vertices[i+1], vertices[(i+2)%vertices.length], vertices[(i+3)%vertices.length]);
    }
	debugRenderer.end();
	Gdx.gl.glLineWidth(1);
}
 
开发者ID:Mignet,项目名称:Inspiration,代码行数:16,代码来源:DebugMarker.java

示例10: toStringParam

import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
public static String toStringParam(Polygon p) {
	StringBuilder sb = new StringBuilder();
	float[] verts = p.getVertices();

	sb.append(verts[0]);

	for (int i = 1; i < verts.length; i++) {
		sb.append(NUMBER_PARAM_SEPARATOR);
		sb.append(verts[i]);
	}

	return sb.toString();
}
 
开发者ID:bladecoder,项目名称:bladecoder-adventure-engine,代码行数:14,代码来源:Param.java

示例11: polygonGround

import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
private static void polygonGround(MapObject object, Map map, Box2DWorld world, Matrix4 transformMat4) {
    PolygonMapObject polyObject = (PolygonMapObject)object;
    Polygon polygon = new Polygon(polyObject.getPolygon().getTransformedVertices());
    polygon.setScale(world.WORLD_TO_BOX, world.WORLD_TO_BOX);

    Vector3 tempVec3 = new Vector3();

    // Transform each vertex by transformation matrix
    for(int ix = 0, iy = 1; iy < polygon.getVertices().length; ix += 2, iy += 2) {
        tempVec3.set(polygon.getVertices()[ix], polygon.getVertices()[iy], 0);
        tempVec3.mul(transformMat4);
        polygon.getVertices()[ix] = tempVec3.x;// - body.getPosition().x;
        polygon.getVertices()[iy] = tempVec3.y;// - body.getPosition().y;
    }

    Polygon[] convexPolygons = GeometryUtils.decompose(polygon);

    BodyDef bd = new BodyDef();
    bd.type = BodyDef.BodyType.StaticBody;
    bd.fixedRotation = true;
    Body body = world.getWorld().createBody(bd);

    for(Polygon convexPolygon : convexPolygons) {
        FixtureDef fixtureDef = new FixtureDef();
        fixtureDef.density = 1f;
        fixtureDef.friction = 0.0f;
        fixtureDef.restitution = 0.0f;

        PolygonShape shape = new PolygonShape();

        shape.set(convexPolygon.getTransformedVertices());
        fixtureDef.shape = shape;

        body.createFixture(fixtureDef);
    }

    body.setUserData(map);
}
 
开发者ID:lukz,项目名称:Simple-Isometric-Game,代码行数:39,代码来源:MapProcessor.java

示例12: getBoundingCircle

import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
/**
 * Creates a minimum circle that contains the given entity. The algorithm
 * takes into account renderers' colliders (if available) and children. The
 * algorithm uses {@link #getBoundingPolygon(EngineEntity, Group, Group)}
 * and then calculates radius and center by finding the pair of vertex with
 * longest distance.
 * 
 * @param entity
 *            The entity to build a bounding circle for.
 * @return The bounding circle, in coordinates of the
 *         {@link Layer#SCENE_CONTENT} layer. May return {@code null} if
 *         this entity is not a descendant of {@link Layer#SCENE_CONTENT}.
 */
public static CircleWrapper getBoundingCircle(EngineEntity entity) {
	Polygon pol = getBoundingPolygon(entity);
	// Calculate pair of vertex with longest distance
	Vector2 center = Pools.obtain(Vector2.class);
	float maxDistance = Float.NEGATIVE_INFINITY;
	for (int i = 0; i < pol.getVertices().length; i += 2) {
		Vector2 vertex1 = Pools.obtain(Vector2.class);
		Vector2 vertex2 = Pools.obtain(Vector2.class);

		Vector2 vertex2toVertex1 = Pools.obtain(Vector2.class);
		vertex1.set(pol.getVertices()[i], pol.getVertices()[i + 1]);
		for (int j = 0; j < pol.getVertices().length - 1; j += 2) {
			if (i == j) {
				continue;
			}
			vertex2.set(pol.getVertices()[j], pol.getVertices()[j + 1]);
			vertex2toVertex1.set(vertex1);
			float distance = vertex2toVertex1.sub(vertex2).len();
			if (distance > maxDistance) {
				maxDistance = distance;
				center.set(vertex2).add(vertex2toVertex1.scl(0.5f));
			}
		}
		Pools.free(vertex1);
		Pools.free(vertex2);
		Pools.free(vertex2toVertex1);
	}
	Circle circle = Pools.obtain(Circle.class);
	circle.set(center.x, center.y, maxDistance / 2.0F);
	Pools.free(center);
	CircleWrapper circleWrapper = Pools.obtain(CircleWrapper.class);
	circleWrapper.set(circle);
	return circleWrapper;
}
 
开发者ID:e-ucm,项目名称:ead,代码行数:48,代码来源:BoundingAreaBuilder.java

示例13: gdxToSchemaPolygon

import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
/**
 * Converts a GDX polygon to an EAD polygon.
 * 
 * @param p
 *            polygon to convert
 * @return a schema polygon
 */
public static es.eucm.ead.schema.data.shape.Polygon gdxToSchemaPolygon(
		Polygon p) {
	float[] cs = p.getVertices();
	Array<Float> resultVertices = new Array<Float>(cs.length);
	for (float f : cs) {
		resultVertices.add(f);
	}
	es.eucm.ead.schema.data.shape.Polygon result = new es.eucm.ead.schema.data.shape.Polygon();
	result.setPoints(resultVertices);
	return result;
}
 
开发者ID:e-ucm,项目名称:ead,代码行数:19,代码来源:SchemaGdxConverter.java

示例14: gdxToJts

import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
/**
 * Converts a gdx polygon to JTS.
 * 
 * @param p
 *            a gdx polygon
 * @return a jts polygon (a subclass of JTS Geometry)
 */
public static com.vividsolutions.jts.geom.Polygon gdxToJts(Polygon p) {
	float vs[] = p.getVertices();

	// note that JTS line-strings must end with the same vertex they start
	Coordinate[] cs = new Coordinate[vs.length / 2 + 1];
	for (int i = 0, j = 0; i < vs.length; i += 2) {
		cs[j++] = new Coordinate(vs[i], vs[i + 1]);
	}
	cs[vs.length / 2] = new Coordinate(vs[0], vs[1]);

	LinearRing shell = new LinearRing(new CoordinateArraySequence(cs), gf);
	return new com.vividsolutions.jts.geom.Polygon(shell, null, gf);
}
 
开发者ID:e-ucm,项目名称:ead,代码行数:21,代码来源:GeometryUtils.java

示例15: renderTriangles

import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
public void renderTriangles(Polygon p, short[] t) {
	float v[] = p.getVertices();
	Color c = Color.valueOf("00aa00bb");
	shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
	for (int i = 0; i < t.length; i += 3) {
		shapeRenderer.setColor(c);
		int t0 = t[i + 0] * 2;
		int t1 = t[i + 1] * 2;
		int t2 = t[i + 2] * 2;
		shapeRenderer.triangle(v[t0], v[t0 + 1], v[t1], v[t1 + 1],
				v[t2], v[t2 + 1]);
		incColor(c);
	}
	shapeRenderer.end();
}
 
开发者ID:e-ucm,项目名称:ead,代码行数:16,代码来源:GeoTester.java


注:本文中的com.badlogic.gdx.math.Polygon.getVertices方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。