Example #1
0
        /// <summary>
        /// Helper function to set the texture coordinates.  Instead of taking a movie
        /// object, this takes a specific texture name, video size, texture size, and
        /// material.  Sets a texture matrix to adjust the existing coordinates.
        /// </summary>
        /// <param name="textureName">
        /// The name of the texture to adjust.
        /// </param>
        /// <param name="videoSize">
        /// The size of the video in pixels.
        /// </param>
        /// <param name="textureSize">
        /// The size of the expected texture in pixels.
        /// </param>
        /// <param name="material">
        /// The name of the material to search for textures.
        /// </param>
        /// <returns>
        /// True if any texture coordinates were adjusted, false if not.
        /// </returns>
        public static bool SetTextureCoordinates(string textureName, Size videoSize, Size textureSize, string material)
        {
            bool ans = false;

            Axiom.Graphics.Material m = MaterialManager.Instance.GetByName(material);
            if (m != null)
            {
                for (int i = 0; i < m.NumTechniques; i++)
                {
                    for (int j = 0; j < m.GetTechnique(i).NumPasses; j++)
                    {
                        Pass p = m.GetTechnique(i).GetPass(j);
                        for (int k = 0; k < p.NumTextureUnitStages; k++)
                        {
                            if (p.GetTextureUnitState(k).TextureName == textureName)
                            {
                                TextureUnitState tu     = p.GetTextureUnitState(k);
                                float            uRatio = ((float)videoSize.Width) / ((float)textureSize.Width);
                                float            vRatio = ((float)videoSize.Height) / ((float)textureSize.Height);
                                tu.SetTextureScale(1.0f / uRatio, 1.0f / vRatio);
                                tu.SetTextureScroll(-0.5f * (1.0f - uRatio), -0.5f * (1.0f - vRatio));
                                ans = true;
                            }
                        }
                    }
                }
            }
            return(ans);
        }
        public void UpdateTextureTransform(TextureUnitState texUnit, float pageX, float pageZ)
        {
            //Axiom.Core.LogManager.Instance.Write("Decal: {0}, {1} page:{2}, {3}", posX, posZ, pageX, pageZ);
            float pageSize = TerrainManager.Instance.PageSize * TerrainManager.oneMeter;
            float scaleX   = sizeX / pageSize;
            float scaleZ   = sizeZ / pageSize;

            texUnit.SetTextureScale(scaleX, scaleZ);
            float centerX = pageX + pageSize / 2f;
            float centerZ = pageZ + pageSize / 2f;

            texUnit.SetTextureScroll((centerX - posX) / (pageSize * scaleX), (centerZ - posZ) / (pageSize * scaleZ));
            texUnit.SetTextureRotate(rot);
        }