예제 #1
0
        /// <summary>
        ///     Creates a fixture and attach it to this body.
        ///     @warning This function is locked during callbacks.
        /// </summary>
        /// <param name="def">The fixture definition.</param>
        public Fixture CreateFixture(FixtureDef def)
        {
            Box2DxDebug.Assert(world.Lock == false);
            if (world.Lock)
            {
                return(null);
            }

            BroadPhase broadPhase = world.BroadPhase;

            Fixture fixture = new Fixture();

            fixture.Create(broadPhase, this, Xf, def);

            fixture.Next = FixtureList;
            FixtureList  = fixture;
            ++FixtureCount;

            fixture.Body = this;

            return(fixture);
        }
예제 #2
0
        /// <summary>
        ///     Creates the broad phase
        /// </summary>
        /// <param name="broadPhase">The broad phase</param>
        /// <param name="body">The body</param>
        /// <param name="xf">The xf</param>
        /// <param name="def">The def</param>
        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;

            ShapeType = def.Type;

            // Allocate and initialize the child shape.
            switch (ShapeType)
            {
            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;
            }
        }