本文整理汇总了Java中org.jbox2d.dynamics.World.step方法的典型用法代码示例。如果您正苦于以下问题:Java World.step方法的具体用法?Java World.step怎么用?Java World.step使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jbox2d.dynamics.World
的用法示例。
在下文中一共展示了World.step方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSimpleBall
import org.jbox2d.dynamics.World; //导入方法依赖的package包/类
@Test
public void testSimpleBall() {
World world = new World(new Vec2(0, -9.8f));
float ballRadius = 0.15f;
BodyDef ballDef = new BodyDef();
ballDef.type = BodyType.DYNAMIC;
FixtureDef fixtureDef = new FixtureDef();
fixtureDef.friction = 0.3f;
fixtureDef.restitution = 0.3f;
fixtureDef.density = 0.2f;
CircleShape shape = new CircleShape();
shape.m_radius = ballRadius;
fixtureDef.shape = shape;
int i=0;
int j=0;
float x = (j + 0.5f) * (ballRadius * 2 + 0.01f);
float y = (i + 0.5f) * (ballRadius * 2 + 0.01f);
ballDef.position.x = 3 + x;
ballDef.position.y = 3 + y;
Body theBall = world.createBody(ballDef);
theBall.createFixture(fixtureDef);
for (int k=0;k<100;k++) {
world.step(0.01f, 20, 40);
}
Vec2 thePosition = theBall.getPosition();
int theX = (int)(thePosition.x * 1000);
int theY = (int) (thePosition.y * 1000);
System.out.println("Finally ended at ");
System.out.println(theX);
System.out.println(theY);
}
示例2: iteration
import org.jbox2d.dynamics.World; //导入方法依赖的package包/类
@Override
public long iteration() {
long count = 0;
for (int k = 0; k < repeats; k++) {
Vec2 gravity = new Vec2(0.0f, -10.0f);
world = new World(gravity);
Body ground = world.createBody(bodyDef);
ground.createFixture(eshape, 0.0f);
RevoluteJointDef jd = new RevoluteJointDef();
jd.collideConnected = false;
final float y = 25.0f;
Body prevBody = ground;
for (int i = 0; i < 35; ++i) {
bodyDef.type = BodyType.DYNAMIC;
bodyDef.position.set(0.5f + i, y);
Body body = world.createBody(bodyDef);
body.createFixture(fixtureDef);
anchor.set(i, y);
jd.initialize(prevBody, body, anchor);
world.createJoint(jd);
prevBody = body;
}
for (int t = 0; t < steps; t++) {
world.step(1.0f / 60, 80, 80);
count++;
}
}
return count;
}
示例3: iteration
import org.jbox2d.dynamics.World; //导入方法依赖的package包/类
@Override
public long iteration() {
long count = 0;
for (int k = 0; k < repeats; k++) {
Vec2 gravity = new Vec2(0.0f, -10.0f);
world = new World(gravity);
Body ground = world.createBody(bodyDef);
ground.createFixture(eshape, 0.0f);
RevoluteJointDef jd = new RevoluteJointDef();
jd.collideConnected = false;
final float y = 25.0f;
Body prevBody = ground;
for (int i = 0; i < 35; ++i) {
bodyDef.type = BodyType.DYNAMIC;
bodyDef.position.set(0.5f + i, y);
Body body = world.createBody(bodyDef);
body.createFixture(fixtureDef);
anchor.set(i, y);
jd.initialize(prevBody, body, anchor);
world.createJoint(jd);
prevBody = body;
}
for (int t = 0; t < steps; t++) {
world.step(1.0f / 60, 4, 80);
count++;
}
}
return count;
}
示例4: iteration
import org.jbox2d.dynamics.World; //导入方法依赖的package包/类
@Override
public long iteration() {
long count = 0;
for (int k = 0; k < repeats; k++) {
world = new World(gravity);
for (int i = 0; i < 10; i++) {
BodyDef platform = new BodyDef();
platform.position = new Vec2(0.0f, 5f + 5f * i);
world.createBody(platform).createFixture(platformFixtureDef);
}
int numPerRow = 26;
for (int i = 0; i < 1; ++i) {
for (int j = 0; j < numPerRow; j++) {
dominoBody.position = new Vec2(-14.75f + j
* (29.5f / (numPerRow - 1)), 7.3f + 5f * i);
if (j == 0) {
dominoBody.angle = -0.1f;
dominoBody.position.x += .1f;
} else
dominoBody.angle = 0f;
dominoBody.bullet = true;
world.createBody(dominoBody).createFixture(dominoFixtureDef);
}
}
floor.position.set(0.0f, -10.0f);
world.createBody(floor).createFixture(floorFixtureDef);
for (int t = 0; t < steps; t++) {
world.step(1.0f / 60, 6, 2);
count++;
}
}
return count;
}
示例5: iteration
import org.jbox2d.dynamics.World; //导入方法依赖的package包/类
@Override
public long iteration() {
long count = 0;
for (int k = 0; k < repeats; k++) {
Vec2 gravity = new Vec2(0.0f, -10.0f);
world = new World(gravity);
Body ground = world.createBody(bodyDef);
ground.createFixture(eshape, 0.0f);
RevoluteJointDef jd = new RevoluteJointDef();
jd.collideConnected = false;
final float y = 25.0f;
Body prevBody = ground;
for (int i = 0; i < 35; ++i) {
bodyDef.type = BodyType.DYNAMIC;
bodyDef.position.set(0.5f + i, y);
Body body = world.createBody(bodyDef);
body.createFixture(fixtureDef);
anchor.set(i, y);
jd.initialize(prevBody, body, anchor);
world.createJoint(jd);
prevBody = body;
}
for (int t = 0; t < steps; t++) {
world.step(1.0f / 60, 80, 4);
count++;
}
}
return count;
}
示例6: iteration
import org.jbox2d.dynamics.World; //导入方法依赖的package包/类
@Override
public long iteration() {
long count = 0;
for (int k = 0; k < repeats; k++) {
world = new World(gravity);
for (int i = 0; i < 10; i++) {
BodyDef platform = new BodyDef();
platform.position = new Vec2(0.0f, 5f + 5f * i);
world.createBody(platform).createFixture(platformFixtureDef);
}
int numPerRow = 15;
for (int i = 0; i < 10; ++i) {
for (int j = 0; j < numPerRow; j++) {
dominoBody.position = new Vec2(-14.75f + j * (16.5f / (numPerRow - 1)), 7.3f + 5f * i);
if (j == 0) {
dominoBody.angle = -0.1f;
dominoBody.position.x += .1f;
} else
dominoBody.angle = 0f;
world.createBody(dominoBody).createFixture(dominoFixtureDef);
}
}
floor.position.set(0.0f, -10.0f);
world.createBody(floor).createFixture(floorFixtureDef);
for (int t = 0; t < steps; t++) {
world.step(1.0f / 60, 6, 2);
count++;
}
}
return count;
}
示例7: iteration
import org.jbox2d.dynamics.World; //导入方法依赖的package包/类
@Override
public long iteration() {
long count = 0;
for (int k = 0; k < repeats; k++) {
Vec2 gravity = new Vec2(0.0f, -10.0f);
world = new World(gravity);
Body ground = world.createBody(bodyDef);
ground.createFixture(eshape, 0.0f);
RevoluteJointDef jd = new RevoluteJointDef();
jd.collideConnected = false;
final float y = 25.0f;
Body prevBody = ground;
for (int i = 0; i < 35; ++i) {
bodyDef.type = BodyType.DYNAMIC;
bodyDef.position.set(0.5f + i, y);
Body body = world.createBody(bodyDef);
body.createFixture(fixtureDef);
anchor.set(i, y);
jd.initialize(prevBody, body, anchor);
world.createJoint(jd);
prevBody = body;
}
for (int t = 0; t < steps; t++) {
world.step(1.0f / 60, 4, 4);
count++;
}
}
return count;
}