IsUserDetected() public method

public IsUserDetected ( ) : bool
return bool
Esempio n. 1
0
    private void Update()
    {
        KinectManager manager = KinectManager.Instance;

        if (!manager || !manager.IsInitialized() || !manager.IsUserDetected())
        {
            return;
        }

        int iJointIndex = (int)TrackedJoint;


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

            if (manager.IsJointTracked(userId, iJointIndex))
            {
                Vector3 posJoint = manager.GetRawSkeletonJointPos(userId, iJointIndex);
                if (posJoint != Vector3.zero)
                {
                    if (posJoint.x <= rangMax && posJoint.x >= rangMin)
                    {
                        SceneManager.LoadScene("Interaccio");
                    }
                }
            }
        }
    }
 private void isCutFruit(RectTransform curFruitRt, ref bool needDestroyFruit)
 {
     if (kinectManager.IsUserDetected())
     {
         //获取用户ID
         long userId    = kinectManager.GetPrimaryUserID();
         int  jointType = (int)KinectInterop.JointType.HandRight;
         if (kinectManager.IsJointTracked(userId, jointType))
         {
             // 获取用户相对Kinect的位置信息
             Vector3 rHandPosition = kinectManager.GetJointKinectPosition(userId, jointType);
             rightTrail.position = rHandPosition;
             Vector3 screenPositionV3           = Camera.main.WorldToScreenPoint(rHandPosition);       //右手位置信息转换成在屏幕上的三维坐标
             Vector2 screenPositionV2           = new Vector2(screenPositionV3.x, screenPositionV3.y); //转换成屏幕上的二维坐标
             KinectInterop.HandState rHandState = kinectManager.GetRightHandState(userId);
             if (rHandState == KinectInterop.HandState.Open && RectTransformUtility.RectangleContainsScreenPoint(curFruitRt, screenPositionV2, Camera.main))
             {
                 //右手切中水果了
                 needDestroyFruit = true;
                 if (curFruit.getType() != Constant.Type_Bomb)
                 {
                     splatterAudio.Play();
                 }
                 else
                 {
                     boomAudio.Play();
                 }
             }
         }
         jointType = (int)KinectInterop.JointType.HandLeft;
         if (kinectManager.IsJointTracked(userId, jointType))
         {
             Vector3 lHandPosition = kinectManager.GetJointKinectPosition(userId, jointType);
             leftTrail.position = lHandPosition;
             Vector3 screenPositionV3           = Camera.main.WorldToScreenPoint(lHandPosition);
             Vector2 screenPositionV2           = new Vector2(screenPositionV3.x, screenPositionV3.y);
             KinectInterop.HandState lHandState = kinectManager.GetLeftHandState(userId);
             if (lHandState == KinectInterop.HandState.Open && RectTransformUtility.RectangleContainsScreenPoint(curFruitRt, screenPositionV2, Camera.main))
             {
                 needDestroyFruit = true;
                 if (curFruit.getType() != Constant.Type_Bomb)
                 {
                     splatterAudio.Play();
                 }
                 else
                 {
                     boomAudio.Play();
                 }
             }
         }
     }
 }
    void SetBasketPos()
    {
        //checar si no hubi problemas de inicializacion
        if (manager != null && manager.IsUserDetected())
        {
            uint    userID  = manager.GetPlayer1ID();
            Vector3 posUser = manager.GetUserPosition(userID);
            transform.position = new Vector3(posUser.x * speed, transform.position.y, posUser.z);
        }

        else
        {
            StartCoroutine(CheckIfPlayerDetected());
        }
    }
Esempio n. 4
0
    // Update is called once per frame
    void Update()
    {
        for (int i = 0; i < 3; i++)
        {
            if (manager.IsUserDetected(i) && !Players[i].gameObject.activeSelf)
            {
                Players[i].gameObject.SetActive(true);
            }
            else if (!manager.IsUserDetected(i) && Players[i].gameObject.activeSelf)

            {
                Players[i].gameObject.SetActive(false);
            }
        }
    }
Esempio n. 5
0
    private void getUserGestureValue()
    {
        if (manager.IsUserDetected())
        {
            DirectionBetweenJoints = new List <Vector3>();
            AngleBetweenJoints     = new List <float>();

            uint p1 = manager.GetPlayer1ID();
            //uint jointLength = 20;
            UserOrientation = manager.GetUserOrientation(p1, flip);

            /*for (int i = 0; i < jointLength; i++)
             * {
             *  JointPosition[i] = manager.GetJointPosition(p1, i);
             *  JointLocalPosition[i] = manager.GetJointLocalPosition(p1, i);
             *  JointOrientation[i] = manager.GetJointOrientation(p1, i, flip);
             *  JointLocalOrientation[i] = manager.GetJointLocalOrientation(p1, i, flip);
             * }*/
            ElbowToShoulder_L = manager.GetDirectionBetweenJoints(p1, (int)Joint.Elbow_Left, (int)Joint.Shoulder_Left, flip, flip);
            ElbowToShoulder_R = manager.GetDirectionBetweenJoints(p1, (int)Joint.Elbow_Right, (int)Joint.Shoulder_Right, flip, flip);
            ElbowToWrist_L    = manager.GetDirectionBetweenJoints(p1, (int)Joint.Elbow_Left, (int)Joint.Wrist_Left, flip, flip);
            ElbowToWrist_R    = manager.GetDirectionBetweenJoints(p1, (int)Joint.Elbow_Right, (int)Joint.Wrist_Right, flip, flip);
            KneeToHip_L       = manager.GetDirectionBetweenJoints(p1, (int)Joint.Knee_Left, (int)Joint.Hip_Left, flip, flip);
            KneeToHip_R       = manager.GetDirectionBetweenJoints(p1, (int)Joint.Knee_Right, (int)Joint.Hip_Right, flip, flip);
            KneeToAnkle_L     = manager.GetDirectionBetweenJoints(p1, (int)Joint.Knee_Left, (int)Joint.Ankle_Left, flip, flip);
            KneeToAnkle_R     = manager.GetDirectionBetweenJoints(p1, (int)Joint.Knee_Right, (int)Joint.Ankle_Right, flip, flip);

            DirectionBetweenJoints.Add(ElbowToShoulder_L);
            DirectionBetweenJoints.Add(ElbowToWrist_L);
            DirectionBetweenJoints.Add(ElbowToShoulder_R);
            DirectionBetweenJoints.Add(ElbowToWrist_R);
            DirectionBetweenJoints.Add(KneeToHip_L);
            DirectionBetweenJoints.Add(KneeToAnkle_L);
            DirectionBetweenJoints.Add(KneeToHip_R);
            DirectionBetweenJoints.Add(KneeToAnkle_R);

            for (int i = 0; i < DirectionBetweenJoints.Count; i++)
            {
                DirectionBetweenJoints[i].Normalize();
            }
            for (int i = 0; i < DirectionBetweenJoints.Count; i += 2)
            {
                AngleBetweenJoints.Add(Vector3.Angle(DirectionBetweenJoints[i], DirectionBetweenJoints[i + 1]));
            }

            //Debug.Log("Get Gesture Value Complete.");
        }
    }
Esempio n. 6
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. 7
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;
                }
            }
        }
    }
    public void ActionWithHand()
    {
        KinectInterop.JointType handJoint = KinectInterop.JointType.HandRight;
        KinectManager           manager   = KinectManager.Instance;

        if (manager && manager.IsInitialized())
        {
            if (manager.IsUserDetected())
            {
                long userId = manager.GetPrimaryUserID();
                if (manager.IsJointTracked(userId, (int)handJoint))
                {
                    KinectInterop.HandState handState = manager.GetRightHandState(userId);
                    if (handState == KinectInterop.HandState.Closed)
                    {
                        focus = true;
                    }
                    else if (handState == KinectInterop.HandState.Open)
                    {
                        focus = false;
                    }
                }
            }
        }
    }
    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. 10
0
    void Update()
    {
        if (manager == null)
        {
            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 joints
            if (manager.IsUserDetected())
            {
                long userId = manager.GetUserIdByIndex(playerIndex);

                OverlayJoint(userId, (int)KinectInterop.JointType.HandLeft, leftHandOverlay, backgroundRect);
                OverlayJoint(userId, (int)KinectInterop.JointType.HandRight, rightHandOverlay, backgroundRect);
            }
        }
    }
Esempio n. 11
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. 12
0
    void Update()
    {
        if (GameController._instance.currentIndex != 0)
        {
            return;
        }
        if (_manager == null)
        {
            _manager = KinectManager.Instance;
        }

        if (_manager && _manager.IsInitialized())//如果初始化成功
        {
            if (_manager.IsUserDetected())
            {
                if (btns[2].localScale.z == 1)
                {
                    boomParticl.SetActive(true);
                }
                c1.Rotate(Vector3.forward, -5 * Time.deltaTime);
                c2.Rotate(Vector3.forward, 5 * Time.deltaTime);
                c3.Rotate(Vector3.forward, 5 * Time.deltaTime);
                fruit1.Rotate(Vector3.forward, 10 * Time.deltaTime);
                fruit2.Rotate(Vector3.forward, -10 * Time.deltaTime);
            }
            else
            {
                boomParticl.SetActive(false);
            }
        }
    }
Esempio n. 13
0
    void Update()
    {
        if (manager == null)
        {
            manager = KinectManager.Instance;
        }

        if (manager && manager.IsInitialized() && foregroundCamera)
        {
            Rect backgroundRect             = foregroundCamera.pixelRect;
            PortraitBackground portraitBack = PortraitBackground.Instance;

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

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

                OverlayJoint(userId, (int)KinectInterop.JointType.HandLeft, leftHandOverlay, backgroundRect);
                OverlayJoint(userId, (int)KinectInterop.JointType.HandRight, rightHandOverlay, backgroundRect);
            }
        }
    }
Esempio n. 14
0
    void SpawnMedicin()
    {
        KinectManager manager = KinectManager.Instance;

        if (eggPrefab && manager && manager.IsInitialized() && manager.IsUserDetected())
        {
            long    userId  = manager.GetPrimaryUserID();
            Vector3 posUser = manager.GetUserPosition(userId);

            int posDrop = Random.Range(0, positionDrop.Length);
            while (posDrop == oldPos)
            {
                posDrop = Random.Range(0, positionDrop.Length);
            }
            oldPos = posDrop;
            float     addXPos      = positionDrop[posDrop].localPosition.x;
            Vector3   spawnPos     = new Vector3(addXPos, 5f, posUser.z);
            Transform eggTransform = Instantiate(eggPrefab, spawnPos, Quaternion.identity) as Transform;
            int       a            = Random.Range(0, 5);
            Debug.Log(a + "//" + CheckListCurrent());
            count++;
            if (count >= 4)
            {
                if (!CheckListCurrent())
                {
                    a = game1Manager.currentDisease;
                }
                count = 0;
            }

            eggTransform.GetComponent <MedicinTrigger>().Init(a, speed);
            eggTransform.parent = transform;
        }
    }
Esempio n. 15
0
    public void SpawnBotton()
    {
        Vector3 spawn = new Vector3(0, 0, 2);
        //  Instantiate(fruit, spawn, transform.rotation);

        KinectManager manager = KinectManager.Instance;

        if (fruitPrefab && manager && manager.IsInitialized() && manager.IsUserDetected())
        {
            int a = Random.Range(0, 100);

            long    userId  = manager.GetPrimaryUserID();
            Vector3 posUser = manager.GetUserPosition(userId);
            Debug.Log(posUser);
            //           float addXPos = Random.Range(-6f, 6f);

            //            Vector3 spawnPos = new Vector3(addXPos, 6, posUser.z);


            // FruitTrigger ft = Instantiate(fruitPrefab, spawnPos, Quaternion.identity);
            FruitTrigger ft = Instantiate(fruit, spawn, transform.rotation);
            if (a < percenGood)
            {
                //random good object
                ft.Init(true);
            }
            else
            {
                //random bad object
                ft.Init(false);
            }

            ft.transform.parent = parrentFruit;
        }
    }
    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. 17
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. 18
0
    void SpawnBalls()
    {
        KinectManager manager = KinectManager.Instance;

        if (ballPrefab && cubePrefab && ballsCount < numberOfObjects &&
            manager && manager.IsInitialized() && manager.IsUserDetected())
        {
            long userId = manager.GetPrimaryUserID();
            posUser = userTransform ? userTransform.position : manager.GetUserPosition(userId);

            float   xPos     = UnityEngine.Random.Range(-instantiateInRange.x, instantiateInRange.x);
            float   zPos     = UnityEngine.Random.Range(-instantiateInRange.z, instantiateInRange.z);
            Vector3 spawnPos = new Vector3(posUser.x + xPos, posUser.y + instantiateInRange.y, posUser.z + zPos);

            int ballOrCube = Mathf.RoundToInt(UnityEngine.Random.Range(0f, 1f));

            Transform ballTransform = Instantiate(ballOrCube > 0 ? ballPrefab : cubePrefab, spawnPos, Quaternion.identity) as Transform;
            ballTransform.GetComponent <Renderer>().material.color = new Color(UnityEngine.Random.Range(0.5f, 1f), UnityEngine.Random.Range(0.5f, 1f), UnityEngine.Random.Range(0.5f, 1f), 1f);
            ballTransform.parent = transform;

            ballsCount++;

            if (OnNewObject != null)
            {
                OnNewObject(ballTransform);
            }
        }
    }
        void Update()
        {
            if (foregroundCamera == null)
            {
                // by default use the main camera
                foregroundCamera = Camera.main;
            }

            if (kinectManager == null)
            {
                kinectManager = KinectManager.Instance;
            }

            if (kinectManager && kinectManager.IsInitialized() && 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();
                }

                // overlay the joints
                if (kinectManager.IsUserDetected(playerIndex))
                {
                    ulong userId = kinectManager.GetUserIdByIndex(playerIndex);

                    OverlayJoint(userId, (int)KinectInterop.JointType.HandLeft, leftHandOverlay, backgroundRect);
                    OverlayJoint(userId, (int)KinectInterop.JointType.HandRight, rightHandOverlay, backgroundRect);
                }
            }
        }
    void Update()
    {
        if (isBrInited)
        {
            // update the background removal
            bool bSuccess = !isUsingOpenCv?sensorData.sensorInterface.UpdateBackgroundRemoval() : true;

            if (bSuccess)
            {
                KinectManager kinectManager = KinectManager.Instance;
                if (kinectManager && kinectManager.IsInitialized() && kinectManager.IsUserDetected())
                {
                    bSuccess = !isUsingOpenCv?
                               sensorData.sensorInterface.PollForegroundFrame(sensorData, colorCameraResolution, defaultColor, ref foregroundImage) :
                                   KinectInterop.PollForegroundFrame(sensorData, colorCameraResolution, defaultColor, ref foregroundImage);

                    if (bSuccess)
                    {
                        foregroundTex.LoadRawTextureData(foregroundImage);
                        foregroundTex.Apply();
                    }
                }
            }
        }
    }
Esempio n. 21
0
    // joint の処理
    IEnumerator GetJoint()
    {
        while (true)
        {
            KinectManager manager = KinectManager.Instance;

            if (manager && manager.IsInitialized() && manager.IsUserDetected())
            {
                // userIdを取得
                uint userId = manager.GetPlayer1ID();

                // 感知したかどうか
                SetIsDetected(true);

                // jointが動いたかどうか
                if (manager.IsJointTracked(userId, JointKinectNumber))
                {
                    JointPosObjUpdate(manager, userId); // 関節のpositionを更新
                }
            }
            else
            {
                // 感知したかどうか
                SetIsDetected(false);
            }

            yield return(new WaitForSeconds(TimeDiff));
        }
    }
    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. 23
0
        void SpawnBalls()
        {
            KinectManager kinectManager = KinectManager.Instance;

            if (ballPrefab && cubePrefab && ballsCount < numberOfObjects &&
                kinectManager && kinectManager.IsInitialized() && kinectManager.IsUserDetected(playerIndex))
            {
                ulong   userId  = kinectManager.GetUserIdByIndex(playerIndex);
                Vector3 posUser = kinectManager.GetUserPosition(userId);

                float   xOfs     = Random.Range(-1.5f, 1.5f);
                float   zOfs     = Random.Range(-2.0f, 1.0f);
                float   yOfs     = Random.Range(1.0f, 4.0f);
                Vector3 spawnPos = new Vector3(posUser.x + xOfs, posUser.y + yOfs, posUser.z + zOfs);

                int ballOrCube = Mathf.RoundToInt(Random.Range(0f, 1f));

                Transform ballTransform = Instantiate(ballOrCube > 0 ? ballPrefab : cubePrefab, spawnPos, Quaternion.identity) as Transform;
                ballTransform.GetComponent <Renderer>().material.color = new Color(Random.Range(0.5f, 1f), Random.Range(0.5f, 1f), Random.Range(0.5f, 1f), 1f);
                ballTransform.GetComponent <Rigidbody>().drag          = Random.Range(1f, 100f);
                ballTransform.parent = transform;

                ballsCount++;
            }
        }
Esempio n. 24
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();
            }

//			Vector3 vRight = BottomRight - BottomLeft;
//			Vector3 vUp = TopLeft - BottomLeft;

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

                foreach (GameObject joint in this.OverlayObjects)
                {
                    KinectWrapper.NuiSkeletonPositionIndex skelton = joint.GetComponent <SkeltonPosIndexName>().getSkelton();
                    int iJointIndex = this.TrackedJoints.IndexOf(skelton);
                    Debug.Log("Pos : " + iJointIndex);

                    if (manager.IsJointTracked(userId, iJointIndex))
                    {
                        Vector3 posJoint = manager.GetRawSkeletonJointPos(userId, (int)skelton);

                        if (posJoint != Vector3.zero)
                        {
                            // 3d position to depth
                            Vector2 posDepth = manager.GetDepthMapPosForJointPos(posJoint);

                            // depth pos to color pos
                            Vector2 posColor = manager.GetColorMapPosForDepthPos(posDepth);

                            float scaleX = (float)posColor.x / KinectWrapper.Constants.ColorImageWidth;
                            float scaleY = 1.0f - (float)posColor.y / KinectWrapper.Constants.ColorImageHeight;

                            //						Vector3 localPos = new Vector3(scaleX * 10f - 5f, 0f, scaleY * 10f - 5f); // 5f is 1/2 of 10f - size of the plane
                            //						Vector3 vPosOverlay = backgroundImage.transform.TransformPoint(localPos);
                            //Vector3 vPosOverlay = BottomLeft + ((vRight * scaleX) + (vUp * scaleY));

                            if (debugText)
                            {
                                debugText.GetComponent <GUIText> ().text = "Tracked user ID: " + userId;                                 // new Vector2(scaleX, scaleY).ToString();
                            }

                            if (OverlayObjects[0])
                            {
                                Vector3 vPosOverlay = Camera.main.ViewportToWorldPoint(new Vector3(scaleX, scaleY, distanceToCamera));
                                OverlayObjects[iJointIndex].transform.position = Vector3.Lerp(OverlayObjects[iJointIndex].transform.position, vPosOverlay, smoothFactor * Time.deltaTime);
                            }
                        }
                    }
                }
            }
        }
    }
    /******************************
    *  KinectManager.csでの言葉の定義
    *       index	:	0-
    *       ID		:	固有の値(乱数?).
    *                               多分、detectされた時に与えられるのかな?
    *                               一旦外れて、再detectされると違う値が入る。
    ******************************/
    void Update()
    {
        b_IsTracked = KinectManager.IsUserDetected(0);         // index.
        NumTracked  = KinectManager.GetUsersCount();

        label = "IsTracked = " + b_IsTracked + ", UserCount = " + NumTracked;
    }
Esempio n. 26
0
    void MenuWindow(int windowID)
    {
        int windowX = windowScreenX >= 0 ? windowScreenX : Screen.width + windowScreenX;

        menuWindowRectangle = new Rect(windowX, 40, 165, Screen.height - 60);

        if (modelThumbs != null)
        {
            GUI.skin.button.fixedWidth  = 120;
            GUI.skin.button.fixedHeight = 163;

            scroll   = GUILayout.BeginScrollView(scroll);
            selected = GUILayout.SelectionGrid(selected, modelThumbs, 1);

            if (selected >= 0 && selected < modelNames.Length && prevSelected != selected)
            {
                KinectManager kinectManager = KinectManager.Instance;

                if (kinectManager && kinectManager.IsInitialized() && kinectManager.IsUserDetected())
                {
                    prevSelected = selected;
                    LoadModel(modelNames[selected]);
                }
            }

            GUILayout.EndScrollView();

            GUI.skin.button.fixedWidth  = 0;
            GUI.skin.button.fixedHeight = 0;
        }
    }
Esempio n. 27
0
    //根据颜色图像和视口矩形获取骨骼节点位置
    public static Vector3 GetJointPosColorOverlay(int playerIndex, int iJointIndex, Camera camera)
    {
        KinectManager manager = KinectManager.Instance;

        if (manager && manager.IsInitialized() && camera)
        {
            // 得到背景矩形(使用肖像的背景,如果可用)
            Rect backgroundRect             = camera.pixelRect;
            PortraitBackground portraitBack = PortraitBackground.Instance;
            if (portraitBack && portraitBack.enabled)
            {
                backgroundRect = portraitBack.GetBackgroundRect();
            }
            // overlay the joint
            if (manager.IsUserDetected())
            {
                long userId = manager.GetUserIdByIndex(playerIndex);

                if (manager.IsJointTracked(userId, iJointIndex))
                {
                    Vector3 posJoint = manager.GetJointPosColorOverlay(userId, iJointIndex, camera, backgroundRect);
                    return(posJoint);
                }
            }
        }
        return(Vector3.zero);
    }
Esempio n. 28
0
    public Vector3 test(KinectInterop.JointType jointType)
    {
        int           joint         = (int)jointType;
        KinectManager kinectManager = KinectManager.Instance;

        if (kinectManager && kinectManager.IsInitialized())
        {
            if (kinectManager.IsUserDetected())
            {
                long userId = kinectManager.GetPrimaryUserID();
                if (kinectManager.IsJointTracked(userId, joint))
                {
                    Vector3 jointPostion = kinectManager.GetJointKinectPosition(userId, joint);
                    if (jointPostion != Vector3.zero)
                    {
                        Vector2 depthPosition = kinectManager.MapSpacePointToDepthCoords(jointPostion);
                        ushort  depthValue    = kinectManager.GetDepthForPixel((int)depthPosition.x, (int)depthPosition.y);
                        if (depthValue > 0)
                        {
                            Vector2 colorPosition = kinectManager.MapDepthPointToColorCoords(depthPosition, depthValue);
                            float   xNorm         = colorPosition.x / kinectManager.GetColorImageWidth();
                            float   yNorm         = colorPosition.x / kinectManager.GetColorImageHeight();
                            Vector3 v3            = Camera.main.ViewportToScreenPoint(new Vector3(xNorm, yNorm, 0));
                            return(v3);
                        }
                    }
                }
            }
        }
        return(Vector3.zero);
    }
Esempio n. 29
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;
                }
            }
        }
    }
Esempio n. 30
0
    private void Update()
    {
        KinectManager manager = KinectManager.Instance;

        if (!manager || !manager.IsInitialized() || !manager.IsUserDetected())
        {
            return;
        }

        int iJointIndex = (int)TrackedJoint;


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

            if (manager.IsJointTracked(userId, iJointIndex))
            {
                Vector3 posJoint = manager.GetRawSkeletonJointPos(userId, iJointIndex);
                if (posJoint != Vector3.zero)
                {
                    Debug.Log("X" + posJoint.x);
                    Debug.Log("Z" + posJoint.z);

                    if (posJoint.x <= rangMax && posJoint.x >= rangMin)
                    {
                        if (interaccio)
                        {
                            variacio.enabled = true;
                            activ            = true;
                            desactiv         = false;
                            AudioInOn();
                        }
                    }
                    else
                    {
                        if (interaccio)
                        {
                            activ    = false;
                            desactiv = true;
                            AudioInOn();
                        }
                    }
                }
            }
        }
    }
    // 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();
    }