private static unsafe void ColourFace( PlanetMapFace face, byte* pixel )
 {
     switch ( face )
     {
         case PlanetMapFace.NegX: pixel[ 0 ] = 0xff; pixel[ 1 ] = 0x80; pixel[ 2 ] = 0x80; break;
         case PlanetMapFace.PosX: pixel[ 0 ] = 0xff; pixel[ 1 ] = 0x00; pixel[ 2 ] = 0x00; break;
         case PlanetMapFace.NegY: pixel[ 0 ] = 0x80; pixel[ 1 ] = 0xff; pixel[ 2 ] = 0x80; break;
         case PlanetMapFace.PosY: pixel[ 0 ] = 0x00; pixel[ 1 ] = 0xff; pixel[ 2 ] = 0x00; break;
         case PlanetMapFace.NegZ: pixel[ 0 ] = 0x80; pixel[ 1 ] = 0x80; pixel[ 2 ] = 0xff; break;
         case PlanetMapFace.PosZ: pixel[ 0 ] = 0x00; pixel[ 1 ] = 0x00; pixel[ 2 ] = 0xff; break;
     }
 }
        public unsafe void GenerateSide( PlanetMapFace face, byte* pixels, int width, int height, int stride )
        {
            for ( int row = 0; row < height; ++row )
            {
                byte* curPixel = pixels + row * stride;
                for ( int col = 0; col < width; ++col )
                {
                    ColourFace( face, curPixel );
                    curPixel += 3;
                }
            }

            using ( Bitmap bmp = new Bitmap( width, height, stride, PixelFormat.Format24bppRgb, ( IntPtr )pixels ) )
            {
                using ( Graphics g = Graphics.FromImage( bmp ) )
                {
                    g.DrawString( face.ToString( ), new Font( "Arial", 8 ), Brushes.White, width / 2, height / 2 );
                }
            }
        }
        public unsafe void GenerateSide( PlanetMapFace face, byte* pixels, int width, int height, int stride )
        {
            float incU = 2.0f / width;
            float incV = 2.0f / height;
            float v = -1;
            for ( int row = 0; row < height; ++row, v += incV )
            {
                float u = -1;
                byte* curPixel = pixels + row * stride;
                for ( int col = 0; col < width; ++col, u += incU )
                {
                    float s, t;
                    PlanetMap.UvToSt( u, v, face, out s, out t );

                    curPixel[ 0 ] = ( byte )( Math.Abs( s ) * ( 255.0f / Constants.Pi ) );
                    curPixel[ 1 ] = ( byte )( t * ( 255.0f / Constants.Pi ) );
                    curPixel[ 2 ] = 0;

                    curPixel += 3;
                }
            }
        }
        private static unsafe Bitmap GeneratePlanetTextureFace( IPlanetTerrainGenerator gen, PlanetMapFace face, int res )
        {
            PixelFormat format = gen.CubeMapFormat;
            Bitmap bmp = new Bitmap( res, res, format );
            BitmapData bmpData = bmp.LockBits( new Rectangle( 0, 0, res, res ), ImageLockMode.WriteOnly, format );

            gen.GenerateSide( face, ( byte* )bmpData.Scan0, res, res, bmpData.Stride );

            bmp.UnlockBits( bmpData );
            return bmp;
        }
        public unsafe void GenerateSide( PlanetMapFace face, byte* pixels, int width, int height, int stride )
        {
            float incU = 2.0f / ( width - 1 );
            float incV = 2.0f / ( height - 1 );
            float v = -1;

            float res = 2.0f;
            for ( int row = 0; row < height; ++row, v += incV )
            {
                float u = -1;
                byte* curPixel = pixels + row * stride;
                for ( int col = 0; col < width; ++col, u += incU )
                {
                    float x, y, z;
                    PlanetMap.UvToXyz( u, v, face, out x, out y, out z );

                    float invLength = res / Functions.Sqrt( u * u + v * v + 1 );
                    x *= invLength;
                    y *= invLength;
                    z *= invLength;

                    int latitude = ( int )( ( LatitudeCount / 2 ) * ( y / res ) ) + 2;

                    float fVal = TerrainHeight( x, y, z );
                    int val = ( int )( fVal * 255.0f );
                    Color colour = TerrainColourMap[ latitude, val ];
                    curPixel[ 0 ] = colour.R;
                    curPixel[ 1 ] = colour.G;
                    curPixel[ 2 ] = colour.B;

                    curPixel += 3;
                }
            }

            //using ( Bitmap bmp = new Bitmap( width, height, stride, PixelFormat.Format24bppRgb, ( IntPtr )pixels ) )
            //{
            //    using ( Graphics g = Graphics.FromImage( bmp ) )
            //    {
            //        g.DrawString( face.ToString( ), new Font( "Arial", 8 ), Brushes.White, 0, 0 );
            //    }
            //}
        }