GetJointOrientation() public method

public GetJointOrientation ( uint UserId, int joint, bool flip ) : Quaternion
UserId uint
joint int
flip bool
return Quaternion
Esempio n. 1
0
    private void FixedUpdate()
    {
        if (manager && manager.IsUserDetected())
        {
            long userId = manager.GetPrimaryUserID();

            if (manager.IsJointTracked(userId, (int)rightKnee))
            {
                Quaternion deltaRot = manager.GetJointOrientation(userId, (int)rightKnee, true) * Quaternion.Inverse(lastKneeRotation);
                Vector3    eulerRot = new Vector3(Mathf.DeltaAngle(0, deltaRot.eulerAngles.x),
                                                  Mathf.DeltaAngle(0, deltaRot.eulerAngles.y), Mathf.DeltaAngle(0, deltaRot.eulerAngles.z));

                angularVelocity  = eulerRot / Time.fixedDeltaTime;
                lastKneeRotation = manager.GetJointOrientation(userId, (int)rightKnee, false);
            }

            rayPos         = new Vector3(transform.position.x + 0.025f, transform.position.y - 0.075f, transform.position.z + 0.19f);
            footRay.origin = rayPos;

            RaycastHit hit;

            if (Physics.Raycast(footRay, out hit, 0.06f))
            {
                if (hit.transform.CompareTag("Ball"))
                {
                    hit.rigidbody.rotation = manager.GetJointOrientation(userId, (int)rightFoot, false);

                    Vector3 direction   = hit.rigidbody.transform.TransformDirection(manager.GetJointDirection(userId, (int)rightFoot, false, true));
                    Vector3 balVelocity = new Vector3(direction.x * angularVelocity.x, direction.y * angularVelocity.y, direction.z * angularVelocity.z);

                    if (balVelocity.y < 0)
                    {
                        balVelocity.y *= -1;
                    }

                    if (balVelocity.z < 0)
                    {
                        balVelocity.z *= -1;
                    }

                    Debug.Log(balVelocity);

                    hit.transform.GetComponent <FootBall>().SetVelocity(balVelocity);

                    /*if (balVelocity.y > 50)
                    *   balVelocity.y = 50;
                    *
                    *  if (balVelocity.z > 50)
                    *   balVelocity.z = 50;
                    *
                    *  balVelocity.y = Mathf.Clamp(balVelocity.y, 10f, 50f);
                    *  balVelocity.z = Mathf.Clamp(balVelocity.z, 10f, 50f);
                    *  Debug.Log(balVelocity);*/
                }
            }
        }
    }
Esempio n. 2
0
    // Apply the rotations tracked by kinect to the joints.
    protected void TransformBone(Int64 userId, KinectInterop.JointType joint, int boneIndex, bool flip)
    {
        Transform boneTransform = bones[boneIndex];

        if (boneTransform == null || kinectManager == null)
        {
            return;
        }
        int iJoint = (int)joint;

        if (iJoint < 0 || !kinectManager.IsJointTracked(userId, iJoint))
        {
            return;
        }

        // Get Kinect joint orientation
        Quaternion jointRotation = kinectManager.GetJointOrientation(userId, iJoint, flip);

        if (jointRotation == Quaternion.identity)
        {
            return;
        }

        // calculate the new orientation
        Quaternion newRotation = Kinect2AvatarRot(jointRotation, boneIndex);



        if (externalRootMotion)
        {
            newRotation = transform.rotation * newRotation;
        }

        // Smoothly transition to the new rotation
        if (smoothFactor != 0f)
        {
            if (flaten && boneIndex > 4)
            {
                newRotation.x = 0.0f;
                newRotation.y = 0.0f;
            }
            if (flaten && boneIndex < 5)
            {
                newRotation.x = 90.0f;
                newRotation.y = 90.0f;
            }
            boneTransform.rotation = Quaternion.Slerp(boneTransform.rotation, newRotation, smoothFactor * Time.deltaTime);
        }

        else
        {
            boneTransform.rotation = newRotation;
        }
    }
Esempio n. 3
0
    void Update()
    {
        KinectManager manager = KinectManager.Instance;

        if (manager && manager.IsInitialized())
        {
            int iJointIndex = (int)trackedJoint;

            if (manager.IsUserDetected())
            {
                long userId = manager.GetPrimaryUserID();

                if (manager.IsJointTracked(userId, iJointIndex))
                {
                    Quaternion qRotObject = manager.GetJointOrientation(userId, iJointIndex, !mirroredView);
                    qRotObject = initialRotation * qRotObject;

                    if (debugText)
                    {
                        Vector3 vRotAngles = qRotObject.eulerAngles;
                        debugText.text = string.Format("{0} - R({1:000}, {2:000}, {3:000})", trackedJoint, vRotAngles.x, vRotAngles.y, vRotAngles.z);
                    }

                    if (smoothFactor != 0f)
                    {
                        transform.rotation = Quaternion.Slerp(transform.rotation, qRotObject, smoothFactor * Time.deltaTime);
                    }
                    else
                    {
                        transform.rotation = qRotObject;
                    }
                }
            }
        }
    }
Esempio n. 4
0
    void Update()
    {
        if (kinectManager && kinectManager.IsInitialized())
        {
            long userId = kinectManager.GetUserIdByIndex(playerIndex);

            if (userId != 0 && kinectManager.IsJointTracked(userId, (int)playerJoint))
            {
                Vector3 headPos = kinectManager.GetJointPosition(userId, (int)playerJoint);
                if (invertedZMovement)
                {
                    headPos.z = -headPos.z;
                }

                headPos           += originPosition;
                transform.position = headPos + transform.forward * 0.1f;

                if (applyJointRotation)
                {
                    Quaternion headRot = kinectManager.GetJointOrientation(userId, (int)playerJoint, !mirroredView);

                    Vector3    jointDir    = kinectManager.GetJointDirection(userId, (int)playerJoint, mirroredView, invertedZMovement);
                    Quaternion invPitchRot = Quaternion.FromToRotation(jointDir, Vector3.up);
                    headRot = headRot * invPitchRot;

                    transform.rotation = Quaternion.Slerp(transform.rotation, initialHeadRot * headRot, smoothFactor * Time.deltaTime);
                }
            }
        }
    }
Esempio n. 5
0
    // Update is called once per frame
    void Update()
    {
        KinectManager manager = KinectManager.Instance;

        long userID = manager ? manager.GetUserIdByIndex(playerIndex) : 0;

        foreach (int joint in System.Enum.GetValues(typeof(JointType)))
        {
            if (manager.IsJointTracked(userID, joint))
            {
                jointPosQuater[joint].position = manager.GetJointPosition(userID, joint);
                jointPosQuater[joint].rotation = manager.GetJointOrientation(userID, joint, true);
            }
        }
        if (manager.IsUserTracked(userID))
        {
            TextNoPlayer.SetActive(false);
            for (int i = 0; i < gesturesList.Length; i++)
            {
                gesturesList[i].SearchForGesture();
            }
        }
        else
        {
            TextNoPlayer.SetActive(true);
        }
    }
Esempio n. 6
0
    // Apply the rotations tracked by kinect to the joints.
    protected void TransformBone(uint userId, KinectWrapper.NuiSkeletonPositionIndex joint, int boneIndex)
    {
        Transform boneTransform = bones[boneIndex];

        if (boneTransform == null || kinectManager == null)
        {
            return;
        }

        int iJoint = (int)joint;

        if (iJoint < 0)
        {
            return;
        }

        // Get Kinect joint orientation
        Quaternion jointRotation = kinectManager.GetJointOrientation(userId, iJoint, false);

        if (jointRotation == Quaternion.identity)
        {
            return;
        }

        boneTransform.rotation = Kinect2AvatarRot(jointRotation, boneIndex);
    }
Esempio n. 7
0
        private Quaternion RotateBone(OverlayObject oo, KinectManager kinectManager, FacetrackingManager facetrackingManager, long key)
        {
            int        iJointIndex = (int)oo.TrackedJointType;
            Quaternion qRotObject  = Quaternion.identity;

            if (iJointIndex == 3)        // if it's the head
            {
                if (facetrackingManager) // && facetrackingManager.IsFaceTrackingInitialized())
                {
                    qRotObject *= facetrackingManager.GetHeadRotation(key, bMirroredMovement: !RearProjection);

                    if (oo.BoneGameObject.FindChild("Jaw") != null)
                    {
                        Transform Jaw;
                        if (facetrackingManager.bGotAU && oo.BoneGameObject.FindChild("Jaw") != null)
                        {
                            Jaw = oo.BoneGameObject.FindChild("Jaw");
                            //  print("Jaw angle : " + facetrackingManager.dictAU[0] * JAWROTATEMULIPLIER);
                            Jaw.localRotation = Quaternion.AngleAxis(facetrackingManager.dictAU[0] * JAWROTATEMULIPLIER, Vector3.right);
                        }
                    }
                }
            }
            else // all joints not the head
            {
                qRotObject = kinectManager.GetJointOrientation(key, iJointIndex, flip: RearProjection);
                Vector3 rotAngles = qRotObject.eulerAngles - oo.InitialRotation.eulerAngles;
                qRotObject = Quaternion.Euler(rotAngles);
            }
            return(Quaternion.Slerp(oo.BoneGameObject.transform.rotation, qRotObject, smoothFactor * Time.deltaTime));
        }
Esempio n. 8
0
 // Update is called once per frame
 void Update()
 {
     if (enabled)
     {
         transform.rotation = kinman.GetJointOrientation(kinman.GetPrimaryUserID(), (int)KinectInterop.JointType.SpineShoulder, true);
     }
 }
Esempio n. 9
0
    // Apply the rotations tracked by kinect to the joints.
    protected void TransformBone(uint userId, KinectWrapper.NuiSkeletonPositionIndex joint, int boneIndex, bool flip)
    {
        Transform boneTransform = bones[boneIndex];

        if (boneTransform == null || kinectManager == null)
        {
            return;
        }

        int iJoint = (int)joint;

        if (iJoint < 0)
        {
            return;
        }

        // Get Kinect joint orientation
        Quaternion jointRotation = kinectManager.GetJointOrientation(userId, iJoint, flip);

        if (jointRotation == Quaternion.identity)
        {
            return;
        }

        // Smoothly transition to the new rotation
        Quaternion newRotation = Kinect2AvatarRot(jointRotation, boneIndex);

        //bodyCtrlData.jointRotation[boneIndex] = newRotation;
        kinectManager.setJointRotation(newRotation, boneIndex);
    }
Esempio n. 10
0
    void Update()
    {
        KinectManager manager = KinectManager.Instance;

        if (manager && manager.IsInitialized() && foregroundCamera)
        {
            //backgroundImage.renderer.material.mainTexture = manager.GetUsersClrTex();
            if (backgroundImage && (backgroundImage.texture == null))
            {
                backgroundImage.texture = manager.GetUsersClrTex();
            }

            // get the background rectangle (use the portrait background, if available)
            Rect backgroundRect             = foregroundCamera.pixelRect;
            PortraitBackground portraitBack = PortraitBackground.Instance;

            if (portraitBack && portraitBack.enabled)
            {
                backgroundRect = portraitBack.GetBackgroundRect();
            }

            // overlay the joint
            long userId = manager.GetUserIdByIndex(playerIndex);

            int iJointIndex = (int)trackedJoint;
            if (manager.IsJointTracked(userId, iJointIndex))
            {
                Vector3 posJoint = manager.GetJointPosColorOverlay(userId, iJointIndex, foregroundCamera, backgroundRect);

                if (posJoint != Vector3.zero)
                {
//					if(debugText)
//					{
//						debugText.text = string.Format("{0} - {1}", trackedJoint, posJoint);
//					}

                    if (overlayObject)
                    {
                        overlayObject.position = posJoint;

                        Quaternion rotJoint = manager.GetJointOrientation(userId, iJointIndex, !objFlipped);
                        rotJoint = initialRotation * rotJoint;

                        overlayObject.rotation = Quaternion.Slerp(overlayObject.rotation, rotJoint, smoothFactor * Time.deltaTime);
                    }
                }
            }
            else
            {
                // make the overlay object invisible
                if (overlayObject && overlayObject.position.z > 0f)
                {
                    Vector3 posJoint = overlayObject.position;
                    posJoint.z             = -10f;
                    overlayObject.position = posJoint;
                }
            }
        }
    }
Esempio n. 11
0
    private void updateJoints(KinectManager manager, uint userID)
    {
        allTrackedVisible = true;

        Vector3    userPosition = transform.position, jointPosition;
        Quaternion userRotation = transform.rotation, jointRotation;
        int        jointIndex;

        // update the local positions of the joints
        foreach (string joint in Tracked.Keys)
        {
            jointIndex = Array.IndexOf(jointNames, joint);

            if (!manager.IsJointTracked(userID, jointIndex) && Tracked[joint] != Head)
            {
                allTrackedVisible = false;
                Tracked[joint].gameObject.SetActive(false);
                continue;
            }

            jointPosition    = manager.GetJointPosition(userID, jointIndex) - userPosition;
            jointPosition.z *= -1;
            jointRotation    = manager.GetJointOrientation(userID, jointIndex, true) * userRotation;

            if (!Tracked[joint].gameObject.activeSelf)
            {
                Tracked[joint].transform.localPosition = jointPosition;
                Tracked[joint].transform.rotation      = jointRotation;
            }
            else
            {
                if ((Tracked[joint].transform.localPosition - jointPosition).magnitude < minimumPositionDelta)
                {
                    Tracked[joint].transform.localPosition = jointPosition;
                }
                else
                {
                    Tracked[joint].transform.localPosition = Vector3.Lerp(
                        Tracked[joint].transform.localPosition,
                        jointPosition,
                        Time.deltaTime * JointAdjustmentSpeed);
                }

                if (Quaternion.Angle(Tracked[joint].transform.rotation, jointRotation) < minimumRotationDelta)
                {
                    Tracked[joint].transform.rotation = jointRotation;
                }
                else
                {
                    Tracked[joint].transform.rotation = Quaternion.Slerp(
                        Tracked[joint].transform.rotation,
                        jointRotation,
                        Time.deltaTime * JointAdjustmentSpeed);
                }
            }
            Tracked[joint].gameObject.SetActive(true);
        }
    }
Esempio n. 12
0
    void Update()
    {
        KinectManager manager = KinectManager.Instance;

        if (manager && manager.IsInitialized() && foregroundCamera)
        {
            //backgroundImage.renderer.material.mainTexture = manager.GetUsersClrTex();
            if (backgroundImage && (backgroundImage.texture == null))
            {
                backgroundImage.texture = manager.GetUsersClrTex();
            }

            // get the background rectangle (use the portrait background, if available)
            Rect backgroundRect             = foregroundCamera.pixelRect;
            PortraitBackground portraitBack = PortraitBackground.Instance;

            if (portraitBack && portraitBack.enabled)
            {
                backgroundRect = portraitBack.GetBackgroundRect();
            }

            // overlay the joint
            for (int i = 0; i < trackedJoint.Length; i++)
            {
                int iJointIndex = (int)trackedJoint [i];

                if (manager.IsUserDetected())
                {
                    long userId = manager.GetUserIdByIndex(playerIndex);

                    if (manager.IsJointTracked(userId, iJointIndex))
                    {
                        Vector3 posJoint = manager.GetJointPosColorOverlay(userId, iJointIndex, foregroundCamera, backgroundRect);

                        if (posJoint != Vector3.zero)
                        {
//						if(debugText)
//						{
//							debugText.GetComponent<GUIText>().text = string.Format("{0} - {1}", trackedJoint, posJoint);
//						}

                            if (overlayObject[i])
                            {
                                overlayObject[i].position = posJoint;

                                Quaternion rotJoint = manager.GetJointOrientation(userId, iJointIndex, false);
                                rotJoint = initialRotation * rotJoint;

                                overlayObject[i].rotation = rotJoint;
                            }
                        }
                    }
                }
            }
        }
    }
Esempio n. 13
0
 void getJointRotation()
 {
     for (int i = 0; i < _numJoints; i++)
     {
         if (manager.IsJointTracked(UserId, i))
         {
             newRot[i] = manager.GetJointOrientation(UserId, i, false);
         }
     }
 }
Esempio n. 14
0
    // Apply the rotations tracked by kinect to the joints.
    protected virtual void TransformBone(uint userId, KinectWrapper.NuiSkeletonPositionIndex joint, int boneIndex, bool flip)
    {
        Transform boneTransform = bones[boneIndex];

        if (boneTransform == null || kinectManager == null)
        {
            return;
        }

        int iJoint = (int)joint;

        if (iJoint < 0)
        {
            return;
        }

        // Get Kinect joint orientation
        Quaternion jointRotation = kinectManager.GetJointOrientation(userId, iJoint, flip);

        if (jointRotation == Quaternion.identity)
        {
            return;
        }

        // Smoothly transition to the new rotation
        Quaternion newRotation = Kinect2AvatarRot(jointRotation, boneIndex);

        if (smoothFactor != 0f)
        {
            boneTransform.rotation = Quaternion.Slerp(boneTransform.rotation, newRotation, smoothFactor * Time.deltaTime);
        }
        else
        {
            boneTransform.rotation = newRotation;
        }

        Vector3 jointPosition = kinectManager.GetJointPosition(userId, iJoint);
        Vector3 newPosition   = Kinect2AvatarPos(jointPosition, true);

        if (avatarMotionMode == AvatarMotionMode.POSITION_ORIENTATION || avatarMotionMode == AvatarMotionMode.MORPHOLOGY_CALIBRATION)
        {
            if (smoothFactor != 0f)
            {
                boneTransform.position = Vector3.Lerp(boneTransform.position, newPosition, smoothFactor * Time.deltaTime);
            }
            else
            {
                boneTransform.position = newPosition;
            }
        }

        avatarToBodyAngleDiff[boneIndex]     = Quaternion.Angle(newRotation, boneTransform.rotation);
        avatarToBodyPositionDiff [boneIndex] = Vector3.Distance(newPosition, boneTransform.position);
    }
Esempio n. 15
0
    private void UpdateArms()
    {
        kinectUserID = kinectManager.GetUserIdByIndex(0);

        Vector3 rootPos = kinectManager.GetUserPosition(kinectUserID);

        Quaternion leftQuat = kinectManager.GetJointOrientation(kinectUserID, (int)KinectInterop.JointType.ElbowLeft, true);

        //leftQuat = leftQuat;
        leftQuat = Quaternion.Slerp(leftRoot.localRotation, leftQuat, smoothFactor * Time.deltaTime);
        leftRoot.localRotation = leftQuat;

        Quaternion rightQuat = kinectManager.GetJointOrientation(kinectUserID, (int)KinectInterop.JointType.ElbowRight, true);

        rightQuat = rightQuat * Quaternion.AngleAxis(angleFlipAmt, angleFlipDirection);
        rightQuat = Quaternion.Slerp(rightRoot.localRotation, rightQuat, smoothFactor * Time.deltaTime);
        rightRoot.localRotation = rightQuat;

        /******************************************************/

        Vector3 rightPos = kinectManager.GetJointPosition(kinectUserID, (int)KinectInterop.JointType.ElbowRight);

        rightPos.z = (rightPos.z * -1f) + rootPos.z;
        rightPos.x = rightPos.x - rootPos.x;
        rightPos.y = rightPos.y - rootPos.y;
        rightPos   = ((rightPos) * positionScale);
        rightPos   = Vector3.Lerp(rightRoot.localPosition, rightPos, smoothFactor * Time.deltaTime);
        rightRoot.localPosition = rightPos;

        Vector3 leftPos = kinectManager.GetJointPosition(kinectUserID, (int)KinectInterop.JointType.ElbowLeft);

        leftPos.z = (leftPos.z * -1f) + rootPos.z;
        leftPos.x = leftPos.x - rootPos.x;
        leftPos.y = leftPos.y - rootPos.y;
        leftPos   = ((leftPos) * positionScale);
        leftPos   = Vector3.Lerp(leftRoot.localPosition, leftPos, smoothFactor * Time.deltaTime);
        leftRoot.localPosition = leftPos;
    }
    // Apply the rotations tracked by kinect to the joints.
    protected void TransformBone(uint userId, KinectWrapper.NuiSkeletonPositionIndex joint, int boneIndex, bool flip)
    {
        Transform boneTransform = bones[boneIndex];

        if (boneTransform == null || kinectManager == null)
        {
            return;
        }

        int iJoint = (int)joint;

        if (iJoint < 0)
        {
            return;
        }

        // Get Kinect joint orientation
        Quaternion jointRotation       = kinectManager.GetJointOrientation(userId, iJoint, flip);
        Quaternion jointRotation_local = kinectManager.GetJointLocalOrientation(userId, iJoint, flip);

        if (jointRotation == Quaternion.identity)
        {
            return;
        }


        // Smoothly transition to the new rotation
        Quaternion newRotation = Kinect2AvatarRot(jointRotation_local, boneIndex);

        if (joint == KinectWrapper.NuiSkeletonPositionIndex.KneeLeft)
        {
            //Eklem_Degerleri.Sol_Diz = 360 - newRotation.eulerAngles[0];
        }
        else if (joint == KinectWrapper.NuiSkeletonPositionIndex.KneeRight)
        {
            Eklem_Degerleri.Sag_Diz = 360 - newRotation.eulerAngles[0];
        }

        //      newRotation = Quaternion.Euler(new Vector3(newRotation.eulerAngles[0], 0, 0));

        //      if (smoothFactor != 0f)
        //          boneTransform.rotation = Quaternion.Slerp(boneTransform.rotation, newRotation, smoothFactor * Time.deltaTime);
        //else
        //	boneTransform.rotation = newRotation;
    }
Esempio n. 17
0
    void Update()
    {
        KinectManager manager = KinectManager.Instance;

        if (manager && manager.IsInitialized())
        {
            //backgroundImage.renderer.material.mainTexture = manager.GetUsersClrTex();
            if (backgroundImage && (backgroundImage.texture == null))
            {
                backgroundImage.texture = manager.GetUsersClrTex();
            }

            int iJointIndex = (int)trackedJoint;

            if (manager.IsUserDetected())
            {
                long userId = manager.GetPrimaryUserID();

                if (manager.IsJointTracked(userId, iJointIndex))
                {
                    Vector3 posJoint = manager.GetJointPosColorOverlay(userId, iJointIndex, Camera.main, Camera.main.pixelRect);

                    if (posJoint != Vector3.zero)
                    {
//						if(debugText)
//						{
//							debugText.GetComponent<GUIText>().text = string.Format("{0} - {1}", trackedJoint, posJoint);
//						}

                        if (overlayObject)
                        {
                            //overlayObject.position = Vector3.Lerp(overlayObject.position, posJoint, smoothFactor * Time.deltaTime);
                            overlayObject.position = posJoint;

                            Quaternion rotJoint = manager.GetJointOrientation(userId, iJointIndex, false);
                            rotJoint = initialRotation * rotJoint;

                            //overlayObject.rotation = Quaternion.Slerp(overlayObject.rotation, rotJoint, smoothFactor * Time.deltaTime);
                            overlayObject.rotation = rotJoint;
                        }
                    }
                }
            }
        }
    }
Esempio n. 18
0
        void Update()
        {
            KinectManager kinectManager = KinectManager.Instance;

            if (kinectManager && kinectManager.IsInitialized())
            {
                if (sensorIndex >= 0 || kinectManager.IsUserDetected(playerIndex))
                {
                    ulong userId = sensorIndex < 0 ? kinectManager.GetUserIdByIndex(playerIndex) : (ulong)playerIndex;

                    if (sensorIndex >= 0 || kinectManager.IsJointTracked(userId, trackedJoint))
                    {
                        if (sensorIndex < 0)
                        {
                            qRotJoint = kinectManager.GetJointOrientation(userId, trackedJoint, !mirroredView);
                        }
                        else
                        {
                            qRotJoint = kinectManager.GetSensorJointOrientation(sensorIndex, (int)userId, trackedJoint, !mirroredView);
                        }

                        qRotJoint = initialRotation * qRotJoint;

                        if (debugText)
                        {
                            Vector3 vRotAngles = qRotJoint.eulerAngles;
                            debugText.text = string.Format("{0} - R({1:000}, {2:000}, {3:000})", trackedJoint,
                                                           vRotAngles.x, vRotAngles.y, vRotAngles.z);
                        }

                        if (smoothFactor != 0f)
                        {
                            transform.rotation = Quaternion.Slerp(transform.rotation, qRotJoint, smoothFactor * Time.deltaTime);
                        }
                        else
                        {
                            transform.rotation = qRotJoint;
                        }
                    }
                }
            }
        }
Esempio n. 19
0
    // Apply the rotations tracked by kinect to the joints.
    void TransformBone(Int64 userId, JointType joint, int boneIndex, bool flip)
    {
        if (joint.Equals(JointType.Head))
        {
            // bones[boneIndex].localRotation = cart.localRotation;
            return;
        }
        Transform boneTransform = bones[boneIndex];

        if (boneTransform == null || kinectManager == null)
        {
            return;
        }

        int iJoint = (int)joint;

        if (iJoint < 0 || !kinectManager.IsJointTracked(userId, iJoint))
        {
            return;
        }

        // Get Kinect joint orientation
        Quaternion jointRotation = kinectManager.GetJointOrientation(userId, iJoint, flip);

        if (jointRotation == Quaternion.identity)
        {
            return;
        }

        // Smoothly transition to the new rotation
        Quaternion newRotation = Kinect2AvatarRot(jointRotation, boneIndex);

        if (SmoothFactor != 0f)
        {
            boneTransform.rotation = Quaternion.Slerp(boneTransform.rotation, newRotation, SmoothFactor * Time.deltaTime);
        }
        else
        {
            boneTransform.rotation = newRotation;
        }
    }
Esempio n. 20
0
    /*ここはめっちゃ大事そう*/

    /*ボーンを動かしてるけど、どこで参照しているのやら
     * boneTransformがbones[index]の参照になっているんかな? あとで調べる*/
    /*その場合ここでunityちゃんのボーンの角度(位置も?)変えてる*/
    // Apply the rotations tracked by kinect to the joints.
    protected void TransformBone(uint userId, KinectWrapper.NuiSkeletonPositionIndex joint, int boneIndex, bool flip)
    {
        Transform boneTransform = bones[boneIndex];         //unityちゃんのボーンの位置とか入れる

        if (boneTransform == null || kinectManager == null) //ボーンなかったりkinectついてなかったらパス
        {
            return;
        }

        int iJoint = (int)joint;            //関節数をいれる  変換できんかったら−なるんかな?

        if (iJoint < 0)
        {
            return;
        }


        /*ここからメイン*/
        //ここでユーザーのある関節の角度ゲットしてる?
        Quaternion jointRotation = kinectManager.GetJointOrientation(userId, iJoint, flip);

        //取得できなかったらreturn
        if (jointRotation == Quaternion.identity)
        {
            return;
        }
        //ここでユーザーのさっきの情報使ってユーザーの回転角度ゲットしてる
        // Smoothly transition to the new rotation
        Quaternion newRotation = Kinect2AvatarRot(jointRotation, boneIndex);

        //前のボーンから今のボーンに移るまでの補完方法 smoothFactorが0以外なら計算時間かかるけどスムーズに動く
        if (smoothFactor != 0f)
        {
            boneTransform.rotation = Quaternion.Slerp(boneTransform.rotation, newRotation, smoothFactor * Time.deltaTime);
        }
        //ないなら強引に新しい位置にかえる
        else
        {
            boneTransform.rotation = newRotation;
        }
    }
Esempio n. 21
0
    // Apply the rotations tracked by kinect to the joints.
    protected void TransformBone(ulong userId, KinectCommon.NuiSkeletonPositionIndex joint, int boneIndex, bool flip)
    {
        //Debug.Log("Before Transforming bone for " + gameObject.name);
        Transform boneTransform = bones[boneIndex];

        if (boneTransform == null || kinectManager == null)
        {
            return;
        }

        //Debug.Log("Enter Transforming bone for " + gameObject.name);

        //Debug.Log("Transforming boneIndex " + boneIndex + " mapping to joint " + joint.ToString("g") + " transform ", boneTransform);

        int iJoint = (int)joint;

        if (iJoint < 0)
        {
            return;
        }

        // Get Kinect joint orientation
        Quaternion jointRotation = kinectManager.GetJointOrientation(userId, iJoint, flip);

        if (jointRotation == Quaternion.identity)
        {
            return;
        }

        // Smoothly transition to the new rotation
        Quaternion newRotation = Kinect2AvatarRot(jointRotation, boneIndex);

        if (smoothFactor != 0f)
        {
            boneTransform.rotation = Quaternion.Slerp(boneTransform.rotation, newRotation, smoothFactor * Time.deltaTime);
        }
        else
        {
            boneTransform.rotation = newRotation;
        }
    }
    // Apply the rotations tracked by kinect to the joints.
    protected void TransformBone(uint userId, KinectWrapper.NuiSkeletonPositionIndex joint, int boneIndex, bool flip)
    {
        if (Hooked)
        {
            return;
        }
        Transform boneTransform = bones[boneIndex];

        if (boneTransform == null || kinectManager == null)
        {
            return;
        }

        int iJoint = (int)joint;

        if (iJoint < 0)
        {
            return;
        }

        // Get Kinect joint orientation
        Quaternion jointRotation = kinectManager.GetJointOrientation(userId, iJoint, flip);

        if (jointRotation == Quaternion.identity)
        {
            return;
        }

        // Smoothly transition to the new rotation
        Quaternion newRotation = Kinect2AvatarRot(jointRotation, boneIndex);

        if (smoothFactor != 0f)
        {
            boneTransform.rotation = Quaternion.Slerp(boneTransform.rotation, newRotation, smoothFactor * Time.deltaTime);
        }
        else
        {
            boneTransform.rotation = newRotation;
        }
    }
        // returns the camera position, according to the camera eye type
        private Vector3 GetCameraPosition(ulong userId)
        {
            Vector3    headPos = kinectManager.GetJointPosition(userId, KinectInterop.JointType.Head);
            Quaternion headRot = initialHeadRot * kinectManager.GetJointOrientation(userId, KinectInterop.JointType.Head, false); // mirrored rotation

            Vector3 eyeOffset = Vector3.zero;

            switch (cameraType)
            {
            case CameraEyeType.LeftEye:
                eyeOffset = new Vector3(eyeDistance, 0f, 0f);
                eyeOffset = headRot * eyeOffset;
                break;

            case CameraEyeType.RightEye:
                eyeOffset = new Vector3(-eyeDistance, 0f, 0f);
                eyeOffset = headRot * eyeOffset;
                break;
            }

            return(headPos + eyeOffset);
        }
Esempio n. 24
0
    // Apply the rotations tracked by kinect to the joints.
    /// <summary>
    /// 将kinect追踪到关节处。
    /// </summary>
    /// <param name="userId">用户ID</param>
    /// <param name="joint">关节</param>
    /// <param name="boneIndex">骨骼索引</param>
    /// <param name="flip">是否镜像</param>
    void TransformBone(Int64 userId, KinectInterop.JointType joint, int boneIndex, bool flip)
    {
        Transform boneTransform = bones[boneIndex];

        if (boneTransform == null || kinectManager == null)
        {
            return;
        }

        int iJoint = (int)joint;

        if (iJoint < 0 || !kinectManager.IsJointTracked(userId, iJoint))
        {
            return;
        }

        // Get Kinect joint orientation
        //得到Kinect联合定位
        Quaternion jointRotation = kinectManager.GetJointOrientation(userId, iJoint, flip);

        if (jointRotation == Quaternion.identity)
        {
            return;
        }

        // Smoothly transition to the new rotation
        //平稳过渡到新的旋转
        Quaternion newRotation = Kinect2AvatarRot(jointRotation, boneIndex);

        if (smoothFactor != 0f)
        {
            boneTransform.rotation = Quaternion.Slerp(boneTransform.rotation, newRotation, smoothFactor * Time.deltaTime);
        }
        else
        {
            boneTransform.rotation = newRotation;
        }
    }
    void Update()
    {
        KinectManager manager = KinectManager.Instance;

        if (manager && manager.IsInitialized())
        {
            int iJointIndex = (int)trackedJoint;

            if (manager.IsUserDetected())
            {
                long userId = manager.GetPrimaryUserID();

                if (manager.IsJointTracked(userId, iJointIndex))
                {
                    Quaternion qRotObject = manager.GetJointOrientation(userId, iJointIndex, !mirroredView);
                    Vector3    vRotAngles = qRotObject.eulerAngles + initialRotation.eulerAngles;
                    qRotObject = Quaternion.Euler(vRotAngles);

                    transform.rotation = Quaternion.Slerp(transform.rotation, qRotObject, smoothFactor * Time.deltaTime);
                }
            }
        }
    }
Esempio n. 26
0
    // Aplicar la rotacion rastreada por el kinect a los joints.
    protected void TransformBone(uint userId, KinectWrapper.NuiSkeletonPositionIndex joint, int boneIndex, bool flip)
    {
        Transform boneTransform = bones[boneIndex];

        if (boneTransform == null || kinectManager == null)
        {
            return;
        }

        int iJoint = (int)joint;

        if (iJoint < 0)
        {
            return;
        }

        // Obtiene la orientacion de los Joints de kinect.
        Quaternion jointRotation = kinectManager.GetJointOrientation(userId, iJoint, flip);

        if (jointRotation == Quaternion.identity)
        {
            return;
        }

        // Transforma de manera suave (smooth) a la nueva rotación.
        Quaternion newRotation = Kinect2AvatarRot(jointRotation, boneIndex);

        //Camera.main.transform.rotation = jointRotation;
        if (smoothFactor != 0f)
        {
            boneTransform.rotation = Quaternion.Slerp(boneTransform.rotation, newRotation, smoothFactor * Time.deltaTime);
        }
        else
        {
            boneTransform.rotation = newRotation;
        }
    }
Esempio n. 27
0
    protected void TransformBone(uint userId, Kinect.JointType joint, int boneIndex)
    {
        bool flip = false;

        Transform boneTransform = bones[boneIndex];

        if (boneTransform == null || kinectManager == null)
        {
            return;
        }

        int iJoint = (int)joint;

        if (iJoint < 0)
        {
            return;
        }

        Quaternion jointRotation = kinectManager.GetJointOrientation(userId, iJoint, flip);

        if (jointRotation == Quaternion.identity)
        {
            return;
        }

        Quaternion newRotation = Kinect2AvatarRot(jointRotation, boneIndex);

        if (smoothFactor != 0f)
        {
            boneTransform.rotation = Quaternion.Slerp(boneTransform.rotation, newRotation, smoothFactor * Time.deltaTime);
        }
        else
        {
            boneTransform.rotation = newRotation;
        }
    }
Esempio n. 28
0
    // Update is called once per frame
    void Update()
    {
        KinectManager manager = KinectManager.Instance;

        // get 1st player
        uint playerID = manager != null?manager.GetPlayer1ID() : 0;

        if (playerID <= 0)
        {
            // reset the pointman position and rotation
            if (transform.position != initialPosition)
            {
                transform.position = initialPosition;
            }

            if (transform.rotation != initialRotation)
            {
                transform.rotation = initialRotation;
            }

            for (int i = 0; i < bones.Length; i++)
            {
                bones[i].gameObject.SetActive(true);

                bones[i].transform.localPosition = Vector3.zero;
                bones[i].transform.localRotation = Quaternion.identity;

                if (SkeletonLine)
                {
                    lines[i].gameObject.SetActive(false);
                }
            }

            return;
        }

        // set the user position in space
        Vector3 posPointMan = manager.GetUserPosition(playerID);

        posPointMan.z = !MirroredMovement ? -posPointMan.z : posPointMan.z;

        // store the initial position
        if (initialPosUserID != playerID)
        {
            initialPosUserID = playerID;
            initialPosOffset = transform.position - (MoveVertically ? posPointMan : new Vector3(posPointMan.x, 0, posPointMan.z));
        }

        transform.position = initialPosOffset + (MoveVertically ? posPointMan : new Vector3(posPointMan.x, 0, posPointMan.z));

        // update the local positions of the bones
        for (int i = 0; i < bones.Length; i++)
        {
            if (bones[i] != null)
            {
                int joint = MirroredMovement ? KinectWrapper.GetSkeletonMirroredJoint(i): i;

                if (manager.IsJointTracked(playerID, joint))
                {
                    bones[i].gameObject.SetActive(true);

                    Vector3 posJoint = manager.GetJointPosition(playerID, joint);
                    posJoint.z = !MirroredMovement ? -posJoint.z : posJoint.z;

                    Quaternion rotJoint = manager.GetJointOrientation(playerID, joint, !MirroredMovement);
                    rotJoint = initialRotation * rotJoint;

                    posJoint -= posPointMan;

                    if (MirroredMovement)
                    {
                        posJoint.x = -posJoint.x;
                        posJoint.z = -posJoint.z;
                    }

                    bones[i].transform.localPosition = posJoint;
                    bones[i].transform.rotation      = rotJoint;
                }
                else
                {
                    bones[i].gameObject.SetActive(false);
                }
            }
        }

        if (SkeletonLine)
        {
            for (int i = 0; i < bones.Length; i++)
            {
                bool bLineDrawn = false;

                if (bones[i] != null)
                {
                    if (bones[i].gameObject.activeSelf)
                    {
                        Vector3 posJoint = bones[i].transform.position;

                        int     parI      = parIdxs[i];
                        Vector3 posParent = bones[parI].transform.position;

                        if (bones[parI].gameObject.activeSelf)
                        {
                            lines[i].gameObject.SetActive(true);

                            //lines[i].SetVertexCount(2);
                            lines[i].SetPosition(0, posParent);
                            lines[i].SetPosition(1, posJoint);

                            bLineDrawn = true;
                        }
                    }
                }

                if (!bLineDrawn)
                {
                    lines[i].gameObject.SetActive(false);
                }
            }
        }
    }
Esempio n. 29
0
    void Update()
    {
        KinectManager manager = KinectManager.Instance;

        // get 1st player
        Int64 userID = manager ? manager.GetPrimaryUserID() : 0;

        if (userID <= 0)
        {
            // reset the pointman position and rotation
            if (transform.position != initialPosition)
            {
                transform.position = initialPosition;
            }

            if (transform.rotation != initialRotation)
            {
                transform.rotation = initialRotation;
            }

            for (int i = 0; i < bones.Length; i++)
            {
                bones[i].gameObject.SetActive(true);

                bones[i].transform.localPosition = Vector3.zero;
                bones[i].transform.localRotation = Quaternion.identity;

                if (LinePrefab)
                {
                    lines[i].gameObject.SetActive(false);
                }
            }

            return;
        }

        // set the position in space
        Vector3 posPointMan = manager.GetUserPosition(userID);

        posPointMan.z = !MirroredMovement ? -posPointMan.z : posPointMan.z;

        // store the initial position
        if (initialPosUserID != userID)
        {
            initialPosUserID = userID;
            initialPosOffset = transform.position - (MoveVertically ? posPointMan : new Vector3(posPointMan.x, 0, posPointMan.z));
        }

        transform.position = initialPosOffset + (MoveVertically ? posPointMan : new Vector3(posPointMan.x, 0, posPointMan.z));

        // update the local positions of the bones
        for (int i = 0; i < bones.Length; i++)
        {
            if (bones[i] != null)
            {
                int joint = (int)manager.GetJointAtIndex(
                    !MirroredMovement ? i : (int)KinectInterop.GetMirrorJoint((KinectInterop.JointType)i));
                if (joint < 0)
                {
                    continue;
                }

                if (manager.IsJointTracked(userID, joint))
                {
                    bones[i].gameObject.SetActive(true);

                    Vector3 posJoint = manager.GetJointPosition(userID, joint);
                    posJoint.z = !MirroredMovement ? -posJoint.z : posJoint.z;

                    Quaternion rotJoint = manager.GetJointOrientation(userID, joint, !MirroredMovement);

                    posJoint -= posPointMan;

                    if (MirroredMovement)
                    {
                        posJoint.x = -posJoint.x;
                        posJoint.z = -posJoint.z;
                    }

                    bones[i].transform.localPosition = posJoint;
                    bones[i].transform.localRotation = rotJoint;

                    if (LinePrefab)
                    {
                        lines[i].gameObject.SetActive(true);
                        Vector3 posJoint2 = bones[i].transform.position;

                        Vector3 dirFromParent = manager.GetJointDirection(userID, joint, false, false);
                        dirFromParent.z = !MirroredMovement ? -dirFromParent.z : dirFromParent.z;
                        Vector3 posParent = posJoint2 - dirFromParent;

                        //lines[i].SetVertexCount(2);
                        lines[i].SetPosition(0, posParent);
                        lines[i].SetPosition(1, posJoint2);
                    }

//					KinectInterop.BodyData bodyData = manager.GetUserBodyData(userID);
//					if(lineTLeft != null && bodyData.liTrackingID != 0 && joint == (int)JointType.HandLeft)
//					{
//						Vector3 leftTDir = bodyData.leftThumbDirection.normalized;
//						leftTDir.z = !MirroredMovement ? -leftTDir.z : leftTDir.z;
//
//						Vector3 posTStart = bones[i].transform.position;
//						Vector3 posTEnd = posTStart + leftTDir;
//
//						lineTLeft.SetPosition(0, posTStart);
//						lineTLeft.SetPosition(1, posTEnd);
//
//						if(lineFLeft != null)
//						{
//							Vector3 leftFDir = bodyData.leftThumbForward.normalized;
//							leftFDir.z = !MirroredMovement ? -leftFDir.z : leftFDir.z;
//
//							Vector3 posFStart = bones[i].transform.position;
//							Vector3 posFEnd = posTStart + leftFDir;
//
//							lineFLeft.SetPosition(0, posFStart);
//							lineFLeft.SetPosition(1, posFEnd);
//						}
//					}
//
//					if(lineTRight != null && bodyData.liTrackingID != 0 && joint == (int)JointType.HandRight)
//					{
//						Vector3 rightTDir = bodyData.rightThumbDirection.normalized;
//						rightTDir.z = !MirroredMovement ? -rightTDir.z : rightTDir.z;
//
//						Vector3 posTStart = bones[i].transform.position;
//						Vector3 posTEnd = posTStart + rightTDir;
//
//						lineTRight.SetPosition(0, posTStart);
//						lineTRight.SetPosition(1, posTEnd);
//
//						if(lineFRight != null)
//						{
//							Vector3 rightFDir = bodyData.rightThumbForward.normalized;
//							rightFDir.z = !MirroredMovement ? -rightFDir.z : rightFDir.z;
//
//							Vector3 posFStart = bones[i].transform.position;
//							Vector3 posFEnd = posTStart + rightFDir;
//
//							lineFRight.SetPosition(0, posFStart);
//							lineFRight.SetPosition(1, posFEnd);
//						}
//					}
                }
                else
                {
                    bones[i].gameObject.SetActive(false);

                    if (LinePrefab)
                    {
                        lines[i].gameObject.SetActive(false);
                    }
                }
            }
        }
    }
Esempio n. 30
0
    void Update()
    {
        KinectManager manager = KinectManager.Instance;

        // get 1st player
        Int64 userID = manager ? manager.GetUserIdByIndex(playerIndex) : 0;

        if (userID <= 0)
        {
            initialPosUserID = 0;
            initialPosOffset = Vector3.zero;
            initialPosSetY   = true;

            // reset the pointman position and rotation
            if (transform.position != initialPosition)
            {
                transform.position = initialPosition;
            }

            if (transform.rotation != initialRotation)
            {
                transform.rotation = initialRotation;
            }

            for (int i = 0; i < bones.Length; i++)
            {
                if (bones[i] != null)
                {
                    bones[i].gameObject.SetActive(false);

                    bones[i].transform.localPosition = Vector3.zero;
                    bones[i].transform.localRotation = Quaternion.identity;
                }

                if (lines[i] != null)
                {
                    lines[i].gameObject.SetActive(false);
                }
            }

            return;
        }

        // set the position in space
        Vector3 posPointMan = GetJointPosition(manager, userID, (int)KinectInterop.JointType.SpineBase);

        Vector3 posPointManWorld = new Vector3(posPointMan.x, posPointMan.y, invertedZMovement ? -posPointMan.z : posPointMan.z) + originPosition;
        Vector3 posPointManHips  = new Vector3(posPointMan.x, posPointMan.y, !mirroredMovement ? -posPointMan.z : posPointMan.z) + originPosition;

        // store the initial position
        if (initialPosUserID != userID)
        {
            initialPosUserID = userID;
            initialPosOffset = posPointManWorld;
        }

        if (!verticalMovement && !initialPosSetY)
        {
            float fFootPosY = 0f;
            if (manager.IsJointTracked(userID, (int)KinectInterop.JointType.FootLeft))
            {
                fFootPosY = GetJointPosition(manager, userID, (int)KinectInterop.JointType.FootLeft).y;
            }
            else if (manager.IsJointTracked(userID, (int)KinectInterop.JointType.FootRight))
            {
                fFootPosY = GetJointPosition(manager, userID, (int)KinectInterop.JointType.FootRight).y;
            }

            initialPosOffset.y = posPointManWorld.y - (fFootPosY + originPosition.y);
            initialPosSetY     = true;
        }

        Vector3 relPosUser = (posPointManWorld - initialPosOffset);

        //relPosUser.z = invertedZMovement ? -relPosUser.z : relPosUser.z;

        transform.position = initialPosOffset +
                             (verticalMovement ? relPosUser * moveRate : new Vector3(relPosUser.x, 0, relPosUser.z) * moveRate);

        if (manager.IsJointTracked(userID, (int)KinectInterop.JointType.Head))
        {
//			float fHeadPosY = GetJointPosition(manager, userID, (int)KinectInterop.JointType.Head).y + originPosition.y;
//			float halfHeight = Mathf.Abs(fHeadPosY - posPointManWorld.y);
//
//			CapsuleCollider collider = GetComponent<CapsuleCollider>();
//			if(collider != null)
//			{
//				collider.height = 2f * halfHeight;
//			}
        }

        // update the local positions of the bones
        for (int i = 0; i < bones.Length; i++)
        {
            if (bones[i] == null && bodyJoint != null)
            {
                if (!DrawLowerHalf && (i > 11))
                {
                    break;
                }

                bones[i] = Instantiate(bodyJoint) as GameObject;
                bones[i].transform.parent = transform;
                bones[i].name             = ((KinectInterop.JointType)i).ToString();

//				if(Array.IndexOf(ColliderJoints, i) >= 0)
//				{
//					bones[i].GetComponent<SphereCollider>().radius = 1f;
//				}
            }

            if (bones[i] != null)
            {
                int joint = !mirroredMovement ? i : (int)KinectInterop.GetMirrorJoint((KinectInterop.JointType)i);
                if (joint < 0)
                {
                    continue;
                }

                if (manager.IsJointTracked(userID, joint))
                {
                    bones[i].gameObject.SetActive(true);

                    Vector3 posJoint = GetJointPosition(manager, userID, joint);
                    posJoint.z = !mirroredMovement ? -posJoint.z : posJoint.z;

                    if (posJoint == Vector3.zero)
                    {
                        bones[i].gameObject.SetActive(false);
                        if (lines[i] != null)
                        {
                            lines[i].gameObject.SetActive(false);
                        }

                        continue;
                    }

                    posJoint += originPosition;
                    posJoint -= posPointManHips;

                    if (mirroredMovement)
                    {
                        posJoint.x = -posJoint.x;
                        posJoint.z = -posJoint.z;
                    }

                    Quaternion rotJoint = manager.GetJointOrientation(userID, joint, !mirroredMovement);
                    rotJoint = initialRotation * rotJoint;

                    bones[i].transform.localPosition = posJoint;
                    bones[i].transform.rotation      = rotJoint;

                    if (lines[i] == null && i > 0 && skeletonLine != null)
                    {
                        lines[i] = Instantiate(skeletonLine) as GameObject;
                        lines[i].transform.parent = transform;
                        lines[i].name             = ((KinectInterop.JointType)i).ToString() + "_Line";
                    }

                    if (lines[i] != null && i > 0)
                    {
                        int jParent = (int)manager.GetParentJoint((KinectInterop.JointType)joint);

                        if (manager.IsJointTracked(userID, jParent))
                        {
                            lines[i].gameObject.SetActive(true);

                            Vector3 posJoint2 = GetJointPosition(manager, userID, jParent);
                            posJoint2.z = !mirroredMovement ? -posJoint2.z : posJoint2.z;

                            if (posJoint2 == Vector3.zero)
                            {
                                lines[i].gameObject.SetActive(false);
                                continue;
                            }

                            posJoint2 += originPosition;
                            posJoint2 -= posPointManHips;

                            if (mirroredMovement)
                            {
                                posJoint2.x = -posJoint2.x;
                                posJoint2.z = -posJoint2.z;
                            }

                            Vector3 dirFromParent = posJoint - posJoint2;

                            lines [i].transform.localPosition = posJoint2 + dirFromParent / 2f;
                            lines [i].transform.up            = transform.rotation * dirFromParent.normalized;

                            Vector3 lineScale = lines [i].transform.localScale;
                            lines [i].transform.localScale = new Vector3(lineScale.x, dirFromParent.magnitude / 2f, lineScale.z);
                        }
                        else
                        {
                            lines[i].gameObject.SetActive(false);
                        }
                    }
                }
                else
                {
                    if (bones[i] != null)
                    {
                        bones[i].gameObject.SetActive(false);
                    }

                    if (lines[i] != null)
                    {
                        lines[i].gameObject.SetActive(false);
                    }
                }
            }
        }
    }