/// <summary> /// Contructor of a constraint. /// </summary> /// <param name="baseJoint"></param> /// <param name="legJointOne"></param> /// <param name="legJointTwo"></param> public Constraint(Joint baseJoint, Joint legJointOne, Joint legJointTwo, double tolerance) { this.baseJoint = baseJoint; this.legJointOne = legJointOne; this.legJointTwo = legJointTwo; this.tolerance = tolerance; calcAngles(); }
/// <summary> /// Constructor for a bone-class. /// </summary> /// <param name="jOne">One joint.</param> /// <param name="jTwo">The other joint.</param> public Bone(Joint jOne, Joint jTwo) { this.jOne = jOne; this.jTwo = jTwo; boneLine = new Line(); boneLine.Stroke = System.Windows.Media.Brushes.Black; // the +10 is neccessary to draw the line between the centers of two ellipses (joints) boneLine.X1 = jOne.getX() + 10; boneLine.X2 = jTwo.getX() + 10; boneLine.Y1 = jOne.getY() + 10; boneLine.Y2 = jTwo.getY() + 10; boneLine.StrokeThickness = 3; // handler to react on the movement of the joints in dragging-mode jOne.Event_onJointIsMoving += new OnJointIsMovingHandler(OnJointOneIsMoving); jTwo.Event_onJointIsMoving += new OnJointIsMovingHandler(OnJointTwoIsMoving); }
/// <summary> /// Helper-method to check, if a constraints already exists. /// </summary> /// <param name="baseJoint"></param> /// <param name="jOne"></param> /// <param name="jTwo"></param> /// <returns>true - if a constraint is found.</returns> private bool isConstraintAlreadyInList(Joint baseJoint, Joint jOne, Joint jTwo) { foreach (Constraint constraint in list_of_constraints) { if (constraint.getBaseJoint().getName().Equals(baseJoint.getName())) { if ((constraint.getLegJointOne().getName().Equals(jOne.getName()) && constraint.getLegJointTwo().getName().Equals(jTwo.getName())) || (constraint.getLegJointOne().getName().Equals(jTwo.getName()) && constraint.getLegJointTwo().getName().Equals(jOne.getName()))) { return true; } } } return false; }
/// <summary> /// Creates the joints and bones and draws the initial skeleton. /// </summary> private void InitSkeleton() { joints = new HashSet<Joint>(); Head = new Joint("Head", skeleton_canvas, 130, 75, this); joints.Add(Head); ShoulderCenter = new Joint("ShoulderCenter", skeleton_canvas, 130, 110, this); joints.Add(ShoulderCenter); ElbowLeft = new Joint("ElbowLeft", skeleton_canvas, 80, 140, this); joints.Add(ElbowLeft); ElbowRight = new Joint("ElbowRight", skeleton_canvas, 180, 140, this); joints.Add(ElbowRight); HandLeft = new Joint("HandLeft", skeleton_canvas, 30, 160, this); joints.Add(HandLeft); HandRight = new Joint("HandRight", skeleton_canvas, 230, 160, this); joints.Add(HandRight); HipCenter = new Joint("HipCenter", skeleton_canvas, 130, 180, this); joints.Add(HipCenter); KneeLeft = new Joint("KneeLeft", skeleton_canvas, 100, 220, this); joints.Add(KneeLeft); KneeRight = new Joint("KneeRight", skeleton_canvas, 160, 220, this); joints.Add(KneeRight); FootLeft = new Joint("FootLeft", skeleton_canvas, 80, 270, this); joints.Add(FootLeft); FootRight = new Joint("FootRight", skeleton_canvas, 180, 270, this); joints.Add(FootRight); left_upper_arm = new Bone(ShoulderCenter, ElbowLeft); right_upper_arm = new Bone(ShoulderCenter, ElbowRight); neck = new Bone(Head, ShoulderCenter); left_lower_arm = new Bone(ElbowLeft, HandLeft); right_lower_arm = new Bone(ElbowRight, HandRight); body = new Bone(ShoulderCenter, HipCenter); right_upper_leg = new Bone(HipCenter, KneeRight); rigth_lower_leg = new Bone(KneeRight, FootRight); left_upper_leg = new Bone(HipCenter, KneeLeft); left_lower_leg = new Bone(KneeLeft, FootLeft); skeleton_canvas.Children.Add(left_upper_arm.getLine()); skeleton_canvas.Children.Add(right_upper_arm.getLine()); skeleton_canvas.Children.Add(neck.getLine()); skeleton_canvas.Children.Add(left_lower_arm.getLine()); skeleton_canvas.Children.Add(right_lower_arm.getLine()); skeleton_canvas.Children.Add(body.getLine()); skeleton_canvas.Children.Add(right_upper_leg.getLine()); skeleton_canvas.Children.Add(rigth_lower_leg.getLine()); skeleton_canvas.Children.Add(left_upper_leg.getLine()); skeleton_canvas.Children.Add(left_lower_leg.getLine()); skeleton_canvas.Children.Add(Head.getCurrentEllipse()); skeleton_canvas.Children.Add(ShoulderCenter.getCurrentEllipse()); skeleton_canvas.Children.Add(ElbowLeft.getCurrentEllipse()); skeleton_canvas.Children.Add(ElbowRight.getCurrentEllipse()); skeleton_canvas.Children.Add(HandLeft.getCurrentEllipse()); skeleton_canvas.Children.Add(HandRight.getCurrentEllipse()); skeleton_canvas.Children.Add(HipCenter.getCurrentEllipse()); skeleton_canvas.Children.Add(KneeLeft.getCurrentEllipse()); skeleton_canvas.Children.Add(KneeRight.getCurrentEllipse()); skeleton_canvas.Children.Add(FootLeft.getCurrentEllipse()); skeleton_canvas.Children.Add(FootRight.getCurrentEllipse()); }