Пример #1
0
        /// <summary>
        /// Return true if contact calculations should be performed between these two shapes.
        /// If you implement your own collision filter you may want to build from this implementation.
        /// @warning for performance reasons this is only called when the AABBs begin to overlap.
        /// </summary>
        public virtual bool ShouldCollide(Fixture fixtureA, Fixture fixtureB)
        {
            FilterData filterA = fixtureA.Filter;
            FilterData filterB = fixtureB.Filter;

            if (filterA.GroupIndex == filterB.GroupIndex && filterA.GroupIndex != 0)
            {
                return(filterA.GroupIndex > 0);
            }

            bool collide = (filterA.MaskBits & filterB.CategoryBits) != 0 && (filterA.CategoryBits & filterB.MaskBits) != 0;

            return(collide);
        }
Пример #2
0
        /// <summary>
        /// Return true if contact calculations should be performed between these two shapes.
        /// If you implement your own collision filter you may want to build from this implementation.
        /// @warning for performance reasons this is only called when the AABBs begin to overlap.
        /// </summary>
        public virtual bool ShouldCollide(Shape shape1, Shape shape2)
        {
            FilterData filter1 = shape1.FilterData;
            FilterData filter2 = shape2.FilterData;

            if (filter1.GroupIndex == filter2.GroupIndex && filter1.GroupIndex != 0)
            {
                return(filter1.GroupIndex > 0);
            }

            bool collide = (filter1.MaskBits & filter2.CategoryBits) != 0 && (filter1.CategoryBits & filter2.MaskBits) != 0;

            return(collide);
        }
Пример #3
0
        public virtual bool ShouldCollide(Shape shape1, Shape shape2)
        {
            FilterData filterData  = shape1.FilterData;
            FilterData filterData2 = shape2.FilterData;
            bool       result;

            if (filterData.GroupIndex == filterData2.GroupIndex && filterData.GroupIndex != 0)
            {
                result = (filterData.GroupIndex > 0);
            }
            else
            {
                bool flag = (filterData.MaskBits & filterData2.CategoryBits) != 0 && (filterData.CategoryBits & filterData2.MaskBits) != 0;
                result = flag;
            }
            return(result);
        }
Пример #4
0
        public void Create(BroadPhase broadPhase, Body body, 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;

            _type = def.Type;

            // Allocate and initialize the child shape.
            switch (_type)
            {
            case ShapeType.CircleShape:
            {
                CircleShape circle    = new CircleShape();
                CircleDef   circleDef = (CircleDef)def;
                circle._position = circleDef.LocalPosition;
                circle._radius   = circleDef.Radius;
                _shape           = circle;
            }
            break;

            case ShapeType.PolygonShape:
            {
                PolygonShape polygon    = new PolygonShape();
                PolygonDef   polygonDef = (PolygonDef)def;
                polygon.Set(polygonDef.Vertices, polygonDef.VertexCount);
                _shape = polygon;
            }
            break;

            case ShapeType.EdgeShape:
            {
                EdgeShape edge    = new EdgeShape();
                EdgeDef   edgeDef = (EdgeDef)def;
                edge.Set(edgeDef.Vertex1, edgeDef.Vertex2);
                _shape = edge;
            }
            break;

            default:
                Box2DXDebug.Assert(false);
                break;
            }

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

            _shape.ComputeAABB(out aabb, xf);

            bool inRange = broadPhase.InRange(aabb);

            // You are creating a shape outside the world box.
            Box2DXDebug.Assert(inRange);

            if (inRange)
            {
                _proxyId = broadPhase.CreateProxy(aabb, this);
            }
            else
            {
                _proxyId = PairManager.NullProxy;
            }
        }