示例#1
0
文件: Body.cs 项目: thdtjsdn/box2dnet
        // 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(m_world.Locked == false);

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

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

            if ((m_flags & e_activeFlag) == e_activeFlag)
            {
                BroadPhase broadPhase = m_world.m_contactManager.m_broadPhase;
                fixture.createProxies(broadPhase, m_xf);
            }

            fixture.m_next = m_fixtureList;
            m_fixtureList = fixture;
            ++m_fixtureCount;

            fixture.m_body = this;

            // Adjust mass properties if needed.
            if (fixture.m_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.
            m_world.m_flags |= World.NEW_FIXTURE;

            return fixture;
        }