本文整理汇总了Java中org.jbox2d.collision.shapes.PolygonShape类的典型用法代码示例。如果您正苦于以下问题:Java PolygonShape类的具体用法?Java PolygonShape怎么用?Java PolygonShape使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PolygonShape类属于org.jbox2d.collision.shapes包,在下文中一共展示了PolygonShape类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initPhysicsBody
import org.jbox2d.collision.shapes.PolygonShape; //导入依赖的package包/类
@Override Body initPhysicsBody(World world, float x, float y, float angle) {
FixtureDef fixtureDef = new FixtureDef();
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyType.STATIC;
bodyDef.position = new Vec2(0, 0);
Body body = world.createBody(bodyDef);
// height of the portal contact box
float boxHeight = getHeight() / 12f;
float boxWidth = getWidth() * 0.75f;
PolygonShape polygonShape = new PolygonShape();
Vec2[] polygon = new Vec2[4];
polygon[0] = new Vec2(-boxWidth/2f, getHeight()/2f - boxHeight);
polygon[1] = new Vec2(boxWidth/2f, getHeight()/2f - boxHeight);
polygon[2] = new Vec2(boxWidth/2f, getHeight()/2f);
polygon[3] = new Vec2(-boxWidth/2f, getHeight()/2f);
polygonShape.set(polygon, polygon.length);
fixtureDef.shape = polygonShape;
fixtureDef.friction = 0.1f;
fixtureDef.restitution = 0.8f;
body.createFixture(fixtureDef);
body.setTransform(new Vec2(x, y), angle);
return body;
}
示例2: Wall
import org.jbox2d.collision.shapes.PolygonShape; //导入依赖的package包/类
Wall(Box2DProcessing box2d, float x_, float y_, float w_, float h_) {
this.box2d = box2d;
x = x_;
y = y_;
w = w_;
h = h_;
PolygonShape sd = new PolygonShape();
float box2dW = box2d.scalarPixelsToWorld(w / 2);
float box2dH = box2d.scalarPixelsToWorld(h / 2);
sd.setAsBox(box2dW, box2dH);
BodyDef bd = new BodyDef();
bd.type = BodyType.STATIC;
bd.position.set(box2d.coordPixelsToWorld(x, y));
b = box2d.createBody(bd);
// Attached the shape to the body using a Fixture
b.createFixture(sd, 1);
}
示例3: makeBody
import org.jbox2d.collision.shapes.PolygonShape; //导入依赖的package包/类
void makeBody(Vec2 center, float w_, float h_) {
// Define a polygon (this is what we use for a rectangle)
PolygonShape sd = new PolygonShape();
float box2dW = box2d.scalarPixelsToWorld(w_ / 2);
float box2dH = box2d.scalarPixelsToWorld(h_ / 2);
sd.setAsBox(box2dW, box2dH);
// Define a fixture
FixtureDef fd = new FixtureDef();
fd.shape = sd;
// Parameters that affect physics
fd.density = 1;
fd.friction = 0.3F;
fd.restitution = 0.5F;
// Define the body and make it from the shape
BodyDef bd = new BodyDef();
bd.type = BodyType.DYNAMIC;
bd.position.set(box2d.coordPixelsToWorld(center));
body = box2d.createBody(bd);
body.createFixture(fd);
// Give it some initial random velocity
shake();
}
示例4: Ground
import org.jbox2d.collision.shapes.PolygonShape; //导入依赖的package包/类
public Ground(Texture texture) {
super(new Vec2(WINDOW_WIDTH/2,WINDOW_HEIGHT-texture.getTexture().height/2),texture);
//Body def
BodyDef bd = new BodyDef();
bd.type = BodyType.STATIC;
bd.position.set(Public.box2d.coordPixelsToWorld(WINDOW_WIDTH/2,WINDOW_HEIGHT-texture.getTexture().height/2) );
bd.setUserData("PhysicalGameObject,Ground");
//Create body
body = Public.box2d.createBody(bd);
//Creat Shape
PolygonShape ps = new PolygonShape();
ps.setAsBox(Public.box2d.scalarPixelsToWorld(Public.p.width*100),-Public.box2d.scalarPixelsToWorld(-texture.getTexture().height/2) );
//Fixture
FixtureDef fd = new FixtureDef();
fd.shape = ps;
fd.density = 1f;
fd.friction = 0.3f;
fd.restitution = 0.15f;
body.createFixture(fd);
}
示例5: addBodies
import org.jbox2d.collision.shapes.PolygonShape; //导入依赖的package包/类
public void addBodies(){
if (m_count < MAX_NUM) {
float x = random(-0.7f, 0.7f);
float y = random(-0.7f, 0.7f);
BodyDef bd = new BodyDef();
bd.type = BodyType.DYNAMIC;
bd.position.set(x, y);
Body body = world.createBody(bd);
PolygonShape shape = new PolygonShape();
shape.setAsBox(0.18f, 0.18f);
Fixture fixture = body.createFixture(shape, 0.01f);
fixture.m_friction = 0.1f;
fixture.m_restitution = 0.5f;
++m_count;
colorMode(HSB, 360, 100, 100);
float hue = (360 * m_count /(float)MAX_NUM) % 360;
world.bodies.add(body, true, color(hue, 100, 100), true, color(hue, 100, 50), 1f);
colorMode(RGB, 255, 255, 255);
}
}
示例6: Create
import org.jbox2d.collision.shapes.PolygonShape; //导入依赖的package包/类
@Override
public void Create()
{
BodyDef def = new BodyDef();
def.position.set(new Vec2(x, y));
def.type = type;
def.angle = 0;
this.body = Game.world.createBody(def);
PolygonShape shape = new PolygonShape();
shape.setAsBox(w/2, h/2);
FixtureDef fixture = new FixtureDef();
Filter filter = new Filter();
filter.groupIndex = 1;
fixture.density = 0.1f;
fixture.setShape(shape);
fixture.setFilter(filter);
fixture.isSensor = false;
fixture.setFriction(0.5f);
fixture.friction = 1;
fixture.setUserData(this.sprite);
Physics.SetPhysicsAccordingly(this.body, fixture, information);
body.createFixture(fixture);
}
示例7: GroundPhysics
import org.jbox2d.collision.shapes.PolygonShape; //导入依赖的package包/类
public GroundPhysics(float x, float y, float w, float h, BodyType type, Ground ground)
{
super(new PhysicsInformation(0, 0, false));
BodyDef def = new BodyDef();
def.position.set(new Vec2(x, y));
def.type = type;
def.angle = 0;
this.body = Game.world.createBody(def);
PolygonShape shape = new PolygonShape();
shape.setAsBox(w/2, h/2);
FixtureDef fixture = new FixtureDef();
Filter filter = new Filter();
filter.groupIndex = 1;
fixture.density = 0.1f;
fixture.setShape(shape);
fixture.setFilter(filter);
fixture.isSensor = false;
fixture.setFriction(0.5f);
fixture.restitution = 0;
fixture.density = 1;
fixture.friction = 1;
fixture.setUserData(ground);
body.createFixture(fixture);
}
示例8: Create
import org.jbox2d.collision.shapes.PolygonShape; //导入依赖的package包/类
@Override
public void Create()
{
BodyDef def = new BodyDef();
def.position.set(new Vec2(x, y));
def.type = type;
def.angle = 0;
this.body = Game.world.createBody(def);
PolygonShape shape = new PolygonShape();
shape.setAsBox(w/2, h/2);
FixtureDef fixture = new FixtureDef();
Filter filter = new Filter();
filter.groupIndex = 1;
fixture.density = 0.1f;
fixture.setShape(shape);
fixture.setFilter(filter);
fixture.isSensor = false;
fixture.setFriction(0.5f);
fixture.friction = 1;
fixture.setUserData(box);
//Physics.SetPhysicsAccordingly(this.body, fixture, information);
body.createFixture(fixture);
}
示例9: set
import org.jbox2d.collision.shapes.PolygonShape; //导入依赖的package包/类
/**
* Initialize the proxy using the given shape. The shape
* must remain in scope while the proxy is in use.
*/
public final void set(final Shape shape){
switch(shape.getType()){
case CIRCLE:
final CircleShape circle = (CircleShape) shape;
m_vertices[0].set(circle.m_p);
m_count = 1;
m_radius = circle.m_radius;
break;
case POLYGON:
final PolygonShape poly = (PolygonShape) shape;
m_count = poly.m_vertexCount;
m_radius = poly.m_radius;
for(int i=0; i<m_count; i++){
m_vertices[i].set(poly.m_vertices[i]);
}
break;
default:
assert(false);
}
}
示例10: makeDomino
import org.jbox2d.collision.shapes.PolygonShape; //导入依赖的package包/类
public void makeDomino(float x, float y, boolean horizontal, World world) {
PolygonShape sd = new PolygonShape();
sd.setAsBox(.5f*dwidth, .5f*dheight);
FixtureDef fd = new FixtureDef();
fd.shape = sd;
fd.density = ddensity;
BodyDef bd = new BodyDef();
bd.type = BodyType.DYNAMIC;
fd.friction = dfriction;
fd.restitution = 0.65f;
bd.position = new Vec2(x, y);
bd.angle = horizontal? (float)(Math.PI/2.0):0f;
Body myBody = world.createBody(bd);
myBody.createFixture(fd);
}
示例11: initTest
import org.jbox2d.collision.shapes.PolygonShape; //导入依赖的package包/类
@Override
public void initTest() {
setTitle("Couple of Things Test");
m_world.setGravity(new Vec2());
for (int i = 0; i < 2; i++)
{
// CircleShape circleShape = new CircleShape();
// circleShape.m_radius = 1;
// Shape shape = circleShape;
PolygonShape polygonShape = new PolygonShape();
polygonShape.setAsBox(1, 1);
Shape shape = polygonShape;
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyType.DYNAMIC;
bodyDef.position.set(5 * i, 0);
bodyDef.angle = (float) (Math.PI / 4 * i);
bodyDef.allowSleep = false;
Body body = m_world.createBody(bodyDef);
body.createFixture(shape, 5.0f);
body.applyForce(new Vec2(-10000 * (i - 1), 0), new Vec2());
}
}
示例12: init
import org.jbox2d.collision.shapes.PolygonShape; //导入依赖的package包/类
@Override
public void init(RunConfig config) throws InvalidTestFormatException {
super.init(config);
eshape = new EdgeShape();
eshape.set(new Vec2(-40.0f, 0.0f), new Vec2(40.0f, 0.0f));
shape = new PolygonShape();
shape.setAsBox(0.6f, 0.125f);
fixtureDef = new FixtureDef();
fixtureDef.shape = shape;
fixtureDef.density = 20.0f;
fixtureDef.friction = 0.2f;
bodyDef = new BodyDef();
anchor = new Vec2(0, 0);
}
示例13: init
import org.jbox2d.collision.shapes.PolygonShape; //导入依赖的package包/类
@Override
public void init(RunConfig config) throws InvalidTestFormatException {
super.init(config);
gravity = new Vec2(0.0f, -10.0f);
platformFixtureDef = new FixtureDef();
PolygonShape platformPolygonShape = new PolygonShape();
platformPolygonShape.setAsBox(15.0f, 0.1f);
platformFixtureDef.shape = platformPolygonShape;
dominoFixtureDef = new FixtureDef();
PolygonShape dominoPolygonShape = new PolygonShape();
dominoPolygonShape.setAsBox(0.2f, 2.5f);
dominoFixtureDef.shape = dominoPolygonShape;
dominoFixtureDef.density = 25.0f;
dominoFixtureDef.friction = .5f;
dominoBody = new BodyDef();
dominoBody.type = BodyType.DYNAMIC;
floorFixtureDef = new FixtureDef();
PolygonShape floorPolygonShape = new PolygonShape();
floorPolygonShape.setAsBox(60.0f, 5.0f);
floorFixtureDef.shape = floorPolygonShape;
floor = new BodyDef();
}
示例14: initPhysicsBody
import org.jbox2d.collision.shapes.PolygonShape; //导入依赖的package包/类
@Override Body initPhysicsBody(World world, float x, float y, float angle) {
FixtureDef fixtureDef = new FixtureDef();
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyType.STATIC;
bodyDef.position = new Vec2(0, 0);
Body body = world.createBody(bodyDef);
PolygonShape polygonShape = new PolygonShape();
Vec2[] polygon = new Vec2[4];
polygon[0] = new Vec2(-getWidth()/2f, -getHeight()/2f + getTopOffset());
polygon[1] = new Vec2(getWidth()/2f, -getHeight()/2f + getTopOffset());
polygon[2] = new Vec2(getWidth()/2f, getHeight()/2f);
polygon[3] = new Vec2(-getWidth()/2f, getHeight()/2f);
polygonShape.set(polygon, polygon.length);
fixtureDef.shape = polygonShape;
fixtureDef.friction = 0.1f;
fixtureDef.restitution = 0.8f;
body.createFixture(fixtureDef);
body.setTransform(new Vec2(x, y), angle);
return body;
}
示例15: initPhysicsBody
import org.jbox2d.collision.shapes.PolygonShape; //导入依赖的package包/类
@Override
Body initPhysicsBody(World world, float x, float y, float angle) {
FixtureDef fixtureDef = new FixtureDef();
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyType.STATIC;
bodyDef.position = new Vec2(0, 0);
Body body = world.createBody(bodyDef);
PolygonShape polygonShape = new PolygonShape();
Vec2[] polygon = new Vec2[3];
polygon[0] = new Vec2(getWidth()/2f, -getHeight()/2f + getTopOffset());
polygon[1] = new Vec2(getWidth()/2f, getHeight()/2f);
polygon[2] = new Vec2(-getWidth()/2f, getHeight()/2f);
polygonShape.set(polygon, polygon.length);
fixtureDef.shape = polygonShape;
fixtureDef.friction = 0.1f;
fixtureDef.restitution = 0.9f;
body.createFixture(fixtureDef);
body.setTransform(new Vec2(x, y), angle);
return body;
}