예제 #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;
 }
예제 #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;
 }
예제 #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;
        }
예제 #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);
        }
예제 #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;
 }
예제 #6
0
 public void SetTranslation(Vector translation)
 {
     _m41 = translation.X;
     _m42 = translation.Y;
     _m43 = translation.Z;
 }
예제 #7
0
 public void SetScale(Vector scale)
 {
     _m11 = scale.X;
     _m22 = scale.Y;
     _m33 = scale.Z;
 }
예제 #8
0
파일: sprite.cs 프로젝트: hnerud/GameLoop
 public void SetPosition(Vector position)
 {
     InitVertexPositions(position, GetWidth(), GetHeight());
 }
예제 #9
0
 //addition vectors
 public Vector Add(Vector r)
 {
     return new Vector(X + r.X, Y + r.Y, Z + r.Z);
 }
예제 #10
0
 //subtraction vector
 public Vector Subtract(Vector r)
 {
     return new Vector(X - r.X, Y - r.Y, Z - r.Z);
 }
예제 #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);
     }
 }
예제 #12
0
 public bool Equals(Vector v)
 {
     return (X == v.X) && (Y == v.Y) && (Z == v.Z);
 }
예제 #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);
 }
예제 #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);
 }
예제 #15
0
파일: renderer.cs 프로젝트: hnerud/GameLoop
 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);
 }
예제 #16
0
 public Circle(Vector position, double radius)
 {
     Position = position;
     Radius = radius;
 }
예제 #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;
 }
예제 #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;
        }
예제 #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();
        }