//e_columnCount = 1, //e_rowCount = 1 public VerticalStack() { { BodyDef bd = new BodyDef(); Body ground = m_world.CreateBody(bd); EdgeShape shape = new EdgeShape(); shape.Set(new Vec2(-40.0f, 0.0f), new Vec2(40.0f, 0.0f)); shape.Density = 0; ground.CreateFixture(shape); shape.Set(new Vec2(20.0f, 0.0f), new Vec2(20.0f, 20.0f)); shape.Density = 0; ground.CreateFixture(shape); } float[] xs = {0.0f, -10.0f, -5.0f, 5.0f, 10.0f}; for (int j = 0; j < e_columnCount; ++j) { PolygonShape shape = new PolygonShape(); shape.SetAsBox(0.5f, 0.5f); FixtureDef fd = new FixtureDef(); fd.shape = shape; fd.Density = 1.0f; fd.friction = 0.3f; for (int i = 0; i < e_rowCount; ++i) { BodyDef bd = new BodyDef(); bd.type = BodyType._dynamicBody; int n = j * e_rowCount + i; Utilities.Assert(n < e_rowCount * e_columnCount); m_indices[n] = n; bd.UserData = m_indices[n]; float x = 0.0f; //float x = RandomFloat(-0.02f, 0.02f); //float x = i % 2 == 0 ? -0.025f : 0.025f; bd.Position.Set(xs[j] + x, 0.752f + 1.54f * i); Body body = m_world.CreateBody(bd); m_bodies[n] = body; body.CreateFixture(fd); } } m_bullet = null; }
public Confined() { { BodyDef bd = new BodyDef(); Body ground = m_world.CreateBody(bd); EdgeShape shape2 = new EdgeShape(); // Floor shape2.Set(new Vec2(-10.0f, 0.0f), new Vec2(10.0f, 0.0f)); shape2.Density = 0; ground.CreateFixture(shape2); // Left wall shape2.Set(new Vec2(-10.0f, 0.0f), new Vec2(-10.0f, 20.0f)); ground.CreateFixture(shape2); // Right wall shape2.Set(new Vec2(10.0f, 0.0f), new Vec2(10.0f, 20.0f)); ground.CreateFixture(shape2); // Roof shape2.Set(new Vec2(-10.0f, 20.0f), new Vec2(10.0f, 20.0f)); ground.CreateFixture(shape2); } float radius = 0.5f; 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.1f; for (int j = 0; j < e_columnCount; ++j) { for (int i = 0; i < e_rowCount; ++i) { BodyDef bd = new BodyDef(); bd.type = BodyType._dynamicBody; bd.Position.Set(-10.0f + (2.1f * j + 1.0f + 0.01f * i) * radius, (2.0f * i + 1.0f) * radius); Body body = m_world.CreateBody(bd); body.CreateFixture(fd); } } m_world.SetGravity(new Vec2(0.0f, 0.0f)); }
Breakable() { // Ground body { BodyDef bd = new BodyDef(); Body ground = m_world.CreateBody(bd); EdgeShape shape = new EdgeShape(); shape.Set(new Vec2(-40.0f, 0.0f), new Vec2(40.0f, 0.0f)); shape.Density = 0; ground.CreateFixture(shape); } // Breakable dynamic body { BodyDef bd = new BodyDef(); bd.type = BodyType._dynamicBody; bd.Position.Set(0.0f, 40.0f); bd.angle = 0.25f * (float)Math.PI; m_body1 = m_world.CreateBody(bd); m_shape1.SetAsBox(0.5f, 0.5f, new Vec2(-0.5f, 0.0f), 0.0f); m_shape1.Density = 1; m_piece1 = m_body1.CreateFixture(m_shape1); m_shape2.SetAsBox(0.5f, 0.5f, new Vec2(0.5f, 0.0f), 0.0f); m_shape2.Density = 1; m_piece2 = m_body1.CreateFixture(m_shape2); } m_break = false; m_broke = false; }
public SphereStack() { { BodyDef bd = new BodyDef(); Body ground = m_world.CreateBody(bd); EdgeShape shape = new EdgeShape(); shape.Set(new Vec2(-40.0f, 0.0f), new Vec2(40.0f, 0.0f)); shape.Density = 0; ground.CreateFixture(shape); } { CircleShape shape = new CircleShape(); shape.m_radius = 1.0f; for (int i = 0; i < e_count; ++i) { BodyDef bd = new BodyDef(); bd.type = BodyType._dynamicBody; bd.Position.Set(0.0f, 4.0f + 3.0f * i); m_bodies[i] = m_world.CreateBody(bd); m_bodies[i].CreateFixture(shape); m_bodies[i].SetLinearVelocity(new Vec2(0.0f, -50.0f)); } } }
public ShapeEditing() { { BodyDef bd1 = new BodyDef(); Body ground = m_world.CreateBody(bd1); EdgeShape shape = new EdgeShape(); shape.Set(new Vec2(-40.0f, 0.0f), new Vec2(40.0f, 0.0f)); shape.Density = 0; ground.CreateFixture(shape); } BodyDef bd = new BodyDef(); bd.type = BodyType._dynamicBody; bd.Position.Set(0.0f, 10.0f); m_body = m_world.CreateBody(bd); PolygonShape shape2 = new PolygonShape(); shape2.SetAsBox(4.0f, 4.0f, new Vec2(0.0f, 0.0f), 0.0f); shape2.Density = 10; m_fixture1 = m_body.CreateFixture(shape2); m_fixture2 = null; m_sensor = false; }
public SensorTest() { { BodyDef bd = new BodyDef(); Body ground = m_world.CreateBody(bd); { EdgeShape shape = new EdgeShape(); shape.Set(new Vec2(-40.0f, 0.0f), new Vec2(40.0f, 0.0f)); shape.Density = 0; ground.CreateFixture(shape); } #if ZERO { FixtureDef sd; sd.SetAsBox(10.0f, 2.0f, new Vec2(0.0f, 20.0f), 0.0f); sd.IsSensor = true; m_sensor = ground.CreateFixture(sd); } #else { CircleShape shape = new CircleShape(); shape.m_radius = 5.0f; shape.m_p.Set(0.0f, 10.0f); FixtureDef fd = new FixtureDef(); fd.shape = shape; fd.IsSensor = true; m_sensor = ground.CreateFixture(fd); } #endif } { CircleShape shape = new CircleShape(); shape.m_radius = 1.0f; for (int i = 0; i < e_count; ++i) { BodyDef bd = new BodyDef(); bd.type = BodyType._dynamicBody; bd.Position.Set(-10.0f + 3.0f * i, 20.0f); bd.UserData = m_touching[i]; m_touching[i] = false; m_bodies[i] = m_world.CreateBody(bd); m_bodies[i].CreateFixture(shape); } } }
public OneSidedPlatform() { // Ground { BodyDef bd = new BodyDef(); Body ground = m_world.CreateBody(bd); EdgeShape shape = new EdgeShape(); shape.Set(new Vec2(-20.0f, 0.0f), new Vec2(20.0f, 0.0f)); shape.Density = 0; ground.CreateFixture(shape); } // Platform { BodyDef bd = new BodyDef(); bd.Position.Set(0.0f, 10.0f); Body body = m_world.CreateBody(bd); PolygonShape shape = new PolygonShape(); shape.SetAsBox(3.0f, 0.5f); shape.Density = 0; m_platform = body.CreateFixture(shape); m_bottom = 10.0f - 0.5f; m_top = 10.0f + 0.5f; } // Actor { BodyDef bd = new BodyDef(); bd.type = BodyType._dynamicBody; bd.Position.Set(0.0f, 12.0f); Body body = m_world.CreateBody(bd); m_radius = 0.5f; CircleShape shape = new CircleShape(); shape.m_radius = m_radius; shape.Density = 20; m_character = body.CreateFixture(shape); body.SetLinearVelocity(new Vec2(0.0f, -50.0f)); m_state = State.e_unknown; } }
public Prismatic() { Body ground = null; { BodyDef bd = new BodyDef(); ground = m_world.CreateBody(bd); EdgeShape shape = new EdgeShape(); shape.Set(new Vec2(-40.0f, 0.0f), new Vec2(40.0f, 0.0f)); shape.Density = 0; ground.CreateFixture(shape); } { PolygonShape shape = new PolygonShape(); shape.SetAsBox(2.0f, 0.5f); shape.Density = 5; BodyDef bd = new BodyDef(); bd.type = BodyType._dynamicBody; bd.Position.Set(-10.0f, 10.0f); bd.angle = 0.5f * (float)Math.PI; bd.allowSleep = false; Body body = m_world.CreateBody(bd); body.CreateFixture(shape); PrismaticJointDef pjd = new PrismaticJointDef(); // Bouncy limit Vec2 axis = new Vec2(2.0f, 1.0f); axis.Normalize(); pjd.Initialize(ground, body, new Vec2(0.0f, 0.0f), axis); // Non-bouncy limit //pjd.Initialize(ground, body, new Vec2(-10.0f, 10.0f), new Vec2(1.0f, 0.0f)); pjd.motorSpeed = 10.0f; pjd.maxMotorForce = 10000.0f; pjd.enableMotor = true; pjd.lowerTranslation = 0.0f; pjd.upperTranslation = 20.0f; pjd.enableLimit = true; m_joint = (PrismaticJoint)m_world.CreateJoint(pjd); } }
public BulletTest() { { BodyDef bd = new BodyDef(); bd.Position.Set(0.0f, 0.0f); Body body = m_world.CreateBody(bd); EdgeShape edge = new EdgeShape(); edge.Set(new Vec2(-10.0f, 0.0f), new Vec2(10.0f, 0.0f)); edge.Density = 0; body.CreateFixture(edge); PolygonShape shape = new PolygonShape(); shape.SetAsBox(0.2f, 1.0f, new Vec2(0.5f, 1.0f), 0.0f); shape.Density = 0; body.CreateFixture(shape); } { BodyDef bd = new BodyDef(); bd.type = BodyType._dynamicBody; bd.Position.Set(0.0f, 4.0f); PolygonShape box = new PolygonShape(); box.SetAsBox(2.0f, 0.1f); box.Density = 100; m_body = m_world.CreateBody(bd); m_body.CreateFixture(box); box.SetAsBox(0.25f, 0.25f); //m_x = RandomFloat(-1.0f, 1.0f); m_x = 0.20352793f; bd.Position.Set(m_x, 10.0f); bd.bullet = true; m_bullet = m_world.CreateBody(bd); m_bullet.CreateFixture(box); m_bullet.SetLinearVelocity(new Vec2(0.0f, -50.0f)); } }
public Chain() { Body ground = null; { BodyDef bd = new BodyDef(); ground = m_world.CreateBody(bd); EdgeShape shape = new EdgeShape(); shape.Set(new Vec2(-40.0f, 0.0f), new Vec2(40.0f, 0.0f)); shape.Density = 0; ground.CreateFixture(shape); } { PolygonShape shape = new PolygonShape(); shape.SetAsBox(0.6f, 0.125f); FixtureDef fd = new FixtureDef(); fd.shape = shape; fd.Density = 20.0f; fd.friction = 0.2f; RevoluteJointDef jd = new RevoluteJointDef(); jd.collideConnected = false; const float y = 25.0f; Body prevBody = ground; for (int i = 0; i < 30; ++i) { BodyDef bd = new BodyDef(); bd.type = BodyType._dynamicBody; bd.Position.Set(0.5f + i, y); Body body = m_world.CreateBody(bd); body.CreateFixture(fd); Vec2 anchor = new Vec2((float)(i), y); jd.Initialize(prevBody, body, anchor); m_world.CreateJoint(jd); prevBody = body; } } }
public Pyramid() { { BodyDef bd = new BodyDef(); Body ground = m_world.CreateBody(bd); EdgeShape shape = new EdgeShape(); shape.Set(new Vec2(-40.0f, 0.0f), new Vec2(40.0f, 0.0f)); shape.Density = 0; ground.CreateFixture(shape); } { float a = 0.5f; PolygonShape shape = new PolygonShape(); shape.SetAsBox(a, a); shape.Density = 5; Vec2 x = new Vec2(-7.0f, 0.75f); Vec2 y; Vec2 deltaX = new Vec2(0.5625f, 1.25f); Vec2 deltaY = new Vec2(1.125f, 0.0f); for (int i = 0; i < e_count; ++i) { y = x; for (int j = i; j < e_count; ++j) { BodyDef bd = new BodyDef(); bd.type = BodyType._dynamicBody; bd.Position = y; Body body = m_world.CreateBody(bd); body.CreateFixture(shape); y += deltaY; } x += deltaX; } } }
public ConveyorBelt() { // Ground { BodyDef bd = new BodyDef(); Body ground = m_world.CreateBody(bd); EdgeShape shape = new EdgeShape(); shape.Set(new Vec2(-20.0f, 0.0f), new Vec2(20.0f, 0.0f)); shape.Density = 0; ground.CreateFixture(shape); } // Platform { BodyDef bd = new BodyDef(); bd.Position.Set(-5.0f, 5.0f); Body body = m_world.CreateBody(bd); PolygonShape shape = new PolygonShape(); shape.SetAsBox(10.0f, 0.5f); FixtureDef fd = new FixtureDef(); fd.shape = shape; fd.friction = 0.8f; m_platform = body.CreateFixture(fd); } // Boxes for (int i = 0; i < 5; ++i) { BodyDef bd = new BodyDef(); bd.type = BodyType._dynamicBody; bd.Position.Set(-10.0f + 2.0f * i, 7.0f); Body body = m_world.CreateBody(bd); PolygonShape shape = new PolygonShape(); shape.SetAsBox(0.5f, 0.5f); shape.Density = 20; body.CreateFixture(shape); } }
public MotorJointTest() { Body ground = null; { BodyDef bd = new BodyDef(); ground = m_world.CreateBody(bd); EdgeShape shape = new EdgeShape(); shape.Set(new Vec2(-20.0f, 0.0f), new Vec2(20.0f, 0.0f)); FixtureDef fd = new FixtureDef(); fd.shape = shape; ground.CreateFixture(fd); } // Define motorized body { BodyDef bd = new BodyDef(); bd.type = BodyType._dynamicBody; bd.Position.Set(0.0f, 8.0f); Body body = m_world.CreateBody(bd); PolygonShape shape = new PolygonShape(); shape.SetAsBox(2.0f, 0.5f); FixtureDef fd = new FixtureDef(); fd.shape = shape; fd.friction = 0.6f; fd.Density = 2.0f; body.CreateFixture(fd); MotorJointDef mjd = new MotorJointDef(); mjd.Initialize(ground, body); mjd.maxForce = 1000.0f; mjd.maxTorque = 1000.0f; m_joint = (MotorJoint)m_world.CreateJoint(mjd); } m_go = false; m_time = 0.0f; }
public VaryingRestitution() { { BodyDef bd = new BodyDef(); Body ground = m_world.CreateBody(bd); EdgeShape shape = new EdgeShape(); shape.Set(new Vec2(-40.0f, 0.0f), new Vec2(40.0f, 0.0f)); shape.Density = 0; ground.CreateFixture(shape); } { CircleShape shape = new CircleShape(); shape.m_radius = 1.0f; FixtureDef fd = new FixtureDef(); fd.shape = shape; fd.Density = 1.0f; float[] restitution = {0.0f, 0.1f, 0.3f, 0.5f, 0.75f, 0.9f, 1.0f}; for (int i = 0; i < 7; ++i) { BodyDef bd = new BodyDef(); bd.type = BodyType._dynamicBody; bd.Position.Set(-10.0f + 3.0f * i, 20.0f); Body body = m_world.CreateBody(bd); fd.restitution = restitution[i]; body.CreateFixture(fd); } } }
public CharacterCollision() { // Ground body { BodyDef bd = new BodyDef(); Body ground = m_world.CreateBody(bd); EdgeShape shape = new EdgeShape(); shape.Set(new Vec2(-20.0f, 0.0f), new Vec2(20.0f, 0.0f)); shape.Density = 0; ground.CreateFixture(shape); } // Collinear edges with no adjacency information. // This shows the problematic case where a box shape can hit // an internal vertex. { BodyDef bd = new BodyDef(); Body ground = m_world.CreateBody(bd); EdgeShape shape = new EdgeShape(); shape.Density = 0; shape.Set(new Vec2(-8.0f, 1.0f), new Vec2(-6.0f, 1.0f)); ground.CreateFixture(shape); shape.Set(new Vec2(-6.0f, 1.0f), new Vec2(-4.0f, 1.0f)); ground.CreateFixture(shape); shape.Set(new Vec2(-4.0f, 1.0f), new Vec2(-2.0f, 1.0f)); ground.CreateFixture(shape); } // Chain shape { BodyDef bd = new BodyDef(); bd.angle = 0.25f * (float)Math.PI; Body ground = m_world.CreateBody(bd); Vec2[] vs = new Vec2[4]; vs[0].Set(5.0f, 7.0f); vs[1].Set(6.0f, 8.0f); vs[2].Set(7.0f, 8.0f); vs[3].Set(8.0f, 7.0f); ChainShape shape = new ChainShape(); shape.CreateChain(vs, 4); shape.Density = 0; ground.CreateFixture(shape); } // Square tiles. This shows that adjacency shapes may // have non-smooth collision. There is no solution // to this problem. { BodyDef bd = new BodyDef(); Body ground = m_world.CreateBody(bd); PolygonShape shape = new PolygonShape(); shape.Density = 0; shape.SetAsBox(1.0f, 1.0f, new Vec2(4.0f, 3.0f), 0.0f); ground.CreateFixture(shape); shape.SetAsBox(1.0f, 1.0f, new Vec2(6.0f, 3.0f), 0.0f); ground.CreateFixture(shape); shape.SetAsBox(1.0f, 1.0f, new Vec2(8.0f, 3.0f), 0.0f); ground.CreateFixture(shape); } // Square made from an edge loop. Collision should be smooth. { BodyDef bd = new BodyDef(); Body ground = m_world.CreateBody(bd); Vec2[] vs = new Vec2[4]; vs[0].Set(-1.0f, 3.0f); vs[1].Set(1.0f, 3.0f); vs[2].Set(1.0f, 5.0f); vs[3].Set(-1.0f, 5.0f); ChainShape shape = new ChainShape(); shape.CreateLoop(vs, 4); shape.Density = 0; ground.CreateFixture(shape); } // Edge loop. Collision should be smooth. { BodyDef bd = new BodyDef(); bd.Position.Set(-10.0f, 4.0f); Body ground = m_world.CreateBody(bd); Vec2[] vs = new Vec2[10]; vs[0].Set(0.0f, 0.0f); vs[1].Set(6.0f, 0.0f); vs[2].Set(6.0f, 2.0f); vs[3].Set(4.0f, 1.0f); vs[4].Set(2.0f, 2.0f); vs[5].Set(0.0f, 2.0f); vs[6].Set(-2.0f, 2.0f); vs[7].Set(-4.0f, 3.0f); vs[8].Set(-6.0f, 2.0f); vs[9].Set(-6.0f, 0.0f); ChainShape shape = new ChainShape(); shape.CreateLoop(vs, 10); shape.Density = 0; ground.CreateFixture(shape); } // Square character 1 { BodyDef bd = new BodyDef(); bd.Position.Set(-3.0f, 8.0f); bd.type = BodyType._dynamicBody; bd.fixedRotation = true; bd.allowSleep = false; Body body = m_world.CreateBody(bd); PolygonShape shape = new PolygonShape(); shape.SetAsBox(0.5f, 0.5f); FixtureDef fd = new FixtureDef(); fd.shape = shape; fd.Density = 20.0f; body.CreateFixture(fd); } // Square character 2 { BodyDef bd = new BodyDef(); bd.Position.Set(-5.0f, 5.0f); bd.type = BodyType._dynamicBody; bd.fixedRotation = true; bd.allowSleep = false; Body body = m_world.CreateBody(bd); PolygonShape shape = new PolygonShape(); shape.SetAsBox(0.25f, 0.25f); FixtureDef fd = new FixtureDef(); fd.shape = shape; fd.Density = 20.0f; body.CreateFixture(fd); } // Hexagon character { BodyDef bd = new BodyDef(); bd.Position.Set(-5.0f, 8.0f); bd.type = BodyType._dynamicBody; bd.fixedRotation = true; bd.allowSleep = false; Body body = m_world.CreateBody(bd); float angle = 0.0f; float delta = (float)Math.PI / 3.0f; Vec2[] vertices = new Vec2[6]; for (int i = 0; i < 6; ++i) { vertices[i].Set(0.5f * (float)Math.Cos(angle), 0.5f * (float)Math.Sin(angle)); angle += delta; } PolygonShape shape = new PolygonShape(); shape.Set(vertices, 6); FixtureDef fd = new FixtureDef(); fd.shape = shape; fd.Density = 20.0f; body.CreateFixture(fd); } // Circle character { BodyDef bd = new BodyDef(); bd.Position.Set(3.0f, 5.0f); bd.type = BodyType._dynamicBody; bd.fixedRotation = true; bd.allowSleep = false; Body body = m_world.CreateBody(bd); CircleShape shape = new CircleShape(); shape.m_radius = 0.5f; FixtureDef fd = new FixtureDef(); fd.shape = shape; fd.Density = 20.0f; body.CreateFixture(fd); } // Circle character { BodyDef bd = new BodyDef(); bd.Position.Set(-7.0f, 6.0f); bd.type = BodyType._dynamicBody; bd.allowSleep = false; m_character = m_world.CreateBody(bd); CircleShape shape = new CircleShape(); shape.m_radius = 0.25f; FixtureDef fd = new FixtureDef(); fd.shape = shape; fd.Density = 20.0f; fd.friction = 1.0f; m_character.CreateFixture(fd); } }
public EdgeTest() { { BodyDef bd = new BodyDef(); Body ground = m_world.CreateBody(bd); Vec2 v1 = new Vec2(-10.0f, 0.0f), v2 = new Vec2(-7.0f, -2.0f), v3 = new Vec2(-4.0f, 0.0f); Vec2 v4 = new Vec2(0.0f, 0.0f), v5 = new Vec2(4.0f, 0.0f), v6 = new Vec2(7.0f, 2.0f), v7 = new Vec2(10.0f, 0.0f); EdgeShape shape = new EdgeShape(); shape.Set(v1, v2); shape.m_hasVertex3 = true; shape.m_vertex3 = v3; shape.Density = 0; ground.CreateFixture(shape); shape.Set(v2, v3); shape.m_hasVertex0 = true; shape.m_hasVertex3 = true; shape.m_vertex0 = v1; shape.m_vertex3 = v4; ground.CreateFixture(shape); shape.Set(v3, v4); shape.m_hasVertex0 = true; shape.m_hasVertex3 = true; shape.m_vertex0 = v2; shape.m_vertex3 = v5; ground.CreateFixture(shape); shape.Set(v4, v5); shape.m_hasVertex0 = true; shape.m_hasVertex3 = true; shape.m_vertex0 = v3; shape.m_vertex3 = v6; ground.CreateFixture(shape); shape.Set(v5, v6); shape.m_hasVertex0 = true; shape.m_hasVertex3 = true; shape.m_vertex0 = v4; shape.m_vertex3 = v7; ground.CreateFixture(shape); shape.Set(v6, v7); shape.m_hasVertex0 = true; shape.m_vertex0 = v5; ground.CreateFixture(shape); } { BodyDef bd = new BodyDef(); bd.type = BodyType._dynamicBody; bd.Position.Set(-0.5f, 0.6f); bd.allowSleep = false; Body body = m_world.CreateBody(bd); CircleShape shape = new CircleShape(); shape.m_radius = 0.5f; body.CreateFixture(shape); } { BodyDef bd = new BodyDef(); bd.type = BodyType._dynamicBody; bd.Position.Set(1.0f, 0.6f); bd.allowSleep = false; Body body = m_world.CreateBody(bd); PolygonShape shape = new PolygonShape(); shape.SetAsBox(0.5f, 0.5f); body.CreateFixture(shape); } }
Bridge() { Body ground = null; { BodyDef bd = new BodyDef(); ground = m_world.CreateBody(bd); EdgeShape shape = new EdgeShape(); shape.Set(new Vec2(-40.0f, 0.0f), new Vec2(40.0f, 0.0f)); shape.Density = 0; ground.CreateFixture(shape); } { PolygonShape shape = new PolygonShape(); shape.SetAsBox(0.5f, 0.125f); FixtureDef fd = new FixtureDef(); fd.shape = shape; fd.Density = 20.0f; fd.friction = 0.2f; RevoluteJointDef jd = new RevoluteJointDef(); Body prevBody = ground; for (int i = 0; i < e_count; ++i) { BodyDef bd = new BodyDef(); bd.type = BodyType._dynamicBody; bd.Position.Set(-14.5f + 1.0f * i, 5.0f); Body body = m_world.CreateBody(bd); body.CreateFixture(fd); Vec2 anchor = new Vec2(-15.0f + 1.0f * i, 5.0f); jd.Initialize(prevBody, body, anchor); m_world.CreateJoint(jd); if (i == (e_count >> 1)) { m_middle = body; } prevBody = body; } Vec2 anchor2 = new Vec2(-15.0f + 1.0f * e_count, 5.0f); jd.Initialize(prevBody, ground, anchor2); m_world.CreateJoint(jd); } for (int i = 0; i < 2; ++i) { Vec2[] vertices = new Vec2[3]; vertices[0].Set(-0.5f, 0.0f); vertices[1].Set(0.5f, 0.0f); vertices[2].Set(0.0f, 1.5f); PolygonShape shape = new PolygonShape(); shape.Set(vertices, 3); FixtureDef fd = new FixtureDef(); fd.shape = shape; fd.Density = 1.0f; BodyDef bd = new BodyDef(); bd.type = BodyType._dynamicBody; bd.Position.Set(-8.0f + 8.0f * i, 12.0f); Body body = m_world.CreateBody(bd); body.CreateFixture(fd); } for (int i = 0; i < 3; ++i) { CircleShape shape = new CircleShape(); shape.m_radius = 0.5f; FixtureDef fd = new FixtureDef(); fd.shape = shape; fd.Density = 1.0f; BodyDef bd = new BodyDef(); bd.type = BodyType._dynamicBody; bd.Position.Set(-6.0f + 6.0f * i, 10.0f); Body body = m_world.CreateBody(bd); body.CreateFixture(fd); } }
public Revolute() { Body ground = null; { BodyDef bd = new BodyDef(); ground = m_world.CreateBody(bd); EdgeShape shape = new EdgeShape(); shape.Set(new Vec2(-40.0f, 0.0f), new Vec2(40.0f, 0.0f)); FixtureDef fd = new FixtureDef(); fd.shape = shape; //fd.Filter.CategoryBits = 2; ground.CreateFixture(fd); } { CircleShape shape = new CircleShape(); shape.m_radius = 0.5f; shape.Density = 5; BodyDef bd = new BodyDef(); bd.type = BodyType._dynamicBody; RevoluteJointDef rjd = new RevoluteJointDef(); bd.Position.Set(-10.0f, 20.0f); Body body = m_world.CreateBody(bd); body.CreateFixture(shape); float w = 100.0f; body.SetAngularVelocity(w); body.SetLinearVelocity(new Vec2(-8.0f * w, 0.0f)); rjd.Initialize(ground, body, new Vec2(-10.0f, 12.0f)); rjd.motorSpeed = 1.0f * (float)Math.PI; rjd.maxMotorTorque = 10000.0f; rjd.enableMotor = false; rjd.lowerAngle = -0.25f * (float)Math.PI; rjd.upperAngle = 0.5f * (float)Math.PI; rjd.enableLimit = true; rjd.collideConnected = true; m_joint = (RevoluteJoint)m_world.CreateJoint(rjd); } { CircleShape circle_shape = new CircleShape(); circle_shape.m_radius = 3.0f; BodyDef circle_bd = new BodyDef(); circle_bd.type = BodyType._dynamicBody; circle_bd.Position.Set(5.0f, 30.0f); FixtureDef fd = new FixtureDef(); fd.Density = 5.0f; fd.Filter.MaskBits = 1; fd.shape = circle_shape; m_ball = m_world.CreateBody(circle_bd); m_ball.CreateFixture(fd); PolygonShape polygon_shape = new PolygonShape(); polygon_shape.SetAsBox(10.0f, 0.2f, new Vec2(-10.0f, 0.0f), 0.0f); polygon_shape.Density = 2; BodyDef polygon_bd = new BodyDef(); polygon_bd.Position.Set(20.0f, 10.0f); polygon_bd.type = BodyType._dynamicBody; polygon_bd.bullet = true; Body polygon_body = m_world.CreateBody(polygon_bd); polygon_body.CreateFixture(polygon_shape); RevoluteJointDef rjd = new RevoluteJointDef(); rjd.Initialize(ground, polygon_body, new Vec2(20.0f, 10.0f)); rjd.lowerAngle = -0.25f * (float)Math.PI; rjd.upperAngle = 0.0f * (float)Math.PI; rjd.enableLimit = true; m_world.CreateJoint(rjd); } // Tests mass computation of a small object far from the origin { BodyDef bodyDef = new BodyDef(); bodyDef.type = BodyType._dynamicBody; Body body = m_world.CreateBody(bodyDef); PolygonShape polyShape = new PolygonShape(); Vec2[] verts = new Vec2[3]; verts[0].Set( 17.63f, 36.31f ); verts[1].Set( 17.52f, 36.69f ); verts[2].Set( 17.19f, 36.36f ); polyShape.Set(verts, 3); FixtureDef polyFixtureDef = new FixtureDef(); polyFixtureDef.shape = polyShape; polyFixtureDef.Density = 1; body.CreateFixture(polyFixtureDef); //assertion hits inside here } }
public EdgeShapes() { // Ground body { BodyDef bd = new BodyDef(); Body ground = m_world.CreateBody(bd); float x1 = -20.0f; float y1 = 2.0f * (float)Math.Cos(x1 / 10.0f * (float)Math.PI); for (int i = 0; i < 80; ++i) { float x2 = x1 + 0.5f; float y2 = 2.0f * (float)Math.Cos(x2 / 10.0f * (float)Math.PI); EdgeShape shape = new EdgeShape(); shape.Set(new Vec2(x1, y1), new Vec2(x2, y2)); shape.Density = 0; ground.CreateFixture(shape); x1 = x2; y1 = y2; } } { Vec2[] vertices = new Vec2[3]; vertices[0].Set(-0.5f, 0.0f); vertices[1].Set(0.5f, 0.0f); vertices[2].Set(0.0f, 1.5f); m_polygons[0].Set(vertices, 3); } { Vec2[] vertices = new Vec2[3]; vertices[0].Set(-0.1f, 0.0f); vertices[1].Set(0.1f, 0.0f); vertices[2].Set(0.0f, 1.5f); m_polygons[1].Set(vertices, 3); } { float w = 1.0f; float b = w / (2.0f + (float)Math.Sqrt(2.0f)); float s = (float)Math.Sqrt(2.0f) * b; Vec2[] vertices = new Vec2[8]; vertices[0].Set(0.5f * s, 0.0f); vertices[1].Set(0.5f * w, b); vertices[2].Set(0.5f * w, b + s); vertices[3].Set(0.5f * s, w); vertices[4].Set(-0.5f * s, w); vertices[5].Set(-0.5f * w, b + s); vertices[6].Set(-0.5f * w, b); vertices[7].Set(-0.5f * s, 0.0f); m_polygons[2].Set(vertices, 8); } { m_polygons[3].SetAsBox(0.5f, 0.5f); } { m_circle.m_radius = 0.5f; } m_bodyIndex = 0; Array.Clear(m_bodies, 0, m_bodies.Length); m_angle = 0.0f; }
public Web() { Body ground = null; { BodyDef bd = new BodyDef(); ground = m_world.CreateBody(bd); EdgeShape shape = new EdgeShape(); shape.Set(new Vec2(-40.0f, 0.0f), new Vec2(40.0f, 0.0f)); shape.Density = 0; ground.CreateFixture(shape); } { PolygonShape shape = new PolygonShape(); shape.SetAsBox(0.5f, 0.5f); shape.Density = 5; BodyDef bd = new BodyDef(); bd.type = BodyType._dynamicBody; bd.Position.Set(-5.0f, 5.0f); m_bodies[0] = m_world.CreateBody(bd); m_bodies[0].CreateFixture(shape); bd.Position.Set(5.0f, 5.0f); m_bodies[1] = m_world.CreateBody(bd); m_bodies[1].CreateFixture(shape); bd.Position.Set(5.0f, 15.0f); m_bodies[2] = m_world.CreateBody(bd); m_bodies[2].CreateFixture(shape); bd.Position.Set(-5.0f, 15.0f); m_bodies[3] = m_world.CreateBody(bd); m_bodies[3].CreateFixture(shape); DistanceJointDef jd = new DistanceJointDef(); Vec2 p1, p2, d; jd.frequencyHz = 2.0f; jd.dampingRatio = 0.0f; jd.bodyA = ground; jd.bodyB = m_bodies[0]; jd.localAnchorA.Set(-10.0f, 0.0f); jd.localAnchorB.Set(-0.5f, -0.5f); p1 = jd.bodyA.GetWorldPoint(jd.localAnchorA); p2 = jd.bodyB.GetWorldPoint(jd.localAnchorB); d = p2 - p1; jd.length = d.Length(); m_joints[0] = m_world.CreateJoint(jd); jd.bodyA = ground; jd.bodyB = m_bodies[1]; jd.localAnchorA.Set(10.0f, 0.0f); jd.localAnchorB.Set(0.5f, -0.5f); p1 = jd.bodyA.GetWorldPoint(jd.localAnchorA); p2 = jd.bodyB.GetWorldPoint(jd.localAnchorB); d = p2 - p1; jd.length = d.Length(); m_joints[1] = m_world.CreateJoint(jd); jd.bodyA = ground; jd.bodyB = m_bodies[2]; jd.localAnchorA.Set(10.0f, 20.0f); jd.localAnchorB.Set(0.5f, 0.5f); p1 = jd.bodyA.GetWorldPoint(jd.localAnchorA); p2 = jd.bodyB.GetWorldPoint(jd.localAnchorB); d = p2 - p1; jd.length = d.Length(); m_joints[2] = m_world.CreateJoint(jd); jd.bodyA = ground; jd.bodyB = m_bodies[3]; jd.localAnchorA.Set(-10.0f, 20.0f); jd.localAnchorB.Set(-0.5f, 0.5f); p1 = jd.bodyA.GetWorldPoint(jd.localAnchorA); p2 = jd.bodyB.GetWorldPoint(jd.localAnchorB); d = p2 - p1; jd.length = d.Length(); m_joints[3] = m_world.CreateJoint(jd); jd.bodyA = m_bodies[0]; jd.bodyB = m_bodies[1]; jd.localAnchorA.Set(0.5f, 0.0f); jd.localAnchorB.Set(-0.5f, 0.0f);; p1 = jd.bodyA.GetWorldPoint(jd.localAnchorA); p2 = jd.bodyB.GetWorldPoint(jd.localAnchorB); d = p2 - p1; jd.length = d.Length(); m_joints[4] = m_world.CreateJoint(jd); jd.bodyA = m_bodies[1]; jd.bodyB = m_bodies[2]; jd.localAnchorA.Set(0.0f, 0.5f); jd.localAnchorB.Set(0.0f, -0.5f); p1 = jd.bodyA.GetWorldPoint(jd.localAnchorA); p2 = jd.bodyB.GetWorldPoint(jd.localAnchorB); d = p2 - p1; jd.length = d.Length(); m_joints[5] = m_world.CreateJoint(jd); jd.bodyA = m_bodies[2]; jd.bodyB = m_bodies[3]; jd.localAnchorA.Set(-0.5f, 0.0f); jd.localAnchorB.Set(0.5f, 0.0f); p1 = jd.bodyA.GetWorldPoint(jd.localAnchorA); p2 = jd.bodyB.GetWorldPoint(jd.localAnchorB); d = p2 - p1; jd.length = d.Length(); m_joints[6] = m_world.CreateJoint(jd); jd.bodyA = m_bodies[3]; jd.bodyB = m_bodies[0]; jd.localAnchorA.Set(0.0f, -0.5f); jd.localAnchorB.Set(0.0f, 0.5f); p1 = jd.bodyA.GetWorldPoint(jd.localAnchorA); p2 = jd.bodyB.GetWorldPoint(jd.localAnchorB); d = p2 - p1; jd.length = d.Length(); m_joints[7] = m_world.CreateJoint(jd); } }
public CollisionProcessing() { // Ground body { EdgeShape shape = new EdgeShape(); shape.Set(new Vec2(-50.0f, 0.0f), new Vec2(50.0f, 0.0f)); FixtureDef sd = new FixtureDef(); sd.shape = shape;; BodyDef bd = new BodyDef(); Body ground = m_world.CreateBody(bd); ground.CreateFixture(sd); } float xLo = -5.0f, xHi = 5.0f; float yLo = 2.0f, yHi = 35.0f; // Small triangle Vec2[] vertices = new Vec2[3]; vertices[0].Set(-1.0f, 0.0f); vertices[1].Set(1.0f, 0.0f); vertices[2].Set(0.0f, 2.0f); PolygonShape polygon = new PolygonShape(); polygon.Set(vertices, 3); FixtureDef triangleShapeDef = new FixtureDef(); triangleShapeDef.shape = polygon; triangleShapeDef.Density = 1.0f; BodyDef triangleBodyDef = new BodyDef(); triangleBodyDef.type = BodyType._dynamicBody; triangleBodyDef.Position.Set(RandomFloat(xLo, xHi), RandomFloat(yLo, yHi)); Body body1 = m_world.CreateBody(triangleBodyDef); body1.CreateFixture(triangleShapeDef); // Large triangle (recycle definitions) vertices[0] *= 2.0f; vertices[1] *= 2.0f; vertices[2] *= 2.0f; polygon.Set(vertices, 3); triangleBodyDef.Position.Set(RandomFloat(xLo, xHi), RandomFloat(yLo, yHi)); Body body2 = m_world.CreateBody(triangleBodyDef); body2.CreateFixture(triangleShapeDef); // Small box polygon.SetAsBox(1.0f, 0.5f); FixtureDef boxShapeDef = new FixtureDef(); boxShapeDef.shape = polygon; boxShapeDef.Density = 1.0f; BodyDef boxBodyDef = new BodyDef(); boxBodyDef.type = BodyType._dynamicBody; boxBodyDef.Position.Set(RandomFloat(xLo, xHi), RandomFloat(yLo, yHi)); Body body3 = m_world.CreateBody(boxBodyDef); body3.CreateFixture(boxShapeDef); // Large box (recycle definitions) polygon.SetAsBox(2.0f, 1.0f); boxBodyDef.Position.Set(RandomFloat(xLo, xHi), RandomFloat(yLo, yHi)); Body body4 = m_world.CreateBody(boxBodyDef); body4.CreateFixture(boxShapeDef); // Small circle CircleShape circle = new CircleShape(); circle.m_radius = 1.0f; FixtureDef circleShapeDef = new FixtureDef(); circleShapeDef.shape = circle; circleShapeDef.Density = 1.0f; BodyDef circleBodyDef = new BodyDef(); circleBodyDef.type = BodyType._dynamicBody; circleBodyDef.Position.Set(RandomFloat(xLo, xHi), RandomFloat(yLo, yHi)); Body body5 = m_world.CreateBody(circleBodyDef); body5.CreateFixture(circleShapeDef); // Large circle circle.m_radius *= 2.0f; circleBodyDef.Position.Set(RandomFloat(xLo, xHi), RandomFloat(yLo, yHi)); Body body6 = m_world.CreateBody(circleBodyDef); body6.CreateFixture(circleShapeDef); }
public CollisionFiltering() { // Ground body { EdgeShape shape = new EdgeShape(); shape.Set(new Vec2(-40.0f, 0.0f), new Vec2(40.0f, 0.0f)); FixtureDef sd = new FixtureDef(); sd.shape = shape; sd.friction = 0.3f; BodyDef bd = new BodyDef(); Body ground = m_world.CreateBody(bd); ground.CreateFixture(sd); } // Small triangle Vec2[] vertices = new Vec2[3]; vertices[0].Set(-1.0f, 0.0f); vertices[1].Set(1.0f, 0.0f); vertices[2].Set(0.0f, 2.0f); PolygonShape polygon = new PolygonShape(); polygon.Set(vertices, 3); FixtureDef triangleShapeDef = new FixtureDef(); triangleShapeDef.shape = polygon; triangleShapeDef.Density = 1.0f; triangleShapeDef.Filter.GroupIndex = k_smallGroup; triangleShapeDef.Filter.CategoryBits = k_triangleCategory; triangleShapeDef.Filter.MaskBits = k_triangleMask; BodyDef triangleBodyDef = new BodyDef(); triangleBodyDef.type = BodyType._dynamicBody; triangleBodyDef.Position.Set(-5.0f, 2.0f); Body body1 = m_world.CreateBody(triangleBodyDef); body1.CreateFixture(triangleShapeDef); // Large triangle (recycle definitions) vertices[0] *= 2.0f; vertices[1] *= 2.0f; vertices[2] *= 2.0f; polygon.Set(vertices, 3); triangleShapeDef.Filter.GroupIndex = k_largeGroup; triangleBodyDef.Position.Set(-5.0f, 6.0f); triangleBodyDef.fixedRotation = true; // look at me! Body body2 = m_world.CreateBody(triangleBodyDef); body2.CreateFixture(triangleShapeDef); { BodyDef bd = new BodyDef(); bd.type = BodyType._dynamicBody; bd.Position.Set(-5.0f, 10.0f); Body body = m_world.CreateBody(bd); PolygonShape p = new PolygonShape(); p.SetAsBox(0.5f, 1.0f); body.CreateFixture(p); PrismaticJointDef jd = new PrismaticJointDef(); jd.bodyA = body2; jd.bodyB = body; jd.enableLimit = true; jd.localAnchorA.Set(0.0f, 4.0f); jd.localAnchorB.SetZero(); jd.localAxisA.Set(0.0f, 1.0f); jd.lowerTranslation = -1.0f; jd.upperTranslation = 1.0f; m_world.CreateJoint(jd); } // Small box polygon.SetAsBox(1.0f, 0.5f); FixtureDef boxShapeDef = new FixtureDef(); boxShapeDef.shape = polygon; boxShapeDef.Density = 1.0f; boxShapeDef.restitution = 0.1f; boxShapeDef.Filter.GroupIndex = k_smallGroup; boxShapeDef.Filter.CategoryBits = k_boxCategory; boxShapeDef.Filter.MaskBits = k_boxMask; BodyDef boxBodyDef = new BodyDef(); boxBodyDef.type = BodyType._dynamicBody; boxBodyDef.Position.Set(0.0f, 2.0f); Body body3 = m_world.CreateBody(boxBodyDef); body3.CreateFixture(boxShapeDef); // Large box (recycle definitions) polygon.SetAsBox(2.0f, 1.0f); boxShapeDef.Filter.GroupIndex = k_largeGroup; boxBodyDef.Position.Set(0.0f, 6.0f); Body body4 = m_world.CreateBody(boxBodyDef); body4.CreateFixture(boxShapeDef); // Small circle CircleShape circle = new CircleShape(); circle.m_radius = 1.0f; FixtureDef circleShapeDef = new FixtureDef(); circleShapeDef.shape = circle; circleShapeDef.Density = 1.0f; circleShapeDef.Filter.GroupIndex = k_smallGroup; circleShapeDef.Filter.CategoryBits = k_circleCategory; circleShapeDef.Filter.MaskBits = k_circleMask; BodyDef circleBodyDef = new BodyDef(); circleBodyDef.type = BodyType._dynamicBody; circleBodyDef.Position.Set(5.0f, 2.0f); Body body5 = m_world.CreateBody(circleBodyDef); body5.CreateFixture(circleShapeDef); // Large circle circle.m_radius *= 2.0f; circleShapeDef.Filter.GroupIndex = k_largeGroup; circleBodyDef.Position.Set(5.0f, 6.0f); Body body6 = m_world.CreateBody(circleBodyDef); body6.CreateFixture(circleShapeDef); }
public Dominos() { Body b1; { EdgeShape shape = new EdgeShape(); shape.Set(new Vec2(-40.0f, 0.0f), new Vec2(40.0f, 0.0f)); shape.Density = 0; BodyDef bd = new BodyDef(); b1 = m_world.CreateBody(bd); b1.CreateFixture(shape); } { PolygonShape shape = new PolygonShape(); shape.SetAsBox(6.0f, 0.25f); BodyDef bd = new BodyDef(); bd.Position.Set(-1.5f, 10.0f); Body ground = m_world.CreateBody(bd); shape.Density = 0; ground.CreateFixture(shape); } { PolygonShape shape = new PolygonShape(); shape.SetAsBox(0.1f, 1.0f); FixtureDef fd = new FixtureDef(); fd.shape = shape; fd.Density = 20.0f; fd.friction = 0.1f; for (int i = 0; i < 10; ++i) { BodyDef bd = new BodyDef(); bd.type = BodyType._dynamicBody; bd.Position.Set(-6.0f + 1.0f * i, 11.25f); Body body = m_world.CreateBody(bd); body.CreateFixture(fd); } } { PolygonShape shape = new PolygonShape(); shape.SetAsBox(7.0f, 0.25f, new Vec2(0, 0), 0.3f); shape.Density = 0; BodyDef bd = new BodyDef(); bd.Position.Set(1.0f, 6.0f); Body ground = m_world.CreateBody(bd); ground.CreateFixture(shape); } Body b2; { PolygonShape shape = new PolygonShape(); shape.SetAsBox(0.25f, 1.5f); shape.Density = 0; BodyDef bd = new BodyDef(); bd.Position.Set(-7.0f, 4.0f); b2 = m_world.CreateBody(bd); b2.CreateFixture(shape); } Body b3; { PolygonShape shape = new PolygonShape(); shape.SetAsBox(6.0f, 0.125f); shape.Density = 10; BodyDef bd = new BodyDef(); bd.type = BodyType._dynamicBody; bd.Position.Set(-0.9f, 1.0f); bd.angle = -0.15f; b3 = m_world.CreateBody(bd); b3.CreateFixture(shape); } RevoluteJointDef jd = new RevoluteJointDef(); Vec2 anchor = new Vec2(); anchor.Set(-2.0f, 1.0f); jd.Initialize(b1, b3, anchor); jd.collideConnected = true; m_world.CreateJoint(jd); Body b4; { PolygonShape shape = new PolygonShape(); shape.SetAsBox(0.25f, 0.25f); BodyDef bd = new BodyDef(); bd.type = BodyType._dynamicBody; bd.Position.Set(-10.0f, 15.0f); b4 = m_world.CreateBody(bd); shape.Density = 10; shape.Density = 10; b4.CreateFixture(shape); } anchor.Set(-7.0f, 15.0f); jd.Initialize(b2, b4, anchor); m_world.CreateJoint(jd); Body b5; { BodyDef bd = new BodyDef(); bd.type = BodyType._dynamicBody; bd.Position.Set(6.5f, 3.0f); b5 = m_world.CreateBody(bd); PolygonShape shape = new PolygonShape(); FixtureDef fd = new FixtureDef(); fd.shape = shape; fd.Density = 10.0f; fd.friction = 0.1f; shape.SetAsBox(1.0f, 0.1f, new Vec2(0.0f, -0.9f), 0.0f); b5.CreateFixture(fd); shape.SetAsBox(0.1f, 1.0f, new Vec2(-0.9f, 0.0f), 0.0f); b5.CreateFixture(fd); shape.SetAsBox(0.1f, 1.0f, new Vec2(0.9f, 0.0f), 0.0f); b5.CreateFixture(fd); } anchor.Set(6.0f, 2.0f); jd.Initialize(b1, b5, anchor); m_world.CreateJoint(jd); Body b6; { PolygonShape shape = new PolygonShape(); shape.SetAsBox(1.0f, 0.1f); BodyDef bd = new BodyDef(); bd.type = BodyType._dynamicBody; bd.Position.Set(6.5f, 4.1f); b6 = m_world.CreateBody(bd); shape.Density = 30; b6.CreateFixture(shape); } anchor.Set(7.5f, 4.0f); jd.Initialize(b5, b6, anchor); m_world.CreateJoint(jd); Body b7; { PolygonShape shape = new PolygonShape(); shape.SetAsBox(0.1f, 1.0f); BodyDef bd = new BodyDef(); bd.type = BodyType._dynamicBody; bd.Position.Set(7.4f, 1.0f); b7 = m_world.CreateBody(bd); shape.Density = 10; b7.CreateFixture(shape); } DistanceJointDef djd = new DistanceJointDef(); djd.bodyA = b3; djd.bodyB = b7; djd.localAnchorA.Set(6.0f, 0.0f); djd.localAnchorB.Set(0.0f, -1.0f); Vec2 d = djd.bodyB.GetWorldPoint(djd.localAnchorB) - djd.bodyA.GetWorldPoint(djd.localAnchorA); djd.length = d.Length(); m_world.CreateJoint(djd); { float radius = 0.2f; CircleShape shape = new CircleShape(); shape.m_radius = radius; for (int i = 0; i < 4; ++i) { BodyDef bd = new BodyDef(); bd.type = BodyType._dynamicBody; bd.Position.Set(5.9f + 2.0f * radius * i, 2.4f); Body body = m_world.CreateBody(bd); shape.Density = 10; body.CreateFixture(shape); } } }
public PolyShapes() { // Ground body { BodyDef bd = new BodyDef(); Body ground = m_world.CreateBody(bd); EdgeShape shape = new EdgeShape(); shape.Set(new Vec2(-40.0f, 0.0f), new Vec2(40.0f, 0.0f)); shape.Density = 0; ground.CreateFixture(shape); } { Vec2[] vertices = new Vec2[3]; vertices[0].Set(-0.5f, 0.0f); vertices[1].Set(0.5f, 0.0f); vertices[2].Set(0.0f, 1.5f); m_polygons[0].Set(vertices, 3); } { Vec2[] vertices = new Vec2[3]; vertices[0].Set(-0.1f, 0.0f); vertices[1].Set(0.1f, 0.0f); vertices[2].Set(0.0f, 1.5f); m_polygons[1].Set(vertices, 3); } { float w = 1.0f; float b = w / (2.0f + (float)Math.Sqrt(2.0f)); float s = (float)Math.Sqrt(2.0f) * b; Vec2[] vertices = new Vec2[8]; vertices[0].Set(0.5f * s, 0.0f); vertices[1].Set(0.5f * w, b); vertices[2].Set(0.5f * w, b + s); vertices[3].Set(0.5f * s, w); vertices[4].Set(-0.5f * s, w); vertices[5].Set(-0.5f * w, b + s); vertices[6].Set(-0.5f * w, b); vertices[7].Set(-0.5f * s, 0.0f); m_polygons[2].Set(vertices, 8); } { m_polygons[3].SetAsBox(0.5f, 0.5f); } { m_circle.m_radius = 0.5f; } m_bodyIndex = 0; Array.Clear(m_bodies, 0, m_bodies.Length); }
public Car() { m_hz = 4.0f; m_zeta = 0.7f; m_speed = 50.0f; Body ground = null; { BodyDef bd = new BodyDef(); ground = m_world.CreateBody(bd); EdgeShape shape = new EdgeShape(); FixtureDef fd = new FixtureDef(); fd.shape = shape; fd.Density = 0.0f; fd.friction = 0.6f; shape.Set(new Vec2(-20.0f, 0.0f), new Vec2(20.0f, 0.0f)); ground.CreateFixture(fd); float[] hs = new float[]{0.25f, 1.0f, 4.0f, 0.0f, 0.0f, -1.0f, -2.0f, -2.0f, -1.25f, 0.0f}; float x = 20.0f, y1 = 0.0f, dx = 5.0f; for (int i = 0; i < 10; ++i) { float y2 = hs[i]; shape.Set(new Vec2(x, y1), new Vec2(x + dx, y2)); ground.CreateFixture(fd); y1 = y2; x += dx; } for (int i = 0; i < 10; ++i) { float y2 = hs[i]; shape.Set(new Vec2(x, y1), new Vec2(x + dx, y2)); ground.CreateFixture(fd); y1 = y2; x += dx; } shape.Set(new Vec2(x, 0.0f), new Vec2(x + 40.0f, 0.0f)); ground.CreateFixture(fd); x += 80.0f; shape.Set(new Vec2(x, 0.0f), new Vec2(x + 40.0f, 0.0f)); ground.CreateFixture(fd); x += 40.0f; shape.Set(new Vec2(x, 0.0f), new Vec2(x + 10.0f, 5.0f)); ground.CreateFixture(fd); x += 20.0f; shape.Set(new Vec2(x, 0.0f), new Vec2(x + 40.0f, 0.0f)); ground.CreateFixture(fd); x += 40.0f; shape.Set(new Vec2(x, 0.0f), new Vec2(x, 20.0f)); ground.CreateFixture(fd); } // Teeter { BodyDef bd = new BodyDef(); bd.Position.Set(140.0f, 1.0f); bd.type = BodyType._dynamicBody; Body body = m_world.CreateBody(bd); PolygonShape box = new PolygonShape(); box.SetAsBox(10.0f, 0.25f); box.Density = 1; body.CreateFixture(box); RevoluteJointDef jd = new RevoluteJointDef(); jd.Initialize(ground, body, body.GetPosition()); jd.lowerAngle = -8.0f * (float)Math.PI / 180.0f; jd.upperAngle = 8.0f * (float)Math.PI / 180.0f; jd.enableLimit = true; m_world.CreateJoint(jd); body.ApplyAngularImpulse(100.0f, true); } // Bridge { int N = 20; PolygonShape shape = new PolygonShape(); shape.SetAsBox(1.0f, 0.125f); FixtureDef fd = new FixtureDef(); fd.shape = shape; fd.Density = 1.0f; fd.friction = 0.6f; RevoluteJointDef jd = new RevoluteJointDef(); Body prevBody = ground; for (int i = 0; i < N; ++i) { BodyDef bd = new BodyDef(); bd.type = BodyType._dynamicBody; bd.Position.Set(161.0f + 2.0f * i, -0.125f); Body body = m_world.CreateBody(bd); body.CreateFixture(fd); Vec2 anchor = new Vec2(160.0f + 2.0f * i, -0.125f); jd.Initialize(prevBody, body, anchor); m_world.CreateJoint(jd); prevBody = body; } Vec2 anchor2 = new Vec2(160.0f + 2.0f * N, -0.125f); jd.Initialize(prevBody, ground, anchor2); m_world.CreateJoint(jd); } // Boxes { PolygonShape box = new PolygonShape(); box.SetAsBox(0.5f, 0.5f); box.Density = 0.5f; Body body = null; BodyDef bd = new BodyDef(); bd.type = BodyType._dynamicBody; bd.Position.Set(230.0f, 0.5f); body = m_world.CreateBody(bd); body.CreateFixture(box); bd.Position.Set(230.0f, 1.5f); body = m_world.CreateBody(bd); body.CreateFixture(box); bd.Position.Set(230.0f, 2.5f); body = m_world.CreateBody(bd); body.CreateFixture(box); bd.Position.Set(230.0f, 3.5f); body = m_world.CreateBody(bd); body.CreateFixture(box); bd.Position.Set(230.0f, 4.5f); body = m_world.CreateBody(bd); body.CreateFixture(box); } // Car { PolygonShape chassis = new PolygonShape(); Vec2[] vertices = new Vec2[8]; vertices[0].Set(-1.5f, -0.5f); vertices[1].Set(1.5f, -0.5f); vertices[2].Set(1.5f, 0.0f); vertices[3].Set(0.0f, 0.9f); vertices[4].Set(-1.15f, 0.9f); vertices[5].Set(-1.5f, 0.2f); chassis.Set(vertices, 6); CircleShape circle = new CircleShape(); circle.m_radius = 0.4f; BodyDef bd = new BodyDef(); bd.type = BodyType._dynamicBody; bd.Position.Set(0.0f, 1.0f); m_car = m_world.CreateBody(bd); m_car.CreateFixture(chassis); FixtureDef fd = new FixtureDef(); fd.shape = circle; fd.Density = 1.0f; fd.friction = 0.9f; bd.Position.Set(-1.0f, 0.35f); m_wheel1 = m_world.CreateBody(bd); m_wheel1.CreateFixture(fd); bd.Position.Set(1.0f, 0.4f); m_wheel2 = m_world.CreateBody(bd); m_wheel2.CreateFixture(fd); WheelJointDef jd = new WheelJointDef(); Vec2 axis = new Vec2(0.0f, 1.0f); jd.Initialize(m_car, m_wheel1, m_wheel1.GetPosition(), axis); jd.motorSpeed = 0.0f; jd.maxMotorTorque = 20.0f; jd.enableMotor = true; jd.frequencyHz = m_hz; jd.dampingRatio = m_zeta; m_spring1 = (WheelJoint)m_world.CreateJoint(jd); jd.Initialize(m_car, m_wheel2, m_wheel2.GetPosition(), axis); jd.motorSpeed = 0.0f; jd.maxMotorTorque = 10.0f; jd.enableMotor = false; jd.frequencyHz = m_hz; jd.dampingRatio = m_zeta; m_spring2 = (WheelJoint)m_world.CreateJoint(jd); } }
public VaryingFriction() { { BodyDef bd = new BodyDef(); Body ground = m_world.CreateBody(bd); EdgeShape shape = new EdgeShape(); shape.Set(new Vec2(-40.0f, 0.0f), new Vec2(40.0f, 0.0f)); shape.Density = 0; ground.CreateFixture(shape); } { PolygonShape shape = new PolygonShape(); shape.SetAsBox(13.0f, 0.25f); BodyDef bd = new BodyDef(); bd.Position.Set(-4.0f, 22.0f); bd.angle = -0.25f; Body ground = m_world.CreateBody(bd); shape.Density = 0; ground.CreateFixture(shape); } { PolygonShape shape = new PolygonShape(); shape.SetAsBox(0.25f, 1.0f); shape.Density = 0; BodyDef bd = new BodyDef(); bd.Position.Set(10.5f, 19.0f); Body ground = m_world.CreateBody(bd); ground.CreateFixture(shape); } { PolygonShape shape = new PolygonShape(); shape.SetAsBox(13.0f, 0.25f); shape.Density = 0; BodyDef bd = new BodyDef(); bd.Position.Set(4.0f, 14.0f); bd.angle = 0.25f; Body ground = m_world.CreateBody(bd); ground.CreateFixture(shape); } { PolygonShape shape = new PolygonShape(); shape.SetAsBox(0.25f, 1.0f); shape.Density = 0; BodyDef bd = new BodyDef(); bd.Position.Set(-10.5f, 11.0f); Body ground = m_world.CreateBody(bd); ground.CreateFixture(shape); } { PolygonShape shape = new PolygonShape(); shape.SetAsBox(13.0f, 0.25f); shape.Density = 0; BodyDef bd = new BodyDef(); bd.Position.Set(-4.0f, 6.0f); bd.angle = -0.25f; Body ground = m_world.CreateBody(bd); ground.CreateFixture(shape); } { PolygonShape shape = new PolygonShape(); shape.SetAsBox(0.5f, 0.5f); FixtureDef fd = new FixtureDef(); fd.shape = shape; fd.Density = 25.0f; float[] friction = new float[]{ 0.75f, 0.5f, 0.35f, 0.1f, 0.0f }; for (int i = 0; i < 5; ++i) { BodyDef bd = new BodyDef(); bd.type = BodyType._dynamicBody; bd.Position.Set(-15.0f + 4.0f * i, 28.0f); Body body = m_world.CreateBody(bd); fd.friction = friction[i]; body.CreateFixture(fd); } } }
public CompoundShapes() { { BodyDef bd = new BodyDef(); bd.Position.Set(0.0f, 0.0f); Body body = m_world.CreateBody(bd); EdgeShape shape = new EdgeShape(); shape.Set(new Vec2(50.0f, 0.0f), new Vec2(-50.0f, 0.0f)); shape.Density = 0; body.CreateFixture(shape); } { CircleShape circle1 = new CircleShape(); circle1.m_radius = 0.5f; circle1.m_p.Set(-0.5f, 0.5f); circle1.Density = 2; CircleShape circle2 = new CircleShape(); circle2.m_radius = 0.5f; circle2.m_p.Set(0.5f, 0.5f); circle2.Density = 0; for (int i = 0; i < 10; ++i) { float x = RandomFloat(-0.1f, 0.1f); BodyDef bd = new BodyDef(); bd.type = BodyType._dynamicBody; bd.Position.Set(x + 5.0f, 1.05f + 2.5f * i); bd.angle = RandomFloat(-(float)Math.PI, (float)Math.PI); Body body = m_world.CreateBody(bd); body.CreateFixture(circle1); body.CreateFixture(circle2); } } { PolygonShape polygon1 = new PolygonShape(); polygon1.SetAsBox(0.25f, 0.5f); polygon1.Density = 2; PolygonShape polygon2 = new PolygonShape(); polygon2.SetAsBox(0.25f, 0.5f, new Vec2(0.0f, -0.5f), 0.5f * (float)Math.PI); polygon2.Density = 2; for (int i = 0; i < 10; ++i) { float x = RandomFloat(-0.1f, 0.1f); BodyDef bd = new BodyDef(); bd.type = BodyType._dynamicBody; bd.Position.Set(x - 5.0f, 1.05f + 2.5f * i); bd.angle = RandomFloat(-(float)Math.PI, (float)Math.PI); Body body = m_world.CreateBody(bd); body.CreateFixture(polygon1); body.CreateFixture(polygon2); } } { Transform xf1 = new Transform(); xf1.q.Set(0.3524f * (float)Math.PI); xf1.p = xf1.q.GetXAxis(); Vec2[] vertices = new Vec2[3]; PolygonShape triangle1 = new PolygonShape(); vertices[0] = Utilities.Mul(xf1, new Vec2(-1.0f, 0.0f)); vertices[1] = Utilities.Mul(xf1, new Vec2(1.0f, 0.0f)); vertices[2] = Utilities.Mul(xf1, new Vec2(0.0f, 0.5f)); triangle1.Set(vertices, 3); Transform xf2 = new Transform(); xf2.q.Set(-0.3524f * (float)Math.PI); xf2.p = -xf2.q.GetXAxis(); PolygonShape triangle2 = new PolygonShape(); vertices[0] = Utilities.Mul(xf2, new Vec2(-1.0f, 0.0f)); vertices[1] = Utilities.Mul(xf2, new Vec2(1.0f, 0.0f)); vertices[2] = Utilities.Mul(xf2, new Vec2(0.0f, 0.5f)); triangle2.Set(vertices, 3); for (int i = 0; i < 10; ++i) { float x = RandomFloat(-0.1f, 0.1f); BodyDef bd = new BodyDef(); bd.type = BodyType._dynamicBody; bd.Position.Set(x, 2.05f + 2.5f * i); bd.angle = 0.0f; Body body = m_world.CreateBody(bd); triangle1.Density = 2; triangle2.Density = 2; body.CreateFixture(triangle1); body.CreateFixture(triangle2); } } { PolygonShape bottom = new PolygonShape(); bottom.SetAsBox( 1.5f, 0.15f ); PolygonShape left = new PolygonShape(); left.SetAsBox(0.15f, 2.7f, new Vec2(-1.45f, 2.35f), 0.2f); PolygonShape right = new PolygonShape(); right.SetAsBox(0.15f, 2.7f, new Vec2(1.45f, 2.35f), -0.2f); BodyDef bd = new BodyDef(); bd.type = BodyType._dynamicBody; bd.Position.Set( 0.0f, 2.0f ); Body body = m_world.CreateBody(bd); bottom.Density = 4; left.Density = 4; right.Density = 4; body.CreateFixture(bottom); body.CreateFixture(left); body.CreateFixture(right); } }
public BodyTypes() { Body ground = null; { BodyDef bd = new BodyDef(); ground = m_world.CreateBody(bd); EdgeShape shape = new EdgeShape(); shape.Set(new Vec2(-20.0f, 0.0f), new Vec2(20.0f, 0.0f)); FixtureDef fd = new FixtureDef(); fd.shape = shape; ground.CreateFixture(fd); } // Define attachment { BodyDef bd = new BodyDef(); bd.type = BodyType._dynamicBody; bd.Position.Set(0.0f, 3.0f); m_attachment = m_world.CreateBody(bd); PolygonShape shape = new PolygonShape(); shape.SetAsBox(0.5f, 2.0f); shape.Density = 2; m_attachment.CreateFixture(shape); } // Define platform { BodyDef bd = new BodyDef(); bd.type = BodyType._dynamicBody; bd.Position.Set(-4.0f, 5.0f); m_platform = m_world.CreateBody(bd); PolygonShape shape = new PolygonShape(); shape.SetAsBox(0.5f, 4.0f, new Vec2(4.0f, 0.0f), 0.5f * (float)Math.PI); FixtureDef fd = new FixtureDef(); fd.shape = shape; fd.friction = 0.6f; fd.Density = 2.0f; m_platform.CreateFixture(fd); RevoluteJointDef rjd = new RevoluteJointDef(); rjd.Initialize(m_attachment, m_platform, new Vec2(0.0f, 5.0f)); rjd.maxMotorTorque = 50.0f; rjd.enableMotor = true; m_world.CreateJoint(rjd); PrismaticJointDef pjd = new PrismaticJointDef(); pjd.Initialize(ground, m_platform, new Vec2(0.0f, 5.0f), new Vec2(1.0f, 0.0f)); pjd.maxMotorForce = 1000.0f; pjd.enableMotor = true; pjd.lowerTranslation = -10.0f; pjd.upperTranslation = 10.0f; pjd.enableLimit = true; m_world.CreateJoint(pjd); m_speed = 3.0f; } // Create a payload { BodyDef bd = new BodyDef(); bd.type = BodyType._dynamicBody; bd.Position.Set(0.0f, 8.0f); Body body = m_world.CreateBody(bd); PolygonShape shape = new PolygonShape(); shape.SetAsBox(0.75f, 0.75f); FixtureDef fd = new FixtureDef(); fd.shape = shape; fd.friction = 0.6f; fd.Density = 2.0f; body.CreateFixture(fd); } }
public ApplyForce() { m_world.SetGravity(new Vec2(0.0f, 0.0f)); const float k_restitution = 0.4f; Body ground; { BodyDef bd = new BodyDef(); bd.Position.Set(0.0f, 20.0f); ground = m_world.CreateBody(bd); EdgeShape shape = new EdgeShape(); FixtureDef sd = new FixtureDef(); sd.shape = shape; sd.Density = 0.0f; sd.restitution = k_restitution; // Left vertical shape.Set(new Vec2(-20.0f, -20.0f), new Vec2(-20.0f, 20.0f)); ground.CreateFixture(sd); // Right vertical shape.Set(new Vec2(20.0f, -20.0f), new Vec2(20.0f, 20.0f)); ground.CreateFixture(sd); // Top horizontal shape.Set(new Vec2(-20.0f, 20.0f), new Vec2(20.0f, 20.0f)); ground.CreateFixture(sd); // Bottom horizontal shape.Set(new Vec2(-20.0f, -20.0f), new Vec2(20.0f, -20.0f)); ground.CreateFixture(sd); } { Transform xf1 = new Transform(); xf1.q.Set(0.3524f * (float)Math.PI); xf1.p = xf1.q.GetXAxis(); Vec2[] vertices = new Vec2[3]; vertices[0] = Utilities.Mul(xf1, new Vec2(-1.0f, 0.0f)); vertices[1] = Utilities.Mul(xf1, new Vec2(1.0f, 0.0f)); vertices[2] = Utilities.Mul(xf1, new Vec2(0.0f, 0.5f)); PolygonShape poly1 = new PolygonShape(); poly1.Set(vertices, 3); FixtureDef sd1 = new FixtureDef(); sd1.shape = poly1; sd1.Density = 4.0f; Transform xf2 = new Transform(); xf2.q.Set(-0.3524f * (float)Math.PI); xf2.p = -xf2.q.GetXAxis(); vertices[0] = Utilities.Mul(xf2, new Vec2(-1.0f, 0.0f)); vertices[1] = Utilities.Mul(xf2, new Vec2(1.0f, 0.0f)); vertices[2] = Utilities.Mul(xf2, new Vec2(0.0f, 0.5f)); PolygonShape poly2 = new PolygonShape(); poly2.Set(vertices, 3); FixtureDef sd2 = new FixtureDef(); sd2.shape = poly2; sd2.Density = 2.0f; BodyDef bd = new BodyDef(); bd.type = BodyType._dynamicBody; bd.angularDamping = 5.0f; bd.linearDamping = 0.1f; bd.Position.Set(0.0f, 2.0f); bd.angle = (float)Math.PI; bd.allowSleep = false; m_body = m_world.CreateBody(bd); m_body.CreateFixture(sd1); m_body.CreateFixture(sd2); } { PolygonShape shape = new PolygonShape(); shape.SetAsBox(0.5f, 0.5f); FixtureDef fd = new FixtureDef(); fd.shape = shape; fd.Density = 1.0f; fd.friction = 0.3f; for (int i = 0; i < 10; ++i) { BodyDef bd = new BodyDef(); bd.type = BodyType._dynamicBody; bd.Position.Set(0.0f, 5.0f + 1.54f * i); Body body = m_world.CreateBody(bd); body.CreateFixture(fd); float gravity = 10.0f; float I = body.GetInertia(); float mass = body.GetMass(); // For a circle: I = 0.5 * m * r * r ==> r = sqrt(2 * I / m) float radius = (float)Math.Sqrt(2.0f * I / mass); FrictionJointDef jd = new FrictionJointDef(); jd.localAnchorA.SetZero(); jd.localAnchorB.SetZero(); jd.bodyA = ground; jd.bodyB = body; jd.collideConnected = true; jd.maxForce = mass * gravity; jd.maxTorque = mass * radius * gravity; m_world.CreateJoint(jd); } } }
public Gears() { Body ground = null; { BodyDef bd = new BodyDef(); ground = m_world.CreateBody(bd); EdgeShape shape = new EdgeShape(); shape.Set(new Vec2(50.0f, 0.0f), new Vec2(-50.0f, 0.0f)); shape.Density = 0; ground.CreateFixture(shape); } { CircleShape circle1 = new CircleShape(); circle1.m_radius = 1.0f; circle1.Density = 5; PolygonShape box = new PolygonShape(); box.SetAsBox(0.5f, 5.0f); box.Density = 5; CircleShape circle2 = new CircleShape(); circle2.m_radius = 2.0f; circle2.Density = 5; BodyDef bd1 = new BodyDef(); bd1.type = BodyType._staticBody; bd1.Position.Set(10.0f, 9.0f); Body body1 = m_world.CreateBody(bd1); body1.CreateFixture(circle1); BodyDef bd2 = new BodyDef(); bd2.type = BodyType._dynamicBody; bd2.Position.Set(10.0f, 8.0f); Body body2 = m_world.CreateBody(bd2); body2.CreateFixture(box); BodyDef bd3 = new BodyDef(); bd3.type = BodyType._dynamicBody; bd3.Position.Set(10.0f, 6.0f); Body body3 = m_world.CreateBody(bd3); body3.CreateFixture(circle2); RevoluteJointDef jd1 = new RevoluteJointDef(); jd1.Initialize(body2, body1, bd1.Position); Joint joint1 = m_world.CreateJoint(jd1); RevoluteJointDef jd2 = new RevoluteJointDef(); jd2.Initialize(body2, body3, bd3.Position); Joint joint2 = m_world.CreateJoint(jd2); GearJointDef jd4 = new GearJointDef(); jd4.bodyA = body1; jd4.bodyB = body3; jd4.joint1 = joint1; jd4.joint2 = joint2; jd4.ratio = circle2.m_radius / circle1.m_radius; m_world.CreateJoint(jd4); } { CircleShape circle1 = new CircleShape(); circle1.m_radius = 1.0f; circle1.Density = 5; CircleShape circle2 = new CircleShape(); circle2.m_radius = 2.0f; circle2.Density = 5; PolygonShape box = new PolygonShape(); box.SetAsBox(0.5f, 5.0f); BodyDef bd1 = new BodyDef(); bd1.type = BodyType._dynamicBody; bd1.Position.Set(-3.0f, 12.0f); Body body1 = m_world.CreateBody(bd1); body1.CreateFixture(circle1); 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._dynamicBody; bd2.Position.Set(0.0f, 12.0f); Body body2 = m_world.CreateBody(bd2); body2.CreateFixture(circle2); RevoluteJointDef jd2 = new RevoluteJointDef(); jd2.Initialize(ground, body2, bd2.Position); m_joint2 = (RevoluteJoint)m_world.CreateJoint(jd2); BodyDef bd3 = new BodyDef(); bd3.type = BodyType._dynamicBody; bd3.Position.Set(2.5f, 12.0f); Body body3 = m_world.CreateBody(bd3); box.Density = 5; body3.CreateFixture(box); 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); } }