Esempio n. 1
0
        // Cache here per time step to reduce cache misses.
        //  Vec2 m_localCenterA, m_localCenterB;
        // float m_invMassA, m_invIA;
        // float m_invMassB, m_invIB;
        protected Joint(IWorldPool worldPool, JointDef def)
        {
            Debug.Assert(def.bodyA != def.bodyB);

            pool = worldPool;
            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_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();
        }
Esempio n. 2
0
        public Body(BodyDef bd, World world)
        {
            Debug.Assert(bd.position.isValid());
            Debug.Assert(bd.linearVelocity.isValid());
            Debug.Assert(bd.gravityScale >= 0.0f);
            Debug.Assert(bd.angularDamping >= 0.0f);
            Debug.Assert(bd.linearDamping >= 0.0f);

            m_flags = 0;

            if (bd.bullet)
            {
                m_flags |= BodyFlags.Bullet;
            }
            if (bd.fixedRotation)
            {
                m_flags |= BodyFlags.FixedRotation;
            }
            if (bd.allowSleep)
            {
                m_flags |= BodyFlags.AutoSleep;
            }
            if (bd.awake)
            {
                m_flags |= BodyFlags.Awake;
            }
            if (bd.active)
            {
                m_flags |= BodyFlags.Active;
            }

            m_world = world;

            m_xf.p.set(bd.position);
            m_xf.q.set(bd.angle);

            m_sweep.localCenter.setZero();
            m_sweep.c0.set(m_xf.p);
            m_sweep.c.set(m_xf.p);
            m_sweep.a0 = bd.angle;
            m_sweep.a = bd.angle;
            m_sweep.alpha0 = 0.0f;

            m_jointList = null;
            m_contactList = null;
            m_prev = null;
            m_next = null;

            m_linearVelocity.set(bd.linearVelocity);
            m_angularVelocity = bd.angularVelocity;

            m_linearDamping = bd.linearDamping;
            m_angularDamping = bd.angularDamping;
            m_gravityScale = bd.gravityScale;

            m_force.setZero();
            m_torque = 0.0f;

            m_sleepTime = 0.0f;

            m_type = bd.type;

            if (m_type == BodyType.DYNAMIC)
            {
                m_mass = 1f;
                m_invMass = 1f;
            }
            else
            {
                m_mass = 0f;
                m_invMass = 0f;
            }

            m_I = 0.0f;
            m_invI = 0.0f;

            m_userData = bd.userData;

            m_fixtureList = null;
            m_fixtureCount = 0;
        }