本文整理汇总了Java中com.badlogic.gdx.math.Polygon.setVertices方法的典型用法代码示例。如果您正苦于以下问题:Java Polygon.setVertices方法的具体用法?Java Polygon.setVertices怎么用?Java Polygon.setVertices使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.badlogic.gdx.math.Polygon
的用法示例。
在下文中一共展示了Polygon.setVertices方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: 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);
}
示例3: 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);
}
示例4: 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);
}
示例5: Enemy
import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
public Enemy(final Application APP, TextureAtlas.AtlasRegion normalTexture, TextureAtlas.AtlasRegion hitTexture, Sprite redBar, Sprite greenBar, int BOUNDING_X, int BOUNDING_Y, int BOUNDING_WIDTH, int BOUNDING_HEIGHT)
{
this.normalTexture = normalTexture;
this.hitTexture = hitTexture;
this.sprite = new Sprite(normalTexture);
squishSFX = APP.assets.get("sounds/squish.wav", Sound.class);
velocity = new Vector2();
position = new Vector2();
forwardVelocity = new Vector2();
bounds = new Polygon();
healthBar = new HealthBar(redBar, greenBar);
this.BOUNDING_X = BOUNDING_X;
this.BOUNDING_Y = BOUNDING_Y;
this.BOUNDING_WIDTH = BOUNDING_WIDTH;
this.BOUNDING_HEIGHT = BOUNDING_HEIGHT;
vertices = new float[]{
0, 0,
0, BOUNDING_HEIGHT,
BOUNDING_WIDTH, BOUNDING_HEIGHT,
BOUNDING_WIDTH, 0};
bounds.setVertices(vertices);
bounds.setPosition(sprite.getX(), sprite.getY());
position.set(this.sprite.getX(), this.sprite.getY());
bounds.setOrigin(BOUNDING_WIDTH / 2, BOUNDING_HEIGHT / 2);
}
示例6: boundingBoxOf
import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
/**
* Returns the bounding box of the given polygon
* @param ptsCombined The points as Vector2 list
* @return A Rectangle object
*/
private Rectangle boundingBoxOf(List<Vector2> ptsCombined) {
float[] rawPtsCombined = new float[ptsCombined.size() * 2];
int ptsCombinedIndex = 0;
for(int i = 0; i < rawPtsCombined.length - 1; i += 2) {
rawPtsCombined[i] = ptsCombined.get(ptsCombinedIndex).x;
rawPtsCombined[i + 1] = ptsCombined.get(ptsCombinedIndex).y;
ptsCombinedIndex++;
}
Polygon polygon = new Polygon();
polygon.setVertices(rawPtsCombined);
Rectangle boundingRect = polygon.getBoundingRectangle();
return boundingRect;
}
示例7: rectangleToPolygon
import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
public static Polygon rectangleToPolygon(Rectangle rectangle) {
Polygon polygon = new Polygon();
polygon.setOrigin(0, 0);
polygon.setPosition(rectangle.x, rectangle.y);
polygon.setVertices(new float[] { 0, 0, 0 + rectangle.width, 0,
0 + rectangle.width, 0 + rectangle.height, 0,
0 + rectangle.height });
return polygon;
}
示例8: buildRectangleCollider
import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
/**
* @return A simple runtime polygon (libgdx) for the given {@code rectangle}
* that can be used as a collider.
*/
public static Polygon buildRectangleCollider(Rectangle rectangle) {
Polygon polygon = new Polygon();
float[] vertices = new float[8]; // four vertex
vertices[0] = 0;
vertices[1] = 0;
vertices[2] = rectangle.getWidth();
vertices[3] = 0;
vertices[4] = rectangle.getWidth();
vertices[5] = rectangle.getHeight();
vertices[6] = 0;
vertices[7] = rectangle.getHeight();
polygon.setVertices(vertices);
return polygon;
}
示例9: buildPolygonCollider
import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
/**
* @return A runtime polygon (libgdx) equivalent to the schema polygon
* provided as argument. The returning polygon can be used as a
* collider
*/
public static Polygon buildPolygonCollider(
es.eucm.ead.schema.data.shape.Polygon schemaPolygon) {
Polygon polygon = new Polygon();
float[] vertices = new float[schemaPolygon.getPoints().size];
for (int i = 0; i < vertices.length; i++) {
vertices[i] = schemaPolygon.getPoints().get(i);
}
polygon.setVertices(vertices);
return polygon;
}
示例10: buildCircleCollider
import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
/**
* Builds a circumscribed polygon for a {@code circle} that can be used as a
* collider.
*
* The number of sides of the polygon is specified through param
* {@code nSides}.
*
* The algorithm to calculate the minimum nSides polygon that covers a
* circle (circumscribed) is as follows:
*
* (To see what a circumscribed polygon is, visit: <a href=
* "http://www.vitutor.com/geometry/plane/circumscribed_polygons.html"
* >http://www.vitutor.com/geometry/plane/circumscribed_polygons.html</a>)
*
* 1) Distance from circle's center to each vertex (equidistant) is
* calculated (d).
*
* 2) A vector with length d is calculated.
*
* 3) Vector is added to the circle's center to get one vertex.
*
* 4) The vector is rotated "a" degrees. "a" is calculated by dividing 360º
* by the number of sides of the polygon.
*
* (3) and (4) are repeated until all the vertices are calculated.
*
* Note: d=r/cos(a/2), where: r: circle's radius a: angle
*
* See <a href="https://github.com/e-ucm/ead/wiki/Shape-renderer">This wiki
* page</a> for more details
*/
public static Polygon buildCircleCollider(Circle circle, int nSides) {
Polygon polygon = new Polygon();
float vertices[] = new float[nSides * 2];
// The radius
float r = circle.getRadius();
// The center of the circle. Since we work on a coordinate system where
// the origin is in the bottom-left corner of the element, the center is
// located in (radius, radius).
float cx = r, cy = r;
// How much we must rotate the radius vector (normal to the circle)
float angleInc = 360.0F / nSides;
double halfAngleIncRad = Math.PI / nSides;
// Distance from center to each of the vertices
float d = (float) (r / Math.cos(halfAngleIncRad));
// Initialization of the vector used to calculate each vertex.
Vector2 centerToVertex = new Vector2();
centerToVertex.set(0, d);
centerToVertex.rotateRad((float) halfAngleIncRad);
for (int i = 0; i < nSides; i++) {
// Calculate vertex
vertices[2 * i] = cx + centerToVertex.x;
vertices[2 * i + 1] = cy + centerToVertex.y;
// Rotate for the next vertex
centerToVertex.rotate(angleInc);
}
polygon.setVertices(vertices);
return polygon;
}
示例11: 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;
}
示例12: createFixtures
import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
/**
* creates {@link Fixture Fixtures} from a {@link MapObject}
*
* @param mapObject the {@link MapObject} to parse
* @return an array of parsed {@link Fixture Fixtures}
*/
public Fixture[] createFixtures(MapObject mapObject) {
Polygon polygon;
if (!(mapObject instanceof PolygonMapObject) || isConvex(polygon = ((PolygonMapObject) mapObject).getPolygon()))
return new Fixture[]{createFixture(mapObject)};
Polygon[] convexPolygons;
if (triangulate) {
if (areVerticesClockwise(polygon)) { // ensure the vertices are in counterclockwise order (not really necessary according to EarClippingTriangulator's javadoc, but sometimes better)
Array<Vector2> vertices = new Array<Vector2>(toVector2Array(polygon.getVertices()));
Vector2 first = vertices.removeIndex(0);
vertices.reverse();
vertices.insert(0, first);
polygon.setVertices(toFloatArray(vertices.items));
}
convexPolygons = toPolygonArray(toVector2Array(new EarClippingTriangulator().computeTriangles(polygon.getTransformedVertices()).toArray()), 3);
} else {
Array<Array<Vector2>> convexPolys = BayazitDecomposer.convexPartition(new Array<Vector2>(toVector2Array(polygon.getTransformedVertices())));
convexPolygons = new Polygon[convexPolys.size];
for (int i = 0; i < convexPolygons.length; i++)
convexPolygons[i] = new Polygon(toFloatArray((Vector2[]) convexPolys.get(i).toArray(Vector2.class)));
}
// create the fixtures using the convex polygons
Fixture[] fixtures = new Fixture[convexPolygons.length];
for (int i = 0; i < fixtures.length; i++) {
PolygonMapObject convexObject = new PolygonMapObject(convexPolygons[i]);
convexObject.setColor(mapObject.getColor());
convexObject.setName(mapObject.getName());
convexObject.setOpacity(mapObject.getOpacity());
convexObject.setVisible(mapObject.isVisible());
convexObject.getProperties().putAll(mapObject.getProperties());
fixtures[i] = createFixture(convexObject);
}
return fixtures;
}
示例13: generateSpokes
import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
/** Generates spokes emanating from the center */
private void generateSpokes () {
worldSpokes = new Array<Polygon>();
// Initial reference angle to offset the spokes from
float referencenAngle = rng.nextFloat() * 360.0f;
float spokeOffset = (MathUtils.PI2 / param.spokeCount) * MathUtils.radDeg;
// Determine the length of the spokes
float halfWidth = (width * 0.5f);
float halfHeight = (height * 0.5f);
float length = (float)Math.sqrt(halfWidth * halfWidth + halfHeight * halfHeight);
// Create the spokes using polygon shapes
for (int i = 0; i < param.spokeCount; i++) {
// Calculate the angle the spoke will be set to
float angle = referencenAngle + (spokeOffset * i);
angle += randomSign() * (rng.nextFloat() * param.spokeScattering);
// Set the vertices of the polygon as a rectangle with a height of spokeWidth and a width of the length
float[] verticies = new float[8];
verticies[0] = 0;
verticies[1] = -param.spokeWidth * 0.5f;
verticies[2] = length;
verticies[3] = -param.spokeWidth * 0.5f;
verticies[4] = length;
verticies[5] = param.spokeWidth * 0.5f;
verticies[6] = 0;
verticies[7] = param.spokeWidth * 0.5f;
// Create the polygon shape
Polygon polygon = new Polygon();
polygon.setVertices(verticies);
polygon.setPosition(halfWidth, halfHeight);
polygon.setRotation(angle);
// Create a spawn point at the end of the spoke
Vector2 spawnPoint = new Vector2(length, 0);
spawnPoint.setAngle(angle);
spawnPoint.add(halfWidth, halfHeight);
WaveSystem.addSpawnPoint(spawnPoint);
worldSpokes.add(polygon);
}
}
示例14: parsePolygon
import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
public static void parsePolygon(Polygon p, String s) {
String[] vs = s.split(NUMBER_PARAM_SEPARATOR);
if (vs.length < 6)
return;
float verts[] = new float[vs.length];
for (int i = 0; i < vs.length; i++) {
verts[i] = Float.parseFloat(vs[i]);
}
p.setVertices(verts);
}
示例15: getPolygon
import com.badlogic.gdx.math.Polygon; //导入方法依赖的package包/类
/**
* WARNING: EXPENSIVE OPERATION USE ONLY IN INITIALISATION STEPS
* This method is used to create a new rectangular polygon
*
* @param x the x coordinate of the polygon
* @param y the y coordinate of the polygon
* @param width the width of the polygon
* @param height the height of the polygon
* @return the created polygon
*/
public static Polygon getPolygon(float x, float y, float width, float height) {
float vals[] = {0, 0, width, 0, width, height, 0, height};
Polygon p = new Polygon();
p.setOrigin(width / 2, height / 2);
p.setScale(1, 1);
p.setVertices(vals);
p.setPosition(x, y);
return p;
}