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


Java Polygon.getTransformedVertices方法代码示例

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


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

示例1: isVertexConcave

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

示例2: inLineOfSight

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

示例3: addObstacleToGrapth

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

示例4: collidePolygon

import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
/**
 * Checks whether two polygons collide
 *
 * @param p1 the first polygon
 * @param p2 the second polygon
 * @return the result
 */
public static boolean collidePolygon(Polygon p1, Polygon p2) {
    float[] v1 = p1.getTransformedVertices();
    float[] v2 = p2.getTransformedVertices();
    float p1x1, p1y1, p1x2, p1y2;
    float p2x1, p2y1, p2x2, p2y2;
    int i, j;

    // To check if any point of one polygon lies inside another polygon

    for(i = 0; i < v1.length-1 ;i+=2)
    {
        if((p2.contains(v1[i],v1[i+1])))
            return true;
    }

    //To check if any of the line segments of polygons intersect at any place

    for (i = 0; i < v1.length; i += 2) {
        p1x1 = v1[i];
        p1y1 = v1[i + 1];
        p1x2 = v1[(i + 2) % v1.length]; //To return back to 0 when i+2 > len
        p1y2 = v1[(i + 3) % v1.length]; //To return back to 0 when i+3 > len
        for (j = 0; j < v2.length; j += 2) {
            p2x1 = v2[j];
            p2y1 = v2[j + 1];
            p2x2 = v2[(j + 2) % v2.length]; //To return back to 0 when j+2 > len
            p2y2 = v2[(j + 3) % v2.length]; //To return back to 0 when j+3 > len
            if (collisionAtPoints(p1x1, p1y1, p1x2, p1y2, p2x1, p2y1, p2x2, p2y2)) {
                if (debug) log.print("Collision at %d of p1 and %d of p2", i / 2 + 1, j / 2 + 1);
                return true;
            }
        }
    }
    return false;
}
 
开发者ID:Benjozork,项目名称:Onyx,代码行数:43,代码来源:PolygonHelper.java

示例5: getPolygonShape

import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
private static Shape getPolygonShape(MapObject object) {
    Polygon polygon = ((PolygonMapObject)object).getPolygon();
    float[] vertices = polygon.getTransformedVertices();
    for (int i = 0; i < vertices.length; i++) {
        vertices[i] *= MainCamera.getInstance().getTileMapScale();
    }

    PolygonShape shape = new PolygonShape();
    shape.set(vertices);

    return shape;
}
 
开发者ID:alexschimpf,项目名称:joe,代码行数:13,代码来源:TiledUtils.java

示例6: containsAnyVertex

import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
/**
 * Returns true if the supplied rectangle contains any vertex of the
 * supplied polygon.
 * 
 * @param polygon
 * @param rectangle
 * @return
 */
public static final boolean containsAnyVertex(Rectangle rectangle, Polygon polygon) {
	float[] vertices = polygon.getTransformedVertices();
	
	for (int i = 0; i < vertices.length; i += 2) {
		if (rectangle.contains(vertices[i], vertices[i+1])) {
			return true;
		}
	}
	return false;
}
 
开发者ID:mganzarcik,项目名称:fabulae,代码行数:19,代码来源:MathUtil.java

示例7: createPolygon

import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
/**
 * 
 * @param world
 * @param polygonObject
 * @param density
 * @param friction
 * @param restitution
 */
private void createPolygon(World world, PolygonMapObject polygonObject, float density, float friction, float restitution){
	Polygon polygon = polygonObject.getPolygon();
	PolygonShape shape = new PolygonShape();
	float[] vertices = polygon.getTransformedVertices();
	float[] worldVertices = new float[vertices.length];
	
	for(int i = 0; i < vertices.length; i++){
		worldVertices[i] = vertices[i] / SupaBox.PPM;
	}
	
	shape.set(worldVertices);
	
	BodyDef bodyDef = new BodyDef();
	bodyDef.type = BodyType.StaticBody;
	
	Body body = world.createBody(bodyDef);
	
	FixtureDef fixtureDef = new FixtureDef();
	fixtureDef.shape = shape;
	fixtureDef.density = density;
	fixtureDef.friction = friction;
	fixtureDef.restitution = restitution;
	
	body.createFixture(fixtureDef);
	
	shape.dispose();
}
 
开发者ID:ryanshappell,项目名称:SupaBax,代码行数:36,代码来源:BodyBuilder.java

示例8: deletePoint

import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
public static boolean deletePoint(Polygon poly, float x, float y,
		float tolerance) {
	float verts[] = poly.getTransformedVertices();

	for (int i = 0; i < verts.length; i += 2) {
		if (Vector2.dst(x, y, verts[i], verts[i + 1]) < tolerance) {
			deletePoint(poly, i);

			return true;
		}
	}

	return false;
}
 
开发者ID:bladecoder,项目名称:bladecoder-adventure-engine,代码行数:15,代码来源:PolygonUtils.java

示例9: getFirstVertexInsideWalkzone

import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
/**
 * Search the first polygon vertex inside the walkzone.
 * 
 * @param p
 *            the polygon
 * @param target
 *            the vertex found
 */
private void getFirstVertexInsideWalkzone(Polygon p, Vector2 target) {
	float verts[] = p.getTransformedVertices();

	for (int i = 0; i < verts.length; i += 2) {
		if (PolygonUtils.isPointInside(walkZone, verts[i], verts[i + 1], true)) {
			target.x = verts[i];
			target.y = verts[i + 1];

			return;
		}
	}
}
 
开发者ID:bladecoder,项目名称:bladecoder-adventure-engine,代码行数:21,代码来源:PolygonalNavGraph.java

示例10: removeDinamicObstacle

import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
public boolean removeDinamicObstacle(Polygon poly) {
	boolean exists = obstacles.remove(poly);

	if (!exists)
		return false;

	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)) {
			for (int j = 0; j < graphNodes.size(); j++) {
				NavNodePolygonal n = graphNodes.get(j);

				if (n.x == verts[i] && n.y == verts[i + 1]) {
					graphNodes.remove(n);
					j--;

					for (NavNodePolygonal n2 : graphNodes) {
						n2.neighbors.removeValue(n, true);
					}

				}
			}
		}
	}

	return true;
}
 
开发者ID:bladecoder,项目名称:bladecoder-adventure-engine,代码行数:30,代码来源:PolygonalNavGraph.java

示例11: drawBBoxActors

import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
public void drawBBoxActors(Scene scn) {
	drawer.setProjectionMatrix(camera.combined);
	drawer.setTransformMatrix(new Matrix4());
	drawer.begin(ShapeType.Line);

	for (BaseActor a : scn.getActors().values()) {

		Polygon p = a.getBBox();

		if (p == null) {
			EditorLogger.error("ERROR DRAWING BBOX FOR: " + a.getId());
		}

		// Rectangle r = a.getBBox().getBoundingRectangle();

		if (a instanceof ObstacleActor) {
			drawer.setColor(Scene.OBSTACLE_COLOR);
			drawer.polygon(p.getTransformedVertices());
		} else if (a instanceof InteractiveActor) {
			InteractiveActor iActor = (InteractiveActor) a;

			if (!scn.getLayer(iActor.getLayer()).isVisible())
				continue;

			drawer.setColor(Scene.ACTOR_BBOX_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);
		}

		// drawer.rect(r.getX(), r.getY(), r.getWidth(), r.getHeight());
	}

	drawer.end();
}
 
开发者ID:bladecoder,项目名称:bladecoder-adventure-engine,代码行数:40,代码来源:CanvasDrawer.java

示例12: drawPolygonVertices

import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
public void drawPolygonVertices(Polygon p, Color c) {
	float verts[] = p.getTransformedVertices();

	drawer.setProjectionMatrix(camera.combined);
	drawer.setTransformMatrix(new Matrix4());

	drawer.begin(ShapeRenderer.ShapeType.Line);
	drawer.setColor(c);

	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);

	drawer.end();
}
 
开发者ID:bladecoder,项目名称:bladecoder-adventure-engine,代码行数:15,代码来源:CanvasDrawer.java

示例13: getClampedPoint

import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
/**
 * Clamp the point to the nearest polygon segment
 * 
 * @param poly
 *            The polygon
 * @param x
 *            The original point X
 * @param y
 *            The original point Y
 * @param dest
 *            The clamped point
 * @return The segment where the clamped point belongs
 */
public static int getClampedPoint(Polygon poly, float x, float y,
		Vector2 dest) {
	float verts[] = poly.getTransformedVertices();
	float dTmp;

	Intersector.nearestSegmentPoint(verts[0], verts[1], verts[2], verts[3],
			x, y, dest);

	int nearest = 0;
	float d = Vector2.dst(x, y, dest.x, dest.y);

	for (int i = 2; i < verts.length; i += 2) {
		Intersector.nearestSegmentPoint(verts[i], verts[i + 1],
				verts[(i + 2) % verts.length],
				verts[(i + 3) % verts.length], x, y, tmp);
		dTmp = Vector2.dst(x, y, tmp.x, tmp.y);

		if (dTmp < d) {
			d = dTmp;
			nearest = i;
			dest.set(tmp);
		}
	}
	
	// ERROR CONTROL:
	// If the clamped point is not in the walkzone 
	// we search for the nearest walkzone vertex
	if (!PolygonUtils.isPointInside(poly, dest.x, dest.y, true)) {
		EngineLogger.debug("> PolygonalPathFinder: CLAMPED FAILED!!");
		
		tmp.set(verts[0], verts[1]);
		d = Vector2.dst(x, y, tmp.x, tmp.y);
		nearest = 0;
		dest.set(tmp);
		
		for (int i = 2; i < verts.length; i += 2) {
			tmp.set(verts[i], verts[i + 1]);
			dTmp = Vector2.dst(x, y, tmp.x, tmp.y);

			if (dTmp < d) {
				d = dTmp;
				nearest = i;
				dest.set(tmp);
			}
		}
	}

	return nearest;
}
 
开发者ID:bladecoder,项目名称:bladecoder-adventure-engine,代码行数:63,代码来源:PolygonUtils.java

示例14: isPointInside

import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
public static boolean isPointInside(Polygon polygon, float x, float y,
		boolean toleranceOnOutside) {
	float verts[] = polygon.getTransformedVertices();

	boolean inside = false;

	float oldX = verts[verts.length - 2];
	float oldY = verts[verts.length - 1];

	float oldSqDist = Vector2.dst2(oldX, oldY, x, y);

	for (int i = 0; i < verts.length; i += 2) {
		float newX = verts[i];
		float newY = verts[i + 1];
		float newSqDist = Vector2.dst2(newX, newY, x, y);

		if (oldSqDist + newSqDist + 2.0f * Math.sqrt(oldSqDist * newSqDist)
				- Vector2.dst2(newX, newY, oldX, oldY) < TOLERANCE_IS_POINT_INSIDE)
			return toleranceOnOutside;

		float leftX = newX;
		float leftY = newY;
		float rightX = oldX;
		float rightY = oldY;

		if (newX > oldX) {
			leftX = oldX;
			leftY = oldY;
			rightX = newX;
			rightY = newY;
		}

		if (leftX < x
				&& x <= rightX
				&& (y - leftY) * (rightX - leftX) < (rightY - leftY)
						* (x - leftX))
			inside = !inside;

		oldX = newX;
		oldY = newY;
		oldSqDist = newSqDist;
	}

	return inside;
}
 
开发者ID:bladecoder,项目名称:bladecoder-adventure-engine,代码行数:46,代码来源:PolygonUtils.java

示例15: createInitialGraph

import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
public void createInitialGraph(Collection<BaseActor> actors) {
	graphNodes.clear();

	// 1.- Add WalkZone convex nodes
	float verts[] = walkZone.getTransformedVertices();

	for (int i = 0; i < verts.length; i += 2) {
		if (!PolygonUtils.isVertexConcave(walkZone, i)) {
			graphNodes.add(new NavNodePolygonal(verts[i], verts[i + 1]));
		}
	}

	// 2.- Add obstacles concave nodes
	obstacles.clear();

	for (BaseActor a : actors) {
		if (a instanceof ObstacleActor && a.isVisible())
			obstacles.add(a.getBBox());
	}

	for (Polygon o : obstacles) {
		verts = o.getTransformedVertices();

		for (int i = 0; i < verts.length; i += 2) {
			if (PolygonUtils.isVertexConcave(o, i)
					&& PolygonUtils.isPointInside(walkZone, verts[i], verts[i + 1], false)) {
				graphNodes.add(new NavNodePolygonal(verts[i], verts[i + 1]));
			}
		}
	}

	// 3.- CALC LINE OF SIGHTs
	for (int i = 0; i < graphNodes.size() - 1; i++) {
		NavNodePolygonal n1 = graphNodes.get(i);

		for (int j = i + 1; 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);
			}
		}
	}
}
 
开发者ID:bladecoder,项目名称:bladecoder-adventure-engine,代码行数:46,代码来源:PolygonalNavGraph.java


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