예제 #1
0
        public void SetTexture(float x, float z, ITexture texture, float rotation)
        {
            int tx = (int)(x / Constants.terrainPieceSize);
            int tz = (int)(z / Constants.terrainPieceSize);
            int cx = tx / Constants.terrainHeightsPerChunk;

            if (tx < 0 && tx % Constants.terrainHeightsPerChunk != 0)
            {
                cx--;
            }
            int cz = tz / Constants.terrainHeightsPerChunk;

            if (tz < 0 && tz % Constants.terrainHeightsPerChunk != 0)
            {
                cz--;
            }

            Vector2D      loc = new Vector2D(cx, cz);
            ITerrainChunk tc  = terrainChunks[loc] as ITerrainChunk;

            if (tc == null)
            {
                tc = TerrainChunk.CreateTerrainChunk(cx * Constants.terrainHeightsPerChunk * Constants.terrainPieceSize, cz * Constants.terrainHeightsPerChunk * Constants.terrainPieceSize, Constants.terrainPieceSize, Constants.terrainHeightsPerChunk);
                terrainChunks.Add(loc, tc);
            }
            tc.DrawTexture(texture, x, z, rotation);
        }
예제 #2
0
        public void Cull(float x, float z)
        {
            int tx = (int)(x / Constants.terrainHeightsPerChunk);
            int tz = (int)(z / Constants.terrainHeightsPerChunk);

            foreach (Vector2D loc in terrainChunks.Keys)
            {
                if (Math.Abs(loc.X - tx) > 2 || Math.Abs(loc.Y - tz) > 2)
                {
                    TerrainChunk tc = terrainChunks[loc] as TerrainChunk;
                    if (tc != null)
                    {
                        tc.Delete();
                        terrainChunks.Remove(loc);
                    }
                    Vector2D height_loc = new Vector2D(0, 0);
                    for (int i = 0; i < Constants.terrainHeightsPerChunk; i++)
                    {
                        for (int j = 0; j < Constants.terrainHeightsPerChunk; j++)
                        {
                            height_loc.Set(loc.X * Constants.terrainHeightsPerChunk + i, loc.Y * Constants.terrainHeightsPerChunk + j);
                            terrainHeights.Remove(height_loc);
                        }
                    }
                }
            }
        }
예제 #3
0
        public static ITerrainChunk CreateTerrainChunk(float x, float z, float gap_size, int heights)
        {
            TerrainChunk t = new TerrainChunk();

            t._gap_size  = gap_size;
            t._heights   = heights;
            t.Position.X = x; t.Position.Z = z;
            t._mesh      = new TVLandscape();
            t._width     = gap_size * heights;
            t._height    = gap_size * heights;
            t._mesh.CreateEmptyTerrain((CONST_TV_LANDSCAPE_PRECISION)(256 / heights),
                                       1, 1,
                                       x, z);
            t._mesh.SetTerrainScale(gap_size * heights / 256F, 1, gap_size * heights / 256F, true);
            return(t);
        }
예제 #4
0
        public void SetHeight(float x, float z, float altitude)
        {
            int      tx  = (int)(x / Constants.terrainPieceSize);
            int      tz  = (int)(z / Constants.terrainPieceSize);
            Vector2D loc = new Vector2D(tx, tz);

            if (terrainHeights.Contains(loc))
            {
                //Strive.Logging.Log.WarningMessage( "Replacing terrain peice " + tpexists.instance_id + " with " + tp.instance_id );
                terrainHeights.Remove(loc);
            }
            terrainHeights.Add(loc, altitude);

            int cx = tx / Constants.terrainHeightsPerChunk;

            if (tx < 0 && tx % Constants.terrainHeightsPerChunk != 0)
            {
                cx--;
            }
            int cz = tz / Constants.terrainHeightsPerChunk;

            if (tz < 0 && tz % Constants.terrainHeightsPerChunk != 0)
            {
                cz--;
            }

            loc.Set(cx, cz);
            ITerrainChunk tc = terrainChunks[loc] as ITerrainChunk;

            if (tc == null)
            {
                tc = TerrainChunk.CreateTerrainChunk(cx * Constants.terrainHeightsPerChunk * Constants.terrainPieceSize, cz * Constants.terrainHeightsPerChunk * Constants.terrainPieceSize, Constants.terrainPieceSize, Constants.terrainHeightsPerChunk);
                terrainChunks.Add(loc, tc);
            }
            tc.SetHeight(x, z, altitude);
            if (tx % Constants.terrainHeightsPerChunk == 0)
            {
                loc.Set(cx - 1, cz);
                tc = terrainChunks[loc] as ITerrainChunk;
                if (tc == null)
                {
                    tc = TerrainChunk.CreateTerrainChunk((cx - 1) * Constants.terrainHeightsPerChunk * Constants.terrainPieceSize, cz * Constants.terrainHeightsPerChunk * Constants.terrainPieceSize, Constants.terrainPieceSize, Constants.terrainHeightsPerChunk);
                    terrainChunks.Add(loc, tc);
                }
                tc.SetHeight(x, z, altitude);
            }
            if (tz % Constants.terrainHeightsPerChunk == 0)
            {
                loc.Set(cx, cz - 1);
                tc = terrainChunks[loc] as ITerrainChunk;
                if (tc == null)
                {
                    tc = TerrainChunk.CreateTerrainChunk(cx * Constants.terrainHeightsPerChunk * Constants.terrainPieceSize, (cz - 1) * Constants.terrainHeightsPerChunk * Constants.terrainPieceSize, Constants.terrainPieceSize, Constants.terrainHeightsPerChunk);
                    terrainChunks.Add(loc, tc);
                }
                tc.SetHeight(x, z, altitude);
            }
            if (tx % Constants.terrainHeightsPerChunk == 0 && tz % Constants.terrainHeightsPerChunk == 0)
            {
                loc.Set(cx - 1, cz - 1);
                tc = terrainChunks[loc] as ITerrainChunk;
                if (tc == null)
                {
                    tc = TerrainChunk.CreateTerrainChunk((cx - 1) * Constants.terrainHeightsPerChunk * Constants.terrainPieceSize, (cz - 1) * Constants.terrainHeightsPerChunk * Constants.terrainPieceSize, Constants.terrainPieceSize, Constants.terrainHeightsPerChunk);
                    terrainChunks.Add(loc, tc);
                }
                tc.SetHeight(x, z, altitude);
            }
        }