Exemplo n.º 1
0
 public Tile(Vector3 relativeLocation, int tileSize, Page p, int tileX, int tileZ)
 {
     this.relativeLocation = relativeLocation;
     page = p;
     size = tileSize;
     indexX = tileX;
     indexZ = tileZ;
 }
        public TerrainPage(Vector3 location, Page page)
        {
            this.location = location;
            pageCoord = new PageCoord(location, TerrainManager.Instance.PageSize);

            terrainMaterial = TerrainManager.Instance.TerrainMaterialConfig.NewTerrainMaterial(pageCoord.X, pageCoord.Z);

            currentPage = page;
            Debug.Assert(location == currentPage.Location, "creating TerrainPage with page at different location");
            numTiles = currentPage.NumTiles;
            patchSize = TerrainManager.Instance.PageSize / numTiles;

            // set up the page height maps for this page of terrain
            subPageSize = TerrainManager.Instance.SubPageSize;
            int subPagesPerPage = TerrainManager.Instance.PageSize / subPageSize;

            pageHeightMap = new PageHeightMap(subPagesPerPage, TerrainManager.Instance.PageSize,
                TerrainManager.Instance.MaxMetersPerSample, TerrainManager.Instance.MinMetersPerSample);

            pageHeightMap.Location = location;

            // create and position a scene node for this terrain page
            string nodeName = String.Format("TerrainPage[{0},{1}]", (int)(location.x / TerrainManager.oneMeter),
                (int)(location.z / TerrainManager.oneMeter));

            // DEBUG - Console.WriteLine("Creating {0}", name);
            sceneNode = TerrainManager.Instance.WorldRootSceneNode.CreateChildSceneNode(nodeName);

            sceneNode.Position = location;

            sceneNode.AttachObject(this);

            // create the render operation
            renderOp = new RenderOperation();
            renderOp.operationType = OperationType.TriangleList;
            renderOp.useIndices = true;

            CreatePatches();

            SetCastShadows();

            UpdateBounds();

            TerrainManager.Instance.ShadowConfig.ShadowTechniqueChange += ShadowTechniqueChangeHandler;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Set the neighbor pointers for this page.  Must be done after all the pages
        /// in the TerrainManager pages array have been constructed.
        /// </summary>
        public void AttachNeighbors()
        {
            if ( indexX > 0 )
            {
                neighborWest = TerrainManager.Instance.LookupPage(indexX - 1, indexZ);
            }
            else
            {
                neighborWest = null;
            }

            if ( indexX < ( TerrainManager.Instance.PageArraySize - 1 ) )
            {
                neighborEast = TerrainManager.Instance.LookupPage(indexX + 1, indexZ);
            }
            else
            {
                neighborEast = null;
            }

            if ( indexZ > 0 )
            {
                neighborNorth = TerrainManager.Instance.LookupPage(indexX, indexZ - 1);
            }
            else
            {
                neighborNorth = null;
            }

            if ( indexZ < ( TerrainManager.Instance.PageArraySize - 1 ) )
            {
                neighborSouth = TerrainManager.Instance.LookupPage(indexX, indexZ + 1);
            }
            else
            {
                neighborSouth = null;
            }

            neighborsAttached = true;

            return;
        }
        private TerrainPage NewTerrainPage(Page p)
        {
            Debug.Assert(p.TerrainPage == null);

            p.TerrainPage = new TerrainPage(p.Location, p);

            OnPageVisibility(true, p.TerrainPage);

            return p.TerrainPage;
        }
        private void FreeTerrainPage(Page p)
        {
            if (p.TerrainPage != null)
            {
                OnPageVisibility(false, p.TerrainPage);

                p.TerrainPage.Dispose();

                p.TerrainPage = null;
            }
        }
        /// <summary>
        /// This method initializes all the pages in the visible area around the camera.  It should only
        /// be called when starting up, or after all the previous pages have been released.
        /// </summary>
        protected void InitPages()
        {
            float startPageOffset = pageSize * oneMeter * visPageRadius;
            Vector3 pv = new Vector3(-startPageOffset, 0, -startPageOffset);
            for ( int x = 0; x < pageArraySize; x++ )
            {
                for ( int z = 0; z < pageArraySize; z++ )
                {
                    pages[x,z] = new Page(pv, x, z);

                    pv.z += pageSize * oneMeter;
                }
                pv.x += pageSize * oneMeter;
                pv.z = -startPageOffset;
            }

            // attach the pages
            foreach ( Page p in pages )
            {
                p.AttachNeighbors();
            }

            // attach the tiles
            foreach ( Page p in pages )
            {
                p.AttachTiles();
            }
        }