Example #1
0
    /// <summary>
    /// Clone this instance.
    /// </summary>
    public object Clone()
    {
        Frame clone = new Frame();

        foreach (string key in bodyPartRotations.Keys)
        {
            clone.AddBodyPartRotation((string)key.Clone(), bodyPartRotations [key]);
        }
        return(clone);
    }
Example #2
0
    /// <summary>
    /// Creates a frame object containng current rotations of each limb.
    /// </summary>
    /// <returns>The current pose frame.</returns>
    private Frame GetCurrentPoseFrame()
    {
        Frame frame = new Frame();

        foreach (GameObject go in endPoints)
        {
            //Make sure endPoit has a drag and drop script before checking its parent's roation.
            DragAndDrop dragAndDrop = go.GetComponent <DragAndDrop> ();
            if (dragAndDrop == null)
            {
                continue;
            }
            //Add end point parent (limb) rotation and name to move.
            float  rotation = go.transform.parent.localEulerAngles.z;
            string name     = go.transform.parent.name;
            frame.AddBodyPartRotation(name, rotation);
        }
        return(frame);
    }
Example #3
0
    /// <summary>
    /// Blends two frames to create a new frame.
    /// </summary>
    /// <returns>The new blended frame.</returns>
    /// <param name="fromFrame">The first frame.</param>
    /// <param name="toFrame">The second frame.</param>
    /// <param name="percentage">The percentage to add from the second frame to the first frame.
    /// At 0 percent, the blended frame is identical to the first, and 100 it is identical to the secont</param>
    public Frame BlendFrames(Frame fromFrame, Frame toFrame, int percentage)
    {
        List <string> bodyPartNames = fromFrame.getBodyPartNames();
        Frame         newFrame      = (Frame)fromFrame.Clone();

        foreach (string name in bodyPartNames)
        {
            float newRotation;
            float fromRot = fromFrame.getRotation(name);
            float toRot   = toFrame.getRotation(name);
            //Make sure rotation around zero does not result in a loop in the wrong direction.
            //Make the angle right of zero (the smaller angle) bigger.
            if (RotationUtils.ZeroInSmallerLimit(fromRot, toRot))
            {
                if (fromRot < toRot)
                {
                    fromRot += 360;
                }
                else if (fromRot > toRot)
                {
                    toRot += 360;
                }
                //Make sure rotation 0 <=> [180-359] does not rotate the wrong way.
            }
            else if (fromRot == 0 && toRot > 180)
            {
                fromRot += 360;
            }
            else if (toRot == 0 && fromRot > 180)
            {
                toRot += 360;
            }
            newRotation = fromRot + (float)percentage / (float)100 * (toRot - fromRot);

            newFrame.AddBodyPartRotation(name, newRotation);
        }
        return(newFrame);
    }