/// <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. /// @warning This function is locked during callbacks. /// </summary> /// <param name="def">the fixture definition.</param> /// <returns></returns> public Fixture CreateFixture(FixtureDef def) { Debug.Assert(_world.IsLocked == false); if (_world.IsLocked == true) { return null; } Fixture fixture = new Fixture(); fixture.Create(this, def); if ((_flags & BodyFlags.Active) == BodyFlags.Active) { BroadPhase broadPhase = _world._contactManager._broadPhase; fixture.CreateProxy(broadPhase, ref _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 |= WorldFlags.NewFixture; return fixture; }