コード例 #1
0
        void RemoveOctreeFromParent(Octree octree)
        {
            if (octree.Parent == null)
            {
                return;
            }

            // 親から自分を削除。
            for (int z = 0; z < 2; z++)
            {
                for (int y = 0; y < 2; y++)
                {
                    for (int x = 0; x < 2; x++)
                    {
                        if (octree.Parent[x, y, z] != octree)
                        {
                            continue;
                        }

                        var parent = octree.Parent;

                        // 自分をプールへ戻す。
                        octreePool.Return(octree);
                        octree.Parent[x, y, z] = null;

                        if (parent.NodeCount == 0)
                        {
                            // 再帰的にノードを持たなくなった先祖がいれば全て削除。
                            RemoveOctreeFromParent(parent);
                        }

                        return;
                    }
                }
            }
        }
コード例 #2
0
ファイル: Octree.cs プロジェクト: willcraftia/TestBlocks
 internal NodeCollection(Octree octree)
 {
     this.octree = octree;
 }
コード例 #3
0
        void Execute(BoundingFrustum frustum, ref BoundingSphere frustumSphere, Action <Octree> action, Octree octree)
        {
            bool intersected;

            // 視錐台球 vs 八分木球
            frustumSphere.Intersects(ref octree.Sphere, out intersected);
            if (!intersected)
            {
                return;
            }

            // 視錐台 vs 八分木球
            frustum.Intersects(ref octree.Sphere, out intersected);
            if (!intersected)
            {
                return;
            }

            // 視錐台 vs 八分木ボックス
            frustum.Intersects(ref octree.Box, out intersected);
            if (!intersected)
            {
                return;
            }

            action(octree);

            for (int z = 0; z < 2; z++)
            {
                for (int y = 0; y < 2; y++)
                {
                    for (int x = 0; x < 2; x++)
                    {
                        var child = octree[x, y, z];
                        if (child != null)
                        {
                            Execute(frustum, ref frustumSphere, action, child);
                        }
                    }
                }
            }
        }