public void Create(BroadPhase broadPhase, Body body, XForm xf, FixtureDef def) { UserData = def.UserData; Friction = def.Friction; Restitution = def.Restitution; Density = def.Density; _body = body; _next = null; Filter = def.Filter; _isSensor = def.IsSensor; _type = def.Type; // Allocate and initialize the child shape. switch (_type) { case ShapeType.CircleShape: { CircleShape circle = new CircleShape(); CircleDef circleDef = (CircleDef)def; circle._position = circleDef.LocalPosition; circle._radius = circleDef.Radius; _shape = circle; } break; case ShapeType.PolygonShape: { PolygonShape polygon = new PolygonShape(); PolygonDef polygonDef = (PolygonDef)def; polygon.Set(polygonDef.Vertices, polygonDef.VertexCount); _shape = polygon; } break; case ShapeType.EdgeShape: { EdgeShape edge = new EdgeShape(); EdgeDef edgeDef = (EdgeDef)def; edge.Set(edgeDef.Vertex1, edgeDef.Vertex2); _shape = edge; } break; default: Box2DXDebug.Assert(false); break; } // Create proxy in the broad-phase. AABB aabb; _shape.ComputeAABB(out aabb, xf); bool inRange = broadPhase.InRange(aabb); // You are creating a shape outside the world box. Box2DXDebug.Assert(inRange); if (inRange) { _proxyId = broadPhase.CreateProxy(aabb, this); } else { _proxyId = PairManager.NullProxy; } }
public override void Keyboard(System.Windows.Forms.Keys key) { switch (key) { case System.Windows.Forms.Keys.B: if (_bullet != null) { _world.DestroyBody(_bullet); _bullet = null; } { CircleDef sd = new CircleDef(); sd.Density = 20.0f; sd.Radius = 0.25f; sd.Restitution = 0.05f; BodyDef bd = new BodyDef(); bd.IsBullet = true; bd.Position.Set(-31.0f, 5.0f); _bullet = _world.CreateBody(bd); _bullet.CreateFixture(sd); _bullet.SetMassFromShapes(); _bullet.SetLinearVelocity(new Vec2(400.0f, 0.0f)); } break; } }