예제 #1
0
    public void RefreshSkeletonData(Avatar.Body body)
    {
        for (JointType jt = JointType.SpineBase; jt <= JointType.ThumbRight; jt++)
        {
            Avatar.Joint srcJoint = body.Joints[jt];
            Avatar.Joint tgtJoint = null;

            if (_BoneMap.ContainsKey(jt))
            {
                tgtJoint = body.Joints[_BoneMap[jt]];
            }
            Transform jointObj = this.transform.Find(jt.ToString());
            jointObj.localPosition = ScalePosition(srcJoint.Position);

            LineRenderer lr = jointObj.GetComponent <LineRenderer>();
            if (tgtJoint != null)
            {
                lr.SetPosition(0, jointObj.localPosition);
                lr.SetPosition(1, ScalePosition(tgtJoint.Position));
                lr.startColor = GetColorForState(srcJoint.TrackingState);
                lr.endColor   = GetColorForState(tgtJoint.TrackingState);
            }
            else
            {
                lr.enabled = false;
            }
        }
    }
예제 #2
0
    private Avatar.Body GetMovingMedianData()
    {
        Dictionary <JointType, Avatar.Joint> medianJoints = new Dictionary <JointType, Avatar.Joint>();

        for (JointType jt = 0; jt <= JointType.ThumbRight; jt++)
        {
            medianJoints[jt]               = new Avatar.Joint();
            medianJoints[jt].JointType     = BodySamples[MaxSamples / 2].Joints[jt].JointType;
            medianJoints[jt].Position      = BodySamples[MaxSamples / 2].Joints[jt].Position;
            medianJoints[jt].Rotation      = BodySamples[MaxSamples / 2].Joints[jt].Rotation;
            medianJoints[jt].TrackingState = BodySamples[MaxSamples / 2].Joints[jt].TrackingState;
        }
        return(new Avatar.Body(medianJoints));
    }
예제 #3
0
    private Avatar.Body GetMovingAverageData()
    {
        Dictionary <JointType, Avatar.Joint> avgJoints = new Dictionary <JointType, Avatar.Joint>();

        for (int i = BodySamples.Count - 1; i >= 0; i--)
        {
            for (JointType jt = 0; jt <= JointType.ThumbRight; jt++)
            {
                if (avgJoints.ContainsKey(jt))
                {
                    avgJoints[jt].Position += BodySamples[i].Joints[jt].Position;

                    Quaternion avgRot    = avgJoints[jt].Rotation;
                    Quaternion sampleRot = BodySamples[i].Joints[jt].Rotation;
                    avgJoints[jt].Rotation = new Quaternion(
                        avgRot.x + sampleRot.x,
                        avgRot.y + sampleRot.y,
                        avgRot.z + sampleRot.z,
                        avgRot.w + sampleRot.w);
                }
                else
                {
                    avgJoints[jt]           = new Avatar.Joint();
                    avgJoints[jt].Position  = BodySamples[i].Joints[jt].Position;
                    avgJoints[jt].Rotation  = BodySamples[i].Joints[jt].Rotation;
                    avgJoints[jt].JointType = BodySamples[i].Joints[jt].JointType;
                }

                //tracking state
                if (i == 0)
                {
                    avgJoints[jt].TrackingState = BodySamples[i].Joints[jt].TrackingState;
                }
            }
        }
        for (JointType jt = JointType.SpineBase; jt <= JointType.ThumbRight; jt++)
        {
            avgJoints[jt].Position = avgJoints[jt].Position / (float)MaxSamples;
            Quaternion avgRot = avgJoints[jt].Rotation;
            float      k      = 1.0f / Mathf.Sqrt(avgRot.x * avgRot.x + avgRot.y * avgRot.y + avgRot.z * avgRot.z + avgRot.w * avgRot.w);
            avgJoints[jt].Rotation = new Quaternion(avgRot.x * k, avgRot.y * k, avgRot.z * k, avgRot.w * k);
        }

        return(new Avatar.Body(avgJoints));
    }