A SubTexture represents a section of another texture. This is achieved solely by manipulation of texture coordinates, making the class very efficient. Note that it is OK to create subtextures of subtextures.
상속: Texture
예제 #1
0
        override public void AdjustTexCoords(VertexData vertexData, uint startIndex, uint count)
        {
            Texture texture = this;
            Matrix  matrix  = Matrix.Create();

            do
            {
                SubTexture subTexture = (SubTexture)texture;
                matrix.AppendMatrix(subTexture.TransformationMatrix);
                texture = subTexture._parent;
            } while (texture.GetType().IsEquivalentTo(typeof(SubTexture)));

            uint endIndex = startIndex + count;

            for (uint i = startIndex; i < endIndex; ++i)
            {
                Vector2 currentCoord = vertexData.Vertices[i].TexCoords;
                vertexData.Vertices[i].TexCoords = TransformVector2(matrix, currentCoord);
            }
        }
예제 #2
0
        private void UpdateMatrices()
        {
            if (_transformationMatrix != null)
            {
                _transformationMatrix.Identity();
            }
            else
            {
                _transformationMatrix = Matrix2D.Create();
            }

            if (_transformationMatrixToRoot != null)
            {
                _transformationMatrixToRoot.Identity();
            }
            else
            {
                _transformationMatrixToRoot = Matrix2D.Create();
            }

            if (_rotated)
            {
                _transformationMatrix.Translate(0, -1);
                _transformationMatrix.Rotate((float)Math.PI / 2.0f);
            }

            _transformationMatrix.Scale(_region.Width / _parent.Width,
                                        _region.Height / _parent.Height);
            _transformationMatrix.Translate(_region.X / _parent.Width,
                                            _region.Y / _parent.Height);

            SubTexture texture = this;

            while (texture != null)
            {
                _transformationMatrixToRoot.AppendMatrix(texture._transformationMatrix);
                texture = texture.Parent as SubTexture;
            }
        }
예제 #3
0
        private void ParseAndLoadChars(XmlDocument xml, float scale)
        {
            XmlNodeList charNodes = xml.GetElementsByTagName("char");
            for (int i = 0; i < charNodes.Count; i++)
            {
                XmlAttributeCollection attributes = charNodes[i].Attributes;

                float x = Convert.ToSingle(attributes["x"].Value);
                float y = Convert.ToSingle(attributes["y"].Value);
                float width = Convert.ToSingle(attributes["width"].Value);
                float height = Convert.ToSingle(attributes["height"].Value);
                float frameX = 0;
                if (_fontTexture.Frame != null)
                {
                    frameX = _fontTexture.Frame.X;
                }
                float frameY = 0;
                if (_fontTexture.Frame != null)
                {
                    frameY = _fontTexture.Frame.Y;
                }

                Rectangle region = new Rectangle(x / scale + frameX, y / scale + frameY, width / scale, height / scale);
                SubTexture texture = new SubTexture(_fontTexture, region);

                int charId = Convert.ToInt32(attributes["id"].Value);
                float xOffset = Convert.ToSingle(attributes["xoffset"].Value);
                float yOffset = Convert.ToSingle(attributes["yoffset"].Value);
                float xAdvance = Convert.ToSingle(attributes["xadvance"].Value);

                BitmapChar bitmapChar = new BitmapChar(charId, texture, xOffset, yOffset, xAdvance);
                _chars.Add(charId, bitmapChar);
            }
        }