Box2D.Dynamics.Fixture.Create C# (CSharp) Method

Create() public method

public Create ( Body body, FixtureDef def ) : void
body Body
def FixtureDef
return void
        public void Create(Body body, FixtureDef def)
        {
            UserData = def.UserData;
            Friction = def.Friction;
            Restitution = def.Restitution;

            Body = body;
            Next = null;

            Filter.Set(def.Filter);

            IsSensor = def.IsSensor;

            Shape = def.Shape.Clone();

            // Reserve proxy space
            int childCount = Shape.ChildCount;
            if (Proxies == null)
            {
                Proxies = new FixtureProxy[childCount];
                for (int i = 0; i < childCount; i++)
                {
                    Proxies[i] = new FixtureProxy {Fixture = null, ProxyId = BroadPhase.NULL_PROXY};
                }
            }

            if (Proxies.Length < childCount)
            {
                FixtureProxy[] old = Proxies;
                int newLen = MathUtils.Max(old.Length * 2, childCount);
                Proxies = new FixtureProxy[newLen];
                Array.Copy(old, 0, Proxies, 0, old.Length);
                for (int i = 0; i < newLen; i++)
                {
                    if (i >= old.Length)
                    {
                        Proxies[i] = new FixtureProxy();
                    }
                    Proxies[i].Fixture = null;
                    Proxies[i].ProxyId = BroadPhase.NULL_PROXY;
                }
            }
            ProxyCount = 0;

            m_density = def.Density;
        }

Usage Example

Esempio n. 1
0
        // TODO djm: check out about this new fixture here
        /// <summary>
        /// Creates a fixture and attach it to this body. Use this function if you need to set some fixture
        /// parameters, like friction. Otherwise you can create the fixture directly from a shape. If the
        /// density is non-zero, this function automatically updates the mass of the body. Contacts are not
        /// created until the next time step.
        /// </summary>
        /// <param name="def">the fixture definition.</param>
        /// <warning>This function is locked during callbacks.</warning>
        public Fixture CreateFixture(FixtureDef def)
        {
            Debug.Assert(World.Locked == false);

            if (World.Locked == true)
            {
                return null;
            }

            // djm TODO from pool?
            Fixture fixture = new Fixture();
            fixture.Create(this, def);

            if ((Flags & TypeFlags.Active) == TypeFlags.Active)
            {
                BroadPhase broadPhase = World.ContactManager.BroadPhase;
                fixture.CreateProxies(broadPhase, Xf);
            }

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

            fixture.Body = this;

            // Adjust mass properties if needed.
            if (fixture.Density > 0.0f)
            {
                ResetMassData();
            }

            // Let the world know we have a new fixture. This will cause new contacts
            // to be created at the beginning of the next time step.
            World.Flags |= World.NEW_FIXTURE;

            return fixture;
        }