void FixedUpdate()
    {
        if (isEnabled)
        {
            Skeleton userSkeleton = CurrentUserTracker.CurrentSkeleton;
            float    totalScore   = 0;

            if (userSkeleton != null)
            {
                Skeleton            techniqueSkeleton = TechniqueAvatar.CurSkeleton;
                ComparisonFrameData result            = Comparer.Compare(userSkeleton, techniqueSkeleton);

                UserAvatar.SetColor(result);
                totalScore = result.TotalScore;

                if (1 - totalScore < MIN_SCORE_THRESHOLD)
                {
                    Comparer.Curve = RelaxedCurveProvider.Curve;
                    CountdownTimer.SetRunning(true);
                }
                else
                {
                    Comparer.Curve = CurveProvider.Curve;
                    CountdownTimer.SetRunning(false);
                    CountdownTimer.Reset();
                    CountdownTimer.Text = "Into Position";
                }
            }

            ScoreBar.UpdateScore(totalScore);
        }
    }
Ejemplo n.º 2
0
    public void SetColor(ComparisonFrameData comparison)
    {
        foreach (KeyValuePair <JointType, float> resultScore in comparison.JointScores)
        {
            JointType type  = resultScore.Key;
            float     score = resultScore.Value;

            SetColor(type, new Color(1, score, score));
        }
    }
Ejemplo n.º 3
0
    void FixedUpdate()
    {
        ComparisonFrameData comparison = comparer.Compare(UserAvatar.CurSkeleton, TechniqueAvatar.CurSkeleton);

        UserAvatar.SetColor(comparison);

        float totalScore = comparison.TotalScore;

        //float totalScore = Mathf.Sqrt(comparison.JointScores.Values.Min());
        FrameScoreBar.UpdateScore(totalScore);
    }
Ejemplo n.º 4
0
    public override ComparisonFrameData Compare(Skeleton s1, Skeleton s2)
    {
        Dictionary <JointType, ScoreTracker> preliminaryScoreTrackers = new Dictionary <JointType, ScoreTracker>();
        ComparisonFrameData comparison = new ComparisonFrameData();

        foreach (JointType centerJoint in Enum.GetValues(typeof(JointType)).Cast <JointType>().ToArray())
        {
            JointType[] adjacentJoints = GetAdjacentJoints(centerJoint);
            if (adjacentJoints != null)
            {
                Vector3 adjacentA1 = s1.GetJoint(adjacentJoints[0]).ToVector3();
                Vector3 center1    = s1.GetJoint(centerJoint).ToVector3();
                Vector3 adjacentB1 = s1.GetJoint(adjacentJoints[1]).ToVector3();

                Vector3 adjacentA2 = s2.GetJoint(adjacentJoints[0]).ToVector3();
                Vector3 center2    = s2.GetJoint(centerJoint).ToVector3();
                Vector3 adjacentB2 = s2.GetJoint(adjacentJoints[1]).ToVector3();

                Vector3 a1 = center1 - adjacentB1;
                Vector3 b1 = adjacentA1 - center1;
                Vector3 c1 = adjacentA1 - adjacentB1;

                Vector3 a2 = center2 - adjacentB2;
                Vector3 b2 = adjacentA2 - center2;
                Vector3 c2 = adjacentA2 - adjacentB2;

                float angle1 = SolveForAngleC(a1.magnitude, b1.magnitude, c1.magnitude);
                float angle2 = SolveForAngleC(a2.magnitude, b2.magnitude, c2.magnitude);

                float firstRatio  = angle1 / angle2;
                float secondRatio = angle2 / angle1;

                float preliminary = Math.Min(firstRatio, secondRatio);
                float score       = curve.Evaluate(preliminary);

                UpdateScore(centerJoint, score, preliminaryScoreTrackers);
                foreach (JointType adjacentJoint in adjacentJoints)
                {
                    UpdateScore(adjacentJoint, score, preliminaryScoreTrackers);
                }
            }
        }

        foreach (KeyValuePair <JointType, ScoreTracker> scoreTracker in preliminaryScoreTrackers)
        {
            JointType    joint   = scoreTracker.Key;
            ScoreTracker tracker = scoreTracker.Value;

            comparison[joint] = tracker.AverageScore;
        }

        return(comparison);
    }
Ejemplo n.º 5
0
    public override ComparisonFrameData Compare(Skeleton s1, Skeleton s2)
    {
        ComparisonFrameData comparisonData = new ComparisonFrameData();

        Skeleton uniformSkeleton1 = UniformSkeleton(s1);
        Skeleton uniformSkeleton2 = UniformSkeleton(s2);

        Joint[] joints1 = uniformSkeleton1.Joints;
        Joint[] joints2 = uniformSkeleton2.Joints;

        for (int i = 0; i < joints1.Length; i++)
        {
            Joint j1 = joints1[i];
            Joint j2 = joints2[i];

            if (j1.Type != j2.Type)
            {
                throw new InvalidOperationException($"wrong type of joints being compared: {j1.Type} != {j2.Type}");
            }

            Vector3 v1 = j1.ToVector3();
            Vector3 v2 = j2.ToVector3();

            Vector3 diff        = v2 - v1;
            float   preliminary = diff.magnitude;

            #region Different preliminary implementations

            //float preliminary = Mathf.Atan(v2.sqrMagnitude/v1.sqrMagnitude);
            //float preliminary = Mathf.Clamp(diff.magnitude, 0, 1);
            //float preliminary = v1 == v2 ? 1.0f : Vector3.Dot(v1, v2);
            //float preliminary = v1 == v2 ? 1.0f : Vector3.Dot(v1, v2);

            #endregion

            //float score = curve.Evaluate(preliminary);
            float score = curve.Evaluate(1 - preliminary);
            if (preliminary > 1.0f)
            {
                Debug.Log($"{j1.Type} : {preliminary}");
            }

            comparisonData[j1.Type] = score;
        }

        return(comparisonData);
    }
Ejemplo n.º 6
0
    public void SetColor(ComparisonFrameData comparison)
    {
        if (training)
        {
            foreach (KeyValuePair <JointType, float> result in comparison.JointScores)
            {
                JointType type  = result.Key;
                float     score = result.Value;

                Color color;
                if (score < 0.5f)
                {
                    color = Color.Lerp(INCORRECT, MIDPOINT, score * 2);
                }
                else
                {
                    color = Color.Lerp(MIDPOINT, CORRECT, (score - 0.5f) * 2);
                }

                SetColor(type, color);
            }
        }
    }