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


Java PolygonShape.getVertex方法代码示例

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


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

示例1: RenderOfPolyFixture

import com.badlogic.gdx.physics.box2d.PolygonShape; //导入方法依赖的package包/类
public RenderOfPolyFixture(Fixture fixture, VertexBufferObjectManager pVBO) {
	super(fixture);

	PolygonShape fixtureShape = (PolygonShape) fixture.getShape();
	int vSize = fixtureShape.getVertexCount();
	float[] xPoints = new float[vSize];
	float[] yPoints = new float[vSize];

	Vector2 vertex = Vector2Pool.obtain();
	for (int i = 0; i < fixtureShape.getVertexCount(); i++) {
		fixtureShape.getVertex(i, vertex);
		xPoints[i] = vertex.x * PhysicsConnector.PIXEL_TO_METER_RATIO_DEFAULT;
		yPoints[i] = vertex.y * PhysicsConnector.PIXEL_TO_METER_RATIO_DEFAULT;
	}
	Vector2Pool.recycle(vertex);

	mEntity = new PolyLine(0, 0, xPoints, yPoints, pVBO);
}
 
开发者ID:mediamonks,项目名称:tilt-game-android,代码行数:19,代码来源:RenderOfPolyFixture.java

示例2: getFixtureVertices

import com.badlogic.gdx.physics.box2d.PolygonShape; //导入方法依赖的package包/类
/**
 * Getter for the Vertices of a given Fixture.
 *
 * @param fixture Fixture to be handled.
 * @return List containing the Fixture's vertices.
 */
private List<Vector2> getFixtureVertices(Fixture fixture) {
    PolygonShape polygon = (PolygonShape) fixture.getShape();
    int verticesCount = polygon.getVertexCount();

    List<Vector2> vertices = new ArrayList<>(verticesCount);
    for (int i = 0; i < verticesCount; i++) {
        Vector2 vertex = new Vector2();
        polygon.getVertex(i, vertex);
        vertices.add(new Vector2(fixture.getBody().getWorldPoint(vertex)));
    }

    return vertices;
}
 
开发者ID:AndreFCruz,项目名称:feup-lpoo-armadillo,代码行数:20,代码来源:BuoyancyController.java

示例3: getFixtureVertices

import com.badlogic.gdx.physics.box2d.PolygonShape; //导入方法依赖的package包/类
private List<Vector2> getFixtureVertices(Fixture fixture) {
	PolygonShape polygon = (PolygonShape) fixture.getShape();
	int verticesCount = polygon.getVertexCount();

	List<Vector2> vertices = new ArrayList<Vector2>(verticesCount);
	for (int i = 0; i < verticesCount; i++) {
		Vector2 vertex = new Vector2();
		polygon.getVertex(i, vertex);
		vertices.add(new Vector2(fixture.getBody().getWorldPoint(vertex)));
	}

	return vertices;
}
 
开发者ID:Leakedbits,项目名称:Codelabs,代码行数:14,代码来源:BuoyancyController.java

示例4: resize

import com.badlogic.gdx.physics.box2d.PolygonShape; //导入方法依赖的package包/类
/**
 * Change the size of an actor, and/or change its position
 *
 * @param x      The new X coordinate of its bottom left corner, in meters
 * @param y      The new Y coordinate of its bototm left corner, in meters
 * @param width  The new width of the actor, in meters
 * @param height The new height of the actor, in meters
 */
public void resize(float x, float y, float width, float height) {
    // set new height and width
    mSize.set(width, height);
    // read old body information
    Body oldBody = mBody;
    Fixture oldFix = oldBody.getFixtureList().get(0);
    // make a new body
    if (mIsCircleBody) {
        setCirclePhysics(oldBody.getType(), x, y, (width > height) ? width / 2 : height / 2);
    } else if (mIsBoxBody) {
        setBoxPhysics(oldBody.getType(), x, y);
    } else if (mIsPolygonBody) {
        // we need to manually scale all the vertices
        float xScale = height / mSize.y;
        float yScale = width / mSize.x;
        PolygonShape ps = (PolygonShape) oldFix.getShape();
        float[] verts = new float[ps.getVertexCount() * 2];
        for (int i = 0; i < ps.getVertexCount(); ++i) {
            ps.getVertex(i, mTempVector);
            verts[2 * i] = mTempVector.x * xScale;
            verts[2 * i + 1] = mTempVector.y * yScale;
        }
        setPolygonPhysics(oldBody.getType(), x, y, verts);
    }
    // Update the user-visible physics values
    setPhysics(oldFix.getDensity(), oldFix.getRestitution(), oldFix.getFriction());
    setFastMoving(oldBody.isBullet());
    // clone forces
    mBody.setAngularVelocity(oldBody.getAngularVelocity());
    mBody.setTransform(mBody.getPosition(), oldBody.getAngle());
    mBody.setGravityScale(oldBody.getGravityScale());
    mBody.setLinearDamping(oldBody.getLinearDamping());
    mBody.setLinearVelocity(oldBody.getLinearVelocity());
    // disable the old body
    oldBody.setActive(false);
}
 
开发者ID:mfs409,项目名称:liblol,代码行数:45,代码来源:BaseActor.java

示例5: renderTiles

import com.badlogic.gdx.physics.box2d.PolygonShape; //导入方法依赖的package包/类
/**
 * Uses the shape renderer to draw all tiles in the List
 *
 * @param tiles the {@link List} of tiles to render
 */
public void renderTiles(List<Body> tiles) {
	shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
	shapeRenderer.setColor(Color.DARK_GRAY);

	// Setup some reusable Vector2s
	Vector2[] verts = new Vector2[4];
	for (int i = 0; i < verts.length; i++)
		verts[i] = new Vector2();
	Vector2 lv = new Vector2();
	Vector2 f = new Vector2();

	for (Body tile : tiles) {
		PolygonShape tileShape = (PolygonShape) tile.getFixtureList().get(0).getShape();

		// Get the vertices for the shape.
		for (int i = 0; i < verts.length; i++) {
			tileShape.getVertex(i, verts[i]);
			tile.getTransform().mul(verts[i]);
		}

		// Set the starting vertices to draw the lines from
		lv.set(verts[0]);
		f.set(verts[0]);

		// For each of the vertices draw a line connecting it to the previous
		for (int i = 1; i < verts.length; i++) {
			Vector2 v = verts[i];
			shapeRenderer.line(lv.x, lv.y, v.x, v.y);
			lv.set(v);
		}
		// Finally draw the last line, connecting back to the first vertex
		shapeRenderer.line(f.x, f.y, lv.x, lv.y);
	}
	shapeRenderer.end();
}
 
开发者ID:zdonnell,项目名称:Android-Genetic-Cars,代码行数:41,代码来源:Renderer.java

示例6: generate

import com.badlogic.gdx.physics.box2d.PolygonShape; //导入方法依赖的package包/类
/**
 * Generates terrain in the provided world.
 *
 * @param world the world to place the terrain in
 * @return a list of all the terrain tiles generated
 */
public static List<Body> generate(World world) {
	List<Body> terrainTiles = new ArrayList<Body>(MAX_GROUND_PIECES);
	Body lastTile;
	Vector2 tilePosition = new Vector2(-5, -2);
	for (int i = 0; i < MAX_GROUND_PIECES; i++) {
		// Create a tile, it's rotation potentially more extreme the closer to the end of the terrain we get.
		lastTile = createTerrainTile(world, tilePosition, (Math.random() * 3 - 1.5) * 1.5 * i / MAX_GROUND_PIECES);
		terrainTiles.add(lastTile);
		PolygonShape lastTileShape = (PolygonShape) lastTile.getFixtureList().get(0).getShape();
		lastTileShape.getVertex(3, tilePosition);
		tilePosition = lastTile.getWorldPoint(tilePosition);
	}
	return terrainTiles;
}
 
开发者ID:zdonnell,项目名称:Android-Genetic-Cars,代码行数:21,代码来源:TerrainGenerator.java

示例7: ComputeCentroid

import com.badlogic.gdx.physics.box2d.PolygonShape; //导入方法依赖的package包/类
static float ComputeCentroid(PolygonShape shape, Vector2 c)
{
   float area = 0.0f;
   c.set(0,0);

   // pRef is the reference point for forming triangles.
   // It's location doesn't change the result (except for rounding error).
   pRef.set(0,0);

   float inv3 = 1.0f / 3.0f;
   
   int count = shape.getVertexCount();
   
   if (count < 3) throw new IndexOutOfBoundsException("Bad vertex count!");

   for (int i = 0; i < count; ++i)
   {
      // Triangle vertices.
      Vector2 p1 = pRef;
      Vector2 p2 = tmp; 
      shape.getVertex(i, p2); // vs[i];
      Vector2 p3 = tmp2;
      shape.getVertex(i + 1 < count ? i+1 : 0,p3); // vs[i+1] : vs[0];

      e1.set(p2).sub(p1); // e1 = p2 - p1;
      e2.set(p3).sub(p1); // e2 = p3 - p1;

      float D = e1.crs(e2);

      float triangleArea = 0.5f * D;
      area += triangleArea;

      // Area weighted centroid
      tmp.set(p1).add(p2).add(p3).scl(triangleArea * inv3);
      c.add(tmp);

   }

   if (area < Float.MIN_VALUE)
   {
      area = 0.25f; // punt.  Instead of throwing an exception, return a minimum.
   }
   // Centroid
   c.scl(1.0f / area);
   
   return area;
}
 
开发者ID:tescott,项目名称:box2dcontrollers,代码行数:48,代码来源:B2ShapeExtensions.java

示例8: ComputeCentroid

import com.badlogic.gdx.physics.box2d.PolygonShape; //导入方法依赖的package包/类
static float ComputeCentroid(PolygonShape shape, Vector2 c)
{
    float area = 0.0f;
    c.set(0,0);

    // pRef is the reference point for forming triangles.
    // It's location doesn't change the result (except for rounding error).
    pRef.set(0,0);

    float inv3 = 1.0f / 3.0f;

    int count = shape.getVertexCount();

    if (count < 3) throw new IndexOutOfBoundsException("Bad vertex count!");

    for (int i = 0; i < count; ++i)
    {
        // Triangle vertices.
        Vector2 p1 = pRef;
        Vector2 p2 = tmp;
        shape.getVertex(i, p2); // vs[i];
        Vector2 p3 = tmp2;
        shape.getVertex(i + 1 < count ? i+1 : 0,p3); // vs[i+1] : vs[0];

        e1.set(p2).sub(p1); // e1 = p2 - p1;
        e2.set(p3).sub(p1); // e2 = p3 - p1;

        float D = e1.crs(e2);

        float triangleArea = 0.5f * D;
        area += triangleArea;

        // Area weighted centroid
        tmp.set(p1).add(p2).add(p3).scl(triangleArea * inv3);
        c.add(tmp);

    }

    if (area < Float.MIN_VALUE)
    {
        area = 0.25f; // punt.  Instead of throwing an exception, return a minimum.
    }
    // Centroid
    c.scl(1.0f / area);

    return area;
}
 
开发者ID:Rubentxu,项目名称:DreamsLibGdx,代码行数:48,代码来源:BuoyancyUtils.java

示例9: renderCars

import com.badlogic.gdx.physics.box2d.PolygonShape; //导入方法依赖的package包/类
/**
 * Draws all the cars in the List provided.
 *
 * @param cars {@link List} of cars
 */
public void renderCars(List<Car> cars) {
	for (Car car : cars) {

		// Calculate an alpha value that represents how much longer the car has before it is killed.
		float lifeLeft = (float) (System.currentTimeMillis() - car.timeLastMoved) / 5000f;
		float alpha = lifeLeft / 1f;

		// draw wheels
		for (Body wheel : car.getWheels()) {
			Vector2 pos = wheel.getPosition();

			// Figure out the color of the wheel based on it's density
			float wheelDensityRange = Wheel.WHEEL_MAX_DENSITY - Wheel.WHEEL_MIN_DENSITY;
			float densityRatio = (wheel.getMass() - Wheel.WHEEL_MIN_DENSITY) / wheelDensityRange;
			densityRatio = 1f - densityRatio;

			// Draw the solid wheel color
			shapeRenderer.begin(ShapeRenderer.ShapeType.FilledCircle);
			shapeRenderer.setColor(densityRatio, densityRatio, densityRatio, 1f - alpha);
			shapeRenderer.filledCircle(pos.x, pos.y, wheel.getFixtureList().get(0).getShape().getRadius(), 30);
			shapeRenderer.end();

			// Draw the wheel outline
			shapeRenderer.begin(ShapeRenderer.ShapeType.Circle);
			shapeRenderer.setColor(0, 0, 0, 1f - alpha);
			shapeRenderer.circle(pos.x, pos.y, wheel.getFixtureList().get(0).getShape().getRadius(), 30);
			shapeRenderer.end();
		}

		// Draw the chassis pieces (triangles)
		Vector2[] v = new Vector2[3];
		for (Fixture chassisPart : car.getChassis().getFixtureList()) {
			PolygonShape chassisPieceShape = (PolygonShape) chassisPart.getShape();

			// Get the vertices for this chassis piece (triangle)
			for (int i = 0; i < 3; i++) {
				v[i] = new Vector2();
				chassisPieceShape.getVertex(i, v[i]);
				car.getChassis().getTransform().mul(v[i]);
			}

			// Draw the light red solid color
			shapeRenderer.begin(ShapeRenderer.ShapeType.FilledTriangle);
			shapeRenderer.setColor(car.isElite ? 0.6f : 0.9f, 0.6f, car.isElite ? 0.9f : 0.6f, 1f - alpha);
			shapeRenderer.filledTriangle(v[0].x, v[0].y, v[1].x, v[1].y, v[2].x, v[2].y);
			shapeRenderer.end();

			// Draw the darker red triangle outlines
			shapeRenderer.begin(ShapeRenderer.ShapeType.Triangle);
			shapeRenderer.setColor(car.isElite ? 0.1f : 0.9f, 0.1f, car.isElite ? 0.9f : 0.1f, 1f - alpha);
			shapeRenderer.triangle(v[0].x, v[0].y, v[1].x, v[1].y, v[2].x, v[2].y);
			shapeRenderer.end();
		}
	}
}
 
开发者ID:zdonnell,项目名称:Android-Genetic-Cars,代码行数:61,代码来源:Renderer.java


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