예제 #1
0
        public void Init(int bodyCapacity, int contactCapacity, int jointCapacity, IContactListener listener)
        {
            // Console.WriteLine("Initializing Island");
            BodyCapacity = bodyCapacity;
            ContactCapacity = contactCapacity;
            JointCapacity = jointCapacity;
            BodyCount = 0;
            ContactCount = 0;
            JointCount = 0;

            Listener = listener;

            if (Bodies == null || BodyCapacity > Bodies.Length)
            {
                Bodies = new Body[BodyCapacity];
            }
            if (Joints == null || JointCapacity > Joints.Length)
            {
                Joints = new Joint[JointCapacity];
            }
            if (Contacts == null || ContactCapacity > Contacts.Length)
            {
                Contacts = new Contact[ContactCapacity];
            }

            // dynamic array
            if (Velocities == null || BodyCapacity > Velocities.Length)
            {
                Velocity[] old = Velocities ?? new Velocity[0];
                Velocities = new Velocity[BodyCapacity];
                Array.Copy(old, 0, Velocities, 0, old.Length);
                for (int i = old.Length; i < Velocities.Length; i++)
                {
                    Velocities[i] = new Velocity();
                }
            }

            // dynamic array
            if (Positions == null || BodyCapacity > Positions.Length)
            {
                Position[] old = Positions ?? new Position[0];
                Positions = new Position[BodyCapacity];
                Array.Copy(old, 0, Positions, 0, old.Length);
                for (int i = old.Length; i < Positions.Length; i++)
                {
                    Positions[i] = new Position();
                }
            }
        }
예제 #2
0
파일: Island.cs 프로젝트: thdtjsdn/box2dnet
        public virtual void init(int bodyCapacity, int contactCapacity, int jointCapacity, ContactListener listener)
        {
            // Console.WriteLine("Initializing Island");
            m_bodyCapacity = bodyCapacity;
            m_contactCapacity = contactCapacity;
            m_jointCapacity = jointCapacity;
            m_bodyCount = 0;
            m_contactCount = 0;
            m_jointCount = 0;

            m_listener = listener;

            if (m_bodies == null || m_bodyCapacity > m_bodies.Length)
            {
                m_bodies = new Body[m_bodyCapacity];
            }
            if (m_joints == null || m_jointCapacity > m_joints.Length)
            {
                m_joints = new Joint[m_jointCapacity];
            }
            if (m_contacts == null || m_contactCapacity > m_contacts.Length)
            {
                m_contacts = new Contact[m_contactCapacity];
            }

            // dynamic array
            if (m_velocities == null || m_bodyCapacity > m_velocities.Length)
            {
                Velocity[] old = m_velocities == null ? new Velocity[0] : m_velocities;
                m_velocities = new Velocity[m_bodyCapacity];
                Array.Copy(old, 0, m_velocities, 0, old.Length);
                for (int i = old.Length; i < m_velocities.Length; i++)
                {
                    m_velocities[i] = new Velocity();
                }
            }

            // dynamic array
            if (m_positions == null || m_bodyCapacity > m_positions.Length)
            {
                Position[] old = m_positions == null ? new Position[0] : m_positions;
                m_positions = new Position[m_bodyCapacity];
                Array.Copy(old, 0, m_positions, 0, old.Length);
                for (int i = old.Length; i < m_positions.Length; i++)
                {
                    m_positions[i] = new Position();
                }
            }
        }