Beispiel #1
0
        /// <summary> Add two matricies
        /// 
        /// </summary>
        /// <param name="A">The first matrix
        /// </param>
        /// <param name="B">The second matrix
        /// </param>
        /// <returns> A newly created matrix containing the result
        /// </returns>
        public static Matrix2f Add(Matrix2f A, Matrix2f B)
        {
            Vector2f temp1 = new Vector2f(A.col1);
            temp1.Add(B.col1);
            Vector2f temp2 = new Vector2f(A.col2);
            temp2.Add(B.col2);

            return new Matrix2f(temp1, temp2);
        }
Beispiel #2
0
 /// <summary> Create a matrix
 /// 
 /// </summary>
 /// <param name="col1">The first column
 /// </param>
 /// <param name="col2">The second column
 /// </param>
 public Matrix2f(Vector2f col1, Vector2f col2)
 {
     this.col1.Reconfigure(col1);
     this.col2.Reconfigure(col2);
 }
Beispiel #3
0
        /// <summary> Project this vector onto another
        /// 
        /// </summary>
        /// <param name="b">The vector to project onto
        /// </param>
        /// <param name="result">The projected vector
        /// </param>
        public virtual void ProjectOntoUnit(ROVector2f b, Vector2f result)
        {
            float dp = b.Dot(this);

            result.x = dp * b.X;
            result.y = dp * b.Y;
        }
Beispiel #4
0
        /// <summary> Subtract one vector from another
        /// 
        /// </summary>
        /// <param name="a">The vector to be subtracted from
        /// </param>
        /// <param name="b">The vector to subtract
        /// </param>
        /// <returns> A newly created containing the result
        /// </returns>
        public static Vector2f Sub(ROVector2f a, ROVector2f b)
        {
            Vector2f temp = new Vector2f(a);
            temp.Sub(b);

            return temp;
        }
Beispiel #5
0
 /// <summary> Make a vector absolute
 /// 
 /// </summary>
 /// <param name="a">The vector to make absolute
 /// </param>
 /// <returns> A newly created result vector
 /// </returns>
 public static Vector2f Abs(Vector2f a)
 {
     return new Vector2f(System.Math.Abs(a.x), System.Math.Abs(a.y));
 }
Beispiel #6
0
        /// <summary> Get the normal of a line x y (or edge). 
        /// When standing on x facing y, the normal will point
        /// to the left.
        /// 
        /// TODO: Move this function somewhere else?
        /// 
        /// </summary>
        /// <param name="x">startingpoint of the line
        /// </param>
        /// <param name="y">endpoint of the line
        /// </param>
        /// <returns> a (normalised) normal
        /// </returns>
        public static Vector2f GetNormal(ROVector2f x, ROVector2f y)
        {
            Vector2f normal = new Vector2f(y);
            normal.Sub(x);

            normal = new Vector2f(normal.y, - normal.x);
            normal.Normalise();

            return normal;
        }
Beispiel #7
0
        /// <summary> Scale a vector by a given value
        /// 
        /// </summary>
        /// <param name="a">The vector to be scaled
        /// </param>
        /// <param name="Scale">The amount to Scale the vector by
        /// </param>
        /// <returns> A newly created vector - a scaled version of the new vector
        /// </returns>
        public static Vector2f Scale(ROVector2f a, float scale)
        {
            Vector2f temp = new Vector2f(a);
            temp.Scale(scale);

            return temp;
        }
Beispiel #8
0
 /// <summary> Find the Cross product of a vector and a float
 /// 
 /// </summary>
 /// <param name="s">The scalar float
 /// </param>
 /// <param name="a">The vector to fidn the Cross of
 /// </param>
 /// <returns> A newly created resultant vector
 /// </returns>
 public static Vector2f Cross(Vector2f a, float s)
 {
     return new Vector2f(s * a.y, (- s) * a.x);
 }
Beispiel #9
0
 /// <summary> Find the Cross product of a vector and a float
 /// 
 /// </summary>
 /// <param name="s">The scalar float
 /// </param>
 /// <param name="a">The vector to fidn the Cross of
 /// </param>
 /// <returns> A newly created resultant vector
 /// </returns>
 public static Vector2f Cross(float s, Vector2f a)
 {
     return new Vector2f((- s) * a.y, s * a.x);
 }
Beispiel #10
0
 /// <summary> Find the Cross product of two vectors
 /// 
 /// </summary>
 /// <param name="a">The first vector
 /// </param>
 /// <param name="b">The second vector
 /// </param>
 /// <returns> The Cross product of the two vectors
 /// </returns>
 public static float Cross(Vector2f a, Vector2f b)
 {
     return a.x * b.y - a.y * b.x;
 }
Beispiel #11
0
        protected override void DrawCircleBody(Body body, Circle circle)
        {
            float x = body.GetPosition().X;
            float y = body.GetPosition().Y;
            float r = circle.Radius;
            float rot = body.Rotation;
            float xo = (float)(System.Math.Cos(rot) * r);
            float yo = (float)(System.Math.Sin(rot) * r);

            var circleSize = new Vector2f(circle.Radius * 2, circle.Radius * 2);

            UIElement e = body.UserData as UIElement;
            if (e == null)
            {
                e = new VisualCircle(circleSize, imagePath);
                canvas.Children.Add(e);
                body.UserData = e;
            }

            UpdateElementPosition(e, x, y, circleSize);
            ApplyRotationToElement(e, circle.Radius * 2, circle.Radius * 2, RadToDeg(body.Rotation));
        }
Beispiel #12
0
        protected virtual void DrawCircleBody(Body body, Circle circle)
        {
            float x = body.GetPosition().X;
            float y = body.GetPosition().Y;
            float r = circle.Radius;
            float rot = body.Rotation;
            float xo = (float)(System.Math.Cos(rot) * r);
            float yo = (float)(System.Math.Sin(rot) * r);

            Ellipse e = body.UserData as Ellipse;
            if (e == null)
            {
                e = new Ellipse();
                e.Stroke = new SolidColorBrush(Colors.Yellow);
                e.StrokeThickness = 1;
                e.Width = r * 2;
                e.Height = r * 2;
                canvas.Children.Add(e);
                body.UserData = e;
            }

            var circleSize = new Vector2f(circle.Radius*2, circle.Radius*2);
            UpdateElementPosition(e, Convert.ToInt32(x), Convert.ToInt32(y), circleSize);
        }