本文整理汇总了Java中org.jbox2d.dynamics.FixtureDef类的典型用法代码示例。如果您正苦于以下问题:Java FixtureDef类的具体用法?Java FixtureDef怎么用?Java FixtureDef使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FixtureDef类属于org.jbox2d.dynamics包,在下文中一共展示了FixtureDef类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makeBody
import org.jbox2d.dynamics.FixtureDef; //导入依赖的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();
}
示例2: Ground
import org.jbox2d.dynamics.FixtureDef; //导入依赖的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);
}
示例3: Create
import org.jbox2d.dynamics.FixtureDef; //导入依赖的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);
}
示例4: GroundPhysics
import org.jbox2d.dynamics.FixtureDef; //导入依赖的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);
}
示例5: Create
import org.jbox2d.dynamics.FixtureDef; //导入依赖的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);
}
示例6: createCircle
import org.jbox2d.dynamics.FixtureDef; //导入依赖的package包/类
public void createCircle()
{
float radius = 2.0f;
CircleShape shape = new CircleShape();
shape.m_p.setZero();
shape.m_radius = radius;
FixtureDef fd = new FixtureDef();
fd.shape = shape;
fd.density = 1.0f;
fd.friction = 0.0f;
Vec2 p = new Vec2((float)Math.random(), 3.0f + (float)Math.random());
BodyDef bd = new BodyDef();
bd.type = BodyType.DYNAMIC;
bd.position = p;
//bd.allowSleep = false;
Body body = m_world.createBody(bd);
body.createFixture(fd);
}
示例7: makeDomino
import org.jbox2d.dynamics.FixtureDef; //导入依赖的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);
}
示例8: init
import org.jbox2d.dynamics.FixtureDef; //导入依赖的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);
}
示例9: init
import org.jbox2d.dynamics.FixtureDef; //导入依赖的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();
}
示例10: initPhysicsBody
import org.jbox2d.dynamics.FixtureDef; //导入依赖的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;
}
示例11: initPhysicsBody
import org.jbox2d.dynamics.FixtureDef; //导入依赖的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;
}
示例12: initPhysicsBody
import org.jbox2d.dynamics.FixtureDef; //导入依赖的package包/类
@Override
Body initPhysicsBody(World world, float x, float y, float angle) {
FixtureDef fixtureDef = new FixtureDef();
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyType.DYNAMIC;
bodyDef.position = new Vec2(0, 0);
Body body = world.createBody(bodyDef);
CircleShape circleShape = new CircleShape();
circleShape.m_radius = getRadius();
fixtureDef.shape = circleShape;
fixtureDef.density = 0.4f;
fixtureDef.friction = 0.1f;
fixtureDef.restitution = 0.35f;
circleShape.m_p.set(0, 0);
body.createFixture(fixtureDef);
body.setLinearDamping(0.2f);
body.setTransform(new Vec2(x, y), angle);
return body;
}
示例13: initPhysicsBody
import org.jbox2d.dynamics.FixtureDef; //导入依赖的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;
}
示例14: initPhysicsBody
import org.jbox2d.dynamics.FixtureDef; //导入依赖的package包/类
Body initPhysicsBody(World world, float x, float y, float angle) {
FixtureDef fixtureDef = new FixtureDef();
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyType.DYNAMIC;
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, polygon[0].y + getSpringBoxHeight());
polygon[3] = new Vec2(-getWidth() / 2f, polygon[1].y + getSpringBoxHeight());
polygonShape.set(polygon, polygon.length);
fixtureDef.shape = polygonShape;
fixtureDef.friction = 0.1f;
fixtureDef.restitution = 1.4f;
body.createFixture(fixtureDef);
body.setTransform(new Vec2(x, y), angle);
return body;
}
示例15: initPhysicsBody
import org.jbox2d.dynamics.FixtureDef; //导入依赖的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 = 1.0f;
fixtureDef.restitution = 0.3f;
body.createFixture(fixtureDef);
body.setTransform(new Vec2(x, y), angle);
return body;
}