Example #1
0
        /// <summary>
        /// Applies the snowfall generator to the TerrainPage.
        /// </summary>
        /// <param name="level">The snow level (elevation).</param>
        /// <param name="blend">The snow blending distance.</param>
        private void CreateSnow(float level, float blend)
        {
            DataCore.Texture tex    = _page.TerrainPatch.GetTexture();
            DataCore.Texture newTex = new Voyage.Terraingine.DataCore.Texture();
            Bitmap           image  = new Bitmap(128, 128, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            float            xScale = _page.TerrainPatch.Width / image.Width;
            float            yScale = _page.TerrainPatch.Height / image.Height;
            string           filename;
            Vector2          origin;
            Vector3          point;
            int   v1, v2, v3;
            float alpha;
            int   fileCount = -1;

            for (int j = 0; j < image.Height; j++)
            {
                for (int i = 0; i < image.Width; i++)
                {
                    origin = new Vector2((float)i * xScale, (float)j * yScale);
                    _page.GetPlane(origin, out v1, out v2, out v3, out point);

                    if (point.Y >= level)
                    {
                        if (point.Y >= level + blend)
                        {
                            image.SetPixel(i, j, Color.FromArgb(0, Color.White));
                        }
                        else
                        {
                            alpha = 255f - (point.Y - level) / blend * 255f;
                            image.SetPixel(i, j, Color.FromArgb((int)alpha, Color.White));
                        }
                    }
                    else
                    {
                        image.SetPixel(i, j, Color.FromArgb(255, Color.White));
                    }
                }
            }

            do
            {
                fileCount++;
                filename = Path.GetDirectoryName(tex.FileName) + "\\" +
                           Path.GetFileNameWithoutExtension(tex.FileName) + "_snowfall" + fileCount + ".bmp";
            } while (File.Exists(filename));

            image.Save(filename, System.Drawing.Imaging.ImageFormat.Bmp);
            newTex.FileName      = filename;
            newTex.Name          = "Snowfall";
            newTex.Operation     = TextureOperation.BlendTextureAlpha;
            newTex.OperationText = "Use Texture Alpha";
            _page.TerrainPatch.AddTexture(newTex);

            _textures = _page.TerrainPatch.Textures;
        }
Example #2
0
 /// <summary>
 /// Creates a copy of a Texture object.
 /// </summary>
 /// <param name="tex">Texture object to copy.</param>
 public Texture( Texture tex )
 {
     if ( tex != null )
     {
         _texture = tex.DXTexture;
         _name = tex._name;
         _file = tex._file;
         _mask = tex._mask;
         _render = tex._render;
         _shift = new Vector2( tex._shift.X, tex._shift.Y );
         _scale = new Vector2( tex._scale.X, tex._scale.Y );
         _operation = tex._operation;
         _operationText = tex._operationText;
     }
     else
     {
         _texture = null;
         Initialize();
     }
 }
Example #3
0
        /// <summary>
        /// Loads data about a texture from the XML document.
        /// </summary>
        /// <param name="xmlNode">The XML node to load data from.</param>
        private void LoadTexture( XmlNode xmlNode )
        {
            DataCore.Texture tex = new Texture();

            // Load the texture name
            xmlNode = xmlNode.FirstChild;
            tex.Name = xmlNode.InnerText;

            // Load the texture filename
            xmlNode = xmlNode.NextSibling;
            tex.FileName = xmlNode.InnerText;

            // Load the texture operation
            xmlNode = xmlNode.NextSibling;
            tex.OperationText = xmlNode.InnerText;

            // Load if the texture is a mask
            xmlNode = xmlNode.NextSibling;
            tex.Mask = Convert.ToBoolean( xmlNode.InnerText );

            // Load the texture scale value
            xmlNode = xmlNode.NextSibling;
            tex.Scale = LoadVector2Node( xmlNode );

            // Load the texture shift value
            xmlNode = xmlNode.NextSibling;
            tex.Shift = LoadVector2Node( xmlNode );

            _textures.Add( tex );
            _page.TerrainPatch.AddBlankTexture();
            _modifiedTextures = true;
        }
Example #4
0
        /// <summary>
        /// Applies the snowmelt generator to the TerrainPage.
        /// </summary>
        private void MeltSnow()
        {
            DataCore.Texture oldTex = _page.TerrainPatch.GetTexture();
            DataCore.Texture tex = new Voyage.Terraingine.DataCore.Texture();
            Bitmap oldImage = oldTex.GetImage();
            Bitmap image = new Bitmap( oldImage.Width, oldImage.Height,
                System.Drawing.Imaging.PixelFormat.Format32bppArgb );
            float xScale = _page.TerrainPatch.Width / image.Width;
            float yScale = _page.TerrainPatch.Height / image.Height;
            string filename;
            Vector2 origin;
            Vector3 point, normal;
            Vector3 n1, n2, n3;
            int v1, v2, v3;
            Vector3 light = (Vector3) _receivedData[0];
            float alpha, dot;
            Color color;
            int fileCount = -1;
            float dist1, dist2, dist3;

            for ( int j = 0; j < image.Height; j++ )
            {
                for ( int i = 0; i < image.Width; i++ )
                {
                    // Get original pixel color
                    color = oldImage.GetPixel( i, j );

                    // Find point on terrain
                    origin = new Vector2( (float) i * xScale, (float) j * yScale );
                    _page.GetPlane( origin, out v1, out v2, out v3, out point );

                    // Determine weighted distance from each vertex
                    dist1 = ( (Vector3) _page.TerrainPatch.Vertices[v1].Position - point ).Length();
                    dist2 = ( (Vector3) _page.TerrainPatch.Vertices[v2].Position - point ).Length();
                    dist3 = ( (Vector3) _page.TerrainPatch.Vertices[v3].Position - point ).Length();

                    // Determine weighted normal
                    n1 = ( dist1 / ( dist1 + dist2 + dist3 ) ) * _page.TerrainPatch.Vertices[v1].Normal;
                    n2 = ( dist2 / ( dist1 + dist2 + dist3 ) ) * _page.TerrainPatch.Vertices[v2].Normal;
                    n3 = ( dist3 / ( dist1 + dist2 + dist3 ) ) * _page.TerrainPatch.Vertices[v3].Normal;
                    normal = n1 + n2 + n3;
                    normal.Normalize();

                    // Determine angle of light against pixel position
                    dot = Vector3.Dot( normal, -light );

                    // Determine alpha of new pixel
                    if ( dot >= 0f )
                        alpha = oldImage.GetPixel( i, j ).A - 255f * dot;
                    else
                        alpha = oldImage.GetPixel( i, j ).A;

                    if ( alpha < 0f )
                        alpha = 0f;
                    else if ( alpha > 255f )
                        alpha = 255f;

                    color = Color.FromArgb( color.ToArgb() );
                    image.SetPixel( i, j, color );
                }
            }

            do
            {
                fileCount++;
                filename = Path.GetDirectoryName( oldTex.FileName ) + "\\" +
                    Path.GetFileNameWithoutExtension( oldTex.FileName ) + "_snowmelt" + fileCount + ".bmp";
            } while ( File.Exists( filename ) );

            image.Save( filename, System.Drawing.Imaging.ImageFormat.Bmp );
            tex.FileName = filename;
            tex.Name = "Snowmelt";
            tex.Operation = TextureOperation.BlendTextureAlpha;
            tex.OperationText = "Use Texture Alpha";
            _page.TerrainPatch.AddTexture( tex );

            _textures = _page.TerrainPatch.Textures;
        }
Example #5
0
        /// <summary>
        /// Applies the snowmelt generator to the TerrainPage.
        /// </summary>
        private void MeltSnow()
        {
            DataCore.Texture oldTex   = _page.TerrainPatch.GetTexture();
            DataCore.Texture tex      = new Voyage.Terraingine.DataCore.Texture();
            Bitmap           oldImage = oldTex.GetImage();
            Bitmap           image    = new Bitmap(oldImage.Width, oldImage.Height,
                                                   System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            float   xScale = _page.TerrainPatch.Width / image.Width;
            float   yScale = _page.TerrainPatch.Height / image.Height;
            string  filename;
            Vector2 origin;
            Vector3 point, normal;
            Vector3 n1, n2, n3;
            int     v1, v2, v3;
            Vector3 light = (Vector3)_receivedData[0];
            float   alpha, dot;
            Color   color;
            int     fileCount = -1;
            float   dist1, dist2, dist3;

            for (int j = 0; j < image.Height; j++)
            {
                for (int i = 0; i < image.Width; i++)
                {
                    // Get original pixel color
                    color = oldImage.GetPixel(i, j);

                    // Find point on terrain
                    origin = new Vector2((float)i * xScale, (float)j * yScale);
                    _page.GetPlane(origin, out v1, out v2, out v3, out point);

                    // Determine weighted distance from each vertex
                    dist1 = ((Vector3)_page.TerrainPatch.Vertices[v1].Position - point).Length();
                    dist2 = ((Vector3)_page.TerrainPatch.Vertices[v2].Position - point).Length();
                    dist3 = ((Vector3)_page.TerrainPatch.Vertices[v3].Position - point).Length();

                    // Determine weighted normal
                    n1     = (dist1 / (dist1 + dist2 + dist3)) * _page.TerrainPatch.Vertices[v1].Normal;
                    n2     = (dist2 / (dist1 + dist2 + dist3)) * _page.TerrainPatch.Vertices[v2].Normal;
                    n3     = (dist3 / (dist1 + dist2 + dist3)) * _page.TerrainPatch.Vertices[v3].Normal;
                    normal = n1 + n2 + n3;
                    normal.Normalize();

                    // Determine angle of light against pixel position
                    dot = Vector3.Dot(normal, -light);

                    // Determine alpha of new pixel
                    if (dot >= 0f)
                    {
                        alpha = oldImage.GetPixel(i, j).A - 255f * dot;
                    }
                    else
                    {
                        alpha = oldImage.GetPixel(i, j).A;
                    }

                    if (alpha < 0f)
                    {
                        alpha = 0f;
                    }
                    else if (alpha > 255f)
                    {
                        alpha = 255f;
                    }

                    color = Color.FromArgb(color.ToArgb());
                    image.SetPixel(i, j, color);
                }
            }

            do
            {
                fileCount++;
                filename = Path.GetDirectoryName(oldTex.FileName) + "\\" +
                           Path.GetFileNameWithoutExtension(oldTex.FileName) + "_snowmelt" + fileCount + ".bmp";
            } while (File.Exists(filename));

            image.Save(filename, System.Drawing.Imaging.ImageFormat.Bmp);
            tex.FileName      = filename;
            tex.Name          = "Snowmelt";
            tex.Operation     = TextureOperation.BlendTextureAlpha;
            tex.OperationText = "Use Texture Alpha";
            _page.TerrainPatch.AddTexture(tex);

            _textures = _page.TerrainPatch.Textures;
        }
Example #6
0
        /// <summary>
        /// Adds a blank texture to the list of textures used by the TerrainPatch.
        /// </summary>
        public void AddBlankTexture()
        {
            Texture tex = new Texture();

            _textures.Add( tex );
            AddTextureCoordinates();
        }