public void CreatePickSpring(sw.Point ptMouse) { xna.Vector2 pointScreen = new xna.Vector2((float)(ptMouse.X), (float)(ptMouse.Y)); xna.Vector2 point = PhysicsCanvas.BoundaryHelper.ScreenToWorld(pointScreen); _mousePickSpring = new FixedMouseJoint(this.BodyObject, point); _mousePickSpring.MaxForce = 1000.0f * this.BodyObject.Mass; _mousePickSpring.Enabled = true; _physicsCanvas.Simulator.AddJoint(_mousePickSpring); this.BodyObject.Awake = true; xna.Vector2 pointBody = PhysicsCanvas.BoundaryHelper.WorldToScreen(this.BodyObject.Position); _lineShowSpring.X1 = pointBody.X; _lineShowSpring.Y1 = pointBody.Y; _lineShowSpring.X2 = pointScreen.X; _lineShowSpring.Y2 = pointScreen.Y; _lineShowSpring.Visibility = Visibility.Visible; }
public static void SetSize(this sw.FrameworkElement element, wf.Size size) { element.Width = size.Width; element.Height = size.Height; }
void HandleMouseMove(sw.Point pt, double rotation) { if (_draggingNonPhysicsSprite) { Canvas.SetLeft(this, pt.X - _ptMouseDownSprite.X); Canvas.SetTop(this, pt.Y - _ptMouseDownSprite.Y); } else if (_mousePickSpring != null) { //pt = new Point(pt.X / _physicsCanvas.TransformRoot.ScaleX, pt.Y / _physicsCanvas.TransformRoot.ScaleY); xna.Vector2 pointScreen = new xna.Vector2((float)(pt.X), (float)(pt.Y)); xna.Vector2 point = PhysicsCanvas.BoundaryHelper.ScreenToWorld(pointScreen); _mousePickSpring.WorldAnchorB = point; if (rotation != 0) { _mousePickSpring.BodyA.Rotation += (float)(rotation); //System.Diagnostics.Debug.WriteLine("rotated " + rotation + " deg."); } _lineShowSpring.X2 = pointScreen.X; _lineShowSpring.Y2 = pointScreen.Y; _lineShowSpring.Visibility = Visibility.Visible; } }
void HandleMouseUp(sw.Point pt) { if (_draggingNonPhysicsSprite) { // "scenery" type element _draggingNonPhysicsSprite = false; if (MousePickCompleted != null) MousePickCompleted(this, _posMouseMoveStart); return; } DestroyPickSpring(); }
public static double DistanceToLine(SysWin.Point lineStart, SysWin.Point lineEnd, SysWin.Point point) { double xDelta = lineEnd.X - lineStart.X; double yDelta = lineEnd.Y - lineStart.Y; double u = ((point.X - lineStart.X) * xDelta + (point.Y - lineStart.Y) * yDelta) / (xDelta * xDelta + yDelta * yDelta); SysWin.Point closestPoint; if (u < 0) closestPoint = lineStart; else if (u > 1) closestPoint = lineEnd; else closestPoint = new SysWin.Point(lineStart.X + u * xDelta, lineStart.Y + u * yDelta); return DistanceBetweenTwoPoints(closestPoint, point); // closestPoint.DistanceTo(point); }
void HandleMouseDown(sw.Point pt) { DestroyPickSpring(); _posMouseMoveStart = this.Position; _ptMouseDown = TransformFromCanvas(this, pt); if (MousePickEnabled && BodyObject == null) { // "scenery" type element _draggingNonPhysicsSprite = true; if (MousePickStarted != null) MousePickStarted(this, this.Position); return; } if (MousePickEnabled && BodyObject.IsStatic && AllowStaticObjectManipulation && BodyObject.Enabled) { // save the static attributes _originalAngularDamping = BodyObject.AngularDamping; BodyObject.AngularDamping = float.MaxValue; _bodyWasStatic = true; BodyObject.IsStatic = false; } if (MousePickEnabled && BodyObject.IsStatic == false && BodyObject.Enabled) { CreatePickSpring(pt); if (MousePickStarted != null) MousePickStarted(this, this.Position); } }
public static double GetAngleBetween(SysWin.Point pt1, SysWin.Point pt2) { double retval = 57.2727272727272727 * Math.Atan2(pt2.X - pt1.X, pt2.Y - pt1.Y); return retval; }
/// <summary> /// A utility function to get a point that is a given distance and angle from another point. /// </summary> /// <param name="angle">The angle to travel</param> /// <param name="distance">The distance (in pixels) to go</param> /// <param name="ptStart">The start point</param> /// <returns></returns> public static SysWin.Point GetPointFromDistanceAngle(double angle, double distance, SysWin.Point ptStart) { double theta = angle * 0.0174532925; SysWin.Point p = new SysWin.Point(); p.X = ptStart.X + distance * Math.Cos(theta); p.Y = ptStart.Y + distance * Math.Sin(theta); return p; }
/// <summary> /// Get the distance, in pixels between two points. /// </summary> public static double DistanceBetweenTwoPoints(SysWin.Point pt1, SysWin.Point pt2) { double a = pt2.X - pt1.X; double b = pt2.Y - pt1.Y; return Math.Sqrt(a * a + b * b); }
public xna.Vector2 ScreenSizeToWorldSize(SysWin.Point size) { return ConvertSize(new xna.Vector2((float)size.X, (float)size.Y), ScreenTopLeft, ScreenBottomRight, WorldTopLeft, WorldBottomRight, true); }
public xna.Vector2 ScreenSizeToWorldSize(SysWin.Size size) { return ConvertSize(new xna.Vector2((float)size.Width, (float)size.Height), ScreenTopLeft, ScreenBottomRight, WorldTopLeft, WorldBottomRight, true); }