Example #1
0
 public QuadNode(Quadtree tree, int minX, int maxX, int minZ, int maxZ, int treeLevel, QuadNode Parent, float minWidth, float minHeight, float width, Matrix worldMatrix, float[,] texData, int pos)
 {
     this.tree = tree;
     this.parent = Parent;
     this.Xmax = maxX;
     this.Xmin = minX;
     this.Zmax = maxZ;
     this.Zmin = minZ;
     this.width = maxX - minX;
     this.height = maxZ - minZ;
     this.box.Min = new Vector3(minX, 0, -maxZ);
     this.box.Max = new Vector3(maxX, 250 * 2, -minZ);
     if (treeLevel == 2)
         tree.nodeList2.Add(this);
     if (maxX - minX > minWidth && maxZ - minZ > minHeight)
     {
         topLeft = new QuadNode(tree, minX, (maxX + minX) / 2, (maxZ + minZ) / 2, maxZ, treeLevel + 1, this, minWidth, minHeight, width / 2f, worldMatrix, texData, 1);
         topRight = new QuadNode(tree, (maxX + minX) / 2, maxX, (maxZ + minZ) / 2, maxZ, treeLevel + 1, this, minWidth, minHeight, width / 2f, worldMatrix, texData, 2);
         bottomLeft = new QuadNode(tree, minX, (maxX + minX) / 2, minZ, (maxZ + minZ) / 2, treeLevel + 1, this, minWidth, minHeight, width / 2f, worldMatrix, texData, 3);
         bottomRight = new QuadNode(tree, (maxX + minX) / 2, maxX, minZ, (maxZ + minZ) / 2, treeLevel + 1, this, minWidth, minHeight, width / 2f, worldMatrix, texData, 4);
         this.box.Min = Vector3.Transform(this.box.Min, worldMatrix);
         this.box.Max = Vector3.Transform(this.box.Max, worldMatrix);
     }
     else
     {
         this.isLeaf = true;
       //  constructVerts(vertices1);
         tree.nodeList.Add(this);
     }
 }
Example #2
0
 private void SetupNodes(Texture2D heightMap, GraphicsDevice device)
 {
     Matrix worldMatrix = Matrix.CreateTranslation(-heightMap.Width / 2.0f, 0, heightMap.Height / 2.0f) * Matrix.CreateScale(2.0f) ;
      root = new QuadNode(this, 0, heightMap.Width, 0, heightMap.Height, 0, null, heightMap.Width / 128, heightMap.Height / 128 , heightMap.Width, worldMatrix, grassData, 1);
      foreach (QuadNode node in nodeList)
      {
          node.box.Min = Vector3.Transform(node.box.Min, worldMatrix);
          node.box.Max = Vector3.Transform(node.box.Max, worldMatrix);
      }
      foreach (QuadNode node in nodeList)
          if (node.isLeaf)
          {
              node.constructVerts(heightData, device, grassData, dirtData, stoneData);
              node.constructLODVerts(heightData, device, grassData, dirtData, stoneData);
              node.constructLOD2Verts(heightData, device, grassData, dirtData, stoneData);
          }
 }
Example #3
0
        public bool CheckVisible(BoundingFrustum frustum, QuadNode ANode)
        {
            int counter = 0;
            int rightIn;
            int outNo;
            int total = 0;
            bool visibility = true;
            frustumPlanes[0] = frustum.Near;
            frustumPlanes[1] = frustum.Far;
            frustumPlanes[2] = frustum.Top;
            frustumPlanes[3] = frustum.Bottom;
            frustumPlanes[4] = frustum.Left;
            frustumPlanes[5] = frustum.Right;
            Vector3[] corners = ANode.box.GetCorners();
            for (int z = 0; z < spheres.Length; z++)
            {
                spheres[z].Center = corners[z];
                spheres[z].Radius = 2.0f;
            }
            for (int x = 0; x < 6; x++)
            {
                rightIn = 0;
                outNo = 0;
                for (int i = 0; i < 8; i++)
                    if (frustumPlanes[x].Intersects(spheres[i]) == PlaneIntersectionType.Back)
                    {
                        outNo++;
                    }
                    else
                        rightIn++;
                if (rightIn == 8)
                    return false;
            }
            return visibility;

            /*        Matrix worldMatrix = Matrix.CreateTranslation(-heightMap.Width / 2.0f, 0, heightMap.Height / 2.0f);
            cameraPosition = Vector3.Transform(cameraPosition, worldMatrix);
            BoundingBox pos = new BoundingBox(new Vector3(cameraPosition.X - 1, cameraPosition.Y - 1, cameraPosition.Z - 1), cameraPosition);
            if (ANode.box.Min.X < cameraPosition.X  &&  cameraPosition.X < ANode.box.Max.X &&
                ANode.box.Min.Y < cameraPosition.Y  && cameraPosition.Y < ANode.box.Max.Y &&
                ANode.box.Min.Z < cameraPosition.Z  && cameraPosition.Z < ANode.box.Max.Z
                )
                return true;
            else
                return false;*/
        }