示例#1
0
		/// 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.
		/// @param def the fixture definition.
		/// @warning This function is locked during callbacks.
		public Fixture CreateFixture(FixtureDef def){
			Utilities.Assert(m_world.IsLocked() == false);
			if (m_world.IsLocked() == true)
			{
			    return null;
			}

			Fixture fixture = new Fixture();
			fixture.Create(this, def);

			if (m_flags.HasFlag(BodyFlags.e_activeFlag))
			{
			    BroadPhase broadPhase = m_world.m_contactManager.m_broadPhase;
			    fixture.CreateProxies(broadPhase, m_xf);
			}

			m_fixtureList.Add(fixture);

			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 |= WorldFlags.e_newFixture;

			return fixture;
		}
示例#2
0
        /// 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.
        /// @param def the fixture definition.
        /// @warning This function is locked during callbacks.
        public Fixture CreateFixture(FixtureDef def)
        {
            Utilities.Assert(m_world.IsLocked() == false);
            if (m_world.IsLocked() == true)
            {
                return(null);
            }

            Fixture fixture = new Fixture();

            fixture.Create(this, def);

            if (m_flags.HasFlag(BodyFlags.e_activeFlag))
            {
                BroadPhase broadPhase = m_world.m_contactManager.m_broadPhase;
                fixture.CreateProxies(broadPhase, m_xf);
            }

            m_fixtureList.Add(fixture);

            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 |= WorldFlags.e_newFixture;

            return(fixture);
        }
示例#3
0
        /// Set the active state of the body. An inactive body is not
        /// simulated and cannot be collided with or woken up.
        /// If you pass a flag of true, all fixtures will be added to the
        /// broad-phase.
        /// If you pass a flag of false, all fixtures will be removed from
        /// the broad-phase and all contacts will be destroyed.
        /// Fixtures and joints are otherwise unaffected. you may continue
        /// to create/destroy fixtures and joints on inactive bodies.
        /// Fixtures on an inactive body are implicitly inactive and will
        /// not participate in collisions, ray-casts, or queries.
        /// Joints connected to an inactive body are implicitly inactive.
        /// An inactive body is still owned by a b2World object and remains
        /// in the body list.
        public void SetActive(bool flag)
        {
            if (flag == IsActive())
            {
                return;
            }

            if (flag)
            {
                _flags |= BodyFlags.Active;

                // Create all proxies.
                BroadPhase broadPhase = _world._contactManager._broadPhase;
                for (Fixture f = _fixtureList; f != null; f = f._next)
                {
                    f.CreateProxies(broadPhase, ref _xf);
                }

                // Contacts are created the next time step.
            }
            else
            {
                _flags &= ~BodyFlags.Active;

                // Destroy all proxies.
                BroadPhase broadPhase = _world._contactManager._broadPhase;
                for (Fixture f = _fixtureList; f != null; f = f._next)
                {
                    f.DestroyProxies(broadPhase);
                }

                // Destroy the attached contacts.
                ContactEdge ce = _contactList;
                while (ce != null)
                {
                    ContactEdge ce0 = ce;
                    ce = ce.Next;
                    _world._contactManager.Destroy(ce0.Contact);
                }
                _contactList = null;
            }
        }
示例#4
0
        /// 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.
        /// @param def the fixture definition.
        /// @warning This function is locked during callbacks.
        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.CreateProxies(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);
        }