/** Set this renderable to be loaded
 */
 public void QueueRenderableLoading( Renderable rend, Tile.Tile tile )
 {
     renderablesLoadQueue.Push( rend );
     tilesLoadQueue.Push( tile );
 }
Esempio n. 2
0
 /** Sets the appropriate neighbor for this TerrainRenderable.  Neighbors are necessary
 to know when to bridge between LODs.
 */
 public void SetNeighbor( Neighbor n, Tile t )
 {
     neighbors[(int) n ] = t;
 }
 protected void addBatch(long num)
 {
     numTiles += num;
     //    mTiles.reserve (mNumTiles);
     //    mTiles.resize (mNumTiles);
     for ( long i = 0; i < num; i++ )
     {
         Tile tile = new Tile( );
         tiles.Add( tile );
         queue.Push( tile );
     }
 }
Esempio n. 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="start">begining of the segment </param>
        /// <param name="end">where it ends</param>
        /// <param name="result">where it intersects with terrain</param>
        /// <param name="modif">If it does modify the terrain</param>
        /// <returns></returns>
        /// <remarks>Intersect mainly with Landscape</remarks>
        public bool IntersectSegment(Vector3 start, Vector3 end, ref Vector3 result, bool modif)
        {
            Vector3 begin = start;
            Vector3 dir   = end - start;

            dir.Normalize();
            Tile.Tile t = pageManager.GetTile(start);
            if (t != null)
            {
                // if you want to be able to intersect from a point outside the canvas
                int   pageSize = (int)options.PageSize - 1;
                float W        = options.World_Width * 0.5f * pageSize * options.Scale.x;
                float H        = options.World_Height * 0.5f * pageSize * options.Scale.z;
                while (start.y > 0.0f && start.y < 999999.0f &&
                       ((start.x < -W || start.x > W) ||
                        (start.z < -H || start.z > H)))
                {
                    start += dir;
                }

                if (start.y < 0.0f || start.y > 999999.0f)
                {
                    result = new Vector3(-1, -1, -1);
                    return(false);
                }
                t = pageManager.GetTile(start);

                // if you don't want to be able to intersect from a point outside the canvas
                //        *result = Vector3( -1, -1, -1 );
                //        return false;
            }

            bool impact = false;

            //special case...
            if (dir.x == 0 && dir.z == 0)
            {
                if (start.y <= data2DManager.GetRealWorldHeight(start.x, start.z, t.Info))
                {
                    result = start;
                    impact = true;
                }
            }
            else
            {
                //    dir.x = dir.x * mOptions.scale.x;
                //    dir.y = dir.y * mOptions.scale.y;
                //    dir.z = dir.z * mOptions.scale.z;
                impact = t.IntersectSegment(start, dir, result);
            }


            // deformation
            if (impact && modif)
            {
                int X = (int)(result.x / options.Scale.x);
                int Z = (int)(result.z / options.Scale.z);

                int pageSize = (int)options.PageSize - 1;

                int W = (int)(options.World_Width * 0.5f * pageSize);
                int H = (int)(options.World_Height * 0.5f * pageSize);

                if (X < -W || X > W || Z < -H || Z > H)
                {
                    return(true);
                }

                impact = (result != Vector3.Zero);
                const int radius = 7;

                // Calculate the minimum X value
                // make sure it is still on the height map
                int Xmin = -radius;
                if (Xmin + X < -W)
                {
                    Xmin = -X - W;
                }

                // Calculate the maximum X value
                // make sure it is still on the height map
                int Xmax = radius;
                if (Xmax + X > W)
                {
                    Xmax = W - X;
                }


                // Main loop to draw the circle on the height map
                // (goes through each X value)

                for (int Xcurr = Xmin; Xcurr <= radius; Xcurr++)
                {
                    float Precalc = (radius * radius) - (Xcurr * Xcurr);
                    if (Precalc > 1.0f)
                    {
                        // Determine the minimum and maximum Z value for that
                        // line in the circle (that X value)
                        int Zmax = (int)Math.Sqrt(Precalc);
                        int Zmin = -Zmax;

                        // Makes sure the values found are both on the height map
                        if (Zmin + Z < -H)
                        {
                            Zmin = -Z - H;
                        }

                        if (Zmax + Z > H)
                        {
                            Zmax = H - Z;
                        }

                        // For each of those Z values, calculate the new Y value
                        for (int Zcurr = Zmin; Zcurr < Zmax; Zcurr++)
                        {
                            // get results by page index ?
                            Vector3   currpoint = new Vector3((X + Xcurr), 0.0f, (Z + Zcurr));
                            Tile.Tile p         = pageManager.GetTileUnscaled(currpoint);
                            if (p != null && p.IsLoaded)
                            {
                                // Calculate the new theoretical height for the current point on the circle
                                float dY = (float)Math.Sqrt((float)(Precalc - (Zcurr * Zcurr))) * 10.0f;                                  //* 0.01f

                                impactInfo = p.Info;
                                data2DManager.DeformHeight(currpoint, dY, p.Info);
                                p.Renderable.NeedUpdate();
                            }
                        }
                    }
                }
            }
            return(true);
        }
 /// <summary>
 /// Marks a tile as free
 /// </summary>
 /// <param name="tile">Tile to free</param>
 public void FreeTile( Tile tile )
 {
     queue.Push( tile );
 }