コード例 #1
0
ファイル: Terrain.cs プロジェクト: sp-alex-osou/TerrainLOD
        private void UpdateNode(Node node, bool frustumCulling, GameTime gameTime)
        {
            node.Visible = true;

            if (frustumCulling)
            {
                ContainmentType result = ViewFrustum.Contains(GetBoundingBox(node));

                if (result == ContainmentType.Disjoint)
                    node.Visible = false;
                else if (result == ContainmentType.Contains)
                    frustumCulling = false;
            }

            if (!node.Visible)
                return;

            if (node.Children != null)
                foreach (Node child in node.Children)
                    UpdateNode(child, frustumCulling, gameTime);

            if (node.Block != null)
                node.Block.Update(gameTime);
        }
コード例 #2
0
ファイル: Terrain.cs プロジェクト: sp-alex-osou/TerrainLOD
 private void InitializeQuadtree()
 {
     root = InitializeNode(BlockCount, 0, 0);
 }
コード例 #3
0
ファイル: Terrain.cs プロジェクト: sp-alex-osou/TerrainLOD
        private BoundingBox GetBoundingBox(Node node)
        {
            Vector3 min = node.BoundingBox.Min;
            Vector3 max = node.BoundingBox.Max;

            if (!HeightmapEnabled || Bumpiness == 0.0f)
            {
                min.Y = HeightOffset - 1.0f;
                max.Y = HeightOffset + 1.0f;
            }
            else
            {
                min.Y *= Bumpiness;
                max.Y *= Bumpiness;
            }

            if (min.Y > max.Y)
            {
                float y = min.Y;
                min.Y = max.Y;
                max.Y = y;
            }

            return new BoundingBox(min, max);
        }
コード例 #4
0
ファイル: Terrain.cs プロジェクト: sp-alex-osou/TerrainLOD
        private Node InitializeNode(int count, int x, int y)
        {
            Node node = new Node();

            if (count > 1)
            {
                node.Children = new List<Node>();

                for (int i = 0; i < 2; i++)
                    for (int j = 0; j < 2; j++ )
                        node.Children.Add(InitializeNode(count / 2, x + i * count / 2, y + j * count / 2));

                foreach (Node child in node.Children)
                    node.BoundingBox = BoundingBox.CreateMerged(node.BoundingBox, child.BoundingBox);
            }
            else
            {
                node.Block = blocks[x, y];
                node.BoundingBox = node.Block.BoundingBox;
            }

            return node;
        }
コード例 #5
0
ファイル: Terrain.cs プロジェクト: sp-alex-osou/TerrainLOD
        private void DrawNode(Node node)
        {
            if (!node.Visible)
                return;

            if (node.Children != null)
                foreach (Node child in node.Children)
                    DrawNode(child);
            else
                DrawBlock(node.Block);
        }