本文整理汇总了Java中org.jbox2d.dynamics.joints.ConstantVolumeJointDef类的典型用法代码示例。如果您正苦于以下问题:Java ConstantVolumeJointDef类的具体用法?Java ConstantVolumeJointDef怎么用?Java ConstantVolumeJointDef使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConstantVolumeJointDef类属于org.jbox2d.dynamics.joints包,在下文中一共展示了ConstantVolumeJointDef类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: init
import org.jbox2d.dynamics.joints.ConstantVolumeJointDef; //导入依赖的package包/类
@Override
public void init(RunConfig config) throws InvalidTestFormatException {
super.init(config);
Vec2 gravity = new Vec2(0.0f, -10.0f);
world = new World(gravity);
ConstantVolumeJointDef constantVolumeJointDef = new ConstantVolumeJointDef();
float cx = 0.0f;
float cy = 10.0f;
float rx = 5.0f;
float ry = 5.0f;
int n = 20;
float circleRadius = 0.5f;
for (int i = 0; i < n; ++i) {
float angle = MathUtils.map(i, 0, n, 0, 2 * (float) Math.PI);
BodyDef circleBodyDef = new BodyDef();
circleBodyDef.fixedRotation = true;
float x = cx + rx * (float) Math.sin(angle);
float y = cy + ry * (float) Math.cos(angle);
circleBodyDef.position.set(new Vec2(x, y));
circleBodyDef.type = BodyType.DYNAMIC;
Body circle = world.createBody(circleBodyDef);
FixtureDef circleFixtureDef = new FixtureDef();
CircleShape cd = new CircleShape();
cd.m_radius = circleRadius;
circleFixtureDef.shape = cd;
circleFixtureDef.density = 1.0f;
circle.createFixture(circleFixtureDef);
constantVolumeJointDef.addBody(circle);
}
constantVolumeJointDef.frequencyHz = 10.0f;
constantVolumeJointDef.dampingRatio = 1.0f;
constantVolumeJointDef.collideConnected = false;
world.createJoint(constantVolumeJointDef);
BodyDef bodyDef2 = new BodyDef();
bodyDef2.type = BodyType.DYNAMIC;
PolygonShape psd = new PolygonShape();
psd.setAsBox(3.0f, 1.5f, new Vec2(cx, cy + 15.0f), 0.0f);
bodyDef2.position = new Vec2(cx, cy + 15.0f);
fallingBox = world.createBody(bodyDef2);
fallingBox.createFixture(psd, 1.0f);
Body ground = null;
PolygonShape sd = new PolygonShape();
sd.setAsBox(50.0f, 0.4f);
BodyDef bodyDef = new BodyDef();
bodyDef.position.set(0.0f, 0.0f);
ground = world.createBody(bodyDef);
ground.createFixture(sd, 0f);
sd.setAsBox(0.4f, 50.0f, new Vec2(-10.0f, 0.0f), 0.0f);
ground.createFixture(sd, 0f);
sd.setAsBox(0.4f, 50.0f, new Vec2(10.0f, 0.0f), 0.0f);
ground.createFixture(sd, 0f);
}
开发者ID:android-workloads,项目名称:JACWfA,代码行数:63,代码来源:Blob.java
注:本文中的org.jbox2d.dynamics.joints.ConstantVolumeJointDef类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论