Exemple #1
0
        private void BuildLookupHeightTable()
        {
            LookupHeightTable = new HeightmapLookupValue[256 * 256];

            for (int i = 0; i < 256; i++)
            {
                for (int j = 0; j < 256; j++)
                {
                    LookupHeightTable[i + (j * 256)] = new HeightmapLookupValue((ushort)(i + (j * 256)), (float)((double)i * ((double)j / 128.0d)));
                }
            }
            Array.Sort <HeightmapLookupValue>(LookupHeightTable);
        }
Exemple #2
0
        static LLRAWData()
        {
            LookupHeightTable = new HeightmapLookupValue[256 * 256];

            for (int i = 0; i < 256; i++)
            {
                for (int j = 0; j < 256; j++)
                {
                    LookupHeightTable[i + (j * 256)] = new HeightmapLookupValue((ushort)(i + (j * 256)), (float)((double)i * ((double)j / 128.0d)));
                }
            }
            Array.Sort(LookupHeightTable);
        }
Exemple #3
0
        public LLRAW()
        {
            LookupHeightTable = new HeightmapLookupValue[256 * 256];

            for (int i = 0; i < 256; i++)
            {
                for (int j = 0; j < 256; j++)
                {
                    LookupHeightTable[i + (j * 256)] = new HeightmapLookupValue(i + (j * 256), ((float)i * ((float)j / 128.0f)));
                }
            }
            Array.Sort <HeightmapLookupValue>(LookupHeightTable);
        }
Exemple #4
0
        /// <summary>
        /// Static constructor, initializes the lookup table for exports
        /// </summary>
        static LLRAW()
        {
            LOOKUP_HEIGHT_TABLE = new HeightmapLookupValue[256 * 256];

            for (int i = 0; i < 256; i++)
            {
                for (int j = 0; j < 256; j++)
                {
                    LOOKUP_HEIGHT_TABLE[i + (j * 256)] = new HeightmapLookupValue(
                        (ushort)(i + (j * 256)), (float)((double)i * ((double)j * OO_128)));
                }
            }

            Array.Sort <HeightmapLookupValue>(LOOKUP_HEIGHT_TABLE);
        }
Exemple #5
0
        public void SaveStream(Stream s, ITerrainChannel map)
        {
            if (LookupHeightTable == null)
            {
                LookupHeightTable = new HeightmapLookupValue[256 * 256];

                for (int i = 0; i < 256; i++)
                {
                    for (int j = 0; j < 256; j++)
                    {
                        LookupHeightTable[i + (j * 256)] = new HeightmapLookupValue((ushort)(i + (j * 256)), (float)((double)i * ((double)j / 128.0d)));
                    }
                }
                Array.Sort <HeightmapLookupValue>(LookupHeightTable);
            }
            BinaryWriter binStream = new BinaryWriter(s);

            // Output the calculated raw
            for (int y = 0; y < map.Height; y++)
            {
                for (int x = 0; x < map.Width; x++)
                {
                    double t = map[x, (map.Height - 1) - y];
                    //if height is less than 0, set it to 0 as
                    //can't save -ve values in a LLRAW file
                    if (t < 0d)
                    {
                        t = 0d;
                    }

                    int index = 0;

                    // The lookup table is pre-sorted, so we either find an exact match or
                    // the next closest (smaller) match with a binary search
                    index = Array.BinarySearch <HeightmapLookupValue>(LookupHeightTable, new HeightmapLookupValue(0, (float)t));
                    if (index < 0)
                    {
                        index = ~index - 1;
                    }

                    index = LookupHeightTable[index].Index;

                    byte       red     = (byte)(index & 0xFF);
                    byte       green   = (byte)((index >> 8) & 0xFF);
                    const byte blue    = 20;
                    const byte alpha1  = 0;
                    const byte alpha2  = 0;
                    const byte alpha3  = 0;
                    const byte alpha4  = 0;
                    const byte alpha5  = 255;
                    const byte alpha6  = 255;
                    const byte alpha7  = 255;
                    const byte alpha8  = 255;
                    byte       alpha9  = red;
                    byte       alpha10 = green;

                    binStream.Write(red);
                    binStream.Write(green);
                    binStream.Write(blue);
                    binStream.Write(alpha1);
                    binStream.Write(alpha2);
                    binStream.Write(alpha3);
                    binStream.Write(alpha4);
                    binStream.Write(alpha5);
                    binStream.Write(alpha6);
                    binStream.Write(alpha7);
                    binStream.Write(alpha8);
                    binStream.Write(alpha9);
                    binStream.Write(alpha10);
                }
            }

            binStream.Close();
        }