public VisualBox(ROVector2f size, string imagePath) : this() { Height = size.Y; Width = size.X; Canvas theCanvas = FindName("TheCanvas") as Canvas; theCanvas.Height = size.Y; theCanvas.Width = size.X; Image theImage = FindName("TheImage") as Image; theImage.Source = new BitmapImage(new Uri(imagePath, UriKind.Relative)); theImage.Width = size.X; theImage.Height = size.Y; }
public VisualCircle(ROVector2f size, string imagePath) : this() { Height = size.Y; Width = size.X; var theCanvas = FindName("TheCanvas") as Canvas; theCanvas.Height = size.Y; theCanvas.Width = size.X; var theEllipse = FindName("TheEllipse") as Ellipse; theEllipse.Height = size.Y; theEllipse.Width = size.X; var brush = new ImageBrush(); brush.ImageSource = new BitmapImage(new Uri(imagePath, UriKind.Relative)); theEllipse.Fill = brush; }
/// <summary> Set the value of this vector /// /// </summary> /// <param name="other">The values to set into the vector /// </param> public virtual void Reconfigure(ROVector2f other) { Reconfigure(other.X, other.Y); }
/// <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; }
/// <summary> Compare two vectors allowing for a (small) error as indicated by the delta. /// Note that the delta is used for the vector's components separately, i.e. /// any other vector that is contained in the square box with sides 2*delta and this /// vector at the center is considered equal. /// /// </summary> /// <param name="other">The other vector to compare this one to /// </param> /// <param name="delta">The allowed error /// </param> /// <returns> True iff this vector is equal to other, with a tolerance defined by delta /// </returns> public virtual bool EqualsDelta(ROVector2f other, float delta) { return (other.X - delta < x && other.X + delta > x && other.Y - delta < y && other.Y + delta > y); }
/// <seealso cref="Silver.Weight.Math.ROVector2f.Dot(Silver.Weight.Math.ROVector2f)"> /// </seealso> public virtual float Dot(ROVector2f other) { return (x * other.X) + (y * other.Y); }
/// <summary> Get the Distance squared from this point to another /// /// </summary> /// <param name="other">The other point we're measuring to /// </param> /// <returns> The Distance to the other point /// </returns> public virtual float DistanceSquared(ROVector2f other) { float dx = other.X - X; float dy = other.Y - Y; return (dx * dx) + (dy * dy); }
/// <summary> Get the Distance from this point to another /// /// </summary> /// <param name="other">The other point we're measuring to /// </param> /// <returns> The Distance to the other point /// </returns> public virtual float Distance(ROVector2f other) { return (float) System.Math.Sqrt(DistanceSquared(other)); }
protected void UpdateElementPosition(UIElement e, float x, float y, ROVector2f size) { double left = Convert.ToDouble(x - (size.X / 2)); double top = Convert.ToDouble(y - (size.Y/2)); e.SetValue(Canvas.LeftProperty, left); e.SetValue(Canvas.TopProperty, top); }
/// <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; }
/// <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; }
/// <summary> Multiply a matrix by a vector /// /// </summary> /// <param name="A">The matrix to be multiplied /// </param> /// <param name="v">The vector to multiple by /// </param> /// <returns> A newly created vector containing the resultant vector /// </returns> public static Vector2f Mul(Matrix2f A, ROVector2f v) { return new Vector2f(A.col1.x * v.X + A.col2.x * v.Y, A.col1.y * v.X + A.col2.y * v.Y); }
/// <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; }
protected void UpdateLinePosition(System.Windows.Shapes.Line line, ROVector2f pointA, ROVector2f pointB) { line.X1 = pointA.X; line.Y1 = pointA.Y; line.X2 = pointB.X; line.Y2 = pointB.Y; }
/// <summary> Subtract a vector from this vector /// /// </summary> /// <param name="v">The vector subtract /// </param> public virtual void Sub(ROVector2f v) { x -= v.X; y -= v.Y; }
/// <summary> Add a vector to this vector /// /// </summary> /// <param name="v">The vector to Add /// </param> public virtual void Add(ROVector2f v) { x += v.X; y += v.Y; }
/// <summary> Create a new vector based on another /// /// </summary> /// <param name="other">The other vector to copy into this one /// </param> public Vector2f(ROVector2f other) : this(other.X, other.Y) { }
protected System.Windows.Shapes.Line MakeLine(ROVector2f pointA, ROVector2f pointB, int thickness, Color color) { System.Windows.Shapes.Line line1 = new System.Windows.Shapes.Line(); UpdateLinePosition(line1, pointA, pointB); line1.StrokeThickness = thickness; line1.Stroke = new SolidColorBrush(color); return line1; }