public void DrawTo(State state, Joint otherJoint, Joint.State otherState) { if (!Visible) { return; } if (DrawType == DrawJointType.CircleLine) { float dx = state.Location.X - otherState.Location.X; float dy = state.Location.Y - otherState.Location.Y; float r = (float)Math.Sqrt((double)(dx * dx + dy * dy)) / 2; float x = otherState.Location.X + dx / 2; float y = otherState.Location.Y + dy / 2; Drawing.Circle(new PointF(x, y), r, state.JointColor); } else if (DrawType == DrawJointType.CircleRadius) { float r = state.Thickness; float x = state.Location.X; float y = state.Location.Y; Drawing.Circle(new PointF(x, y), r, state.JointColor, 5 * (int)Math.Sqrt(r)); } else { Drawing.CappedLine(state.Location, otherState.Location, state.Thickness, state.JointColor); } if (state.BitmapIndex != -1) { int ID = Bitmaps[state.BitmapIndex].Item1; Bitmap bitmap = Bitmaps[state.BitmapIndex].Item2.Item2; double angle = MathUtil.Angle(state.Location, otherState.Location); double angleDiff = Math.PI * BitmapOffsets[bitmap].Item1 / 180; angle += angleDiff; PointF Offsets = MathUtil.Rotate(BitmapOffsets[bitmap].Item2, (float)angle); angle *= 180.0 / Math.PI; Drawing.BitmapOriginRotation(new PointF( state.Location.X + Offsets.X, state.Location.Y + Offsets.Y), bitmap.Size, (float)angle, 255, ID); } }
public static Tuple <Joint, Joint.State> FindJointStatePair(Joint rootJoint, Joint.State rootState, PointF pos) { if (MathUtil.IsPointInPoint(rootState.Location, pos, 4)) { return(new Tuple <Joint, Joint.State>(rootJoint, rootState)); } for (int i = 0; i < rootJoint.Children.Count; i++) { var pair = FindJointStatePair(rootJoint.Children[i], rootState.Children[i], pos); if (pair != null) { return(pair); } } return(null); }
public ManipulateResult TryManipulate(IEntityState _state, Point location, System.Windows.Forms.MouseButtons button, System.Windows.Forms.Keys modifiers, bool fromEditor) { State state = _state as State; if (state == null) { return(null); } ManipulateResult result = new ManipulateResult(); ManipulateParams mparams = new ManipulateParams(); result.Params = mparams; if (fromEditor) { mparams.DisableIK = true; } if (button == MouseButtons.Right) { result.Target = state.Root; mparams.AbsoluteDrag = true; mparams.AbsoluteOffset = new PointF(location.X - state.Root.Location.X, location.Y - state.Root.Location.Y); } else { Joint.State target = state.Root.JointAtLocation(location); if (target == null) { return(null); } result.Target = target; mparams.AbsoluteDrag = false; } return(result); }
public void Read(BinaryReader reader, UInt16 version) { Root = new Joint.State(); Root.Read(reader, version); }
public ManipulateResult TryManipulate(IEntityState _state, Point location, MouseButtons button, Keys modifiers) { State state = _state as State; if (state == null) { return(null); } ManipulateResult result = new ManipulateResult(); ManipulateParams mparams = new ManipulateParams(); result.Params = mparams; if (modifiers == Keys.Shift) { mparams.PivotDrag = true; } else if (modifiers == Keys.Alt) { mparams.DisableIK = true; } if (button == MouseButtons.Right) { result.Target = state.Root; mparams.AbsoluteDrag = true; mparams.AbsoluteOffset = new PointF(location.X - state.Root.Location.X, location.Y - state.Root.Location.Y); } else { Joint.State target = state.Root.JointAtLocation(location); if (target == null) { return(null); } if (mparams.PivotDrag && target.Parent != null) { mparams.PivotLength = (float)MathUtil.Length(target.Location, target.Parent.Location); mparams.PivotAngle = (float)MathUtil.Angle(target.Location, target.Parent.Location); // you need to go through every descendant (not child) of target here and store their angle and distance to target's parent mparams.PivotInfo = new Dictionary <Joint.State, Tuple <float, float> >(); Stack <Joint.State> open = new Stack <Joint.State>(); open.Push(target); while (open.Count > 0) { Joint.State current = open.Pop(); foreach (Joint.State child in current.Children) { open.Push(child); float distance = (float)MathUtil.Length(target.Parent.Location, child.Location); float angle = (float)MathUtil.Angle(child.Location, target.Parent.Location); // or the other way around, depends mparams.PivotInfo[child] = new Tuple <float, float>(distance, angle); } } } result.Target = target; mparams.AbsoluteDrag = false; } return(result); }
public void ManipulateUpdate(IManipulatable _target, IManipulatableParams mparams, Point location) { Joint.State target = _target as Joint.State; target.Move(location, (ManipulateParams)mparams, null); }