示例#1
0
        /// Creates a fixture from a shape and attach it to this body.
        /// This is a convenience function. Use FixtureDef if you need to set parameters
        /// like friction, restitution, user data, or filtering.
        /// @param shape the shape to be cloned.
        /// @param density the shape density (set to zero for static bodies).
        /// @warning This function is locked during callbacks.
        public Fixture CreateFixture(Shape shape, float density)
        {
            Debug.Assert(_world.IsLocked == false);
            if (_world.IsLocked == true)
            {
                return(null);
            }

            BroadPhase broadPhase = _world._contactManager._broadPhase;

            FixtureDef def = new FixtureDef();

            def.shape   = shape;
            def.density = density;

            Fixture fixture = new Fixture();

            fixture.Create(broadPhase, this, ref _xf, def);

            fixture._next = _fixtureList;
            _fixtureList  = fixture;
            ++_fixtureCount;

            fixture._body = this;

            // Let the world know we have a new fixture.
            _world._flags |= WorldFlags.NewFixture;

            return(fixture);
        }
示例#2
0
        // We need separation create/destroy functions from the ructor/destructor because
        // the destructor cannot access the allocator or broad-phase (no destructor arguments allowed by C++).
        internal void Create(BroadPhase broadPhase, Body body, ref 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;

            _shape = def.shape.Clone();

            // Create proxy in the broad-phase.
            AABB aabb;

            _shape.ComputeAABB(out aabb, ref xf);

            _proxyId = broadPhase.CreateProxy(ref aabb, this);
        }
示例#3
0
        // We need separation create/destroy functions from the ructor/destructor because
        // the destructor cannot access the allocator or broad-phase (no destructor arguments allowed by C++).
        internal void Create(BroadPhase broadPhase, Body body, ref 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;

            _shape = def.shape.Clone();

            // Create proxy in the broad-phase.
            AABB aabb;
            _shape.ComputeAABB(out aabb, ref xf);

            _proxyId = broadPhase.CreateProxy(ref aabb, this);
        }
示例#4
0
        /// Creates a fixture from a shape and attach it to this body.
        /// This is a convenience function. Use FixtureDef if you need to set parameters
        /// like friction, restitution, user data, or filtering.
        /// @param shape the shape to be cloned.
        /// @param density the shape density (set to zero for static bodies).
        /// @warning This function is locked during callbacks.
        public Fixture CreateFixture(Shape shape, float density)
        {
            Debug.Assert(_world.IsLocked == false);
            if (_world.IsLocked == true)
            {
                return null;
            }

            BroadPhase broadPhase = _world._contactManager._broadPhase;

            FixtureDef def = new FixtureDef();
            def.shape = shape;
            def.density = density;

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

            fixture._next = _fixtureList;
            _fixtureList = fixture;
            ++_fixtureCount;

            fixture._body = this;

            // Let the world know we have a new fixture.
            _world._flags |= WorldFlags.NewFixture;

            return fixture;
        }