Exemplo n.º 1
0
        public MTQuadTreeNode(int depth, Vector3 min, Vector3 max)
        {
            Vector3 center = 0.5f * (min + max);
            Vector3 size   = max - min;

            Bound = new Bounds(center, size);
            if (depth > 0)
            {
                mSubNode = new MTQuadTreeNode[4];
                Vector3 subMin = new Vector3(center.x - 0.5f * size.x, min.y, center.z - 0.5f * size.z);
                Vector3 subMax = new Vector3(center.x, max.y, center.z);
                mSubNode[0] = new MTQuadTreeNode(depth - 1, subMin, subMax);
                subMin      = new Vector3(center.x, min.y, center.z - 0.5f * size.z);
                subMax      = new Vector3(center.x + 0.5f * size.x, max.y, center.z);
                mSubNode[1] = new MTQuadTreeNode(depth - 1, subMin, subMax);
                subMin      = new Vector3(center.x - 0.5f * size.x, min.y, center.z);
                subMax      = new Vector3(center.x, max.y, center.z + 0.5f * size.z);
                mSubNode[2] = new MTQuadTreeNode(depth - 1, subMin, subMax);
                subMin      = new Vector3(center.x, min.y, center.z);
                subMax      = new Vector3(center.x + 0.5f * size.x, max.y, center.z + 0.5f * size.z);
                mSubNode[3] = new MTQuadTreeNode(depth - 1, subMin, subMax);
            }
        }
Exemplo n.º 2
0
        protected MTQuadTreeNode[] m_SubNodes;//四个子Node
        public MTQuadTreeNode(int depth, Vector3 min, Vector3 max, Vector3 offset)
        {
            Vector3 center = 0.5f * (min + max);
            Vector3 size   = max - min;

            Bound  = new Bounds(center + offset, size);
            Offset = offset;
            if (depth > 0)
            {
                m_SubNodes = new MTQuadTreeNode[4];
                Vector3 subMin = new Vector3(center.x - 0.5f * size.x, min.y, center.z - 0.5f * size.z);
                Vector3 subMax = new Vector3(center.x, max.y, center.z);
                m_SubNodes[0] = new MTQuadTreeNode(depth - 1, subMin, subMax, offset);
                subMin        = new Vector3(center.x, min.y, center.z - 0.5f * size.z);
                subMax        = new Vector3(center.x + 0.5f * size.x, max.y, center.z);
                m_SubNodes[1] = new MTQuadTreeNode(depth - 1, subMin, subMax, offset);
                subMin        = new Vector3(center.x - 0.5f * size.x, min.y, center.z);
                subMax        = new Vector3(center.x, max.y, center.z + 0.5f * size.z);
                m_SubNodes[2] = new MTQuadTreeNode(depth - 1, subMin, subMax, offset);
                subMin        = new Vector3(center.x, min.y, center.z);
                subMax        = new Vector3(center.x + 0.5f * size.x, max.y, center.z + 0.5f * size.z);
                m_SubNodes[3] = new MTQuadTreeNode(depth - 1, subMin, subMax, offset);
            }
        }