Пример #1
0
        //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);
                }
            }
        }
Пример #2
0
        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);
        }
Пример #3
0
        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();
        }
Пример #4
0
        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;
        }
Пример #5
0
        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;
        }
Пример #6
0
 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;
 }
Пример #7
0
 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;
 }