GetJointPosition() public method

public GetJointPosition ( uint UserId, int joint ) : Vector3
UserId uint
joint int
return Vector3
    public void FloatWithArm()
    {
        KinectInterop.JointType handJoint     = KinectInterop.JointType.HandRight;
        KinectInterop.JointType shoulderJoint = KinectInterop.JointType.ShoulderRight;
        KinectManager           manager       = KinectManager.Instance;

        if (manager && manager.IsInitialized())
        {
            if (manager.IsUserDetected())
            {
                long    userId = manager.GetPrimaryUserID();
                Vector3 handPos, shoulderPos;
                if (manager.IsJointTracked(userId, (int)shoulderJoint))
                {
                    shoulderPos = manager.GetJointPosition(userId, (int)shoulderJoint);
                    if (manager.IsJointTracked(userId, (int)handJoint))
                    {
                        handPos   = manager.GetJointPosition(userId, (int)handJoint);
                        armEffect = new Vector3(-3 * (handPos.x - shoulderPos.x), 3 * (handPos.y - shoulderPos.y), -3 * (handPos.z - shoulderPos.z));
                        ParticleSystem.VelocityOverLifetimeModule module = particle.velocityOverLifetime;
                    }
                }
            }
        }
    }
Esempio n. 2
0
    void Update()
    {
        KinectManager manager = KinectManager.Instance;

        if (manager && manager.IsInitialized())
        {
            if (manager.IsUserDetected())
            {
                uint userId = manager.GetPlayer1ID();
                if (manager.IsJointTracked(userId, (int)KinectWrapper.NuiSkeletonPositionIndex.ShoulderLeft) &&
                    manager.IsJointTracked(userId, (int)KinectWrapper.NuiSkeletonPositionIndex.ShoulderRight))
                {
                    Vector3 posLeftShoulder  = manager.GetJointPosition(userId, (int)KinectWrapper.NuiSkeletonPositionIndex.ShoulderLeft);
                    Vector3 posRightShoulder = manager.GetJointPosition(userId, (int)KinectWrapper.NuiSkeletonPositionIndex.ShoulderRight);
                    posLeftShoulder.z  = -posLeftShoulder.z;
                    posRightShoulder.z = -posRightShoulder.z;

                    Vector3 dirLeftRight = posRightShoulder - posLeftShoulder;
                    dirLeftRight -= Vector3.Project(dirLeftRight, Vector3.up);
                    Quaternion rotationShoulders = Quaternion.FromToRotation(Vector3.right, dirLeftRight);

                    transform.rotation = rotationShoulders;
                }
            }
        }
    }
    void Update()
    {
        KinectManager manager = KinectManager.Instance;

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

                if (manager.IsJointTracked(userId, (int)KinectInterop.JointType.ShoulderLeft) &&
                    manager.IsJointTracked(userId, (int)KinectInterop.JointType.ShoulderRight))
                {
                    Vector3 posLeftShoulder  = manager.GetJointPosition(userId, (int)KinectInterop.JointType.ShoulderLeft);
                    Vector3 posRightShoulder = manager.GetJointPosition(userId, (int)KinectInterop.JointType.ShoulderRight);

                    posLeftShoulder.z  = -posLeftShoulder.z;
                    posRightShoulder.z = -posRightShoulder.z;

                    Vector3 dirLeftRight = posRightShoulder - posLeftShoulder;
                    dirLeftRight -= Vector3.Project(dirLeftRight, Vector3.up);

                    Quaternion rotationShoulders = Quaternion.FromToRotation(Vector3.right, dirLeftRight);

                    transform.rotation = rotationShoulders;
                }
            }
        }
    }
Esempio n. 4
0
    private bool GetUserBodyHeight(KinectManager manager, float scaleFactor, ref float height)
    {
        height = 0f;

        if (manager && manager.IsJointTracked(currentUserId, (int)KinectInterop.JointType.HipLeft) &&
            manager.IsJointTracked(currentUserId, (int)KinectInterop.JointType.HipRight) &&
            manager.IsJointTracked(currentUserId, (int)KinectInterop.JointType.ShoulderLeft) &&
            manager.IsJointTracked(currentUserId, (int)KinectInterop.JointType.ShoulderRight))
        {
            //Vector3 posHipCenter = manager.GetJointPosition(currentUserId, (int)KinectInterop.JointType.SpineBase);
            Vector3 posHipLeft   = manager.GetJointPosition(currentUserId, (int)KinectInterop.JointType.HipLeft);
            Vector3 posHipRight  = manager.GetJointPosition(currentUserId, (int)KinectInterop.JointType.HipRight);
            Vector3 posHipCenter = (posHipLeft + posHipRight) / 2;

            Vector3 posShoulderLeft   = manager.GetJointPosition(currentUserId, (int)KinectInterop.JointType.ShoulderLeft);
            Vector3 posShoulderRight  = manager.GetJointPosition(currentUserId, (int)KinectInterop.JointType.ShoulderRight);
            Vector3 posShoulderCenter = (posShoulderLeft + posShoulderRight) / 2;

            height = (posShoulderCenter.y - posHipCenter.y) * scaleFactor;

            return(true);
        }

        return(false);
    }
Esempio n. 5
0
        public bool OnHandInteracting(long userID)
        {
            KinectManager kinectManager = KinectManager.Instance;

            if (handIndex == 1)
            {
                //左手处理
                handInfo.IsIboxValid = kinectManager.GetLeftHandInteractionBox(userID, ref handInfo.IboxLeftBotBack, ref handInfo.IboxRightTopFront, handInfo.IsIboxValid);

                handInfo.handPos = kinectManager.GetJointPosition(userID, (int)KinectInterop.JointType.HandLeft);

                handInfo.IsHandInteracting = (handInfo.handPos.x >= (handInfo.IboxLeftBotBack.x - 1.0f)) && (handInfo.handPos.x <= (handInfo.IboxRightTopFront.x + 0.5f)) &&
                                             (handInfo.handPos.y >= (handInfo.IboxLeftBotBack.y - 0.1f)) && (handInfo.handPos.y <= (handInfo.IboxRightTopFront.y + 0.7f)) &&
                                             (handInfo.IboxLeftBotBack.z >= handInfo.handPos.z) && (handInfo.IboxRightTopFront.z * 0.8f <= handInfo.handPos.z);
            }
            else
            {
                //右手处理
                handInfo.IsIboxValid = kinectManager.GetRightHandInteractionBox(userID, ref handInfo.IboxLeftBotBack, ref handInfo.IboxRightTopFront, handInfo.IsIboxValid);

                handInfo.handPos = kinectManager.GetJointPosition(userID, (int)KinectInterop.JointType.HandRight);

                handInfo.IsHandInteracting = (handInfo.handPos.x >= (handInfo.IboxLeftBotBack.x - 0.5f)) && (handInfo.handPos.x <= (handInfo.IboxRightTopFront.x + 1.0f)) &&
                                             (handInfo.handPos.y >= (handInfo.IboxLeftBotBack.y - 0.1f)) && (handInfo.handPos.y <= (handInfo.IboxRightTopFront.y + 0.7f)) &&
                                             (handInfo.IboxLeftBotBack.z >= handInfo.handPos.z) && (handInfo.IboxRightTopFront.z * 0.8f <= handInfo.handPos.z);
            }

            return(handInfo.IsHandInteracting);
        }
Esempio n. 6
0
        /// <summary>
        /// Create new player data
        /// </summary>
        /// <param name="pi_UserId">User Id of the player</param>
        /// <param name="pi_Handedness">Selected handedness</param>
        public BodyData(long pi_UserId, Handedness pi_Handedness)
        {
            // Fetch kinect manager
            KinectManager manager = KinectManager.Instance;

            // Manager is needed
            if (manager == null)
            {
                return;
            }
            // Init data
            Handedness        = pi_Handedness;
            CompletedGestures = new Dictionary <KinectGestures.Gestures, List <float> >();
            // Calculate and fetch necessary data
            HeadPos   = manager.GetJointPosition(pi_UserId, (int)KinectInterop.JointType.Head);
            HipPos    = manager.GetJointPosition(pi_UserId, (int)KinectInterop.JointType.SpineBase);
            AnklesPos = (manager.GetJointPosition(pi_UserId, (int)KinectInterop.JointType.AnkleRight) +
                         manager.GetJointPosition(pi_UserId, (int)KinectInterop.JointType.AnkleRight)) / 2.0f;
            Width = Vector3.Distance(manager.GetJointPosition(pi_UserId, (int)KinectInterop.JointType.ShoulderLeft),
                                     manager.GetJointPosition(pi_UserId, (int)KinectInterop.JointType.ShoulderRight));
            Height    = Vector3.Distance(HeadPos, AnklesPos);
            ArmLength = (Vector3.Distance(manager.GetJointPosition(pi_UserId, (int)KinectInterop.JointType.ShoulderLeft),
                                          manager.GetJointPosition(pi_UserId, (int)KinectInterop.JointType.HandLeft)) +
                         Vector3.Distance(manager.GetJointPosition(pi_UserId, (int)KinectInterop.JointType.ShoulderRight),
                                          manager.GetJointPosition(pi_UserId, (int)KinectInterop.JointType.HandRight))) / 2.0f;
        }
    void Update()
    {
        if (scalerInited && kinectManager && kinectManager.IsInitialized())
        {
            // get the plane rectangle to be used for object overlay
            if (backgroundPlane && !planeRectSet)
            {
                planeRectSet = true;

                planeRect.width  = 10f * Mathf.Abs(backgroundPlane.localScale.x);
                planeRect.height = 10f * Mathf.Abs(backgroundPlane.localScale.z);
                planeRect.x      = backgroundPlane.position.x - planeRect.width / 2f;
                planeRect.y      = backgroundPlane.position.y - planeRect.height / 2f;
            }

            long userId = kinectManager.GetUserIdByIndex(playerIndex);

            // check user distance and hand positions
            if (userId != 0 && minUserDistance > 0f)
            {
                Vector3 userPos = kinectManager.GetUserPosition(userId);

                bool    lHandTracked = kinectManager.IsJointTracked(userId, (int)KinectInterop.JointType.WristLeft);
                Vector3 lHandPos     = lHandTracked ? kinectManager.GetJointPosition(userId, (int)KinectInterop.JointType.WristLeft) : Vector3.zero;

                bool    rHandTracked = kinectManager.IsJointTracked(userId, (int)KinectInterop.JointType.WristRight);
                Vector3 rHandPos     = rHandTracked ? kinectManager.GetJointPosition(userId, (int)KinectInterop.JointType.WristRight) : Vector3.zero;

                if (userPos.z < minUserDistance ||
                    !lHandTracked || (lHandPos.z - userPos.z) <= -0.3f ||
                    !rHandTracked || (rHandPos.z - userPos.z) <= -0.3f)
                {
                    // don't scale the model
                    userId = 0;
                    //Debug.Log ("Avatar scaling skipped.");
                }
            }

            if (userId != currentUserId)
            {
                currentUserId = userId;

                if (userId != 0)
                {
                    GetUserBodySize(true, true, true);

//					if (fixModelHipsAndShoulders)
//						FixJointsBeforeScale();
                    ScaleAvatar(0f, true);
                }
            }
        }

        if (currentUserId != 0 && continuousScaling)
        {
            GetUserBodySize(true, true, true);
            ScaleAvatar(smoothFactor, false);
        }
    }
Esempio n. 8
0
 private void getPosJoint(uint userId)
 {
     posJoint[0] = manager.GetJointPosition(userId, 8);  //Shoulder_Right
     posJoint[1] = manager.GetJointPosition(userId, 11); //Hand_Right
     posJoint[2] = manager.GetJointPosition(userId, 4);  //Shoulder_Left
     posJoint[3] = manager.GetJointPosition(userId, 7);  //Hand_Left
     posJoint[4] = manager.GetJointPosition(userId, 0);  //Hip_Center
 }
Esempio n. 9
0
    public static Vector3 GetVectorBetween(JointIndex joint1, JointIndex joint2, KinectManager manager)//순서 중요 | joint1->joint2
    {
        uint playerID = manager != null?manager.GetPlayer1ID() : 0;

        Vector3 pos1 = manager.GetJointPosition(playerID, (int)joint1);
        Vector3 pos2 = manager.GetJointPosition(playerID, (int)joint2);

        return(pos2 - pos1);
    }
Esempio n. 10
0
    Vector3 GetVectorBetween(JointIndex joint1, JointIndex joint2)//순서 중요
    {
        uint playerID = manager != null?manager.GetPlayer1ID() : 0;

        Vector3 pos1 = manager.GetJointPosition(playerID, (int)joint1);
        Vector3 pos2 = manager.GetJointPosition(playerID, (int)joint2);

        return(pos2 - pos1);
    }
Esempio n. 11
0
    // Update is called once per frame
    void Update()
    {
        // update Kinect interaction
        if (kinectManager != null && kinectManager.IsInitialized() &&
            interactionManager != null && interactionManager.IsInteractionInited())
        {
            playerUserID = kinectManager.GetUserIdByIndex(playerIndex);

            if (playerUserID != 0)
            {
                rightFootPos = kinectManager.GetJointPosition(playerUserID, (int)KinectInterop.JointType.FootRight);
                leftFootPos  = kinectManager.GetJointPosition(playerUserID, (int)KinectInterop.JointType.FootLeft);

                //Debug.Log(rightFootPos);
                //Debug.Log(leftFootPos);

                if (calibracionConfirmada)
                {
                    //Primero miramos si está dentro del cuadro el pie derecho
                    bool pieDentro = EstaDentroDelCuadro(rightFootPos);

                    if (infoText != null)
                    {
                        infoText.text = "Pie derecho dentro del cuadro: " + pieDentro;
                    }

                    if (pieDentro)
                    {
                        //x=>ancho y=>alto  z=0 (no se usa)
                        Vector3 coordenadasPantalla = GetPosicionEnPantalla(rightFootPos);
                        //Asignamos la posición a la imagen del pie
                        playerFootRight.rectTransform.anchoredPosition3D = coordenadasPantalla;
                    }

                    //Despues miramos el izquierdo
                    pieDentro = EstaDentroDelCuadro(leftFootPos);

                    if (infoText != null)
                    {
                        infoText.text = infoText.text + "\nPie izquierdo dentro del cuadro: " + pieDentro;
                    }

                    if (pieDentro)
                    {
                        //x=>ancho y=>alto  z=0 (no se usa)
                        Vector3 coordenadasPantalla = GetPosicionEnPantalla(leftFootPos);
                        //Asignamos la posición a la imagen del pie
                        playerFootLeft.rectTransform.anchoredPosition3D = coordenadasPantalla;
                    }

                    //if (camera != null)
                    // CheckCollision(Vector3.zero);
                }
            }
        }
    }
Esempio n. 12
0
        private float AdultTorsoQuotient(KinectManager kinectManager, long key)
        {
            int   spineBaseIndex = 0;
            int   headIndex      = 3;
            float torsoLength    = (kinectManager.GetJointPosition(key, headIndex) - kinectManager.GetJointPosition(key, spineBaseIndex)).magnitude;
            float boneScale      = torsoLength - MINTORSOLENGTH;

            boneScale /= TORSOLENGTHRANGE;
            return(boneScale);
        }
Esempio n. 13
0
    // Update is called once per frame
    void Update()
    {
        KinectManager kinectManager = KinectManager.Instance;

        leftHandPos      = kinectManager.GetJointPosition(playerUserID, (int)KinectInterop.JointType.HandLeft);
        rightHandPos     = kinectManager.GetJointPosition(playerUserID, (int)KinectInterop.JointType.HandRight);
        headPos          = kinectManager.GetJointPosition(playerUserID, (int)KinectInterop.JointType.Head);
        joinPosText.text =
            "Left Hand Pos: " + "X: " + leftHandPos.x + " Y: " + leftHandPos.y + " Z: " + leftHandPos.z + System.Environment.NewLine +
            "Right Hand Pos: " + "X: " + rightHandPos.x + " Y: " + rightHandPos.y + " Z: " + rightHandPos.z + System.Environment.NewLine +
            "Head Pos: " + "X: " + headPos.x + " Y: " + headPos.y + " Z: " + headPos.z;
    }
Esempio n. 14
0
    string Whichfoot()
    {
        KinectManager manager = KinectManager.Instance;

        if (manager.GetJointPosition(1, 19).z > manager.GetJointPosition(1, 15).z)
        {
            return("left foot");
        }
        else
        {
            return("right foot");
        }
    }
Esempio n. 15
0
    public bool FixJointsBeforeScale()
    {
        Animator      animatorComponent = GetComponent <Animator>();
        KinectManager manager           = KinectManager.Instance;

        if (animatorComponent && modelBodyHeight > 0f && bodyHeight > 0f)
        {
            Transform hipCenter = animatorComponent.GetBoneTransform(HumanBodyBones.Hips);
            if ((hipCenter.localScale - Vector3.one).magnitude > 0.01f)
            {
                return(false);
            }

            Transform leftUpperLeg  = animatorComponent.GetBoneTransform(HumanBodyBones.LeftUpperLeg);
            Transform rightUpperLeg = animatorComponent.GetBoneTransform(HumanBodyBones.RightUpperLeg);

            Transform leftUpperArm  = animatorComponent.GetBoneTransform(HumanBodyBones.LeftUpperArm);
            Transform rightUpperArm = animatorComponent.GetBoneTransform(HumanBodyBones.RightUpperArm);

            if (leftUpperArm && rightUpperArm && leftUpperLeg && rightUpperLeg)
            {
                if (manager && manager.IsJointTracked(currentUserId, (int)KinectInterop.JointType.ShoulderLeft) &&
                    manager.IsJointTracked(currentUserId, (int)KinectInterop.JointType.ShoulderRight) &&
                    manager.IsJointTracked(currentUserId, (int)KinectInterop.JointType.HipLeft) &&
                    manager.IsJointTracked(currentUserId, (int)KinectInterop.JointType.HipRight))
                {
                    Vector3 posHipCenter = manager.GetJointPosition(currentUserId, (int)KinectInterop.JointType.SpineBase);

                    Vector3 posHipLeft  = manager.GetJointPosition(currentUserId, (int)KinectInterop.JointType.HipLeft);
                    Vector3 posHipRight = manager.GetJointPosition(currentUserId, (int)KinectInterop.JointType.HipRight);

                    Vector3 posShoulderLeft  = manager.GetJointPosition(currentUserId, (int)KinectInterop.JointType.ShoulderLeft);
                    Vector3 posShoulderRight = manager.GetJointPosition(currentUserId, (int)KinectInterop.JointType.ShoulderRight);

                    SetupUnscaledJoint(hipCenter, leftUpperLeg, posHipCenter, (!mirroredAvatar ? posHipLeft : posHipRight), modelBodyHeight, bodyHeight);
                    SetupUnscaledJoint(hipCenter, rightUpperLeg, posHipCenter, (!mirroredAvatar ? posHipRight : posHipLeft), modelBodyHeight, bodyHeight);

                    SetupUnscaledJoint(hipCenter, leftUpperArm, posHipCenter, (!mirroredAvatar ? posShoulderLeft : posShoulderRight), modelBodyHeight, bodyHeight);
                    SetupUnscaledJoint(hipCenter, rightUpperArm, posHipCenter, (!mirroredAvatar ? posShoulderRight : posShoulderLeft), modelBodyHeight, bodyHeight);

                    // recalculate model joints
                    Start();

                    return(true);
                }
            }
        }

        return(false);
    }
Esempio n. 16
0
    //set the speed value = offset / time = (currentPos - originPos) / time
    private void updatePositionInfo_(Int64 userID)
    {
        if (kinectManager != null)
        {
            float temp1 = currentLeftFootJointPosition;
            float temp2 = currentRightFootJointPosition;
            float temp3 = currentShouldJointPositon;
            //update left foot joint
            if (kinectManager.IsJointTracked(userID, (int)KinectInterop.JointType.FootLeft))
            {
                // output the joint position for easy tracking
                currentLeftFootJointPosition = Kinect2AvatarPos(kinectManager.GetJointPosition(userID, (int)KinectInterop.JointType.FootLeft), true).y;
            }
            //update right foot joint
            if (kinectManager.IsJointTracked(userID, (int)KinectInterop.JointType.FootRight))
            {
                // output the joint position for easy tracking
                currentRightFootJointPosition = Kinect2AvatarPos(kinectManager.GetJointPosition(userID, (int)KinectInterop.JointType.FootRight), true).y;
            }

            //update head joint
            if (kinectManager.IsJointTracked(userID, (int)KinectInterop.JointType.Head))
            {
                // output the joint position for easy tracking
                currentHeadJointPostion = Kinect2AvatarPos(kinectManager.GetJointPosition(userID, (int)KinectInterop.JointType.Head), true).y;
            }

            //update right knee joint
            if (kinectManager.IsJointTracked(userID, (int)KinectInterop.JointType.KneeRight))
            {
                // output the joint position for easy tracking
                currentKneeJointPositon = Kinect2AvatarPos(kinectManager.GetJointPosition(userID, (int)KinectInterop.JointType.KneeRight), true).y;
            }

            if (kinectManager.IsJointTracked(userID, (int)(KinectInterop.JointType.SpineMid)))
            {
                currentShouldJointPositon = Kinect2AvatarPos(kinectManager.GetJointPosition(userID, (int)KinectInterop.JointType.SpineMid), true).x;
            }

            //since refresh  rate = 30/s, thus divide 1 / 30 = * 30;
            currentLeftFootJointSpeed  = (currentLeftFootJointPosition - originLeftFootJointPosition) * 30;
            currentRightFootJointSpeed = (currentRightFootJointPosition - originRightFootJointPosition) * 30;

            originLeftFootJointPosition  = temp1;
            originRightFootJointPosition = temp2;
            originShouldJointPosition    = temp3;
        }
    }
Esempio n. 17
0
    // Update is called once per frame
    void Update()
    {
        // get the joint position
        if (manager == null)
        {
            manager = KinectManager.Instance;
        }

        if (manager && manager.IsInitialized())
        {
            if (manager.IsUserDetected())
            {
                uint userId = manager.GetPlayer1ID();

                if (manager.IsJointTracked(userId, (int)joint))
                {
                    // output the joint position for easy tracking
                    Vector3 jointPos = manager.GetJointPosition(userId, (int)joint);
                    //aumentar tamanho do movimento e rapides
                    jointPos.Set(jointPos.x * 2, jointPos.y * 2, jointPos.z);
                    transform.localPosition = jointPos;
                }
            }
        }
    }
Esempio n. 18
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);
        }
    }
    void Update()
    {
        headPosValid = false;

        if (kinectManager && kinectManager.IsInitialized())
        {
            long userId = kinectManager.GetUserIdByIndex(playerIndex);

            if (kinectManager.IsUserTracked(userId) && kinectManager.IsJointTracked(userId, (int)KinectInterop.JointType.Head))
            {
                jointHeadPos    = kinectManager.GetJointPosition(userId, (int)KinectInterop.JointType.Head);
                headRelPosition = jointHeadPos - screenCenterPos;
                headPosValid    = true;

                if (initialRelPos == Vector3.zero)
                {
                    initialRelPos = headRelPosition;
                }

                if (statusText)
                {
                    string sStatusMsg = string.Format("Head position: {0}\nRelative to screen: {1}", jointHeadPos, headRelPosition);
                    statusText.text = sStatusMsg;
                }
            }
            else
            {
                initialRelPos = Vector3.zero;
            }
        }
    }
Esempio n. 20
0
    private void FixedUpdate()
    {
        //assigning the type of joint based on user selection
        if (ThirdGameMenu.tempHand == 0)
        {
            joint = KinectInterop.JointType.HandLeft;
        }
        else
        {
            joint = KinectInterop.JointType.HandRight;
        }
        KinectManager kinectManager = KinectManager.Instance;

        //checking is the kinect is connected and intialized
        if (kinectManager && kinectManager.IsInitialized())
        {
            //checking for the users presence
            if (kinectManager.IsUserDetected())
            {
                long userID = kinectManager.GetPrimaryUserID();
                if (kinectManager.IsJointTracked(userID, (int)joint))
                {
                    jointPos = kinectManager.GetJointPosition(userID, (int)joint);
                    //scaling the ratio to fit the screen size
                    jointPos.z         = 0;
                    jointPos.x        *= 30;
                    jointPos.y        *= 20;
                    jointPos.y        -= 20;
                    transform.position = jointPos;
                }
            }
        }
    }
Esempio n. 21
0
        void Update()
        {
            KinectManager kinectManager = KinectManager.Instance;

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

                if (kinectManager.IsUserDetected(playerIndex))
                {
                    ulong userId = kinectManager.GetUserIdByIndex(playerIndex);

                    if (kinectManager.IsJointTracked(userId, iJointIndex))
                    {
                        if (sensorTransform != null)
                        {
                            vPosJoint = kinectManager.GetJointKinectPosition(userId, iJointIndex, true);
                        }
                        else
                        {
                            vPosJoint = kinectManager.GetJointPosition(userId, iJointIndex);
                        }

                        vPosJoint.z = invertedZMovement ? -vPosJoint.z : vPosJoint.z;


                        if (sensorTransform)
                        {
                            vPosJoint = sensorTransform.TransformPoint(vPosJoint);
                        }

                        if (userId != currentUserId)
                        {
                            currentUserId     = userId;
                            initialUserOffset = vPosJoint;
                        }

                        Vector3 vPosObject = relToInitialPos ? initialPosition + (vPosJoint - initialUserOffset) : vPosJoint;

                        if (debugText)
                        {
                            debugText.text = string.Format("{0} - ({1:F3}, {2:F3}, {3:F3})", trackedJoint,
                                                           vPosObject.x, vPosObject.y, vPosObject.z);
                        }

                        //if(moveTransform)
                        {
                            if (smoothFactor != 0f)
                            {
                                transform.position = Vector3.Lerp(transform.position, vPosObject, smoothFactor * Time.deltaTime);
                            }
                            else
                            {
                                transform.position = vPosObject;
                            }
                        }
                    }
                }
            }
        }
Esempio n. 22
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);
                }
            }
        }
    }
    void Update()
    {
        if (isSaving)
        {
            // create the file, if needed
            if (!File.Exists(saveFilePath))
            {
                using (StreamWriter writer = File.CreateText(saveFilePath))
                {
                    // csv file header
                    string sLine = "time,joint,pos_x,pos_y,poz_z";
                    writer.WriteLine(sLine);
                }
            }

            // check the start time
            if (saveStartTime < 0f)
            {
                saveStartTime = Time.time;
            }
        }

        // get the joint position
        KinectManager manager = KinectManager.Instance;

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

                foreach (int joint in Enum.GetValues(typeof(KinectInterop.JointType)))
                {
                    if (manager.IsJointTracked(userId, (int)joint))
                    {
                        // output the joint position for easy tracking
                        Vector3 jointPos = manager.GetJointPosition(userId, joint);
                        jointPosition = jointPos;

                        if (isSaving)
                        {
                            if ((secondsToSave == 0f) || ((Time.time - saveStartTime) <= secondsToSave))
                            {
#if !UNITY_WSA
                                using (StreamWriter writer = File.AppendText(saveFilePath))
                                {
                                    string sLine = string.Format("{0:F3},{1},{2:F3},{3:F3},{4:F3}", Time.time, ((KinectInterop.JointType)joint).ToString(), jointPos.x, jointPos.y, jointPos.z);
                                    writer.WriteLine(sLine);
                                }
#else
                                string sLine = string.Format("{0:F3},{1},{2:F3},{3:F3},{4:F3}", Time.time, ((KinectInterop.JointType)joint).ToString(), jointPos.x, jointPos.y, jointPos.z);
                                Debug.Log(sLine);
#endif
                            }
                        }
                    }
                }
            }
        }
    }
Esempio n. 24
0
        // returns body joint position
        private Vector3 GetJointPosition(ulong userId, int joint)
        {
            Vector3 posJoint = Vector3.zero;

            if (sensorTransform)
            {
                posJoint = kinectManager.GetSensorJointKinectPosition(sensorIndex, playerIndex, joint, true);

                if (referencePose == ReferencePose.ColorCameraPose)
                {
                    KinectInterop.SensorData sensorData = kinectManager.GetSensorData(sensorIndex);

                    if (sensorData != null)
                    {
                        Vector3 spaceScale = sensorData.sensorSpaceScale;
                        float   u2mScale   = sensorData.unitToMeterFactor;
                        float   m2uScale   = 1f / u2mScale;

                        posJoint = new Vector3(posJoint.x * spaceScale.x * m2uScale, posJoint.y * spaceScale.y * m2uScale, posJoint.z * spaceScale.z * m2uScale);
                        posJoint = kinectManager.SensorTransformPoint(sensorIndex, sensorData.depth2ColorExtr, posJoint);
                        posJoint = new Vector3(posJoint.x * spaceScale.x * u2mScale, posJoint.y * spaceScale.y * u2mScale, posJoint.z * spaceScale.z * u2mScale);
                    }
                }
            }
            else
            {
                posJoint = kinectManager.GetJointPosition(userId, joint);
            }

            return(posJoint);
        }
    // gets the joint position in space
    private Vector3 GetJointPosition(KinectManager manager, int joint)
    {
        Vector3 vPosJoint = Vector3.zero;

        if (manager.IsJointTracked(currentUserId, joint))
        {
            if (foregroundCamera)
            {
                // 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();
                }

                // get the color overlay position
                vPosJoint = manager.GetJointPosColorOverlay(currentUserId, joint, foregroundCamera, backgroundRect);
            }

//			else
            if (vPosJoint == Vector3.zero)
            {
                vPosJoint = manager.GetJointPosition(currentUserId, joint);
            }
        }

        return(vPosJoint);
    }
    // Moves the avatar in 3D space - pulls the tracked position of the spine and applies it to root.
    // Only pulls positional, not rotational.
    protected void MoveAvatar(uint UserID)
    {
        if (Hooked)
        {
            return;
        }
        if (bodyRoot == null || kinectManager == null || Hooked)
        {
            return;
        }
        if (!kinectManager.IsJointTracked(UserID, (int)KinectWrapper.NuiSkeletonPositionIndex.HipCenter))
        {
            return;
        }

        // Get the position of the body and store it.
        Vector3 trans = kinectManager.GetUserPosition(UserID);

        HipPos = kinectManager.GetJointPosition(UserID, 0);

        // If this is the first time we're moving the avatar, set the offset. Otherwise ignore it.
        if (!offsetCalibrated)
        {
            offsetCalibrated = true;

            xOffset = !mirroredMovement ? trans.x * moveRate : -trans.x * moveRate;
            yOffset = trans.y * moveRate;
            zOffset = -trans.z * moveRate;

            if (offsetRelativeToSensor)
            {
                Vector3 cameraPos = Camera.main.transform.position;

                float   yRelToAvatar = (offsetNode != null ? offsetNode.transform.position.y : transform.position.y) - cameraPos.y;
                Vector3 relativePos  = new Vector3(trans.x * moveRate, yRelToAvatar, trans.z * moveRate);
                Vector3 offsetPos    = cameraPos + relativePos;

                if (offsetNode != null)
                {
                    offsetNode.transform.position = offsetPos;
                }
                else
                {
                    transform.position = offsetPos;
                }
            }
        }

        // Smoothly transition to the new position
        Vector3 targetPos = Kinect2AvatarPos(trans, verticalMovement);

        if (smoothFactor != 0f)
        {
            bodyRoot.localPosition = Vector3.Lerp(bodyRoot.localPosition, targetPos, smoothFactor * Time.deltaTime);
        }
        else
        {
            bodyRoot.localPosition = targetPos;
        }
    }
Esempio n. 27
0
    void Update()
    {
        if (kinectManager && kinectManager.IsInitialized())
        {
            long userId = kinectManager.GetUserIdByIndex(playerIndex);

            if (kinectManager.IsUserTracked(userId) && kinectManager.IsJointTracked(userId, (int)KinectInterop.JointType.SpineBase))
            {
                Vector3 userPos = kinectManager.GetJointPosition(userId, (int)KinectInterop.JointType.SpineBase);

                if (userPos.x >= -limitLeftRight && userPos.x <= limitLeftRight)
                {
                    // calculate the relative position in the movie
                    float relPos = (userPos.x + limitLeftRight) / (2f * limitLeftRight);
                    currentFrame = Mathf.RoundToInt(relPos * (numberOfFrames - 1));

                    if (statusText)
                    {
                        statusText.text = string.Format("X-Pos: {0:F2}, RelPos: {1:F3}, Frame: {2}", userPos.x, relPos, currentFrame);
                    }
                }
            }

            // add here code to display the frame with 'currentFrame' number
            // ...
        }
    }
Esempio n. 28
0
        /// <summary>
        /// Assigns the positions of each joints based on Kinect data.
        /// </summary>
        public void GetAllJointsPosition()
        {
            LeftHandPos  = manager.GetJointPosition(manager.GetPrimaryUserID(), leftHandIndex);
            RightHandPos = manager.GetJointPosition(manager.GetPrimaryUserID(), rightHandIndex);

            LeftElbowPos  = manager.GetJointPosition(manager.GetPrimaryUserID(), leftElbowIndex);
            RightElbowPos = manager.GetJointPosition(manager.GetPrimaryUserID(), rightElbowIndex);

            LeftShoulderPos  = manager.GetJointPosition(manager.GetPrimaryUserID(), leftShoulderIndex);
            RightShoulderPos = manager.GetJointPosition(manager.GetPrimaryUserID(), rightShoulderIndex);

            hipCenterPos      = manager.GetJointPosition(manager.GetPrimaryUserID(), hipCenterIndex);
            ShoulderCenterPos = manager.GetJointPosition(manager.GetPrimaryUserID(), shoulderCenterIndex);

            LeftHipPos  = manager.GetJointPosition(manager.GetPrimaryUserID(), leftHipIndex);
            RightHipPos = manager.GetJointPosition(manager.GetPrimaryUserID(), rightHipIndex);
        }
Esempio n. 29
0
    private bool GetUserBoneLength(KinectManager manager, KinectInterop.JointType baseJoint, KinectInterop.JointType endJoint, float scaleFactor, ref float length)
    {
        length = 0f;

        if (manager && manager.IsJointTracked(currentUserId, (int)baseJoint) &&
            manager.IsJointTracked(currentUserId, (int)endJoint))
        {
            Vector3 vPos1 = manager.GetJointPosition(currentUserId, (int)baseJoint);
            Vector3 vPos2 = manager.GetJointPosition(currentUserId, (int)endJoint);

            length = (vPos2 - vPos1).magnitude * scaleFactor;

            return(true);
        }

        return(false);
    }
    void Update()
    {
        if (manager == null || !manager.IsInitialized())
        {
            return;
        }

        // get user texture
        if (GetComponent <Renderer>().material.mainTexture == null)
        {
            BackgroundRemovalManager backManager = BackgroundRemovalManager.Instance;
            GetComponent <Renderer>().material.mainTexture = backManager ? (Texture)sensorData.depth2ColorTexture : (Texture)manager.GetUsersLblTex();
        }

        // get kinect-to-world matrix
        kinectToWorld = manager.GetKinectToWorldMatrix();

        if (playerIndex >= 0)
        {
            long lastUserId = userId;
            userId = manager.GetUserIdByIndex(playerIndex);

            userBodyIndex = (byte)manager.GetBodyIndexByUserId(userId);
            if (userBodyIndex == 255)
            {
                userBodyIndex = 222;
            }

            // get user mesh position
            userMeshPos = manager.GetJointKinectPosition(userId, (int)KinectInterop.JointType.SpineBase);

            if (!mirroredMovement)
            {
                userMeshPos.x = -userMeshPos.x;
            }

            userMeshPos = kinectToWorld.MultiplyPoint3x4(userMeshPos);              // convert to world coords

            // set transform position
            Vector3 newUserPos = manager.GetJointPosition(userId, (int)KinectInterop.JointType.SpineBase) + originPosition;

            if (invertedZMovement)
            {
                newUserPos.z = -newUserPos.z;
            }

            transform.position = lastUserId != 0 && smoothFactor != 0f ? Vector3.Lerp(transform.position, newUserPos, smoothFactor * Time.deltaTime) : newUserPos;
        }
        else
        {
            userId        = 0;
            userBodyIndex = 255;
            userMeshPos   = Vector3.zero;
        }

        // update the mesh
        UpdateMesh();
    }
    // Use this for initialization
    void Start()
    {
        // キネクトマネージャーの取得
        manager = KinectManager.Instance;

        // リズムカウントの配列を初期化
        rhythmTimes = new Queue<float>(rhythmCalcNum);

        float initRhythm = 60.0f / initBPM;
        for (int i = 0; i < rhythmTimes.Count; i++) {
            rhythmTimes.Enqueue(initRhythm);
        }

        checkObjectPosY = new Queue<float>(checkObjectPosYNum);
        // チェックオブジェクトの高さ検出に関する初期化

        // 初期位置で配列を埋める
        long userId = manager.GetUserIdByIndex (0);
        Vector3 pos = manager.GetJointPosition (userId, (int)checkBodyType);
    }
    // Update is called once per frame
    void Update()
    {
        km = KinectManager.Instance;
        string trackedJointsString = "Tracked Joints:";
        if (km != null) {
            if (km.IsUserDetected()) {
                uint userId = km.GetPlayer1ID();
                /*trackedJointsString += "\nchecking joints";
                if(km.IsJointTracked(userId, (int)rightHand))
                    trackedJointsString += "\nRight hand";
                if(km.IsJointTracked(userId, (int)rightWrist))
                    trackedJointsString += "\nRight wrist";
                if(km.IsJointTracked(userId, (int)centreHip))
                    trackedJointsString += "\nCentre Hip";
                if(km.IsJointTracked(userId, (int)leftShoulder))
                    trackedJointsString += "\nLeft shoulder";
                if(km.IsJointTracked(userId, (int)centreShoulder))
                    trackedJointsString += "\nCentre shoulder";
                if(km.IsJointTracked(userId, (int)rightShoulder))
                    trackedJointsString += "\nRight shoulder";
                trackedJointsString += "\ndone checking joints";*/

                if (km.IsJointTracked(userId, (int)rightHand) && km.IsJointTracked(userId, (int)rightShoulder))
                    wristVector = km.GetJointPosition(userId, (int)rightHand) - km.GetJointPosition(userId, (int)rightShoulder);
                if (km.IsJointTracked(userId, (int)rightShoulder) && km.IsJointTracked(userId, (int)leftShoulder))
                    shouldersVector = km.GetJointPosition(userId, (int)rightShoulder) - km.GetJointPosition(userId, (int)leftShoulder);
                if (km.IsJointTracked(userId, (int)centreShoulder) && km.IsJointTracked(userId, (int)centreHip))
                    backVector = km.GetJointPosition(userId, (int)centreShoulder) - km.GetJointPosition(userId, (int)centreHip);

                //GramSchmidt Orthonormal Space
                Vector3 e2 = backVector.normalized;
                Vector3 e1 = (shouldersVector - Vector3.Dot (shouldersVector,e2) * e2).normalized;

                wristVectorInPlane = new Vector2(Vector3.Dot(e1, wristVector), Vector3.Dot(e2, wristVector));

            }
        }
        trackedJointsText.text = trackedJointsString;
        CheckPointingTopRight();
    }
Esempio n. 33
0
    private bool GetUserBodyHeight(KinectManager manager, float scaleFactor, ref float height)
    {
        height = 0f;

        if(manager && manager.IsJointTracked(currentUserId, (int)KinectInterop.JointType.HipLeft) &&
           manager.IsJointTracked(currentUserId, (int)KinectInterop.JointType.HipRight) &&
           manager.IsJointTracked(currentUserId, (int)KinectInterop.JointType.ShoulderLeft) &&
           manager.IsJointTracked(currentUserId, (int)KinectInterop.JointType.ShoulderRight))
        {
            //Vector3 posHipCenter = manager.GetJointPosition(currentUserId, (int)KinectInterop.JointType.SpineBase);
            Vector3 posHipLeft = manager.GetJointPosition(currentUserId, (int)KinectInterop.JointType.HipLeft);
            Vector3 posHipRight = manager.GetJointPosition(currentUserId, (int)KinectInterop.JointType.HipRight);
            Vector3 posHipCenter = (posHipLeft + posHipRight) / 2;

            Vector3 posShoulderLeft = manager.GetJointPosition(currentUserId, (int)KinectInterop.JointType.ShoulderLeft);
            Vector3 posShoulderRight = manager.GetJointPosition(currentUserId, (int)KinectInterop.JointType.ShoulderRight);
            Vector3 posShoulderCenter = (posShoulderLeft + posShoulderRight) / 2;

            height = (posShoulderCenter.y - posHipCenter.y) * scaleFactor;

            return true;
        }

        return false;
    }
Esempio n. 34
0
    private bool GetUserBoneLength(KinectManager manager, KinectInterop.JointType baseJoint, KinectInterop.JointType endJoint, float scaleFactor, ref float length)
    {
        length = 0f;

        if(manager && manager.IsJointTracked(currentUserId, (int)baseJoint) &&
           manager.IsJointTracked(currentUserId, (int)endJoint))
        {
            Vector3 vPos1 = manager.GetJointPosition(currentUserId, (int)baseJoint);
            Vector3 vPos2 = manager.GetJointPosition(currentUserId, (int)endJoint);

            length = (vPos2 - vPos1).magnitude * scaleFactor;

            return true;
        }

        return false;
    }
Esempio n. 35
0
    // Update is called once per frame
    void Update()
    {
        initText.text = noUser + straightKnees + inRange + groundedFeet;

        manager = KinectManager.Instance;
        long userID = manager ? manager.GetUserIdByIndex (0) : 0;
        if (userID == 0)
        {
            noUser = "******";
            return;
        }
        else
            noUser = "******";

        // Joints
        bottomSpine = manager.GetJointPosition (userID, 0);
        bottomHead = manager.GetJointPosition (userID, 2);
        leftHip = manager.GetJointPosition (userID, 12);
        leftKnee = manager.GetJointPosition (userID, 13);
        leftFoot = manager.GetJointPosition (userID, 15);
        rightHip = manager.GetJointPosition (userID, 16);
        rightKnee = manager.GetJointPosition (userID, 17);
        rightFoot = manager.GetJointPosition (userID, 19);

        LegAngles();
        LowestFoot();

        // check distance from the sensor
        if (bottomSpine.z > 2.0f)
        {
            inRange = "Too far!\n";
            distanceBool = false;
        }
        else if (bottomSpine.z < 1.25f)
        {
            inRange = "Too close!\n";
            distanceBool = false;
        }
        else
        {
            distanceBool = true;
            inRange = "\n";
        }

        // check for straight legs
        if ((leftLegAngle < 165.0f) || (rightLegAngle < 165.0f) || (leftUp < 155.0f) || (rightUp < 155.0f))
        {
            straightKnees = "Stand up straight!\n";
            angleBool = false;
        }
        else
        {
            angleBool = true;
            straightKnees = "\n";
        }

        // check for feet on ground
        if (Mathf.Abs (leftFoot.y - rightFoot.y) > 0.05f)
        {
            groundedFeet = "Keep both feet grounded!\n";
            groundedBool = false;
        }
        else
        {
            groundedBool = true;
            groundedFeet = "\n";
        }

        if (distanceBool && angleBool && groundedBool && !coroutineStarted)
        {
            coroutineStarted = true;
            StartCoroutine(InitCount());
        }
    }
 // Update is called once per frame
 void Update()
 {
     kinect = KinectManager.Instance;
     if (!kinectInterpreter.useGamepad) {
         isDraggingLeft = false;
         isDraggingRight = false;
         isDraggingUp = false;
         isDraggingDown = false;
         if (canDrag && HandIsGrabbing (kinect)) {
             if (!wasDragging) {
                 dragStartPos = (Vector2)(kinect.GetJointPosition (userId, (int)handJoint));
                 controller.OnHandClosed (userId);
             }
             wasDragging = true;
             Vector2 dragVector = (Vector2)(kinect.GetJointPosition (userId, (int)handJoint)) - dragStartPos;
             float dragTan = Mathf.Abs (dragVector.x / dragVector.y);
             if (dragTan < tan15 || dragTan > tan75) {
                 int steps = Mathf.FloorToInt (dragVector.magnitude / dragStepDistance);
                 if (steps > 0) {
                     steps = Mathf.Min (steps, maxDragSteps);
                     if (Time.time - lastDragTime > dragBaseRepeatTime / steps) {
                         lastDragTime = Time.time;
                         if (dragVector.x > dragVector.y && dragVector.x > -(dragVector.y)) {
                             isDraggingRight = true;
                         } else if (dragVector.x < dragVector.y && dragVector.x < -(dragVector.y)) {
                             isDraggingLeft = true;
                         } else if (dragVector.y > dragVector.x && dragVector.y > -(dragVector.x)) {
                             isDraggingUp = true;
                         } else if (dragVector.y < dragVector.x && dragVector.y < -(dragVector.x)) {
                             isDraggingDown = true;
                         }
                     }
                 }
             }
         } else if (wasDragging) {
             wasDragging = false;
             controller.OnHandOpened (userId);
         }
     } else {
         wasDragging = HandIsGrabbing (kinect);
         isDraggingLeft = Input.GetAxis("Horizontal" + kinectInterpreter.gamepad) > 0f;
         isDraggingRight = Input.GetAxis("Horizontal" + kinectInterpreter.gamepad) < 0f;
         isDraggingUp = Input.GetAxis("Vertical" + kinectInterpreter.gamepad) > 0f;
         isDraggingDown = Input.GetAxis("Vertical" + kinectInterpreter.gamepad) < 0f;
     }
 }
Esempio n. 37
0
    // Update is called once per frame
    void FixedUpdate()
    {
        // show pause screen and return if isPaused
        if (isPaused)
        {
            overlay.waitingForPlayer.SetActive(false);
            overlay.pauseScreen.SetActive(true);
            begin = false;
            Cursor.visible = true;
            return;
        }
        else
            Cursor.visible = false;
        overlay.pauseScreen.SetActive(false);

        // setup kinect & return if no user found
        manager = KinectManager.Instance;
        long userID = manager ? manager.GetUserIdByIndex (0) : 0;
        if (userID == 0)
        {
            overlay.waitingForPlayer.SetActive(true);
            begin = false;
            return;
        }
        begin = true;
        overlay.waitingForPlayer.SetActive(false);

        // set joints
        bottomSpine = manager.GetJointPosition (userID, 0);
        bottomHead = manager.GetJointPosition (userID, 2);
        leftShoulder = manager.GetJointPosition (userID, 4);
        leftHand = manager.GetJointPosition (userID, 6);
        rightShoulder = manager.GetJointPosition (userID, 8);
        rightHand = manager.GetJointPosition (userID, 10);
        leftHip = manager.GetJointPosition (userID, 12);
        leftKnee = manager.GetJointPosition (userID, 13);
        leftFoot = manager.GetJointPosition (userID, 15);
        rightHip = manager.GetJointPosition (userID, 16);
        rightKnee = manager.GetJointPosition (userID, 17);
        rightFoot = manager.GetJointPosition (userID, 19);

        xBottom = bottomSpine.x;

        // Horizontal movement
        HorizontalMovement();

        // Forward movement
        MoveForward();

        // Calculate leg angles
        CalcAngles();

        // Calculate lowest foot
        LowestFoot();
    }
Esempio n. 38
0
    // gets the joint position in space
    private Vector3 GetJointPosition(KinectManager manager, int joint)
    {
        Vector3 vPosJoint = Vector3.zero;

        if(manager.IsJointTracked(currentUserId, joint))
        {
            if(foregroundCamera)
            {
                // 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();
                }

                // get the color overlay position
                vPosJoint = manager.GetJointPosColorOverlay(currentUserId, joint, foregroundCamera, backgroundRect);
            }
            else
            //if(vPosJoint == Vector3.zero)
            {
                vPosJoint = manager.GetJointPosition(currentUserId, joint);
            }
        }

        return vPosJoint;
    }