Esempio n. 1
0
        private void CreateText(double x, double y, double maxWidth)
        {
            _bitmapText.Clear();
            double currentX = 0;
            double currentY = 0;

            string[] words = _text.Split(' ');

            foreach (string word in words)
            {
                Vector nextWordLength = _font.MeasureFont(word);

                if (maxWidth != -1 &&
                    (currentX + nextWordLength.X) > maxWidth)
                {
                    currentX = 0;
                    currentY += nextWordLength.Y;
                }

                string wordWithSpace = word + " "; // add the space character that was removed.

                foreach (char c in wordWithSpace)
                {
                    CharacterSprite sprite = _font.CreateSprite(c);
                    float xOffset = ((float)sprite.Data.XOffset) / 2;
                    float yOffset = (((float)sprite.Data.Height) * 0.5f) + ((float)sprite.Data.YOffset);
                    sprite.Sprite.SetPosition(x + currentX + xOffset, y - currentY - yOffset);
                    currentX += sprite.Data.XAdvance;
                    _bitmapText.Add(sprite);
                }
            }
            _dimensions = _font.MeasureFont(_text, _maxWidth);
            _dimensions.Y = currentY;
            SetColor(_color);
        }
Esempio n. 2
0
        public Vector MeasureFont(string text, double maxWidth)
        {
            Vector dimensions = new Vector();

            foreach (char c in text)
            {
                CharacterData data = _characterData[c];
                dimensions.X += data.XAdvance;
                dimensions.Y = Math.Max(dimensions.Y, data.Height + data.YOffset);
            }
            return dimensions;
        }
Esempio n. 3
0
        private void InitVertexPositions(Vector position, double width, double height)
        {
            double halfWidth = width / 2;
            double halfHeight = height / 2;
            // Clockwise creation of two triangles to make a quad.

            // TopLeft, TopRight, BottomLeft
            _vertexPositions[0] = new Vector(position.X - halfWidth, position.Y + halfHeight, position.Z);
            _vertexPositions[1] = new Vector(position.X + halfWidth, position.Y + halfHeight, position.Z);
            _vertexPositions[2] = new Vector(position.X - halfWidth, position.Y - halfHeight, position.Z);

            // TopRight, BottomRight, BottomLeft
            _vertexPositions[3] = new Vector(position.X + halfWidth, position.Y + halfHeight, position.Z);
            _vertexPositions[4] = new Vector(position.X + halfWidth, position.Y - halfHeight, position.Z);
            _vertexPositions[5] = new Vector(position.X - halfWidth, position.Y - halfHeight, position.Z);
        }
Esempio n. 4
0
public Vector CrossProduct(Vector v)
{
    double nx = Y * v.Z - Z * v.Y;
    double ny = Z * v.X - X * v.Z;
    double nz = X * v.Y - Y * v.X;
    return new Vector(nx, ny, nz);
}
Esempio n. 5
0
public bool Equals(Vector v)
{
    return (X == v.X) && (Y == v.Y) && (Z == v.Z);
}
Esempio n. 6
0
public Vector Subtract(Vector r)
{
    return new Vector(X - r.X, Y - r.Y, Z - r.Z);
}
Esempio n. 7
0
public Vector Add(Vector r)
{
    return new Vector(X + r.X, Y + r.Y, Z + r.Z);
}
Esempio n. 8
0
public Vector Normalise(Vector v)
{
    double r = v.Length();
    if (r != 0.0)				// guard against divide by zero
    {
        return new Vector(v.X / r, v.Y / r, v.Z / r);	// normalise and return
    }
    else
    {
        return new Vector(0, 0, 0);
    }
}
Esempio n. 9
0
public double DotProduct(Vector v)
{
    return (v.X * X) + (Y * v.Y) + (Z * v.Z);
}
Esempio n. 10
0
 public void DrawImmediateModeVertex(Vector position, Color color, Point uvs)
 {
     Gl.glColor4f(color.Red, color.Green, color.Blue, color.Alpha);
     Gl.glTexCoord2f(uvs.X, uvs.Y);
     Gl.glVertex3d(position.X, position.Y, position.Z);
 }
Esempio n. 11
0
 public void SetPosition(Vector position)
 {
     InitVertexPositions(position, GetWidth(), GetHeight());
 }