Example #1
0
 public Matrix(Vector x, Vector y, Vector z, Vector o)
 {
     _m11 = x.X; _m12 = x.Y; _m13 = x.Z;
     _m21 = y.X; _m22 = y.Y;  _m23 = y.Z;
     _m31 = z.X; _m32 = z.Y; _m33 = z.Z;
     _m41 = o.X; _m42 =o.Y; _m43 = o.Z;
 }
Example #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;
 }
Example #3
0
        public bool Intersects(Point point)
        {
            // Change point to a vector
            Vector vPoint = new Vector(point.X, point.Y, 0);
            Vector vFromCircleToPoint = Position - vPoint;
            double distance = vFromCircleToPoint.Length();

            if (distance > Radius)
            {
                return false;
            }
            return true;
        }
Example #4
0
        public 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);
        }
Example #5
0
 public void SetPosition(Vector position)
 {
     // InitVertexPositions(position, GetWidth(), GetHeight());
     Matrix m = new Matrix();
     m.SetTranslation(new Vector(_positionX, _positionY, 0));
     ApplyMatrix(m.Inverse());
     m.SetTranslation(position);
     ApplyMatrix(m);
     _positionX = position.X;
     _positionY = position.Y;
 }
Example #6
0
 public void SetTranslation(Vector translation)
 {
     _m41 = translation.X;
     _m42 = translation.Y;
     _m43 = translation.Z;
 }
Example #7
0
 public void SetScale(Vector scale)
 {
     _m11 = scale.X;
     _m22 = scale.Y;
     _m33 = scale.Z;
 }
Example #8
0
 public void SetPosition(Vector position)
 {
     InitVertexPositions(position, GetWidth(), GetHeight());
 }
Example #9
0
 //addition vectors
 public Vector Add(Vector r)
 {
     return new Vector(X + r.X, Y + r.Y, Z + r.Z);
 }
Example #10
0
 //subtraction vector
 public Vector Subtract(Vector r)
 {
     return new Vector(X - r.X, Y - r.Y, Z - r.Z);
 }
Example #11
0
 //determine if character is within a range by normalizing to 1 it can be in range or out of 1 range etc.
 public Vector Normalise(Vector v)
 {
     double r = v.Length();
     if (r != 0.0)               //division by zero is a no-no!
     {
         return new Vector(v.X / r, v.Y / r, v.Z / r);
     }
     else
     {
         return new Vector(0, 0, 0);
     }
 }
Example #12
0
 public bool Equals(Vector v)
 {
     return (X == v.X) && (Y == v.Y) && (Z == v.Z);
 }
Example #13
0
 //dot product to determine what side of wall and if characters facing each other
 public double DotProduct(Vector v)
 {
     return (v.X * X) + (Y * v.Y) + (Z * v.Z);
 }
Example #14
0
 //find the normal to a plane used to direct an objects movement forwar etc.
 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);
 }
Example #15
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);
 }
Example #16
0
 public Circle(Vector position, double radius)
 {
     Position = position;
     Radius = radius;
 }
Example #17
0
 public Vector GetScale()
 {
     Vector result = new Vector();
     result.X = (new Vector(_m11, _m12, _m13)).Length();
     result.Y = (new Vector(_m21, _m22, _m23)).Length();
     result.Z = (new Vector(_m31, _m32, _m33)).Length();
     return result;
 }
Example #18
0
        public void SetRotate(Vector axis, double angle)
        {
            double angleSin = Math.Sin(angle);
            double angleCos = Math.Cos(angle);
            double a = 1.0 - angleCos;
            double ax = a * axis.X;
            double ay = a * axis.Y;
            double az = a * axis.Z;

            _m11 = ax * axis.X + angleCos;
            _m12 = ax * axis.Y + axis.Z * angleSin;
            _m13 = ax * axis.Z - axis.Y * angleSin;

            _m21 = ay * axis.X - axis.Z * angleSin;
            _m22 = ay * axis.Y + angleCos;
            _m23 = ay * axis.Z - axis.X * angleSin;

            _m31 = az * axis.X + axis.Y * angleSin;
            _m32 = az * axis.Y - axis.X * angleSin;
            _m33 = az * axis.Z + angleCos;
        }
Example #19
0
        private void CreateText(double x, double y, double maxWidth)
        {
            _bitmapText.Clear();
            double currentX = x;
            double currentY = y;
            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 + " ";

                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();
        }