CSharpGL.TextModel.SetupGlyphPositions C# (CSharp) Method

SetupGlyphPositions() private method

private SetupGlyphPositions ( string content, IFontTexture fontTexture ) : void
content string
fontTexture IFontTexture
return void
        private unsafe void SetupGlyphPositions(string content, IFontTexture fontTexture)
        {
            FullDictionary<char, GlyphInfo> charInfoDict = fontTexture.GlyphInfoDictionary;
            IntPtr pointer = this.positionBuffer.MapBuffer(MapBufferAccess.ReadWrite);
            var array = (TextModel.GlyphPosition*)pointer.ToPointer();
            float currentWidth = 0; int currentHeight = 0;
            /*
             * 0     3  4     7 8     11 12   15
             * -------  ------- -------  -------
             * |     |  |     | |     |  |     |
             * |     |  |     | |     |  |     |
             * |     |  |     | |     |  |     |
             * -------  ------- -------  -------
             * 1     2  5     6 9     10 13   14
             */
            for (int i = 0; i < content.Length; i++)
            {
                char ch = content[i];
                GlyphInfo info = charInfoDict[ch];
                array[i] = new TextModel.GlyphPosition(
                    new vec2(currentWidth, currentHeight + fontTexture.GlyphHeight),
                    new vec2(currentWidth, currentHeight),
                    new vec2(currentWidth + info.width, currentHeight),
                    new vec2(currentWidth + info.width, currentHeight + fontTexture.GlyphHeight));
                currentWidth += info.width + fontTexture.GlyphHeight / 10;
            }
            // move to center
            for (int i = 0; i < content.Length; i++)
            {
                TextModel.GlyphPosition position = array[i];

                position.leftUp.x -= currentWidth / 2.0f;
                //position.leftUp.x /= currentWidth / factor;
                position.leftDown.x -= currentWidth / 2.0f;
                //position.leftDown.x /= currentWidth / factor;
                position.rightUp.x -= currentWidth / 2.0f;
                //position.rightUp.x /= currentWidth / factor;
                position.rightDown.x -= currentWidth / 2.0f;
                //position.rightDown.x /= currentWidth / factor;
                position.leftUp.y -= (currentHeight + fontTexture.GlyphHeight) / 2.0f;
                position.leftDown.y -= (currentHeight + fontTexture.GlyphHeight) / 2.0f;
                position.rightUp.y -= (currentHeight + fontTexture.GlyphHeight) / 2.0f;
                position.rightDown.y -= (currentHeight + fontTexture.GlyphHeight) / 2.0f;

                position.leftUp.x /= (currentHeight + fontTexture.GlyphHeight);
                position.leftDown.x /= (currentHeight + fontTexture.GlyphHeight);
                position.rightUp.x /= (currentHeight + fontTexture.GlyphHeight);
                position.rightDown.x /= (currentHeight + fontTexture.GlyphHeight);
                position.leftUp.y /= (currentHeight + fontTexture.GlyphHeight);
                position.leftDown.y /= (currentHeight + fontTexture.GlyphHeight);
                position.rightUp.y /= (currentHeight + fontTexture.GlyphHeight);
                position.rightDown.y /= (currentHeight + fontTexture.GlyphHeight);
                array[i] = position;
            }
            this.positionBuffer.UnmapBuffer();
        }