本文整理汇总了Java中org.jbox2d.collision.shapes.PolygonShape.setAsEdge方法的典型用法代码示例。如果您正苦于以下问题:Java PolygonShape.setAsEdge方法的具体用法?Java PolygonShape.setAsEdge怎么用?Java PolygonShape.setAsEdge使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jbox2d.collision.shapes.PolygonShape
的用法示例。
在下文中一共展示了PolygonShape.setAsEdge方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initTest
import org.jbox2d.collision.shapes.PolygonShape; //导入方法依赖的package包/类
/**
* @see org.jbox2d.testbed.framework.TestbedTest#initTest()
*/
@Override
public void initTest() {
Body ground = null;
{
BodyDef bd = new BodyDef();
ground = m_world.createBody(bd);
PolygonShape shape = new PolygonShape();
shape.setAsEdge(new Vec2(50.0f, 0.0f), new Vec2(-50.0f, 0.0f));
ground.createFixture(shape, 0.0f);
}
{
CircleShape circle1 = new CircleShape();
circle1.m_radius = 1.0f;
CircleShape circle2 = new CircleShape();
circle2.m_radius = 2.0f;
PolygonShape box = new PolygonShape();
box.setAsBox(0.5f, 5.0f);
BodyDef bd1 = new BodyDef();
bd1.type = BodyType.DYNAMIC;
bd1.position.set(-3.0f, 12.0f);
Body body1 = m_world.createBody(bd1);
body1.createFixture(circle1, 5.0f);
RevoluteJointDef jd1 = new RevoluteJointDef();
jd1.bodyA = ground;
jd1.bodyB = body1;
jd1.localAnchorA = ground.getLocalPoint(bd1.position);
jd1.localAnchorB = body1.getLocalPoint(bd1.position);
jd1.referenceAngle = body1.getAngle() - ground.getAngle();
m_joint1 = (RevoluteJoint)m_world.createJoint(jd1);
BodyDef bd2 = new BodyDef();
bd2.type = BodyType.DYNAMIC;
bd2.position.set(0.0f, 12.0f);
Body body2 = m_world.createBody(bd2);
body2.createFixture(circle2, 5.0f);
RevoluteJointDef jd2 = new RevoluteJointDef();
jd2.initialize(ground, body2, bd2.position);
m_joint2 = (RevoluteJoint)m_world.createJoint(jd2);
BodyDef bd3 = new BodyDef();
bd3.type = BodyType.DYNAMIC;
bd3.position.set(2.5f, 12.0f);
Body body3 = m_world.createBody(bd3);
body3.createFixture(box, 5.0f);
PrismaticJointDef jd3 = new PrismaticJointDef();
jd3.initialize(ground, body3, bd3.position, new Vec2(0.0f, 1.0f));
jd3.lowerTranslation = -5.0f;
jd3.upperTranslation = 5.0f;
jd3.enableLimit = true;
m_joint3 = (PrismaticJoint)m_world.createJoint(jd3);
GearJointDef jd4 = new GearJointDef();
jd4.bodyA = body1;
jd4.bodyB = body2;
jd4.joint1 = m_joint1;
jd4.joint2 = m_joint2;
jd4.ratio = circle2.m_radius / circle1.m_radius;
m_joint4 = (GearJoint)m_world.createJoint(jd4);
GearJointDef jd5 = new GearJointDef();
jd5.bodyA = body2;
jd5.bodyB = body3;
jd5.joint1 = m_joint2;
jd5.joint2 = m_joint3;
jd5.ratio = -1.0f / circle2.m_radius;
m_joint5 = (GearJoint)m_world.createJoint(jd5);
}
}
示例2: PeaWorld
import org.jbox2d.collision.shapes.PolygonShape; //导入方法依赖的package包/类
public PeaWorld(GroupLayer scaledLayer) {
staticLayerBack = graphics().createGroupLayer();
scaledLayer.add(staticLayerBack);
dynamicLayer = graphics().createGroupLayer();
scaledLayer.add(dynamicLayer);
staticLayerFront = graphics().createGroupLayer();
scaledLayer.add(staticLayerFront);
// create the physics world
Vec2 gravity = new Vec2(0.0f, 10.0f);
world = new World(gravity, true);
world.setWarmStarting(true);
world.setAutoClearForces(true);
world.setContactListener(this);
// create the ground
Body ground = world.createBody(new BodyDef());
PolygonShape groundShape = new PolygonShape();
groundShape.setAsEdge(new Vec2(0, height), new Vec2(width, height));
ground.createFixture(groundShape, 0.0f);
// create the walls
Body wallLeft = world.createBody(new BodyDef());
PolygonShape wallLeftShape = new PolygonShape();
wallLeftShape.setAsEdge(new Vec2(0, 0), new Vec2(0, height));
wallLeft.createFixture(wallLeftShape, 0.0f);
Body wallRight = world.createBody(new BodyDef());
PolygonShape wallRightShape = new PolygonShape();
wallRightShape.setAsEdge(new Vec2(width, 0), new Vec2(width, height));
wallRight.createFixture(wallRightShape, 0.0f);
if (showDebugDraw) {
CanvasLayer canvasLayer =
graphics().createCanvasLayer((int) (width / Peas.physUnitPerScreenUnit),
(int) (height / Peas.physUnitPerScreenUnit));
graphics().rootLayer().add(canvasLayer);
debugDraw = new DebugDrawBox2D();
debugDraw.setCanvas(canvasLayer);
debugDraw.setFlipY(false);
debugDraw.setStrokeAlpha(150);
debugDraw.setFillAlpha(75);
debugDraw.setStrokeWidth(2.0f);
debugDraw.setFlags(DebugDraw.e_shapeBit | DebugDraw.e_jointBit | DebugDraw.e_aabbBit);
debugDraw.setCamera(0, 0, 1f / Peas.physUnitPerScreenUnit);
world.setDebugDraw(debugDraw);
}
}
示例3: initTest
import org.jbox2d.collision.shapes.PolygonShape; //导入方法依赖的package包/类
/**
* @see org.jbox2d.testbed.framework.TestbedTest#initTest(boolean)
*/
@Override
public void initTest(boolean argDeserialized) {
Body ground = null;
{
BodyDef bd = new BodyDef();
ground = getWorld().createBody(bd);
PolygonShape shape = new PolygonShape();
shape.setAsEdge(new Vec2(50.0f, 0.0f), new Vec2(-50.0f, 0.0f));
ground.createFixture(shape, 0.0f);
}
{
CircleShape circle1 = new CircleShape();
circle1.m_radius = 1.0f;
CircleShape circle2 = new CircleShape();
circle2.m_radius = 2.0f;
PolygonShape box = new PolygonShape();
box.setAsBox(0.5f, 5.0f);
BodyDef bd1 = new BodyDef();
bd1.type = BodyType.DYNAMIC;
bd1.position.set(-3.0f, 12.0f);
Body body1 = getWorld().createBody(bd1);
body1.createFixture(circle1, 5.0f);
RevoluteJointDef jd1 = new RevoluteJointDef();
jd1.bodyA = ground;
jd1.bodyB = body1;
jd1.localAnchorA = ground.getLocalPoint(bd1.position);
jd1.localAnchorB = body1.getLocalPoint(bd1.position);
jd1.referenceAngle = body1.getAngle() - ground.getAngle();
m_joint1 = (RevoluteJoint)getWorld().createJoint(jd1);
BodyDef bd2 = new BodyDef();
bd2.type = BodyType.DYNAMIC;
bd2.position.set(0.0f, 12.0f);
Body body2 = getWorld().createBody(bd2);
body2.createFixture(circle2, 5.0f);
RevoluteJointDef jd2 = new RevoluteJointDef();
jd2.initialize(ground, body2, bd2.position);
m_joint2 = (RevoluteJoint)getWorld().createJoint(jd2);
BodyDef bd3 = new BodyDef();
bd3.type = BodyType.DYNAMIC;
bd3.position.set(2.5f, 12.0f);
Body body3 = getWorld().createBody(bd3);
body3.createFixture(box, 5.0f);
PrismaticJointDef jd3 = new PrismaticJointDef();
jd3.initialize(ground, body3, bd3.position, new Vec2(0.0f, 1.0f));
jd3.lowerTranslation = -5.0f;
jd3.upperTranslation = 5.0f;
jd3.enableLimit = true;
m_joint3 = (PrismaticJoint)getWorld().createJoint(jd3);
GearJointDef jd4 = new GearJointDef();
jd4.bodyA = body1;
jd4.bodyB = body2;
jd4.joint1 = m_joint1;
jd4.joint2 = m_joint2;
jd4.ratio = circle2.m_radius / circle1.m_radius;
m_joint4 = (GearJoint)getWorld().createJoint(jd4);
GearJointDef jd5 = new GearJointDef();
jd5.bodyA = body2;
jd5.bodyB = body3;
jd5.joint1 = m_joint2;
jd5.joint2 = m_joint3;
jd5.ratio = -1.0f / circle2.m_radius;
m_joint5 = (GearJoint)getWorld().createJoint(jd5);
}
}