コード例 #1
0
    public void SetFrame(int frame)
    {
        if (recordingController.recordedClip.Count == 0)
        {
            for (JointType jt = JointType.SpineBase; jt <= JointType.ThumbRight; jt++)
            {
                _BoneMap[jt].transform.localPosition = noPlayerPosition;
            }
            lrc.RefreshPoints();
            player = -1;
            return;
        }
        Frame skeletonFrame = recordingController.recordedClip[frame];

        if (skeletonFrame == null)
        {
            return;
        }
        float currentAngle = (float)bodySourceManager.tiltRadians;
        float cos          = Mathf.Cos(currentAngle);
        float sin          = Mathf.Sin(currentAngle);

        CameraSpacePoint[] points = new CameraSpacePoint[skeletonFrame.bones.Length];
        int j = 0;

        ColorSpacePoint[] cPoints = new ColorSpacePoint[skeletonFrame.bones.Length];

        for (JointType jt = JointType.SpineBase; jt <= JointType.ThumbRight; jt++, j++)
        {
            MyVector pos  = skeletonFrame.bones[j].Clone();
            float    newY = pos.y * cos - pos.z * sin;
            float    newZ = pos.z * cos + pos.y * sin;
            pos.y     = newY - offset.y;
            pos.z     = newZ - offset.z;
            points[j] = Frame.MyVectorToCameraSpacePoint(pos);
        }



        KinectSensor.GetDefault().CoordinateMapper.MapCameraPointsToColorSpace(points, cPoints);
        j = 0;

        for (JointType jt = JointType.SpineBase; jt <= JointType.ThumbRight; jt++, j++)
        {
            Vector3 pos = Frame.ColorSpacePointToVector3(cPoints[j]);
            pos.x -= 960;
            pos.y  = 540 - pos.y;

            if (_BoneMap[jt] != null && pos.y != Mathf.Infinity)
            {
                _BoneMap[jt].transform.localPosition = Vector3.Lerp(_BoneMap[jt].transform.localPosition, pos, Time.deltaTime * lerpSpeed);
            }
        }
        lrc.RefreshPoints();
    }
コード例 #2
0
    void Update()
    {
        Body body = GetTrackedBody();

        if (body != null)
        {
            var shoulder = body.Joints[JointType.ShoulderLeft];
            var elbow    = body.Joints[JointType.ElbowRight];
            var wrist    = body.Joints[JointType.WristRight];

            /*  float currentAngle = (float)bodySourceManager.tiltRadians;
             * float cos = Mathf.Cos(currentAngle);
             * float sin = Mathf.Sin(currentAngle);*/
            CameraSpacePoint[] points = new CameraSpacePoint[body.Joints.Count];
            int j = 0;
            ColorSpacePoint[] cPoints = new ColorSpacePoint[body.Joints.Count];
            LegsPosition      = (Frame.CameraSpacePointToVector3(body.Joints[JointType.FootLeft].Position) + Frame.CameraSpacePointToVector3(body.Joints[JointType.FootRight].Position)) / 2f;
            SpineBasePosition = Frame.CameraSpacePointToVector3(body.Joints[JointType.SpineBase].Position);
            for (JointType jt = JointType.SpineBase; jt <= JointType.ThumbRight; jt++, j++)
            {
                points[j] = body.Joints[jt].Position;
            }
            KinectSensor.GetDefault().CoordinateMapper.MapCameraPointsToColorSpace(points, cPoints);
            j = 0;
            for (JointType jt = JointType.SpineBase; jt <= JointType.ThumbRight; jt++, j++)
            {
                //Vector3 pos = Frame.CameraSpacePointToVector3(body.Joints[jt].Position);
                Vector3 pos = Frame.ColorSpacePointToVector3(cPoints[j]);
                pos.x -= 960;
                pos.y  = 540 - pos.y;

                /*  float newY = pos.y * cos + pos.z * sin;
                 * float newZ = pos.z * cos - pos.y * sin;
                 * pos.y = newY;
                 * pos.z = newZ;*/
                if (pos.y != Mathf.Infinity)
                {
                    _BoneMap[jt].transform.localPosition = Vector3.Lerp(_BoneMap[jt].transform.localPosition, pos, lerpSpeed * Time.deltaTime);
                }
            }
        }
        else
        {
            for (JointType jt = JointType.SpineBase; jt <= JointType.ThumbRight; jt++)
            {
                _BoneMap[jt].transform.localPosition = startPosition;
            }
        }
        lrc.RefreshPoints();
    }