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
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            device = GraphicsDevice;// Create a new SpriteBatch, which can be used to draw textures.
            Mouse.SetPosition(device.Viewport.Width / 2, device.Viewport.Height / 2);
            originalMouseState = Mouse.GetState();
            effect = Content.Load<Effect>("Effects");
            spriteBatch = new SpriteBatch(GraphicsDevice);
            LoadTextures();
            terrainWidth = heightMap.Width;
            terrainHeight = heightMap.Height;
            UpdateViewMatrix();
             //   viewMatrix = Matrix.CreateLookAt(new Vector3(0, 100, 100), new Vector3(0, 0, 0), new Vector3(0, 1, 0));
            projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, device.Viewport.AspectRatio, 0.3f, 2500.0f);

            Plane = Content.Load<Model>("Spaceship");
            Matrix lulz = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, device.Viewport.AspectRatio, 0.3f, 1.2f);
            LODProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, device.Viewport.AspectRatio, 0.3f, 350.0f);
            LOD2ProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, device.Viewport.AspectRatio, 0.3f, 1000.0f);
            cameraFrustum = new BoundingFrustum(viewMatrix * projectionMatrix);
            A = new Quadtree(heightMap, colorMap, heightData, TextureVertices, cameraPos, cameraFrustum, device);
            A.LODFrustum = new BoundingFrustum(viewMatrix * projectionMatrix);
            A.LOD2Frustum = new BoundingFrustum(viewMatrix * LOD2ProjectionMatrix);
            constructVerts(A.heightData, A.grassData, A.dirtData, A.stoneData);

            // TODO: use this.Content to load your game content here
        }