Joint definitions are used to construct joints.
Пример #1
0
        // Cache here per time step to reduce cache misses.
        //	final Vec2 m_localCenterA, m_localCenterB;
        //	float m_invMassA, m_invIA;
        //	float m_invMassB, m_invIB;

        protected internal Joint(IWorldPool argWorldPool, JointDef def)
        {
            Debug.Assert(def.BodyA != def.BodyB);

            Pool             = argWorldPool;
            Type             = def.Type;
            Prev             = null;
            Next             = null;
            BodyA            = def.BodyA;
            BodyB            = def.BodyB;
            CollideConnected = def.CollideConnected;
            IslandFlag       = false;
            UserData         = def.UserData;
            Index            = 0;

            EdgeA       = new JointEdge();
            EdgeA.Joint = null;
            EdgeA.Other = null;
            EdgeA.Prev  = null;
            EdgeA.Next  = null;

            EdgeB       = new JointEdge();
            EdgeB.Joint = null;
            EdgeB.Other = null;
            EdgeB.Prev  = null;
            EdgeB.Next  = null;

            //		m_localCenterA = new Vec2();
            //		m_localCenterB = new Vec2();
        }
Пример #2
0
        // Cache here per time step to reduce cache misses.
        //    final Vec2 m_localCenterA, m_localCenterB;
        //    float m_invMassA, m_invIA;
        //    float m_invMassB, m_invIB;
        protected internal Joint(IWorldPool argWorldPool, JointDef def)
        {
            Debug.Assert(def.bodyA != def.bodyB);

            pool = argWorldPool;
            m_type = def.type;
            m_prev = null;
            m_next = null;
            m_bodyA = def.bodyA;
            m_bodyB = def.bodyB;
            m_collideConnected = def.collideConnected;
            m_islandFlag = false;
            m_userData = def.userData;
            m_index = 0;

            m_edgeA = new JointEdge();
            m_edgeA.joint = null;
            m_edgeA.other = null;
            m_edgeA.prev = null;
            m_edgeA.next = null;

            m_edgeB = new JointEdge();
            m_edgeB.joint = null;
            m_edgeB.other = null;
            m_edgeB.prev = null;
            m_edgeB.next = null;

            //		m_localCenterA = new Vec2();
            //		m_localCenterB = new Vec2();
        }
Пример #3
0
        public static Joint Create(World argWorld, JointDef def)
        {
            //Joint joint = null;
            switch (def.Type)
            {
            case JointType.Mouse:
                return(new MouseJoint(argWorld.Pool, (MouseJointDef)def));

            case JointType.Distance:
                return(new DistanceJoint(argWorld.Pool, (DistanceJointDef)def));

            case JointType.Prismatic:
                return(new PrismaticJoint(argWorld.Pool, (PrismaticJointDef)def));

            case JointType.Revolute:
                return(new RevoluteJoint(argWorld.Pool, (RevoluteJointDef)def));

            case JointType.Weld:
                return(new WeldJoint(argWorld.Pool, (WeldJointDef)def));

            case JointType.Friction:
                return(new FrictionJoint(argWorld.Pool, (FrictionJointDef)def));

            //case JointType.WHEEL:
            //    return new WheelJoint(argWorld.Pool, (LineJointDef)def);

            //case JointType.GEAR:
            //    return new GearJoint(argWorld.Pool, (GearJointDef)def);

            case JointType.Pulley:
                return(new PulleyJoint(argWorld.Pool, (PulleyJointDef)def));

            case JointType.ConstantVolume:
                return(new ConstantVolumeJoint(argWorld, (ConstantVolumeJointDef)def));
            }
            return(null);
        }
Пример #4
0
        /// <summary>
        /// create a joint to constrain bodies together. No reference to the definition is retained. This
        /// may cause the connected bodies to cease colliding.
        /// </summary>
        /// <warning>This function is locked during callbacks.</warning>
        /// <param name="def"></param>
        /// <returns></returns>
        public virtual Joint createJoint(JointDef def)
        {
            Debug.Assert(Locked == false);
            if (Locked)
            {
                return null;
            }

            Joint j = Joint.create(this, def);

            // Connect to the world list.
            j.m_prev = null;
            j.m_next = m_jointList;
            if (m_jointList != null)
            {
                m_jointList.m_prev = j;
            }
            m_jointList = j;
            ++m_jointCount;

            // Connect to the bodies' doubly linked lists.
            j.m_edgeA.joint = j;
            j.m_edgeA.other = j.m_bodyB;
            j.m_edgeA.prev = null;
            j.m_edgeA.next = j.m_bodyA.m_jointList;
            if (j.m_bodyA.m_jointList != null)
            {
                j.m_bodyA.m_jointList.prev = j.m_edgeA;
            }
            j.m_bodyA.m_jointList = j.m_edgeA;

            j.m_edgeB.joint = j;
            j.m_edgeB.other = j.m_bodyA;
            j.m_edgeB.prev = null;
            j.m_edgeB.next = j.m_bodyB.m_jointList;
            if (j.m_bodyB.m_jointList != null)
            {
                j.m_bodyB.m_jointList.prev = j.m_edgeB;
            }
            j.m_bodyB.m_jointList = j.m_edgeB;

            Body bodyA = def.bodyA;
            Body bodyB = def.bodyB;

            // If the joint prevents collisions, then flag any contacts for filtering.
            if (def.collideConnected == false)
            {
                ContactEdge edge = bodyB.ContactList;
                while (edge != null)
                {
                    if (edge.other == bodyA)
                    {
                        // Flag the contact for filtering at the next time step (where either
                        // body is awake).
                        edge.contact.flagForFiltering();
                    }

                    edge = edge.next;
                }
            }

            // Note: creating a joint doesn't wake the bodies.

            return j;
        }
Пример #5
0
        /// <summary>
        /// create a joint to constrain bodies together. No reference to the definition is retained. This
        /// may cause the connected bodies to cease colliding.
        /// </summary>
        /// <warning>This function is locked during callbacks.</warning>
        /// <param name="def"></param>
        /// <returns></returns>
        public Joint CreateJoint(JointDef def)
        {
            Debug.Assert(Locked == false);
            if (Locked)
            {
                return null;
            }

            Joint j = Joint.Create(this, def);

            // Connect to the world list.
            j.Prev = null;
            j.Next = JointList;
            if (JointList != null)
            {
                JointList.Prev = j;
            }
            JointList = j;
            ++JointCount;

            // Connect to the bodies' doubly linked lists.
            j.EdgeA.Joint = j;
            j.EdgeA.Other = j.BodyB;
            j.EdgeA.Prev = null;
            j.EdgeA.Next = j.BodyA.JointList;
            if (j.BodyA.JointList != null)
            {
                j.BodyA.JointList.Prev = j.EdgeA;
            }
            j.BodyA.JointList = j.EdgeA;

            j.EdgeB.Joint = j;
            j.EdgeB.Other = j.BodyA;
            j.EdgeB.Prev = null;
            j.EdgeB.Next = j.BodyB.JointList;
            if (j.BodyB.JointList != null)
            {
                j.BodyB.JointList.Prev = j.EdgeB;
            }
            j.BodyB.JointList = j.EdgeB;

            Body bodyA = def.BodyA;
            Body bodyB = def.BodyB;

            // If the joint prevents collisions, then flag any contacts for filtering.
            if (def.CollideConnected == false)
            {
                ContactEdge edge = bodyB.ContactList;
                while (edge != null)
                {
                    if (edge.Other == bodyA)
                    {
                        // Flag the contact for filtering at the next time step (where either
                        // body is awake).
                        edge.Contact.SetFlagForFiltering();
                    }

                    edge = edge.Next;
                }
            }

            // Note: creating a joint doesn't wake the bodies.

            return j;
        }
Пример #6
0
        // Cache here per time step to reduce cache misses.
        //    final Vec2 m_localCenterA, m_localCenterB;
        //    float m_invMassA, m_invIA;
        //    float m_invMassB, m_invIB;
        protected internal Joint(IWorldPool argWorldPool, JointDef def)
        {
            Debug.Assert(def.BodyA != def.BodyB);

            Pool = argWorldPool;
            Type = def.Type;
            Prev = null;
            Next = null;
            BodyA = def.BodyA;
            BodyB = def.BodyB;
            CollideConnected = def.CollideConnected;
            IslandFlag = false;
            UserData = def.UserData;
            Index = 0;

            EdgeA = new JointEdge();
            EdgeA.Joint = null;
            EdgeA.Other = null;
            EdgeA.Prev = null;
            EdgeA.Next = null;

            EdgeB = new JointEdge();
            EdgeB.Joint = null;
            EdgeB.Other = null;
            EdgeB.Prev = null;
            EdgeB.Next = null;

            //		m_localCenterA = new Vec2();
            //		m_localCenterB = new Vec2();
        }
Пример #7
0
        public static Joint Create(World argWorld, JointDef def)
        {
            //Joint joint = null;
            switch (def.Type)
            {

                case JointType.Mouse:
                    return new MouseJoint(argWorld.Pool, (MouseJointDef)def);

                case JointType.Distance:
                    return new DistanceJoint(argWorld.Pool, (DistanceJointDef)def);

                case JointType.Prismatic:
                    return new PrismaticJoint(argWorld.Pool, (PrismaticJointDef)def);

                case JointType.Revolute:
                    return new RevoluteJoint(argWorld.Pool, (RevoluteJointDef)def);

                case JointType.Weld:
                    return new WeldJoint(argWorld.Pool, (WeldJointDef)def);

                case JointType.Friction:
                    return new FrictionJoint(argWorld.Pool, (FrictionJointDef)def);

                //case JointType.WHEEL:
                //    return new WheelJoint(argWorld.Pool, (LineJointDef)def);

                //case JointType.GEAR:
                //    return new GearJoint(argWorld.Pool, (GearJointDef)def);

                case JointType.Pulley:
                    return new PulleyJoint(argWorld.Pool, (PulleyJointDef)def);

                case JointType.ConstantVolume:
                    return new ConstantVolumeJoint(argWorld, (ConstantVolumeJointDef)def);
            }
            return null;
        }
Пример #8
0
        public static Joint create(World argWorld, JointDef def)
        {
            //Joint joint = null;
            switch (def.type)
            {

                case JointType.MOUSE:
                    return new MouseJoint(argWorld.Pool, (MouseJointDef)def);

                case JointType.DISTANCE:
                    return new DistanceJoint(argWorld.Pool, (DistanceJointDef)def);

                case JointType.PRISMATIC:
                    return new PrismaticJoint(argWorld.Pool, (PrismaticJointDef)def);

                case JointType.REVOLUTE:
                    return new RevoluteJoint(argWorld.Pool, (RevoluteJointDef)def);

                case JointType.WELD:
                    return new WeldJoint(argWorld.Pool, (WeldJointDef)def);

                case JointType.FRICTION:
                    return new FrictionJoint(argWorld.Pool, (FrictionJointDef)def);

                //case JointType.WHEEL:
                //    return new WheelJoint(argWorld.Pool, (LineJointDef)def);

                //case JointType.GEAR:
                //    return new GearJoint(argWorld.Pool, (GearJointDef)def);

                case JointType.PULLEY:
                    return new PulleyJoint(argWorld.Pool, (PulleyJointDef)def);

                case JointType.CONSTANT_VOLUME:
                    return new ConstantVolumeJoint(argWorld, (ConstantVolumeJointDef)def);
            }
            return null;
        }