Example #1
0
        //-------------------------------------------------------------------------
        public bool intersectSegment(Vector3 start, Vector3 end, ref Vector3 result)
        {
            TerrainZoneRenderable t = GetTerrainTile(start);

            if (null == t)
            {
                result = new Vector3(-1, -1, -1);
                return(false);
            }

            return(t.IntersectSegment(start, end, ref result));
        }
Example #2
0
        //-------------------------------------------------------------------------
        public float GetHeightAt(float x, float z)
        {
            var pt = new Vector3(x, 0f, z);

            TerrainZoneRenderable t = GetTerrainTile(pt);

            if (null == t)
            {
                //  printf( "No tile found for point\n" );
                return(-1);
            }

            float h = t.GetHeightAt(x, z);

            // printf( "Height is %f\n", h );
            return(h);
        }
Example #3
0
        public TerrainZoneRenderable GetTerrainZoneTile(Vector3 pt)
        {
            /* Since we don't know if the terrain is square, or has holes, we use a line trace
             * to find the containing tile...
             */

            TerrainZoneRenderable tile = this.tiles[0][0];

            while (null != tile)
            {
                AxisAlignedBox b = tile.BoundingBox;

                if (pt.x < b.Minimum.x)
                {
                    tile = tile.GetNeighbor(Neighbor.WEST);
                }
                else if (pt.x > b.Maximum.x)
                {
                    tile = tile.GetNeighbor(Neighbor.EAST);
                }
                else if (pt.z < b.Minimum.z)
                {
                    tile = tile.GetNeighbor(Neighbor.NORTH);
                }
                else if (pt.z > b.Maximum.z)
                {
                    tile = tile.GetNeighbor(Neighbor.SOUTH);
                }
                else
                {
                    return(tile);
                }
            }

            return(null);
        }
Example #4
0
        public virtual TerrainZonePage BuildPage(Real[] heightData, Material pMaterial)
        {
            string name;

            // Create a TerrainZone Page
            var page = new TerrainZonePage((ushort)((this.mPageSize - 1) / (this.mTileSize - 1)));
            // Create a node for all tiles to be attached to
            // Note we sequentially name since page can be attached at different points
            // so page x/z is not appropriate
            int pageIndex = this.mTerrainZone.PageCount;

            name  = this.mTerrainZone.Name + "_page[";
            name += pageIndex + "]_Node";
            if (this.mTerrainZone.mPCZSM.HasSceneNode(name))
            {
                page.PageSceneNode = this.mTerrainZone.mPCZSM.GetSceneNode(name);
                // set the home zone of the scene node to the terrainzone
                ((PCZSceneNode)(page.PageSceneNode)).AnchorToHomeZone(this.mTerrainZone);
                // EXPERIMENTAL - prevent terrain zone pages from visiting other zones
                ((PCZSceneNode)(page.PageSceneNode)).AllowToVisit = false;
            }
            else
            {
                page.PageSceneNode = this.mTerrainZone.TerrainRootNode.CreateChildSceneNode(name);
                // set the home zone of the scene node to the terrainzone
                ((PCZSceneNode)(page.PageSceneNode)).AnchorToHomeZone(this.mTerrainZone);
                // EXPERIMENTAL - prevent terrain zone pages from visiting other zones
                ((PCZSceneNode)(page.PageSceneNode)).AllowToVisit = false;
            }

            int q = 0;

            for (int j = 0; j < this.mPageSize - 1; j += (this.mTileSize - 1))
            {
                int p = 0;

                for (int i = 0; i < this.mPageSize - 1; i += (this.mTileSize - 1))
                {
                    // Create scene node for the tile and the TerrainZoneRenderable
                    name = this.mTerrainZone.Name + "_tile[" + pageIndex + "][" + p + "," + q + "]_Node";

                    SceneNode c;
                    if (this.mTerrainZone.mPCZSM.HasSceneNode(name))
                    {
                        c = this.mTerrainZone.mPCZSM.GetSceneNode(name);
                        if (c.Parent != page.PageSceneNode)
                        {
                            page.PageSceneNode.AddChild(c);
                        }
                        // set the home zone of the scene node to the terrainzone
                        ((PCZSceneNode)c).AnchorToHomeZone(this.mTerrainZone);
                        // EXPERIMENTAL - prevent terrain zone pages from visiting other zones
                        ((PCZSceneNode)c).AllowToVisit = false;
                    }
                    else
                    {
                        c = page.PageSceneNode.CreateChildSceneNode(name);
                        // set the home zone of the scene node to the terrainzone
                        ((PCZSceneNode)c).AnchorToHomeZone(this.mTerrainZone);
                        // EXPERIMENTAL - prevent terrain zone pages from visiting other zones
                        ((PCZSceneNode)c).AllowToVisit = false;
                    }

                    var tile = new TerrainZoneRenderable(name, this.mTerrainZone);
                    // set queue
                    tile.RenderQueueGroup = this.mTerrainZone.mPCZSM.WorldGeometryRenderQueueId;
                    // Initialise the tile
                    tile.Material = pMaterial;
                    tile.Initialize(i, j, heightData);
                    // Attach it to the page
                    page.tiles[p][q] = tile;
                    // Attach it to the node
                    c.AttachObject(tile);
                    p++;
                }

                q++;
            }

            pageIndex++;

            // calculate neighbours for page
            page.LinkNeighbours();

            if (this.mTerrainZone.Options.lit)
            {
                q = 0;
                for (int j = 0; j < this.mPageSize - 1; j += (this.mTileSize - 1))
                {
                    int p = 0;

                    for (int i = 0; i < this.mPageSize - 1; i += (this.mTileSize - 1))
                    {
                        page.tiles[p][q].CalculateNormals();
                        p++;
                    }
                    q++;
                }
            }

            return(page);
        }