Пример #1
0
        public QuadNode(NodeType nodeType, int nodeSize, int nodeDepth, QuadNode parent, QuadTree parentTree, int positionIndex)
        {
            NodeType = nodeType;
            _nodeSize = nodeSize;
            _nodeDepth = nodeDepth;
            _positionIndex = positionIndex;

            _parent = parent;
            _parentTree = parentTree;

            //Add the 9 vertices
            AddVertices();

            Bounds = new BoundingBox(_parentTree.Vertices[VertexTopLeft.Index].Position,
                        _parentTree.Vertices[VertexBottomRight.Index].Position);

            if (nodeSize >= 4)
                AddChildren();

            //Make call to UpdateNeighbors from the parent node.
            //This will update all neighbors recursively for the
            //children as well.  This ensures all nodes are created
            //prior to updating neighbors.
            if (_nodeDepth == 1)
            {
                AddNeighbors();

                VertexTopLeft.Activated = true;
                VertexTopRight.Activated = true;
                VertexCenter.Activated = true;
                VertexBottomLeft.Activated = true;
                VertexBottomRight.Activated = true;

            }
        }
Пример #2
0
        /// <summary>
        /// Create terrain at <paramref name="position"/>
        /// </summary>
        /// <param name="position"></param>
        /// <param name="textures"></param>
        /// <param name="device"></param>
        /// <param name="scale"></param>
        /// <param name="Content"></param>
        /// <param name="camera"></param>
        public QuadTree(Vector3 position, List<Texture2D> textures, GraphicsDevice device, int scale, ContentManager Content, GameCamera.FreeCamera camera)
        {
            shadow = new LightsAndShadows.Shadow();
            light = new LightsAndShadows.Light(0.7f, 0.4f, new Vector3(513, 100, 513));

            ViewFrustrum = new BoundingFrustum(camera.View * camera.Projection);
             //  Model model = Content.Load<Model>("Models/stone2");
              //  this.model = new LoadModel(model, Vector3.One, Vector3.Up, new Vector3(1), device);
            this.textures = textures;
            effect = Content.Load<Effect>("Effects/MultiTextured");
            effect2 = Content.Load<Effect>("Effects/Shadows");
            Device = device;

            _position = position;
            _topNodeSize = textures[4].Width - 1;

            _vertices = new MapRender(textures[4],scale);
            _buffers = new BufferManager(_vertices.Vertices, device);
            _rootNode = new QuadNode(NodeType.FullNode, _topNodeSize, 1, null, this, 0);

            //Construct an array large enough to hold all of the indices we'll need.
            Indices = _vertices.indices;

            envBilbList.Add(new EnvBilb(textures[6], textures[5], device, Content, scale));
             foreach (EnvBilb pass in envBilbList)
            {
                pass.GenerateObjPositions(_vertices.Vertices, _vertices.TerrainWidth, _vertices.TerrainLength, _vertices.heightData);
                pass.CreateBillboardVerticesFromList();
            }

            /*
            envModelList.Add(new EnvModel(textures[6], model, device, Content, scale));

               foreach (EnvModel pass1 in envModelList)
            {
                pass1.GenerateObjPositions(_vertices.Vertices, _vertices.TerrainWidth, _vertices.TerrainLength, _vertices.heightData);
                pass1.CreateModelFromList();
            }
             * */

               effect.Parameters["xTexture0"].SetValue(textures[1]);
               effect.Parameters["xTexture1"].SetValue(textures[0]);
               effect.Parameters["xTexture2"].SetValue(textures[2]);
               effect.Parameters["xTexture3"].SetValue(textures[3]);
               effect.Parameters["xTexture5"].SetValue(textures[7]);
               Matrix worldMatrix = Matrix.Identity;
               effect.Parameters["xWorld"].SetValue(worldMatrix);
               effect.Parameters["xEnableLighting"].SetValue(true);
               effect.Parameters["xAmbient"].SetValue(light.Ambient);
               effect.Parameters["xLightPower"].SetValue(light.LightPower);

               effect.Parameters["Ground"].SetValue(textures[7]);
               effect.Parameters["GroundText0"].SetValue(textures[8]);
               effect.Parameters["GroundText1"].SetValue(textures[9]);
               effect.Parameters["GroundText2"].SetValue(textures[10]);

               _rootNode.EnforceMinimumDepth();
        }
Пример #3
0
        /// <summary>
        /// Update reference to neighboring quads
        /// </summary>
        private void AddNeighbors()
        {
            switch (NodeType)
            {
                case NodeType.TopLeft: //Top Left Corner
                    //Top neighbor
                    if (_parent.NeighborTop != null)
                        NeighborTop = _parent.NeighborTop.ChildBottomLeft;

                    //Right neighbor
                    NeighborRight = _parent.ChildTopRight;
                    //Bottom neighbor
                    NeighborBottom = _parent.ChildBottomLeft;

                    //Left neighbor
                    if (_parent.NeighborLeft != null)
                        NeighborLeft = _parent.NeighborLeft.ChildTopRight;

                    break;

                case NodeType.TopRight: //Top Right Corner
                    //Top neighbor
                    if (_parent.NeighborTop != null)
                        NeighborTop = _parent.NeighborTop.ChildBottomRight;

                    //Right neighbor
                    if (_parent.NeighborRight != null)
                        NeighborRight = _parent.NeighborRight.ChildTopLeft;

                    //Bottom neighbor
                    NeighborBottom = _parent.ChildBottomRight;

                    //Left neighbor
                    NeighborLeft = _parent.ChildTopLeft;

                    break;

                case NodeType.BottomLeft: //Bottom Left Corner
                    //Top neighbor
                    NeighborTop = _parent.ChildTopLeft;

                    //Right neighbor
                    NeighborRight = _parent.ChildBottomRight;

                    //Bottom neighbor
                    if (_parent.NeighborBottom != null)
                        NeighborBottom = _parent.NeighborBottom.ChildTopLeft;

                    //Left neighbor
                    if (_parent.NeighborLeft != null)
                        NeighborLeft = _parent.NeighborLeft.ChildBottomRight;

                    break;

                case NodeType.BottomRight: //Bottom Right Corner
                    //Top neighbor
                    NeighborTop = _parent.ChildTopRight;

                    //Right neighbor
                    if (_parent.NeighborRight != null)
                        NeighborRight = _parent.NeighborRight.ChildBottomLeft;

                    //Bottom neighbor
                    if (_parent.NeighborBottom != null)
                        NeighborBottom = _parent.NeighborBottom.ChildTopRight;

                    //Left neighbor
                    NeighborLeft = _parent.ChildBottomLeft;

                    break;
            }

            if (this.HasChildren)
            {
                ChildTopLeft.AddNeighbors();
                ChildTopRight.AddNeighbors();
                ChildBottomLeft.AddNeighbors();
                ChildBottomRight.AddNeighbors();
            }
        }
Пример #4
0
        /// <summary>
        /// Add the 4 child quad nodes.
        /// </summary>
        private void AddChildren()
        {
            //Add top left (northwest) child
            ChildTopLeft = new QuadNode(NodeType.TopLeft, _nodeSize / 2, _nodeDepth + 1, this, _parentTree, VertexTopLeft.Index);

            //Add top right (northeast) child
            ChildTopRight = new QuadNode(NodeType.TopRight, _nodeSize / 2, _nodeDepth + 1, this, _parentTree, VertexTop.Index);

            //Add bottom left (southwest) child
            ChildBottomLeft = new QuadNode(NodeType.BottomLeft, _nodeSize / 2, _nodeDepth + 1, this, _parentTree, VertexLeft.Index);

            //Add bottom right (southeast) child
            ChildBottomRight = new QuadNode(NodeType.BottomRight, _nodeSize / 2, _nodeDepth + 1, this, _parentTree, VertexCenter.Index);

            HasChildren = true;
        }
Пример #5
0
        /// <summary>
        /// Create terrain at <paramref name="position"/>
        /// </summary>
        /// <param name="position"></param>
        /// <param name="textures"></param>
        /// <param name="device"></param>
        /// <param name="scale"></param>
        /// <param name="Content"></param>
        /// <param name="camera"></param>
        public QuadTree(Vector2 position, List<Texture2D> textures, GraphicsDevice device, int scale, ContentManager Content, GameCamera.FreeCamera camera)
        {
            light = new LightsAndShadows.Light(0.7f, 0.4f, new Vector3(513, 100, 513));

            ViewFrustrum = new BoundingFrustum(camera.View * camera.Projection);
            this.textures = textures;
            effect = Content.Load<Effect>("Effects/MultiTextured");

            Device = device;

            _topNodeSize = textures[15].Width - 1;

            _vertices = new MapRender(textures[15], scale, position);
            _buffers = new BufferManager(_vertices.Vertices, device);
            _rootNode = new QuadNode(NodeType.FullNode, _topNodeSize, 1, null, this, 0);

            //Construct an array large enough to hold all of the indices we'll need.
            Indices = _vertices.indices;

            envBilbList.Add(new EnvBilb(textures[19], textures[20], device, Content, scale));
            envBilbList.Add(new EnvBilb(textures[17], textures[18], device, Content, scale));

            foreach (EnvBilb pass in envBilbList)
            {
                pass.GenerateObjPositions(_vertices.TerrainLength2, _vertices.TerrainWidth2, _vertices.heightDataToControl);
                pass.CreateBillboardVerticesFromList();
            }

            Matrix worldMatrix = Matrix.Identity;
            effect.Parameters["xWorld"].SetValue(worldMatrix);
            effect.Parameters["xEnableLighting"].SetValue(true);
            effect.Parameters["xAmbient"].SetValue(light.Ambient);
            effect.Parameters["xLightPower"].SetValue(light.LightPower);
            #region tekstury Alphy
            effect.Parameters["xTexture0"].SetValue(textures[0]);
            effect.Parameters["xTexture1"].SetValue(textures[1]);
            effect.Parameters["xTexture2"].SetValue(textures[2]);
            effect.Parameters["xTexture3"].SetValue(textures[3]);
            effect.Parameters["xTexture4"].SetValue(textures[4]);
            effect.Parameters["xTexture5"].SetValue(textures[5]);
            effect.Parameters["xTexture6"].SetValue(textures[6]);
            #endregion
            #region Tekstury Terenu
            effect.Parameters["xTexture7"].SetValue(textures[7]);
            effect.Parameters["xTexture8"].SetValue(textures[8]);
            effect.Parameters["xTexture9"].SetValue(textures[9]);
            effect.Parameters["xTexture10"].SetValue(textures[10]);
            effect.Parameters["xTexture11"].SetValue(textures[11]);

            effect.Parameters["xTexture12"].SetValue(textures[12]);
            effect.Parameters["xTexture13"].SetValue(textures[13]);
            effect.Parameters["xTexture14"].SetValue(textures[14]);
            #endregion
            #region Proj
            //  effect.Parameters["xTexture14"].SetValue(textures[26]);
            #endregion
            MinimumDepth = 9;
            _rootNode.EnforceMinimumDepth();
            MinimumDepth = 7;
            QuadNodeController.ustawione = true;
            _rootNode.EnforceMinimumDepth();
        }
Пример #6
0
 /// <summary>
 /// Make sure neighbor parents are split to ensure
 /// consistency with vertex sharing and tessellation.
 /// </summary>
 private static void EnsureNeighborParentSplit(QuadNode neighbor)
 {
     //Checking for null neighbor and null parent in case
     //we recode for additional quad trees in the future.
     if (neighbor != null && neighbor.Parent != null)
         if (!neighbor.Parent.IsSplit)
             neighbor.Parent.Split();
 }