本文整理汇总了Java中org.jbox2d.collision.shapes.ShapeType.CIRCLE属性的典型用法代码示例。如果您正苦于以下问题:Java ShapeType.CIRCLE属性的具体用法?Java ShapeType.CIRCLE怎么用?Java ShapeType.CIRCLE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.jbox2d.collision.shapes.ShapeType
的用法示例。
在下文中一共展示了ShapeType.CIRCLE属性的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: render
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: setShape
/**
* Any Shape given as a brush. Use (0,0) as center.
* only ShapeType.CIRCLE and ShapeType.POLYGON can be used
*
*/
public void setShape(Shape shape){
boolean is_circle = ShapeType.CIRCLE == shape.getType();
boolean is_polygon = ShapeType.POLYGON == shape.getType();
if(is_circle || is_polygon){
this.shape = shape;
}
}
示例3: setShape
/**
* Any Shape given as a brush. Use (0,0) as center.
* only ShapeType.CIRCLE and ShapeType.POLYGON can be used
*
*/
public void setShape(Shape shape){
boolean is_circle = ShapeType.CIRCLE == shape.getType();
boolean is_polygon = ShapeType.POLYGON == shape.getType();
if(is_circle || is_polygon){
group_def.shape = shape;
}
}
示例4: getType
/** Get the type of the child shape. You can use this to down cast to the concrete shape.
* @return the shape type. */
public Type getType () {
ShapeType type = fixture.getType();
if (type == ShapeType.CIRCLE) return Type.Circle;
if (type == ShapeType.EDGE) return Type.Edge;
if (type == ShapeType.POLYGON) return Type.Polygon;
if (type == ShapeType.CHAIN) return Type.Chain;
return Type.Circle;
}
示例5: getShape
/** Returns the shape of this fixture */
public Shape getShape () {
if (shape == null) {
org.jbox2d.collision.shapes.Shape shape2 = fixture.getShape();
ShapeType type = shape2.getType();
if (type == ShapeType.CHAIN) shape = new ChainShape((org.jbox2d.collision.shapes.ChainShape)shape2);
if (type == ShapeType.CIRCLE) shape = new CircleShape((org.jbox2d.collision.shapes.CircleShape)shape2);
if (type == ShapeType.EDGE) shape = new EdgeShape((org.jbox2d.collision.shapes.EdgeShape)shape2);
if (type == ShapeType.POLYGON) shape = new PolygonShape((org.jbox2d.collision.shapes.PolygonShape)shape2);
}
return shape;
}
示例6: render
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();
}
示例7: render
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();
}
示例8: render
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();
}
示例9: render
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();
}
示例10: ShapelessShape
public ShapelessShape(double mass) {
super(ShapeType.CIRCLE);
this.mass = mass;
}
示例11: paint
@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);
}
示例12: isAbove
public boolean isAbove(Box2dPhysicsBody body, Fixture otherFixture) {
// compute top-left and top-right points of the one-way platform
Transform t = body.body.getTransform();
Vec2 pos = body.getBodyCenterCorrection();
Vec2 v1 = Transform.mul(t, new Vec2( pos.x-body.width/2.f, pos.y-body.height/2.f).mul(BOX2D_SCALE_FACTOR));
Vec2 v2 = Transform.mul(t, new Vec2( pos.x+body.width/2.f, pos.y-body.height/2.f).mul(BOX2D_SCALE_FACTOR));
if( otherFixture.getType() == ShapeType.CIRCLE ) {
CircleShape shape = (CircleShape) otherFixture.m_shape;
pos = Transform.mul(this.body.getTransform(), shape.m_p);
if( isPointAbove(v1, v2, pos) ) {
float r = shape.m_radius;
// compute the shortest distance between the point and the line(v1 -> v2)
Vec2 n = new Vec2(v1.x-v2.x, v1.y-v2.y);
n.normalize(); // line unit vector
Vec2 c1 = v1.sub(pos);
Vec2 c2 = n.mul(Vec2.dot(c1, n));
// special case at corners
// if( (this.body.m_linearVelocity.y > .0) && ( (pos.x < v1.x && v1.y <= v2.y) || ( pos.x > v2.x && v2.y <= v1.y ) ) )
// return c1.sub(c2).length() >= r-0.1f;
return c1.sub(c2).length() >= r-0.01f; // -0.01f because of inaccuracy reasons
}
}
// bottom-left and bottom-right points of the entity/player
t = this.body.getTransform();
pos = getBodyCenterCorrection();
Vec2 p1 = Transform.mul(t, new Vec2( pos.x-width/2.f, pos.y+height/2.f ).mul(BOX2D_SCALE_FACTOR));
Vec2 p2 = Transform.mul(t, new Vec2( pos.x+width/2.f, pos.y+height/2.f ).mul(BOX2D_SCALE_FACTOR));
if( p1.x < v1.x && v1.y < v2.y)
return p1.y <= v1.y && p1.y <= v2.y;
if( p2.x > v2.x && v2.y < v1.y)
return p1.y <= v1.y && p1.y <= v2.y;
// the cross product of 2 vectors tells us whether the second vector is on the left(cp<0), right(cp>0) side of the first vector or above(cp=0)
// we construct 2 vectors using 3 points(v1,v2,p1 and v1,v2,p2) and check the sign of the cross product
return isPointAbove(v1, v2, p1) && isPointAbove(v1, v2, p2);
}