本文整理汇总了Java中org.jbox2d.collision.shapes.PolygonShape.getVertices方法的典型用法代码示例。如果您正苦于以下问题:Java PolygonShape.getVertices方法的具体用法?Java PolygonShape.getVertices怎么用?Java PolygonShape.getVertices使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jbox2d.collision.shapes.PolygonShape
的用法示例。
在下文中一共展示了PolygonShape.getVertices方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: render
import org.jbox2d.collision.shapes.PolygonShape; //导入方法依赖的package包/类
private static void render() {
renderingContext2D.clear();
renderingContext2D.save();
renderingContext2D.translate(0, 600);
renderingContext2D.scale(1, -1);
renderingContext2D.scale(100, 100);
renderingContext2D.lineWidth(0.01f);
for (Body body = scene.getWorld().getBodyList(); body != null; body = body.getNext()) {
Vec2 center = body.getPosition();
renderingContext2D.save();
renderingContext2D.translate(center.x, center.y);
renderingContext2D.rotate(body.getAngle());
for (Fixture fixture = body.getFixtureList(); fixture != null; fixture = fixture.getNext()) {
Shape shape = fixture.getShape();
if (shape.getType() == ShapeType.CIRCLE) {
CircleShape circle = (CircleShape) shape;
renderingContext2D.beginPath();
renderingContext2D.arc(circle.m_p.x, circle.m_p.y, circle.getRadius(), 0, Math.PI * 2, true);
renderingContext2D.closePath();
renderingContext2D.stroke();
} else if (shape.getType() == ShapeType.POLYGON) {
PolygonShape poly = (PolygonShape) shape;
Vec2[] vertices = poly.getVertices();
renderingContext2D.beginPath();
renderingContext2D.moveTo(vertices[0].x, vertices[0].y);
for (int i = 1; i < poly.getVertexCount(); ++i) {
renderingContext2D.lineTo(vertices[i].x, vertices[i].y);
}
renderingContext2D.closePath();
renderingContext2D.stroke();
}
}
renderingContext2D.restore();
}
renderingContext2D.restore();
}
示例2: render
import org.jbox2d.collision.shapes.PolygonShape; //导入方法依赖的package包/类
/**
* Renderizador de objetos do jogo.
* @param container Container do jogo.
* @param game Informa��es do estado atual do jogo.
* @param g Objeto gr�fico para desenho.
*/
@SuppressWarnings("rawtypes")
public void render(GameContainer container, StateBasedGame game, Graphics g, Color filter) throws SlickException {
for (Body b = this.world.getBodyList(); b != null; b = b.m_next) {
if (b.m_userData instanceof Image) { //Objetos do jogo que contenham imagens.
Image img = (Image)b.m_userData;
Utils.drawImage(img, b.getWorldCenter(), b.getAngle(), this.transform, g, new Color(Color.white));
} else if (b.m_userData instanceof LevelObject) { //Objetos de n�vel.
((LevelObject)b.m_userData).render(container, game, g, filter);
} else if (b.m_userData instanceof Animation) { //Objetos do jogo que contenham anima��es.
Animation anim = (Animation)b.m_userData;
Utils.drawImage(anim.getCurrentFrame(), b.getWorldCenter(), b.getAngle(), this.transform, g, filter);
} else if (b.m_userData instanceof Player) { //Personagem do jogo.
Image frame = ((Player)b.m_userData).getCurrentFrame();
Utils.drawImage(frame, b.getWorldCenter(), b.getAngle(), this.transform, g, filter);
} else if (b.m_userData instanceof String) { //Desenhos do jogo.
if (b.m_userData.equals("draw")) {
for (Shape s = b.getShapeList(); s != null; s = s.getNext()) {
final XForm xf = b.getMemberXForm();
//Obt�m os vertices do pol�gono.
final PolygonShape poly = (PolygonShape)s;
final Vec2[] vertex = poly.getVertices();
//Obt�m os vetores de posi��o dos v�rtices.
Vec2 v0 = XForm.mul(xf, vertex[0]); //Bottom left
Vec2 v1 = XForm.mul(xf, vertex[1]); //Bottom left
Vec2 v2 = XForm.mul(xf, vertex[3]); //Upper right
//Obt�m o �ngulo a partir da base do ret�ngulo.
float angle = (float) Math.atan2(v1.y - v0.y, v1.x - v0.x);
//Obt�m a posi��o do centro do ret�ngulo.
Vec2 pos = new Vec2(v1.x + (v2.x - v1.x) / 2, v1.y + (v2.y - v1.y) / 2);
//Desenha a imagem.
Utils.drawImage(this.drawingImage, pos , angle, this.transform, g, filter);
}
}
}
}
}
示例3: render
import org.jbox2d.collision.shapes.PolygonShape; //导入方法依赖的package包/类
private static void render() {
WasmCanvas.save();
setupCanvas();
for (Body body = scene.getWorld().getBodyList(); body != null; body = body.getNext()) {
Vec2 center = body.getPosition();
WasmCanvas.save();
WasmCanvas.translate(center.x, center.y);
WasmCanvas.rotate(body.getAngle());
for (Fixture fixture = body.getFixtureList(); fixture != null; fixture = fixture.getNext()) {
Shape shape = fixture.getShape();
if (shape.getType() == ShapeType.CIRCLE) {
CircleShape circle = (CircleShape) shape;
WasmCanvas.beginPath();
WasmCanvas.arc(circle.m_p.x, circle.m_p.y, circle.getRadius(), 0, Math.PI * 2, true);
WasmCanvas.closePath();
WasmCanvas.stroke();
} else if (shape.getType() == ShapeType.POLYGON) {
PolygonShape poly = (PolygonShape) shape;
Vec2[] vertices = poly.getVertices();
WasmCanvas.beginPath();
WasmCanvas.moveTo(vertices[0].x, vertices[0].y);
for (int i = 1; i < poly.getVertexCount(); ++i) {
WasmCanvas.lineTo(vertices[i].x, vertices[i].y);
}
WasmCanvas.closePath();
WasmCanvas.stroke();
}
}
WasmCanvas.restore();
}
WasmCanvas.restore();
}
示例4: render
import org.jbox2d.collision.shapes.PolygonShape; //导入方法依赖的package包/类
private static void render() {
CanvasRenderingContext2D context = (CanvasRenderingContext2D) canvas.getContext("2d");
context.setFillStyle("white");
context.setStrokeStyle("grey");
context.fillRect(0, 0, 600, 600);
context.save();
context.translate(0, 600);
context.scale(1, -1);
context.scale(100, 100);
context.setLineWidth(0.01);
for (Body body = scene.getWorld().getBodyList(); body != null; body = body.getNext()) {
Vec2 center = body.getPosition();
context.save();
context.translate(center.x, center.y);
context.rotate(body.getAngle());
for (Fixture fixture = body.getFixtureList(); fixture != null; fixture = fixture.getNext()) {
Shape shape = fixture.getShape();
if (shape.getType() == ShapeType.CIRCLE) {
CircleShape circle = (CircleShape) shape;
context.beginPath();
context.arc(circle.m_p.x, circle.m_p.y, circle.getRadius(), 0, Math.PI * 2, true);
context.closePath();
context.stroke();
} else if (shape.getType() == ShapeType.POLYGON) {
PolygonShape poly = (PolygonShape) shape;
Vec2[] vertices = poly.getVertices();
context.beginPath();
context.moveTo(vertices[0].x, vertices[0].y);
for (int i = 1; i < poly.getVertexCount(); ++i) {
context.lineTo(vertices[i].x, vertices[i].y);
}
context.closePath();
context.stroke();
}
}
context.restore();
}
context.restore();
}
示例5: render
import org.jbox2d.collision.shapes.PolygonShape; //导入方法依赖的package包/类
private static void render() {
GraphicsContext2D context = HTML5Graphics.getOrCreate("benchmark-canvas");
context.setFillStyle(new Style.Color("white"));
context.setStrokeStyle(new Style.Color("grey"));
context.fillRect(0, 0, 600, 600);
context.save();
context.translate(0, 600);
context.scale(1, -1);
context.scale(100, 100);
context.setLineWidth(0.01);
for (Body body = scene.getWorld().getBodyList(); body != null; body = body.getNext()) {
Vec2 center = body.getPosition();
context.save();
context.translate(center.x, center.y);
context.rotate(body.getAngle());
for (Fixture fixture = body.getFixtureList(); fixture != null; fixture = fixture.getNext()) {
Shape shape = fixture.getShape();
if (shape.getType() == ShapeType.CIRCLE) {
CircleShape circle = (CircleShape) shape;
context.beginPath();
context.arc(circle.m_p.x, circle.m_p.y, circle.getRadius(), 0, Math.PI * 2, true);
context.closePath();
context.stroke();
} else if (shape.getType() == ShapeType.POLYGON) {
PolygonShape poly = (PolygonShape) shape;
Vec2[] vertices = poly.getVertices();
context.beginPath();
context.moveTo(vertices[0].x, vertices[0].y);
for (int i = 1; i < poly.getVertexCount(); ++i) {
context.lineTo(vertices[i].x, vertices[i].y);
}
context.closePath();
context.stroke();
}
}
context.restore();
}
context.restore();
}
示例6: render
import org.jbox2d.collision.shapes.PolygonShape; //导入方法依赖的package包/类
private void render() {
Context2d context = canvas.getContext2d();
context.setFillStyle("white");
context.setStrokeStyle("grey");
context.fillRect(0, 0, 600, 600);
context.save();
context.translate(0, 600);
context.scale(1, -1);
context.scale(100, 100);
context.setLineWidth(0.01);
for (Body body = scene.getWorld().getBodyList(); body != null; body = body.getNext()) {
Vec2 center = body.getPosition();
context.save();
context.translate(center.x, center.y);
context.rotate(body.getAngle());
for (Fixture fixture = body.getFixtureList(); fixture != null; fixture = fixture.getNext()) {
Shape shape = fixture.getShape();
if (shape.getType() == ShapeType.CIRCLE) {
CircleShape circle = (CircleShape) shape;
context.beginPath();
context.arc(circle.m_p.x, circle.m_p.y, circle.getRadius(), 0, Math.PI * 2, true);
context.closePath();
context.stroke();
} else if (shape.getType() == ShapeType.POLYGON) {
PolygonShape poly = (PolygonShape) shape;
Vec2[] vertices = poly.getVertices();
context.beginPath();
context.moveTo(vertices[0].x, vertices[0].y);
for (int i = 1; i < poly.getVertexCount(); ++i) {
context.lineTo(vertices[i].x, vertices[i].y);
}
context.closePath();
context.stroke();
}
}
context.restore();
}
context.restore();
}
示例7: paint
import org.jbox2d.collision.shapes.PolygonShape; //导入方法依赖的package包/类
@Override
public void paint(Graphics g) {
Graphics2D gfx = (Graphics2D) g;
gfx.setBackground(Color.white);
gfx.setPaint(Color.black);
gfx.clearRect(0, 0, 600, 600);
AffineTransform originalTransformation = gfx.getTransform();
gfx.translate(0, 600);
gfx.scale(1, -1);
gfx.scale(100, 100);
gfx.setStroke(new BasicStroke(0.01f));
for (Body body = scene.getWorld().getBodyList(); body != null; body = body.getNext()) {
Vec2 center = body.getPosition();
AffineTransform bodyTransform = gfx.getTransform();
gfx.translate(center.x, center.y);
gfx.rotate(body.getAngle());
for (Fixture fixture = body.getFixtureList(); fixture != null; fixture = fixture.getNext()) {
Shape shape = fixture.getShape();
if (shape.getType() == ShapeType.CIRCLE) {
CircleShape circle = (CircleShape) shape;
Arc2D arc = new Arc2D.Float(circle.m_p.x - circle.getRadius(),
circle.m_p.y - circle.getRadius(), circle.getRadius() * 2, circle.getRadius() * 2,
0, 360, Arc2D.CHORD);
gfx.draw(arc);
} else if (shape.getType() == ShapeType.POLYGON) {
PolygonShape poly = (PolygonShape) shape;
Vec2[] vertices = poly.getVertices();
Path2D path = new Path2D.Float(Path2D.WIND_EVEN_ODD);
path.moveTo(vertices[0].x, vertices[0].y);
for (int i = 1; i < poly.getVertexCount(); ++i) {
path.lineTo(vertices[i].x, vertices[i].y);
}
path.closePath();
gfx.draw(path);
}
}
gfx.setTransform(bodyTransform);
}
gfx.setTransform(originalTransformation);
}