Beispiel #1
0
        /// <summary>
        /// Splits the node and inserts the elements into the children
        /// </summary>
        public void split()
        {
            if (m_children != null)
            {
                return;
            }
            Vector3 center = new Vector3();
            center.X = (m_bb.Min.X + m_bb.Max.X) * 0.5f;
            center.Y = (m_bb.Min.Y + m_bb.Max.Y) * 0.5f;
            center.Z = (m_bb.Min.Z + m_bb.Max.Z) * 0.5f;

            m_children = new OctreeNode[8];
            for (short i = 0; i < 8; ++i)
            {
                Vector3 vec = subVecs[i];
                Vector3 min = new Vector3(), max = new Vector3();
                min.X = center.X + (m_bb.Min.X * (1.0f - vec.X));
                min.Y = center.Y + (m_bb.Min.Y * (1.0f - vec.Y));
                min.Z = center.Z + (m_bb.Min.Z * (1.0f - vec.Z));

                max.X = center.X + (m_bb.Max.X * vec.X);
                max.Y = center.Y + (m_bb.Max.Y * vec.Y);
                max.Z = center.Z + (m_bb.Max.Z * vec.Z);

                m_children[i] = new OctreeNode( new BoundingBox(min, max),(short)(m_level + 1), this);
            }
        }
Beispiel #2
0
 public OctreeNode(BoundingBox bb, short level, OctreeNode parent)
 {
     m_bb = bb;
     m_level = level;
     m_parent = parent;
 }