Example #1
0
        public b2Fixture GetFixtureList()
        {
            global::System.IntPtr cPtr = Box2dPINVOKE.b2Body_GetFixtureList__SWIG_0(swigCPtr);
            b2Fixture             ret  = (cPtr == global::System.IntPtr.Zero) ? null : new b2Fixture(cPtr, false);

            return(ret);
        }
Example #2
0
        public b2Fixture CreateFixture(b2FixtureDef def)
        {
            global::System.IntPtr cPtr = Box2dPINVOKE.b2Body_CreateFixture__SWIG_0(swigCPtr, b2FixtureDef.getCPtr(def));
            b2Fixture             ret  = (cPtr == global::System.IntPtr.Zero) ? null : new b2Fixture(cPtr, false);

            return(ret);
        }
Example #3
0
        public b2Contact(b2Fixture fA, int indexA, b2Fixture fB, int indexB)
        {
            m_flags = b2ContactFlags.e_enabledFlag;

            m_fixtureA = fA;
            m_fixtureB = fB;

            m_indexA = indexA;
            m_indexB = indexB;

            m_manifold            = b2Manifold.Create();
            m_manifold.pointCount = 0;

            Prev = null;
            Next = null;

            m_NodeA         = new b2ContactEdge();
            m_NodeA.Contact = null;
            m_NodeA.hasPrev = false;
            m_NodeA.hasNext = false;
            m_NodeA.Other   = null;

            m_nodeB         = new b2ContactEdge();
            m_nodeB.Contact = null;
            m_nodeB.hasPrev = false;
            m_nodeB.hasNext = false;
            m_nodeB.Other   = null;

            m_toiCount = 0;

            m_friction    = b2Math.b2MixFriction(m_fixtureA.Friction, m_fixtureB.Friction);
            m_restitution = b2Math.b2MixRestitution(m_fixtureA.Restitution, m_fixtureB.Restitution);
        }
Example #4
0
        public override float ReportFixture(b2Fixture fixture, b2Vec2 point,
                                            b2Vec2 normal, float fraction)
        {
            b2Body body     = fixture.Body;
            object userData = body.UserData;

            if (userData != null)
            {
                int index = (int)userData;
                if (index == 0)
                {
                    // filter
                    return(-1.0f);
                }
            }

            Debug.Assert(m_count < e_maxCount);

            m_points[m_count]  = point;
            m_normals[m_count] = normal;
            ++m_count;

            if (m_count == e_maxCount)
            {
                return(0.0f);
            }

            return(1.0f);
        }
Example #5
0
        void SetPhysicsToSquare(Square square)
        {
            // Define the dynamic body.
            //Set up a 1m squared box in the physics world
            b2BodyDef def = new b2BodyDef();

            def.position = new b2Vec2(square.Position.X / PTM_RATIO, square.Position.Y / PTM_RATIO);
            def.type     = b2BodyType.b2_dynamicBody;
            b2Body body = _world.CreateBody(def);
            // Define another box shape for our dynamic body.
            var dynamicBox = new b2PolygonShape();

            dynamicBox.SetAsBox(0.5f, 0.5f); //These are mid points for our 1m box

            // Define the dynamic body fixture.
            b2FixtureDef fd = new b2FixtureDef();

            fd.shape    = dynamicBox;
            fd.density  = 1f;
            fd.friction = 0.3f;
            b2Fixture fixture = body.CreateFixture(fd);

            square.PhysicsBody = body;
            //_world.SetContactListener(new Myb2Listener());

            // _world.Dump();
        }
Example #6
0
        public void DrawFixture(b2Fixture fixture)
        {
            b2Color     color = new b2Color(0.95f, 0.95f, 0.6f);
            b2Transform xf    = fixture.Body.Transform;

            switch (fixture.ShapeType)
            {
            case b2ShapeType.e_circle:
            {
                b2CircleShape circle = (b2CircleShape)fixture.Shape;

                b2Vec2 center = b2Math.b2Mul(xf, circle.Position);
                float  radius = circle.Radius;

                m_debugDraw.DrawCircle(center, radius, color);
            }
            break;

            case b2ShapeType.e_polygon:
            {
                b2PolygonShape poly        = (b2PolygonShape)fixture.Shape;
                int            vertexCount = poly.VertexCount;
                Debug.Assert(vertexCount <= b2Settings.b2_maxPolygonVertices);
                b2Vec2[] vertices = new b2Vec2[b2Settings.b2_maxPolygonVertices];

                for (int i = 0; i < vertexCount; ++i)
                {
                    vertices[i] = b2Math.b2Mul(xf, poly.Vertices[i]);
                }

                m_debugDraw.DrawPolygon(vertices, vertexCount, color);
            }
            break;
            }
        }
Example #7
0
    protected b2Contact(b2Fixture fA, int indexA, b2Fixture fB, int indexB)
    {
        m_flags = ContactFlags.e_enabledFlag;

        m_fixtureA = fA;
        m_fixtureB = fB;

        m_indexA = indexA;
        m_indexB = indexB;

        m_manifold.pointCount = 0;

        m_prev = null;
        m_next = null;

        m_nodeA.contact = null;
        m_nodeA.prev    = null;
        m_nodeA.next    = null;
        m_nodeA.other   = null;

        m_nodeB.contact = null;
        m_nodeB.prev    = null;
        m_nodeB.next    = null;
        m_nodeB.other   = null;

        m_toiCount = 0;

        m_friction    = Utils.b2MixFriction(m_fixtureA.m_friction, m_fixtureB.m_friction);
        m_restitution = Utils.b2MixRestitution(m_fixtureA.m_restitution, m_fixtureB.m_restitution);

        m_tangentSpeed = 0.0f;
    }
Example #8
0
    /// Dump this body to a log file
    public void Dump()
    {
        int bodyIndex = m_islandIndex;

        Utils.b2Log("{\n");
        Utils.b2Log("  b2BodyDef bd;\n");
        Utils.b2Log("  bd.type = b2BodyType(%d);\n", m_type);
        Utils.b2Log("  bd.position.Set(%.15lef, %.15lef);\n", m_xf.p.x, m_xf.p.y);
        Utils.b2Log("  bd.angle = %.15lef;\n", m_sweep.a);
        Utils.b2Log("  bd.linearVelocity.Set(%.15lef, %.15lef);\n", m_linearVelocity.x, m_linearVelocity.y);
        Utils.b2Log("  bd.angularVelocity = %.15lef;\n", m_angularVelocity);
        Utils.b2Log("  bd.linearDamping = %.15lef;\n", m_linearDamping);
        Utils.b2Log("  bd.angularDamping = %.15lef;\n", m_angularDamping);
        Utils.b2Log("  bd.allowSleep = bool(%d);\n", m_flags & BodyFlags.e_autoSleepFlag);
        Utils.b2Log("  bd.awake = bool(%d);\n", m_flags & BodyFlags.e_awakeFlag);
        Utils.b2Log("  bd.fixedRotation = bool(%d);\n", m_flags & BodyFlags.e_fixedRotationFlag);
        Utils.b2Log("  bd.bullet = bool(%d);\n", m_flags & BodyFlags.e_bulletFlag);
        Utils.b2Log("  bd.active = bool(%d);\n", m_flags & BodyFlags.e_activeFlag);
        Utils.b2Log("  bd.gravityScale = %.15lef;\n", m_gravityScale);
        Utils.b2Log("  bodies[%d] = m_world->CreateBody(&bd);\n", m_islandIndex);
        Utils.b2Log("\n");
        for (b2Fixture f = m_fixtureList; f != null; f = f.m_next)
        {
            Utils.b2Log("  {\n");
            f.Dump(bodyIndex);
            Utils.b2Log("  }\n");
        }
        Utils.b2Log("}\n");
    }
Example #9
0
    internal static b2Contact Create(b2Fixture fixtureA, int indexA, b2Fixture fixtureB, int indexB)
    {
        if (s_initialized == false)
        {
            InitializeRegisters();
            s_initialized = true;
        }

        b2Shape.Type type1 = fixtureA.GetType();
        b2Shape.Type type2 = fixtureB.GetType();

        Debug.Assert(0 <= ((int)type1) && type1 < b2Shape.Type.e_typeCount);
        Debug.Assert(0 <= ((int)type2) && type2 < b2Shape.Type.e_typeCount);

        b2ContactCreateFcn createFcn = s_registers[(int)type1, (int)type2].createFcn;

        if (createFcn != null)
        {
            if (s_registers[(int)type1, (int)type2].primary)
            {
                return(createFcn(fixtureA, indexA, fixtureB, indexB));
            }
            else
            {
                return(createFcn(fixtureB, indexB, fixtureA, indexA));
            }
        }
        else
        {
            return(null);
        }
    }
Example #10
0
        public b2Fixture GetFixtureA()
        {
            global::System.IntPtr cPtr = Box2DPINVOKE.b2Contact_GetFixtureA__SWIG_0(swigCPtr);
            b2Fixture             ret  = (cPtr == global::System.IntPtr.Zero) ? null : new b2Fixture(cPtr, false);

            return(ret);
        }
Example #11
0
        public b2Fixture CreateFixture(b2Shape shape, float density)
        {
            global::System.IntPtr cPtr = Box2dPINVOKE.b2Body_CreateFixture__SWIG_1(swigCPtr, b2Shape.getCPtr(shape), density);
            b2Fixture             ret  = (cPtr == global::System.IntPtr.Zero) ? null : new b2Fixture(cPtr, false);

            return(ret);
        }
Example #12
0
        public override void PreSolve(b2Contact contact, b2Manifold oldManifold)
        {
            b2Manifold manifold = contact.GetManifold();

            if (manifold.pointCount == 0)
            {
                return;
            }

            b2Fixture fixtureA = contact.GetFixtureA();
            b2Fixture fixtureB = contact.GetFixtureB();

            b2Collision.b2GetPointStates(state1, state2, oldManifold, manifold);

            contact.GetWorldManifold(ref worldManifold);

            for (int i = 0; i < manifold.pointCount && m_pointCount < k_maxContactPoints; ++i)
            {
                ContactPoint cp = m_points[m_pointCount];
                if (cp == null)
                {
                    cp = new ContactPoint();
                    m_points[m_pointCount] = cp;
                }
                cp.fixtureA = fixtureA;
                cp.fixtureB = fixtureB;
                cp.position = worldManifold.points[i];
                cp.normal   = worldManifold.normal;
                cp.state    = state2[i];
                ++m_pointCount;
            }
        }
Example #13
0
        private void createWithCollider2d(Collider2D coll)
        {
            b2FixtureDef      fixtureDef = new b2FixtureDef();
            PhysicsMaterial2D material   = coll.sharedMaterial;

            if (material != null)
            {
                fixtureDef.restitution = material.bounciness;
                fixtureDef.friction    = material.friction;
            }
            fixtureDef.isSensor = coll.isTrigger;

            if (coll is BoxCollider2D)
            {
                BoxCollider2D  boxColl = coll as BoxCollider2D;
                b2PolygonShape s       = b2PolygonShape.AsOrientedBox(boxColl.size.x * 0.5f,
                                                                      boxColl.size.y * 0.5f,
                                                                      new b2Vec2(boxColl.offset.x, boxColl.offset.y),
                                                                      0 /*transform.eulerAngles.z*Mathf.Deg2Rad*/);
                scaleShape(s);
                fixtureDef.shape   = s;
                _fixtureDict[coll] = new b2Fixture[] { _body.CreateFixture(fixtureDef) };
            }
            else if (coll is CircleCollider2D)
            {
                CircleCollider2D circleColl = coll as CircleCollider2D;
                b2CircleShape    s          = new b2CircleShape(circleColl.radius);
                s.SetLocalPosition(new b2Vec2(circleColl.offset.x, circleColl.offset.y));
                scaleShape(s);
                fixtureDef.shape   = s;
                _fixtureDict[coll] = new b2Fixture[] { _body.CreateFixture(fixtureDef) };
            }
            else if (coll is PolygonCollider2D)
            {
                int i, j;
                PolygonCollider2D polyColl = coll as PolygonCollider2D;

                List <b2Fixture> fixtureList = new List <b2Fixture>();
                int pathCount = polyColl.pathCount;
                for (i = 0; i < pathCount; i++)
                {
                    Vector2[] path     = polyColl.GetPath(i);
                    b2Vec2[]  vertices = new b2Vec2[path.Length];
                    for (j = 0; j < path.Length; j++)
                    {
                        vertices[j] = new b2Vec2(path[j].x, path[j].y);
                    }
                    b2Separator sep      = new b2Separator();
                    b2Fixture[] fixtures = sep.Separate(_body, fixtureDef, vertices, 100, polyColl.offset.x, polyColl.offset.y);             //必须放大100倍进行计算
                    for (j = 0; j < fixtures.Length; j++)
                    {
                        scaleShape(fixtures[j].GetShape());
                    }
                    fixtureList.AddRange(fixtures);
                }
                _fixtureDict[coll] = fixtureList.ToArray();
            }
        }
Example #14
0
        public override float ReportFixture(b2Fixture fixture, b2Vec2 point,
                                            b2Vec2 normal, float fraction)
        {
            m_fixture = fixture;
            m_point   = point;
            m_normal  = normal;

            return(fraction);
        }
Example #15
0
    /// Set the type of this body. This may alter the mass and velocity.
    public void SetType(BodyType type)
    {
        Debug.Assert(m_world.IsLocked() == false);
        if (m_world.IsLocked() == true)
        {
            return;
        }

        if (m_type == type)
        {
            return;
        }

        m_type = type;

        ResetMassData();

        if (m_type == BodyType.b2_staticBody)
        {
            m_linearVelocity.SetZero();
            m_angularVelocity = 0.0f;
            m_sweep.a0        = m_sweep.a;


            m_sweep.c0 = m_sweep.c;
            SynchronizeFixtures();
        }

        SetAwake(true);

        m_force.SetZero();
        m_torque = 0.0f;

        // Delete the attached contacts.
        b2ContactEdge ce = m_contactList;

        while (ce != null)
        {
            b2ContactEdge ce0 = ce;
            ce = ce.next;
            m_world.m_contactManager.Destroy(ce0.contact);
        }
        m_contactList = null;

        // Touch the proxies so that new contacts will be created (when appropriate)
        b2BroadPhase broadPhase = m_world.m_contactManager.m_broadPhase;

        for (b2Fixture f = m_fixtureList; f != null; f = f.m_next)
        {
            int proxyCount = f.m_proxyCount;
            for (int i = 0; i < proxyCount; ++i)
            {
                broadPhase.TouchProxy(f.m_proxies[i].proxyId);
            }
        }
    }
Example #16
0
        public override bool ReportFixture(b2Fixture fixture)
        {
            if ((fixture.GetFilterData().categoryBits & _CollisionMask) == 0)
            {
                return(true);
            }
            ICollider collider = _Physics2DControl.GetPhysicsObject(fixture.GetBody().GetUserData().data).GetCollider(fixture.GetUserData().data);

            return(_Callback.Invoke(collider));
        }
Example #17
0
        public override float ReportFixture(b2Fixture fixture, b2Vec2 point, b2Vec2 normal, float fraction)
        {
            if ((fixture.GetFilterData().categoryBits & _CollisionMask) == 0)
            {
                return(-1f);
            }
            ICollider collider = _Physics2DControl.GetPhysicsObject(fixture.GetBody().GetUserData().data).GetCollider(fixture.GetUserData().data);

            return(_Callback.Invoke(collider, point.ToVector2(), normal.ToVector2(), fraction));
        }
Example #18
0
        public virtual float ReportFixture(b2Fixture fixture, b2Vec2 point, b2Vec2 normal, float fraction)
        {
            float ret = Box2dPINVOKE.b2RayCastCallback_ReportFixture(swigCPtr, b2Fixture.getCPtr(fixture), b2Vec2.getCPtr(point), b2Vec2.getCPtr(normal), fraction);

            if (Box2dPINVOKE.SWIGPendingException.Pending)
            {
                throw Box2dPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Example #19
0
            public override float ReportFixture(b2Fixture fixture, b2Vec2 point, b2Vec2 normal, float fraction)
            {
                if ((fixture.GetFilterData().categoryBits & 1) == 0)
                {
                    return(1);
                }

                P2       = point;
                Fraction = fraction;
                return(0);
            }
Example #20
0
    internal void SynchronizeFixtures()
    {
        b2Transform xf1 = new b2Transform();

        xf1.q.Set(m_sweep.a0);
        xf1.p = m_sweep.c0 - Utils.b2Mul(xf1.q, m_sweep.localCenter);

        b2BroadPhase broadPhase = m_world.m_contactManager.m_broadPhase;

        for (b2Fixture f = m_fixtureList; f != null; f = f.m_next)
        {
            f.Synchronize(broadPhase, xf1, m_xf);
        }
    }
Example #21
0
    /// Return true if contact calculations should be performed between these two shapes.
    /// @warning for performance reasons this is only called when the AABBs begin to overlap.

    // 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.
    public virtual bool ShouldCollide(b2Fixture fixtureA, b2Fixture fixtureB)
    {
        b2Filter filterA = fixtureA.GetFilterData();
        b2Filter filterB = fixtureB.GetFilterData();

        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);
    }
Example #22
0
        /**在编辑器更改碰撞器Center时*/
        public void onEditShapeCenter(object[] args)
        {
            Collider2D collider = (Collider2D)args [0];
            float      cx       = (float)args [1];
            float      cy       = (float)args [2];
            float      oldCX    = (float)args[3];
            float      oldCY    = (float)args[4];

            b2Fixture[] fixtures = _fixtureDict [collider];
            if (fixtures != null)
            {
                for (int i = 0; i < fixtures.Length; i++)
                {
                    b2Fixture fixture = fixtures[i];
                    b2Shape   s       = fixture.GetShape();
                    if (collider is BoxCollider2D)
                    {
                        b2PolygonShape boxShape = s as b2PolygonShape;
                        BoxCollider2D  boxColl  = collider as BoxCollider2D;
                        boxShape.SetAsOrientedBox(boxColl.size.x * 0.5f, boxColl.size.y * 0.5f, new b2Vec2(cx, cy), 0);
                        scaleShape(boxShape);
                        _body.SetAwake(true);
                    }
                    else if (collider is CircleCollider2D)
                    {
                        b2CircleShape circleShape = s as b2CircleShape;
                        circleShape.SetLocalPosition(new b2Vec2(cx, cy));
                        scaleShape(circleShape, true);
                        _body.SetAwake(true);
                    }
                    else if (collider is PolygonCollider2D)
                    {
                        b2PolygonShape    polyShape = s as b2PolygonShape;
                        PolygonCollider2D polyColl  = collider as PolygonCollider2D;
                        List <b2Vec2>     vertices  = polyShape.GetVertices();
                        for (int j = 0; j < vertices.Count; j++)
                        {
                            b2Vec2 v = vertices[j];
                            v.x -= oldCX;
                            v.y -= oldCY;
                            v.x += cx;
                            v.y += cy;
                        }
                        //scaleShape(polyShape);
                        _body.SetAwake(true);
                    }
                }
            }
        }
Example #23
0
        /**
         * Separates a non-convex polygon into convex polygons and adds them as fixtures to the <code>body</code> parameter.<br/>
         * There are some rules you should follow (otherwise you might get unexpected results) :
         * <ul>
         * <li>This class is specifically for non-convex polygons. If you want to create a convex polygon, you don't need to use this class - Box2D's <code>b2PolygonShape</code> class allows you to create convex shapes with the <code>setAsArray()</code>/<code>setAsVector()</code> method.</li>
         * <li>The vertices must be in clockwise order.</li>
         * <li>No three neighbouring points should lie on the same line segment.</li>
         * <li>There must be no overlapping segments and no "holes".</li>
         * </ul> <p/>
         * @param body The b2Body, in which the new fixtures will be stored.
         * @param fixtureDef A b2FixtureDef, containing all the properties (friction, density, etc.) which the new fixtures will inherit.
         * @param verticesVec The vertices of the non-convex polygon, in clockwise order.
         * @param scale <code>[optional]</code> The scale which you use to draw shapes in Box2D. The bigger the scale, the better the precision. The default value is 30.
         * @see b2PolygonShape
         * @see b2PolygonShape.SetAsArray()
         * @see b2PolygonShape.SetAsVector()
         * @see b2Fixture
         * */

        public b2Fixture[] Separate(b2Body body, b2FixtureDef fixtureDef, b2Vec2[] verticesVec, float scale = 100, float offsetX = 0, float offsetY = 0)
        {
            int            i;
            int            n = verticesVec.Length;
            int            j;
            int            m;
            List <b2Vec2>  vec = new List <b2Vec2>();
            ArrayList      figsVec;
            b2PolygonShape polyShape;

            for (i = 0; i < n; i++)
            {
                vec.Add(new b2Vec2((verticesVec[i].x + offsetX) * scale, (verticesVec[i].y + offsetY) * scale));
            }
            if (!getIsConvexPolygon(vec, vec.Count))
            {
                int validate = Validate(vec);
                if (validate == 2 || validate == 3)
                {
                    vec.Reverse();                    //add by kingBook 2017.2.14
                }
            }
            //Debug.Log(string.Format("Validate:{0}",Validate(vec)));
            figsVec = calcShapes(vec);
            n       = figsVec.Count;



            b2Fixture[] fixtures = new b2Fixture[n];

            for (i = 0; i < n; i++)
            {
                vec = (List <b2Vec2>)figsVec[i];
                vec.Reverse();//add by kingBook 2017.2.14
                m           = vec.Count;
                verticesVec = new b2Vec2[m];
                for (j = 0; j < m; j++)
                {
                    verticesVec[j] = new b2Vec2(vec[j].x / scale, vec[j].y / scale);
                }

                polyShape = new b2PolygonShape();
                polyShape.SetAsArray(verticesVec, m);
                fixtureDef.shape = polyShape;
                fixtures[i]      = body.CreateFixture(fixtureDef);
            }
            return(fixtures);
        }
Example #24
0
        /**在编辑器更改碰撞器Trigger时*/
        private void onEditColliderTrigger(object[] args)
        {
            Collider2D collider  = (Collider2D)args [0];
            bool       isTrigger = (bool)args [1];

            b2Fixture[] fixtures = _fixtureDict[collider];
            if (fixtures != null)
            {
                for (int i = 0; i < fixtures.Length; i++)
                {
                    b2Fixture fixture = fixtures[i];
                    fixture.SetSensor(isTrigger);
                }
                _body.SetAwake(true);
            }
        }
        public b2Contact Create(b2Fixture fixtureA, b2Fixture fixtureB)
        {
            int type1 = fixtureA.GetType();
            int type2 = fixtureB.GetType();

            //b2Settings.b2Assert(b2Shape.e_unknownShape < type1 && type1 < b2Shape.e_shapeTypeCount);
            //b2Settings.b2Assert(b2Shape.e_unknownShape < type2 && type2 < b2Shape.e_shapeTypeCount);

            b2ContactRegister reg = m_registers[type1][type2];

            b2Contact c;

            if (reg.pool != null)
            {
                // Pop a contact off the pool
                c        = reg.pool;
                reg.pool = c.m_next;
                reg.poolCount--;
                c.Reset(fixtureA, fixtureB);
                return(c);
            }

            Func <object, b2Contact> createFcn = reg.createFcn;

            if (createFcn != null)
            {
                if (reg.primary)
                {
                    c = createFcn(m_allocator);
                    c.Reset(fixtureA, fixtureB);
                    return(c);
                }
                else
                {
                    c = createFcn(m_allocator);
                    c.Reset(fixtureB, fixtureA);
                    return(c);
                }
            }
            else
            {
                return(null);
            }
        }
Example #26
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)
    {
        Debug.Assert(m_world.IsLocked() == false);

        if (flag == IsActive())
        {
            return;
        }

        if (flag)
        {
            m_flags |= BodyFlags.e_activeFlag;

            // Create all proxies.
            b2BroadPhase broadPhase = m_world.m_contactManager.m_broadPhase;
            for (b2Fixture f = m_fixtureList; f != null; f = f.m_next)
            {
                f.CreateProxies(broadPhase, m_xf);
            }

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

            // Destroy all proxies.
            b2BroadPhase broadPhase = m_world.m_contactManager.m_broadPhase;
            for (b2Fixture f = m_fixtureList; f != null; f = f.m_next)
            {
                f.DestroyProxies(broadPhase);
            }

            // Destroy the attached contacts.
            b2ContactEdge ce = m_contactList;
            while (ce != null)
            {
                b2ContactEdge ce0 = ce;
                ce = ce.next;
                m_world.m_contactManager.Destroy(ce0.contact);
            }
            m_contactList = null;
        }
    }
Example #27
0
        public override bool ReportFixture(b2Fixture fixture)
        {
            b2Body body = fixture.Body;

            if (body.BodyType == b2BodyType.b2_dynamicBody)
            {
                bool inside = fixture.TestPoint(m_point);
                if (inside)
                {
                    m_fixture = fixture;

                    // We are done, terminate the query.
                    return(false);
                }
            }

            // Continue the query.
            return(true);
        }
Example #28
0
        /** @private */
        virtual public void Reset(b2Fixture fixtureA = null, b2Fixture fixtureB = null)
        {
            m_flags = e_enabledFlag;

            if (fixtureA == null || fixtureB == null)
            {
                m_fixtureA = null;
                m_fixtureB = null;
                return;
            }

            if (fixtureA.IsSensor() || fixtureB.IsSensor())
            {
                m_flags |= e_sensorFlag;
            }

            b2Body bodyA = fixtureA.GetBody();
            b2Body bodyB = fixtureB.GetBody();

            if (bodyA.GetType() != b2Body.b2_dynamicBody || bodyA.IsBullet() || bodyB.GetType() != b2Body.b2_dynamicBody || bodyB.IsBullet())
            {
                m_flags |= e_continuousFlag;
            }

            m_fixtureA = fixtureA;
            m_fixtureB = fixtureB;

            m_manifold.m_pointCount = 0;

            m_prev = null;
            m_next = null;

            m_nodeA.contact = null;
            m_nodeA.prev    = null;
            m_nodeA.next    = null;
            m_nodeA.other   = null;

            m_nodeB.contact = null;
            m_nodeB.prev    = null;
            m_nodeB.next    = null;
            m_nodeB.other   = null;
        }
Example #29
0
        /**在编辑器更改碰撞器Density时*/
        private void onEditColliderDensity(object[] args)
        {
            Collider2D collider = (Collider2D)args [0];
            float      density  = (float)args [1];

            b2Fixture[] fixtures = _fixtureDict[collider];
            if (fixtures != null)
            {
                b2Fixture[] nFixtures = new b2Fixture[fixtures.Length];
                for (int i = 0; i < fixtures.Length; i++)
                {
                    b2Fixture fixture = fixtures[i];
                    b2Shape   s       = fixture.GetShape();
                    _body.DestroyFixture(fixture);
                    nFixtures[i] = _body.CreateFixture2(s, density);
                }
                _fixtureDict[collider] = nFixtures;
                _body.SetAwake(true);
            }
        }
Example #30
0
        /// Called for each fixture found in the query AABB.
        /// @return false to terminate the query.
        public override bool ReportFixture(b2Fixture fixture)
        {
            if (m_count == e_maxCount)
            {
                return(false);
            }

            b2Body  body      = fixture.Body;
            b2Shape shape     = fixture.Shape;
            var     transform = body.Transform;
            bool    overlap   = b2Collision.b2TestOverlap(shape, 0, m_circle, 0, ref transform, ref m_transform);

            if (overlap)
            {
                DrawFixture(fixture);
                ++m_count;
            }

            return(true);
        }
 public b2ChainAndCircleContact(b2Fixture fixtureA, int indexA, b2Fixture fixtureB, int indexB)
     : base(fixtureA, indexA, fixtureB, indexB)
 {
     Debug.Assert(m_fixtureA.ShapeType == b2ShapeType.e_chain);
     Debug.Assert(m_fixtureB.ShapeType == b2ShapeType.e_circle);
 }
 public b2EdgeAndCircleContact(b2Fixture fixtureA, int indexA, b2Fixture fixtureB, int indexB)
     : this(fixtureA, fixtureB)
 {
 }
 public b2PolygonContact(b2Fixture fixtureA, b2Fixture fixtureB)
     : base(fixtureA, 0, fixtureB, 0)
 {
     Debug.Assert(m_fixtureA.ShapeType == b2ShapeType.e_polygon);
     Debug.Assert(m_fixtureB.ShapeType == b2ShapeType.e_polygon);
 }
		public b2PolygonContact(b2Fixture fixtureA, int indexA, b2Fixture fixtureB, int indexB)
			: this(fixtureA, fixtureB)
		{	}
 public b2EdgeAndCircleContact(b2Fixture fixtureA, b2Fixture fixtureB)
     : base(fixtureA, 0, fixtureB, 0)
 {
     Debug.Assert(m_fixtureA.ShapeType == b2ShapeType.e_edge);
     Debug.Assert(m_fixtureB.ShapeType == b2ShapeType.e_circle);
 }
Example #36
0
        public b2Contact(b2Fixture fA, int indexA, b2Fixture fB, int indexB)
        {
            m_flags = b2ContactFlags.e_enabledFlag;

            m_fixtureA = fA;
            m_fixtureB = fB;

            m_indexA = indexA;
            m_indexB = indexB;

            m_manifold = b2Manifold.Create();
            m_manifold.pointCount = 0;

            Prev = null;
            Next = null;

            m_NodeA = new b2ContactEdge();
            m_NodeA.Contact = null;
            m_NodeA.hasPrev = false;
            m_NodeA.hasNext = false;
            m_NodeA.Other = null;

            m_nodeB = new b2ContactEdge();
            m_nodeB.Contact = null;
            m_nodeB.hasPrev = false;
            m_nodeB.hasNext = false;
            m_nodeB.Other = null;

            m_toiCount = 0;

            m_friction = b2Math.b2MixFriction(m_fixtureA.Friction, m_fixtureB.Friction);
            m_restitution = b2Math.b2MixRestitution(m_fixtureA.Restitution, m_fixtureB.Restitution);
        }
Example #37
0
        public static b2Contact Create(b2Fixture fixtureA, int indexA, b2Fixture fixtureB, int indexB)
        {
            b2ShapeType type1 = fixtureA.ShapeType;
            b2ShapeType type2 = fixtureB.ShapeType;

            Debug.Assert(0 <= type1 && type1 < b2ShapeType.e_typeCount);
            Debug.Assert(0 <= type2 && type2 < b2ShapeType.e_typeCount);

            Type createFcn = s_registers[(int)type1, (int)type2].contactType;

            if (createFcn != null)
            {
                if (s_registers[(int)type1, (int)type2].isPrimary)
                {
                    return ((b2Contact)Activator.CreateInstance(createFcn, new object[] { fixtureA, indexA, fixtureB, indexB }));
                }
                else
                {
                    return ((b2Contact)Activator.CreateInstance(createFcn, new object[] { fixtureB, indexB, fixtureA, indexA }));
                }
            }
            return (null);
        }