Ejemplo n.º 1
0
        /// <summary>
        /// The get.
        /// </summary>
        /// <param name="x">
        /// The x.
        /// </param>
        /// <param name="y">
        /// The y.
        /// </param>
        /// <param name="z">
        /// The z.
        /// </param>
        /// <returns>
        /// The <see cref="T"/>.
        /// </returns>
        public T Get(long x, long y, long z)
        {
            PositionOctreeNode <T> current = this;

            while (current != null && current.m_CurrentDepth != current.m_MaximalDepth)
            {
                if ((x & current.m_MaskDepth) == 0)
                {
                    if ((y & current.m_MaskDepth) == 0)
                    {
                        if ((z & current.m_MaskDepth) == 0)
                        {
                            current = current.m_Nodes[0];
                        }
                        else
                        {
                            current = current.m_Nodes[1];
                        }
                    }
                    else
                    {
                        if ((z & current.m_MaskDepth) == 0)
                        {
                            current = current.m_Nodes[2];
                        }
                        else
                        {
                            current = current.m_Nodes[3];
                        }
                    }
                }
                else
                {
                    if ((y & current.m_MaskDepth) == 0)
                    {
                        if ((z & current.m_MaskDepth) == 0)
                        {
                            current = current.m_Nodes[4];
                        }
                        else
                        {
                            current = current.m_Nodes[5];
                        }
                    }
                    else
                    {
                        if ((z & current.m_MaskDepth) == 0)
                        {
                            current = current.m_Nodes[6];
                        }
                        else
                        {
                            current = current.m_Nodes[7];
                        }
                    }
                }
            }

            if (current == null)
            {
                return(null);
            }

            return(current.m_Value);
        }
Ejemplo n.º 2
0
 public PositionOctree()
 {
     this.RootNode = new PositionOctreeNode <T>(0, 64);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// The set.
        /// </summary>
        /// <param name="value">
        /// The value.
        /// </param>
        /// <param name="x">
        /// The x.
        /// </param>
        /// <param name="y">
        /// The y.
        /// </param>
        /// <param name="z">
        /// The z.
        /// </param>
        public void Set(T value, long x, long y, long z)
        {
            PositionOctreeNode <T> current = this;

            while (current != null && current.m_CurrentDepth != current.m_MaximalDepth)
            {
                if ((x & current.m_MaskDepth) == 0)
                {
                    if ((y & current.m_MaskDepth) == 0)
                    {
                        if ((z & current.m_MaskDepth) == 0)
                        {
                            if (current.m_Nodes[0] == null)
                            {
                                current.m_Nodes[0] = current.CreateSubnode(-1, -1, -1);
                            }

                            current = current.m_Nodes[0];
                        }
                        else
                        {
                            if (current.m_Nodes[1] == null)
                            {
                                current.m_Nodes[1] = current.CreateSubnode(-1, -1, 1);
                            }

                            current = current.m_Nodes[1];
                        }
                    }
                    else
                    {
                        if ((z & current.m_MaskDepth) == 0)
                        {
                            if (current.m_Nodes[2] == null)
                            {
                                current.m_Nodes[2] = current.CreateSubnode(-1, 1, -1);
                            }

                            current = current.m_Nodes[2];
                        }
                        else
                        {
                            if (current.m_Nodes[3] == null)
                            {
                                current.m_Nodes[3] = current.CreateSubnode(-1, 1, 1);
                            }

                            current = current.m_Nodes[3];
                        }
                    }
                }
                else
                {
                    if ((y & current.m_MaskDepth) == 0)
                    {
                        if ((z & current.m_MaskDepth) == 0)
                        {
                            if (current.m_Nodes[4] == null)
                            {
                                current.m_Nodes[4] = current.CreateSubnode(1, -1, -1);
                            }

                            current = current.m_Nodes[4];
                        }
                        else
                        {
                            if (current.m_Nodes[5] == null)
                            {
                                current.m_Nodes[5] = current.CreateSubnode(1, -1, 1);
                            }

                            current = current.m_Nodes[5];
                        }
                    }
                    else
                    {
                        if ((z & current.m_MaskDepth) == 0)
                        {
                            if (current.m_Nodes[6] == null)
                            {
                                current.m_Nodes[6] = current.CreateSubnode(1, 1, -1);
                            }

                            current = current.m_Nodes[6];
                        }
                        else
                        {
                            if (current.m_Nodes[7] == null)
                            {
                                current.m_Nodes[7] = current.CreateSubnode(1, 1, 1);
                            }

                            current = current.m_Nodes[7];
                        }
                    }
                }
            }

            current.m_Value = value;
        }