本文整理汇总了Java中com.badlogic.gdx.math.Polygon.contains方法的典型用法代码示例。如果您正苦于以下问题:Java Polygon.contains方法的具体用法?Java Polygon.contains怎么用?Java Polygon.contains使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.badlogic.gdx.math.Polygon
的用法示例。
在下文中一共展示了Polygon.contains方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTilesFromPolygon
import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
private IntArray getTilesFromPolygon(Polygon polygon) {
IntArray tiles = new IntArray();
Polygon transformedPolygon = transformTiledPolygon(gameMap, polygon);
Rectangle rectangle = transformedPolygon.getBoundingRectangle();
int startX = (int) rectangle.getX();
int startY = (int) rectangle.getY();
int endX = startX + (int) rectangle.getWidth();
int endY = startY + (int) rectangle.getHeight();
for (int x = startX; x <= endX; ++x) {
for (int y = startY; y <= endY; ++y) {
if (transformedPolygon.contains(x, y)) {
tiles.add(x);
tiles.add(y);
}
}
}
return tiles;
}
示例2: hit
import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
@Override
public Actor hit(float x, float y, boolean touchable) {
Actor actor = super.hit(x, y, touchable);
if (actor == null || actor == this) {
Array<Polygon> collider = getCollider();
if (collider != null && collider.size > 0) {
int polygonsHit = 0;
for (Polygon p : collider) {
if (p.contains(x, y)) {
polygonsHit++;
}
}
return polygonsHit % 2 == 1 ? this : null;
}
}
return actor;
}
示例3: 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;
}
示例4: isContainedIn
import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
/**
* Returns true if all the tiles of this ground object
* are contained in the supplied polygon.
* @param polygon
* @return
*/
public boolean isContainedIn(Polygon polygon) {
for (Tile tile : groundTiles) {
if (!polygon.contains(tile.getX(), tile.getY())) {
return false;
}
}
return true;
}
示例5: isContainedInVisibleShapePolygon
import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
/**
* Returns true of this LOS contains the supplied coordinates
* in any visible shape polygons it currently contains.
*
* @param x
* @param y
* @return
*/
public boolean isContainedInVisibleShapePolygon(int x, int y) {
float xf = x * map.getTileSizeX();
float yf = y * map.getTileSizeY();
for (Polygon polygon : visibleShapePolygons) {
if (polygon.contains(xf, yf)) {
return true;
}
}
return false;
}
示例6: eval
import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
/** Evaluates a x,y pair with fBm applied OpenSimplexNoise. Applies a radial mask to the value.
*
* @param x The x coord
* @param y The y coord
* @return The heightmap value */
private float eval (int x, int y) {
float total = 0.0f;
float frequency = param.frequency;
float amplitude = param.gain;
for (int i = 0; i < param.octaves; i++) {
total += noise.eval((float)x * frequency, (float)y * frequency) * amplitude;
frequency *= param.lacunarity;
amplitude *= param.gain;
}
// Apply a radial mask to the heightmap.
// Lowers noise value as distance from center increases.
float centerToX = x - radius;
float centerToY = y - radius;
float distanceToCenter = Math.abs((float)Math.sqrt(centerToX * centerToX + centerToY * centerToY));
float distanceScalar = (distanceToCenter / radius);
total -= distanceScalar;
// Futher more if the array of spokes is not null factor those in as well
if (worldSpokes != null) {
for (Polygon polygon : worldSpokes) {
if (polygon.contains(x, y)) {
total += 1; // Lower it down
}
}
}
// Forces the center to be clear and the edges to be closed
// if(distanceScalar <= 0.45f ){
// total = 1;
// } else if(distanceToCenter / radius >= 0.9f){
// total -= distanceScalar;
// }
total = MathUtils.clamp(total, -1.0f, 1.0f);
return total;
}
示例7: selectLayer
import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
/**
* @return if there was any element in the given coordinates
*/
public boolean selectLayer(float x, float y) {
layersTouched.clear();
Vector2 origin = Pools.obtain(Vector2.class);
Vector2 size = Pools.obtain(Vector2.class);
Vector2 tmp = Pools.obtain(Vector2.class);
Polygon polygon = Pools.obtain(Polygon.class);
for (Actor actor : editedGroup.getChildren()) {
EngineUtils.calculateBounds(actor, origin, size);
int j = 0;
for (int i = 0; i < 4; i++) {
tmp.set(i == 0 || i == 3 ? origin.x : origin.x + size.x,
i > 1 ? origin.y : origin.y + size.y);
actor.localToAscendantCoordinates(this, tmp);
points[j++] = tmp.x;
points[j++] = tmp.y;
}
polygon.setVertices(points);
if (polygon.contains(x, y)) {
layersTouched.add(actor);
} else {
for (int i = 0; i < 8; i += 2) {
if (nearEnough(x, y, points[i], points[i + 1])) {
layersTouched.add(actor);
break;
}
}
}
}
Pools.free(polygon);
Pools.free(tmp);
Pools.free(origin);
Pools.free(size);
if (layersTouched.size > 0) {
showLayerSelector(x, y);
return true;
}
return false;
}
示例8: contains
import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
/**
* Checks if the shape contains the point
*
* @param bounds
* @param p
* @return
*/
public static boolean contains(Polygon bounds, Vector2 p) {
return bounds.contains(p.x, p.y);
}