//Base as in it has no parent... I know the comparison is iffy at best. Just deal with it. public void setAsBase(StickJoint centre) { if (centre.parent == null) return; sunIter(centre.parent, centre); centre.parent = null; for (int i = 0; i < Joints.Count(); i++) { if (Joints[i].parent != null) { Joints[i].CalcLength(null); } } }
private void sunIter(StickJoint next, StickJoint prev) { if (next.parent != null) sunIter(next.parent, next); next.children.Remove(prev); next.parent = prev; prev.children.Add(next); }
public void Recalc(StickJoint pStart = null) { if (pStart == null) return; int xDiff, yDiff, f, g = 0; double dAngle, dRads, cx, cy; StickJoint pJoint; for (f = 0; f < pStart.children.Count() && g < 100; f++, g++) { pJoint = pStart.children[f]; xDiff = pStart.location.X - pJoint.location.X; yDiff = pStart.location.Y - pJoint.location.Y; dAngle = 180 * (1 + Math.Atan2(yDiff, xDiff) / Math.PI); if ((pJoint.state == 3) | (pJoint.state == 4)) { if (!(pStart.parent == null)) { xDiff = pStart.parent.location.X - pStart.location.X; yDiff = pStart.parent.location.Y - pStart.location.Y; dAngle = 180 * (1 + Math.Atan2(yDiff, xDiff) / Math.PI); dAngle = (dAngle - pJoint.AngleToParent); } } else { if (!(pStart.parent == null)) { xDiff = pStart.parent.location.X - pStart.location.X; yDiff = pStart.parent.location.Y - pStart.location.Y; pJoint.AngleToParent = (180 * (1 + Math.Atan2(yDiff, xDiff) / Math.PI)) - dAngle; } } dRads = Functions.DegToRads(dAngle); cx = Math.Round(pJoint.length * Math.Cos(dRads)); cy = Math.Round(pJoint.length * Math.Sin(dRads)); pJoint.SetPosAbs(Math.Round(pStart.location.X + cx), Math.Round(pStart.location.Y + cy)); Recalc(pJoint); } this.ParentFigure.onJointMoved(); }
public double CalcLength(StickJoint start) { if (start == null) { start = this; } if (!(start.parent == null)) start.length = Math.Round(Math.Sqrt(((start.parent.location.X - start.location.X) * (start.parent.location.X - start.location.X)) + ((start.parent.location.Y - start.location.Y) * (start.parent.location.Y - start.location.Y)))); return start.length; }
public StickJoint AddChild(int vx, int vy) { StickJoint pJoint; int xDiff, yDiff; double dAngle1, dAngle2; pJoint = new StickJoint("Child", new Point(0, 0), 10, Color.Black, Color.Blue); pJoint.SetPos(vx, vy); pJoint.parent = this; xDiff = pJoint.location.X - location.X; yDiff = pJoint.location.Y - location.Y; pJoint.length = Math.Round(Math.Sqrt((xDiff * xDiff) + (yDiff * yDiff))); pJoint.AngleToParent = 360; if (parent != null) { dAngle1 = 180 * (1 + Math.Atan2(yDiff, xDiff) / Math.PI); xDiff = location.X - parent.location.X; yDiff = location.Y - parent.location.Y; dAngle2 = 180 * (1 + Math.Atan2(yDiff, xDiff) / Math.PI); pJoint.AngleToParent = (dAngle2 - dAngle1); } children.Add(pJoint); return pJoint; }
public StickJoint(StickJoint obj, StickJoint newParent) { name = obj.name; location = obj.location; thickness = obj.thickness; color = obj.color; handleColor = obj.handleColor; defaultHandleColor = obj.defaultHandleColor; state = obj.state; drawState = obj.drawState; fill = obj.fill; parent = newParent; handleDrawn = obj.handleDrawn; }
public StickJoint(string newname, Point newLocation, int newThickness, Color newColor, Color newHandleColor, int newState = 0, int newDrawState = 0, bool newFill = false, StickJoint newParent = null, bool newHandleDrawn = true) { name = newname; location = newLocation; thickness = newThickness; color = newColor; handleColor = newHandleColor; defaultHandleColor = newHandleColor; state = newState; drawState = newDrawState; fill = newFill; parent = newParent; handleDrawn = newHandleDrawn; }