コード例 #1
0
ファイル: Body.cs プロジェクト: Nomad1/sharpbox2d
        /**
           * 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 World object and remains in
           * the body list.
           *
           * @param flag
           */
        public void setActive(bool flag)
        {
            Debug.Assert(m_world.isLocked() == false);

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

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

                // Create all proxies.
                BroadPhase broadPhase = m_world.m_contactManager.m_broadPhase;
                for (Fixture 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.Active;

                // Destroy all proxies.
                BroadPhase broadPhase = m_world.m_contactManager.m_broadPhase;
                for (Fixture f = m_fixtureList; f != null; f = f.m_next)
                {
                    f.destroyProxies(broadPhase);
                }

                // Destroy the attached contacts.
                ContactEdge ce = m_contactList;
                while (ce != null)
                {
                    ContactEdge ce0 = ce;
                    ce = ce.next;
                    m_world.m_contactManager.destroy(ce0.contact);
                }
                m_contactList = null;
            }
        }
コード例 #2
0
ファイル: Body.cs プロジェクト: Nomad1/sharpbox2d
        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;
        }
コード例 #3
0
ファイル: Body.cs プロジェクト: Nomad1/sharpbox2d
        /**
           * Set the type of this body. This may alter the mass and velocity.
           *
           * @param type
           */
        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.STATIC)
            {
                m_linearVelocity.setZero();
                m_angularVelocity = 0.0f;
                m_sweep.a0 = m_sweep.a;
                m_sweep.c0.set(m_sweep.c);
                synchronizeFixtures();
            }

            setAwake(true);

            m_force.setZero();
            m_torque = 0.0f;

            // Delete the attached contacts.
            ContactEdge ce = m_contactList;
            while (ce != null)
            {
                ContactEdge 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)
            BroadPhase broadPhase = m_world.m_contactManager.m_broadPhase;
            for (Fixture 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);
                }
            }
        }
コード例 #4
0
ファイル: Contact.cs プロジェクト: Nomad1/sharpbox2d
 protected Contact(IWorldPool argPool)
 {
     m_fixtureA = null;
     m_fixtureB = null;
     m_nodeA = new ContactEdge();
     m_nodeB = new ContactEdge();
     m_manifold = new Manifold();
     pool = argPool;
 }