// Update is called once per frame
    void Update()
    {
        if (player == -1)
        {
            return;
        }
        //update all of the bones positions
        if (sw.pollSkeleton())
        {
            Debug.Log("After pollSkeleton() ");
            for (int ii = 0; ii < (int)Kinect.NuiSkeletonPositionIndex.Count; ii++)
            {
                //_bonePos[ii] = sw.getBonePos(ii);
                if (((uint)Mask & (uint)(1 << ii)) > 0)
                {
                    //_bones[ii].transform.localPosition = sw.bonePos[player,ii];
                    _bones[ii].transform.localPosition = new Vector3(
                        sw.bonePos[player, ii].x * scale,
                        sw.bonePos[player, ii].y * scale,
                        sw.bonePos[player, ii].z * scale);
                    Debug.Log(sw.bonePos[player, ii].x * scale);

                    isTracked = isTracked | (sw.boneState[player, ii] == Kinect.NuiSkeletonPositionTrackingState.Tracked);
                }
            }
        }
    }
Exemplo n.º 2
0
 // Update is called once per frame
 void Update()
 {
     if (player == -1)
     {
         //isTracked = false;
         return;
     }
     //update all of the bones positions
     if (sw.pollSkeleton())
     {
         for (int ii = 0; ii < (int)Kinect.NuiSkeletonPositionIndex.Count; ii++)
         {
             //_bonePos[ii] = sw.getBonePos(ii);
             if (((uint)Mask & (uint)(1 << ii)) > 0)
             {
                 isTracked = true;
                 //_bones[ii].transform.localPosition = sw.bonePos[player,ii];
                 _bones[ii].transform.localPosition = new Vector3(
                     sw.bonePos[player, ii].x * scale,
                     sw.bonePos[player, ii].y * scale,
                     sw.bonePos[player, ii].z * scale);
             }
         }
     }
 }
Exemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        if (player == -1)
        {
            return;
        }
        //update all of the bones positions
        if (sw.pollSkeleton())
        {
            for (int ii = 0; ii < (int)Kinect.NuiSkeletonPositionIndex.Count; ii++)
            {
                //_bonePos[ii] = sw.getBonePos(ii);
                if (((uint)Mask & (uint)(1 << ii)) > 0)
                {
                    //_bones[ii].transform.localPosition = sw.bonePos[player,ii];
                    _bones[ii].transform.localPosition = new Vector3(
                        sw.bonePos[player, ii].x * scale,
                        sw.bonePos[player, ii].y * scale,
                        sw.bonePos[player, ii].z * scale);

                    _bones [ii].transform.rotation = sw.boneAbsoluteOrientation [player, ii];


                    AliceSync.s.UpdateBodyPart((ulong)player, ii.ToString(), _bones[ii].transform.position, _bones [ii].transform.rotation, 0);
                }
            }
        }
    }
Exemplo n.º 4
0
    void Update()
    {
        if (sw.pollSkeleton())
        {
            Vector3 headPos = new Vector3(sw.bonePos[0, (int)Kinect.NuiSkeletonPositionIndex.Head].x,
                                          sw.bonePos[0, (int)Kinect.NuiSkeletonPositionIndex.Head].y,
                                          sw.bonePos[0, (int)Kinect.NuiSkeletonPositionIndex.Head].z);
            headPos *= scale;

            _handLeftPos = new Vector3(sw.bonePos[0, (int)Kinect.NuiSkeletonPositionIndex.HandLeft].x,
                                       sw.bonePos[0, (int)Kinect.NuiSkeletonPositionIndex.HandLeft].y,
                                       sw.bonePos[0, (int)Kinect.NuiSkeletonPositionIndex.HandLeft].z);
            _handLeftPos *= scale;

            _handRightPos = new Vector3(sw.bonePos[0, (int)Kinect.NuiSkeletonPositionIndex.HandRight].x,
                                        sw.bonePos[0, (int)Kinect.NuiSkeletonPositionIndex.HandRight].y,
                                        sw.bonePos[0, (int)Kinect.NuiSkeletonPositionIndex.HandRight].z);
            _handRightPos *= scale;

            _handLeftPos  = _handLeftPos - headPos;
            _handRightPos = _handRightPos - headPos;

            Hand_Left.transform.localPosition  = _handLeftPos;
            Hand_Right.transform.localPosition = _handRightPos;

            UpdateButtons();
            UpdateHUD();
        }
    }
 // Update is called once per frame
 void Update()
 {
     if (player == -1)
     {
         isTracked = false;
         return;
     }
     //update all of the bones positions
     if (sw.pollSkeleton())
     {
         Debug.Log("After pollSkeleton() ");
         isTracked = false;
         for (int ii = 0; ii < (int)Kinect.NuiSkeletonPositionIndex.Count; ii++)
         {
             //_bonePos[ii] = sw.getBonePos(ii);
             if (((uint)Mask & (uint)(1 << ii)) > 0)
             {
                 //_bones[ii].transform.localPosition = sw.bonePos[player,ii];
                 _bones[ii].transform.localPosition = new Vector3(
                     sw.bonePos[player, ii].x * scale,
                     sw.bonePos[player, ii].y * scale,
                     sw.bonePos[player, ii].z * scale);
                 Debug.Log(sw.bonePos[player, ii].x * scale);
                 /* Ajout F. Davesne pour repérer si les éléments du squelette intéressants sont trackés => isTracked */
                 isTracked = isTracked | (sw.boneState[player, ii] == Kinect.NuiSkeletonPositionTrackingState.Tracked);
                 /* Fin Ajout F. Davesne */
             }
         }
     }
 }
Exemplo n.º 6
0
    // Update is called once per frame
    void Update()
    {
        if (player == -1)
        {
            return;
        }
        if (sw.pollSkeleton())
        {
            Vector3 Hip_Center = new Vector3(
                sw.bonePos [player, 0].x,
                sw.bonePos [player, 0].y,
                sw.bonePos [player, 0].z);

            Vector3 Shoulder_Center = new Vector3(
                sw.bonePos [player, 2].x,
                sw.bonePos [player, 2].y,
                sw.bonePos [player, 2].z);
            this.leftRight = Shoulder_Center.x - Hip_Center.x;
            this.upDown    = Hip_Center.y;
            mouseLook.SendMessage("setX", leftRight);
            fpsinputController.SendMessage("setIsDown", this.getUpDown());
            gt.text = leftRight.ToString();
        }
        else
        {
            mouseLook.SendMessage("setX", 0.0f);
        }
    }
    // Update is called once per frame
    void Update()
    {
        hipCenter.x = Hip_Center.transform.position.x;
        hipCenter.y = Hip_Center.transform.position.y;
        hipCenter.z = Hip_Center.transform.position.z;


        if (player == -1)
        {
            return;
        }
        //update all of the bones positions
        if (sw.pollSkeleton())
        {
            for (int ii = 0; ii < (int)Kinect.NuiSkeletonPositionIndex.Count; ii++)
            {
                //_bonePos[ii] = sw.getBonePos(ii);
                if (((uint)Mask & (uint)(1 << ii)) > 0)
                {
                    //_bones[ii].transform.localPosition = sw.bonePos[player,ii];
                    _bones[ii].transform.localPosition = new Vector3(
                        sw.bonePos[player, ii].x * scale,
                        sw.bonePos[player, ii].y * scale,
                        sw.bonePos[player, ii].z * scale);
                }
            }
        }
    }
Exemplo n.º 8
0
    // Update is called once per frame
    void Update()
    {
        // 更新瞳距
        Vector3 eyePos = Vector3.zero;

        eyePos.x = -IPD * 0.5f * scale;
        leftEyeTrans.localPosition = eyePos;
        eyePos.x = IPD * 0.5f * scale;
        rightEyeTrans.localPosition = eyePos;

        if (skeletonWrapper.pollSkeleton())
        {
            // 获取头关节位移
            m_headPosition          = skeletonWrapper.bonePos [player, m_targetJointId];
            m_headPosition         += eyeBias;
            m_headPosition         -= sensor.kinectCenter;
            m_headPosition.y       -= sensor.sensorHeight;
            transform.localPosition = m_headPosition * scale;
            // 获取头关节旋转
            if (jointRotation)
            {
                m_headOrien = skeletonWrapper.boneAbsoluteOrientation[player, m_targetJointId];
                Vector3 euler = m_headOrien.eulerAngles;
                // 获得的旋转四元数是右手坐标系下的,做变换到左手坐标系
                euler.y = 180.0f - euler.y;
                euler.z = -euler.z;
                transform.localRotation = Quaternion.Euler(euler);
            }
        }
    }
Exemplo n.º 9
0
 // Update is called once per frame
 void Update()
 {
     if (skeletonWrapper.pollSkeleton())
     {
         Vector3 pos = skeletonWrapper.bonePos[player, m_targetJointId] * scale;
         pos   -= sensor.kinectCenter;
         pos.y -= sensor.sensorHeight;
         transform.localPosition = pos;
     }
 }
Exemplo n.º 10
0
 // Update is called once per frame
 void Update()
 {
     if (sw.pollSkeleton())
     {
         Vector3 playerNeckDirection = sw.bonePos[player, (int)NuiSkeletonPositionIndex.Head] - sw.bonePos[player, (int)NuiSkeletonPositionIndex.ShoulderCenter];
         Debug.Log("neckBaseRotation: " + neckBaseRotation.eulerAngles + "; AbsoluteOrientation: " +
                   sw.boneAbsoluteOrientation[player, (int)NuiSkeletonPositionIndex.Head].eulerAngles + "; neckBaseRotation: " +
                   sw.boneLocalOrientation[player, (int)NuiSkeletonPositionIndex.Head].eulerAngles);
         neck.rotation = Quaternion.Euler(sw.boneAbsoluteOrientation[player, (int)NuiSkeletonPositionIndex.Head].eulerAngles + neckBaseRotation.eulerAngles + new Vector3(0f, 180f, 0f));
     }
 }
Exemplo n.º 11
0
 // Update is called once per frame
 void Update()
 {
     //	lastHeadPos = headPos;
     if (sw.pollSkeleton())
     {
         trackerPosition = sw.bonePos[player, (int)Kinect.NuiSkeletonPositionIndex.Head];
         //headPos = trackerPosition;
     }
     trackerPosition.z += 0f;
     //cam.transform.Translate(deltaHead.x*10, deltaHead.y*10, deltaHead.z*10);
 }
 // Update is called once per frame
 void Update()
 {
     if (sw.pollSkeleton())
     {
         this.rightHandPos = sw.bonePos[PlayerID, 11];
         int dx = (int)((this.rightHandPos.x - this.preRightHandPos.x) * scaleX);
         int dy = (int)((this.rightHandPos.y - this.preRightHandPos.y) * scaleY);
         GetCursorPos(out mousePos);
         mousePos.X += dx;
         mousePos.Y -= dy;
         SetCursorPos(mousePos.X, mousePos.Y);
         this.preRightHandPos = this.rightHandPos;
     }
 }
Exemplo n.º 13
0
 void Update()
 {
     //update the data from the kinect if necessary
     if (sw.pollSkeleton())
     {
         for (int ii = 0; ii < (int)Kinect.NuiSkeletonPositionIndex.Count; ii++)
         {
             if (((uint)Mask & (uint)(1 << ii)) > 0 && (_nullMask & (uint)(1 << ii)) <= 0)
             {
                 RotateJoint(ii);
             }
         }
     }
 }
Exemplo n.º 14
0
 // Update is called once per frame
 void Update()
 {
     //update all of the bones positions
     if (sw.pollSkeleton())
     {
         for (int ii = 0; ii < (int)Kinect.NuiSkeletonPositionIndex.Count; ii++)
         {
             //_bonePos[ii] = sw.getBonePos(ii);
             if (((uint)Mask & (uint)(1 << ii)) > 0)
             {
                 _bones[ii].transform.localPosition = sw.bonePos[player, ii];
             }
         }
     }
 }
Exemplo n.º 15
0
 // Update is called once per frame
 void Update()
 {
     if (player == -1)
     {
         return;
     }
     //update all of the bones positions
     if (sw.pollSkeleton())
     {
         _bones[0].transform.localPosition = new Vector3(
             sw.bonePos[player, 0].x * scale,
             sw.bonePos[player, 0].y * scale,
             sw.bonePos[player, 0].z * scale);
     }
 }
    void Update()
    {
        bool plSkel = sw.pollSkeleton();

//		Debug.Log("player: " + player + ", plSkel: " + plSkel);
        //update the data from the kinect if necessary
        if (plSkel)
        {
            for (int ii = 0; ii < (int)Kinect.NuiSkeletonPositionIndex.Count; ii++)
            {
                if (((uint)Mask & (uint)(1 << ii)) > 0 && (_nullMask & (uint)(1 << ii)) <= 0)
                {
                    RotateJoint(ii);
                }
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (null != __m_skeletonWrapper)
        {
            if (__m_skeletonWrapper.pollSkeleton(this))
            {
                //example code: get all KinectUser, DO NOT include user which has been leaved

                /*
                 * Hashtable h = m_sw.getKinectUserTable();
                 * IDictionaryEnumerator ide = h.GetEnumerator();
                 * while (ide.MoveNext())
                 * {
                 *      KinectUser kuser = (KinectUser)(((DictionaryEntry)(ide.Current)).Value);
                 * }
                 */
            }
        }
    }
Exemplo n.º 18
0
 // Update is called once per frame
 void Update()
 {
     if (sw.pollSkeleton())
     {
         if (sw.playerState[player] != -4)//Check which player state
         {
             if (dw.pollDepth())
             {
                 //depthMapTex.SetPixels32(convertDepthToColor(dw.depthImg));
                 depthMapTex.SetPixels32(convertPlayersToCutout(dw.segmentations, dw.depthImg));
                 depthMapTex.Apply();
             }
         }
         else
         {
             ClearTexture(depthMapTex);
         }
     }
 }
Exemplo n.º 19
0
	// Update is called once per frame
	void Update () {
		Debug.Log ("Kinect Point Controller Update Active");
		if (detect == true) {
			StartCoroutine ("WaveSegments");
			//StartCoroutine ("Armextension");
			StartCoroutine ("Namaste");
			if (detect == false) {
				yield return new WaitForSeconds (5);
			}
			StartCoroutine ("deinitskel");
			if (detect == false) {
				yield return new WaitForSeconds (5);
			}
		} else {
			
			StartCoroutine ("initskel");
			if (detect == true) {
				yield return new WaitForSeconds (5);
			}
		}
		if(player == -1)
			return;
		//update all of the bones positions
		if (sw.pollSkeleton())
		{
			
			for (int ii = 0; ii < (int)Kinect.NuiSkeletonPositionIndex.Count; ii++) {
				
				//_bonePos[ii] = sw.getBonePos(ii);
				if (((uint)Mask & (uint)(1 << ii)) > 0) {
					

					//_bones[ii].transform.localPosition = sw.bonePos[player,ii];
					_bones [ii].transform.localPosition = new Vector3 (
						sw.bonePos [player, ii].x * scale,
						sw.bonePos [player, ii].y * scale,
						sw.bonePos [player, ii].z * scale);
					
				}
			}
		}
	}
Exemplo n.º 20
0
    // Update is called once per frame
    void Update()
    {
        //키넥트 초기화
        #region kinect initialize
        if (player == -1)
        {
            return;
        }
        if (sw.pollSkeleton())
        {
            for (int ii = 0; ii < (int)Kinect.NuiSkeletonPositionIndex.Count; ii++)
            {
                //_bonePos[ii] = sw.getBonePos(ii);
                if (((uint)Mask & (uint)(1 << ii)) > 0)
                {
                    //_bones[ii].transform.localPosition = sw.bonePos[player,ii];
                    _boneposition[ii] = new Vector3(
                        sw.bonePos[player, ii].x * scale,
                        sw.bonePos[player, ii].y * scale,
                        sw.bonePos[player, ii].z * scale);
                }
            }
        }
        int hipcenter = (int)Kinect.NuiSkeletonPositionIndex.HipCenter;      // 엉덩이
        int shoulder  = (int)Kinect.NuiSkeletonPositionIndex.ShoulderCenter; // 어ㄲㅐ
        int head      = (int)Kinect.NuiSkeletonPositionIndex.Head;           //머리
        int lefthand  = (int)Kinect.NuiSkeletonPositionIndex.HandLeft;
        int righthand = (int)Kinect.NuiSkeletonPositionIndex.HandRight;
        int leftfoot  = (int)Kinect.NuiSkeletonPositionIndex.FootLeft;
        int rightfoot = (int)Kinect.NuiSkeletonPositionIndex.FootRight;
        #endregion
        // Use this for initialization

        if ((_boneposition[righthand].y - _boneposition[shoulder].y > 0.3f) && (
                _boneposition[lefthand].y - _boneposition[shoulder].y > 0.3f))
        {
            check   = 0;
            script1 = GameObject.Find("Retry").GetComponent <Home_Button>();
            script1.OnClick();
            Debug.Log("처음 화면으로!");
        } // RETRY
    }
 void Update()
 {
     //update the data from the kinect if necessary
     if (sw.pollSkeleton())
     {
         /* Ajout F. Davesne */
         isTracked = false;
         /* Fin ajout F. Davesne */
         for (int ii = 0; ii < (int)Kinect.NuiSkeletonPositionIndex.Count; ii++)
         {
             if (((uint)Mask & (uint)(1 << ii)) > 0 && (_nullMask & (uint)(1 << ii)) <= 0)
             {
                 RotateJoint(ii);
                 /* Ajout F. Davesne pour repérer si les éléments du squelette intéressants sont trackés => isTracked */
                 isTracked = isTracked | (sw.boneState[player, ii] == Kinect.NuiSkeletonPositionTrackingState.Tracked);
                 /* Fin Ajout F. Davesne */
             }
         }
     }
 }
Exemplo n.º 22
0
 // Update is called once per frame
 void Update()
 {
     if (player == -1)
     {
         return;
     }
     //update all of the bones positions
     if (sw.pollSkeleton())
     {
         for (int ii = 0; ii < 20; ii++)
         {
             //_bonePos[ii] = sw.getBonePos(ii);
             //_bones[ii].transform.localPosition = sw.bonePos[player,ii];
             _bones[ii].transform.position = new Vector3(
                 pm_bones[ii].transform.position.x * scale,
                 pm_bones[ii].transform.position.y * scale,
                 pm_bones[ii].transform.position.z * scale);
         }
     }
 }
Exemplo n.º 23
0
 void Update()
 {
     /*if (dw.track_skeleton == false) {
      *      Debug.Log ("Skeleton traack false");
      *      for (i = 0; i < (int)Kinect.NuiSkeletonPositionIndex.Count + 5; i++) {
      *              _bones [i] = null;
      *      }
      * }*/
     //update the data from the kinect if necessary
     if (sw.pollSkeleton())
     {
         for (int ii = 0; ii < (int)Kinect.NuiSkeletonPositionIndex.Count; ii++)
         {
             if (((uint)Mask & (uint)(1 << ii)) > 0 && (_nullMask & (uint)(1 << ii)) <= 0)
             {
                 RotateJoint(ii);
             }
         }
     }
 }
Exemplo n.º 24
0
    // Update is called once per frame
    void Update()
    {
        if (player == -1)
        {
            return;
        }
        //update all of the bones positions
        if (sw.pollSkeleton())
        {
            if ((int)Kinect.NuiSkeletonPositionIndex.Count >= 4)
            {
                headpos.x = sw.bonePos[player, 3].x;
                headpos.y = sw.bonePos[player, 3].y;
                headpos.z = sw.bonePos[player, 3].z;
                headpos   = headpos + transformVec;
                headpos  *= scale;
                this.gameObject.transform.position = headpos;

                float radian = Mathf.Atan2(headpos.x, headpos.z * (-1.0f));
                float angle  = radian * 180.0f / Mathf.PI;

                this.gameObject.transform.eulerAngles = new Vector3(0, -angle, 0);


                Debug.Log(headpos.x + " " + headpos.y + " " + headpos.z);
            }

            /*
             * for( int ii = 0; ii < (int)Kinect.NuiSkeletonPositionIndex.Count; ii++) {
             *      //_bonePos[ii] = sw.getBonePos(ii);
             *      if( ((uint)Mask & (uint)(1 << ii) ) > 0 ){
             *              //_bones[ii].transform.localPosition = sw.bonePos[player,ii];
             *              _bones[ii].transform.localPosition = new Vector3(
             *                      sw.bonePos[player,ii].x * scale,
             *                      sw.bonePos[player,ii].y * scale,
             *                      sw.bonePos[player,ii].z * scale);
             *      }
             * }
             */
        }
    }
 void Update()
 {
     if (bPollSkeleton)
     {
         if (sAutoMotionCaptureDevicesSelecter != null)
         {
             sAutoMotionCaptureDevicesSelecter.bInitMoveTransform = true;
         }
         fFBXRecStart -= Time.deltaTime;
         if (fFBXRecStart <= 0.0)
         {
             if (sFBXExporterForUnity != null)
             {
                 sFBXExporterForUnity.bOutAnimation = true;
             }
         }
     }
     if (sw.pollSkeleton())
     {
         for (int ii = 0; ii < (int)Kinect.NuiSkeletonPositionIndex.Count; ii++)
         {
             if (((uint)Mask & (uint)(1 << ii)) > 0 && (_nullMask & (uint)(1 << ii)) <= 0)
             {
                 RotateJoint(ii);
             }
         }
         //Root.transform.localRotation = Quaternion.Euler(5.0f, 0.0f, 0.0f);
         //RootHip.transform.localRotation = Quaternion.Euler(Root.transform.localRotation.eulerAngles.x + 20.0f, Root.transform.localRotation.eulerAngles.y, Root.transform.localRotation.eulerAngles.z);
     }
     if (!bFixedUpdateMode)
     {
         fLerpDeltaTime = Time.deltaTime;
         if (bPollSkeleton)
         {
             for (int ii = 0; ii < 25; ii++)
             {
                 RotateJointUpdate(ii);
             }
         }
     }
 }
Exemplo n.º 26
0
    // Update is called once per frame
    void Update()
    {
        if (sw.pollSkeleton())
        {
            switch (sw.playerState[player]) //Check which player state
            {
            case 0:                         // Tracking is ok
                if (dw.pollDepth())
                {
                    //depthMapTex.SetPixels32(convertDepthToColor(dw.depthImg));
                    depthMapTex.SetPixels32(convertPlayersToCutout(dw.segmentations, dw.depthImg));
                    depthMapTex.Apply();
                }
                break;

            case -1:     // too right
                //gameRunUi.ShowMessage("请左移");
                break;

            case 1:     // too left
                //gameRunUi.ShowMessage("请右移");
                break;

            case -3:     // too near
                //gameRunUi.ShowMessage("请后退");
                break;

            case 3:     // too far
                //gameRunUi.ShowMessage("请靠近");
                break;

            case -4:     // no user, waiting
                //gameRunUi.HideMessagePanel();
                break;

            default: break;
            }
        }
    }
Exemplo n.º 27
0
    // Update is called once per frame
    void Update()
    {
        //update all of the bones positions
        if (sw.pollSkeleton())
        {
            for (int ii = 0; ii < (int)Kinect.NuiSkeletonPositionIndex.Count; ii++)
            {
                //_bonePos[ii] = sw.getBonePos(ii);
                if (((uint)Mask & (uint)(1 << ii)) > 0)
                {
                    _bones[ii].transform.localPosition = sw.bonePos[player, ii];

                    if (ii == (int)Kinect.NuiSkeletonPositionIndex.HandLeft)
                    {
                        _bones[ii].transform.localScale = sw.handState[player, 0] ? new Vector3(0.4f, 0.4f, 0.4f) : new Vector3(0.1f, 0.1f, 0.1f);
                    }
                    else if (ii == (int)Kinect.NuiSkeletonPositionIndex.HandRight)
                    {
                        _bones[ii].transform.localScale = sw.handState[player, 1] ? new Vector3(0.4f, 0.4f, 0.4f) : new Vector3(0.1f, 0.1f, 0.1f);
                    }
                }
            }
        }
    }
    void Update()
    {
        //update the data from the kinect if necessary
        if (sw.pollSkeleton())
        {
            if (sw.playerState[player] != 0)
            {
            }// Pause // Waterstrong Add
            switch (sw.playerState[player]) //Check which player state // Waterstrong Add
            {
            case 0:     // Tracking is ok
            {
                //guiTxt.text = "Tracking";
                // iTween.Resume();
                //gameRunUi.HideMessagePanel();
                for (int ii = 0; ii < (int)Kinect.NuiSkeletonPositionIndex.Count; ii++)
                {
                    if (((uint)Mask & (uint)(1 << ii)) > 0 && (_nullMask & (uint)(1 << ii)) <= 0)
                    {
                        rotateJoint(ii);
                    }
                }
                // Move in space // Waterstrong Add
                if (MovesInSpace)
                {
                    moveAvatar();
                }

                // offset is for left/right action,convert to cm
                float offset = 100 * (sw.rawBonePos[player, (int)Kinect.NuiSkeletonPositionIndex.Head].x - sw.rawBonePos[player, (int)Kinect.NuiSkeletonPositionIndex.HipCenter].x);
                if (offset > 10f)
                {
                    //playerCtr.MoveRight();
                }
                else if (offset < -10f)
                {
                    //playerCtr.MoveLeft();
                }
                else
                {
                }

                // offset is for left/right action,convert to dm
                //float offset = 10*(sw.playerPos[player].x + 2*(sw.bonePos[player, (int)Kinect.NuiSkeletonPositionIndex.ShoulderCenter].x - sw.bonePos[player, (int)Kinect.NuiSkeletonPositionIndex.HipCenter].x));
                //guiTxt.text = offset.ToString();
                //left or right action, offset > 2~2.5dm take effect, use offset as a rate

                //if (Math.Abs(offset) > 10f)
                //{
                //    guiTxt.text = offset > 0 ? "Right : " + offset.ToString() : "Left : " + offset.ToString();
                //}
                //else
                //{
                //    guiTxt.text = "Default";
                //}



                // Motion recognition // Waterstrong Add
                //_featureData.SetRelativeJoints(sw.rawBonePos, player);
                //switch (_motion.HandleDataEx(_featureData))
                //{
                //    case MotionType.Jump:
                //        //Debug.Log("jump");
                //        guiTxt.text = "Jump";
                //        break;
                //    case MotionType.Left:
                //        //Debug.Log("left");
                //        guiTxt.text = "Left";
                //        break;
                //    case MotionType.Right:
                //        //Debug.Log("right");
                //        guiTxt.text = "Right";
                //        break;
                //    default: guiTxt.text = "tracking default"; break;
                //}
            }
            break;

            case -1:     // too right

                //gameRunUi.ShowMessage("Çë×óÒÆ");
                break;

            case 1:     // too left

                //gameRunUi.ShowMessage("ÇëÓÒÒÆ");
                break;

            case -3:     // too near

                //gameRunUi.ShowMessage("ÇëºóÍË");
                break;

            case 3:     // too far

                //gameRunUi.ShowMessage("Çë¿¿½ü");
                break;

            case -4:     // no user, waiting

                //gameRunUi.showStop();
                //gameRunUi.HideMessagePanel();
                break;

            default: break;
            }
        }
    }
Exemplo n.º 29
0
    void Update()
    {
        //update the data from the kinect if necessary



        Vector3 dir1 = new Vector3();

        dir1 = s_shoulderleft_2.position - s_elbowleft_1.position;
        Elbow_Left1.position += dir1;

        Vector3 dir2 = new Vector3();

        dir2 = s_collarleft_2.position - s_shoulderleft_1.position;
        Shoulder_Left1.position += dir2;


        Vector3 dir3 = new Vector3();

        dir3 = s_shoulderright_2.position - s_elbowright_1.position;
        Elbow_Right1.position += dir3;

        Vector3 dir4 = new Vector3();

        dir4 = s_collarright_2.position - s_shoulderright_1.position;
        Shoulder_Right1.position += dir4;

        Vector3 dir5 = new Vector3();

        dir5 = s_thighright_2.position - s_kneeright_1.position;
        Knee_Right1.position += dir5;

        Vector3 dir6 = new Vector3();

        dir6 = s_chest_right.position - s_thighright_1.position;
        Thigh_Right1.position += dir6;


        Vector3 dir7 = new Vector3();

        dir7 = s_thighleft_2.position - s_kneeleft_1.position;
        Knee_Left1.position += dir7;

        Vector3 dir8 = new Vector3();

        dir8 = s_chest_left.position - s_thighleft_1.position;
        Thigh_Left1.position += dir8;
        int depthflag = 0;

        if (sw.pollSkeleton())
        {
            for (int ii = 0; ii < (int)Kinect.NuiSkeletonPositionIndex.Count; ii++)
            {
                if (((uint)Mask & (uint)(1 << ii)) > 0 && (_nullMask & (uint)(1 << ii)) <= 0)
                {
                    RotateJoint(ii);
                    if (count_frame == 0)
                    {
                        count_frame++;
                        factor = (float)(sw.bonePos[player, (int)Kinect.NuiSkeletonPositionIndex.HipCenter].y * 10) - 3.5f;
                    }
                    float zbody = (float)(sw.bonePos[player, (int)Kinect.NuiSkeletonPositionIndex.HipCenter].z);
                    if (depthflag == 0)
                    {
                        mainbody.position = new Vector3((float)(sw.bonePos[player, (int)Kinect.NuiSkeletonPositionIndex.HipCenter].x * 10), (((float)(sw.bonePos[player, (int)Kinect.NuiSkeletonPositionIndex.HipCenter].y * 10)) - factor), -8f);
                        far_text.text     = "";
                    }
                    Debug.Log(zbody);
                    //Vector3 position = new Vector3 (0,0,0);

                    if (zbody > 0 && depthflag == 0)
                    {
                        far_text.text = "Too close to Kinect";
                        //GameObject textclone = (GameObject) Instantiate (far_text,position,Quaternion.identity);
                        mainbody.position = new Vector3(1000, 1000, 1000);
                        depthflag         = -1;
                    }
                    if (zbody < -2 && depthflag == 0)
                    {
                        far_text.text = "Too far from Kinect";
                        //GameObject textclone = (GameObject) Instantiate (far_text,position,Quaternion.identity);
                        mainbody.position = new Vector3(1000, 1000, 1000);
                        depthflag         = 1;
                    }
                    if (zbody > -2 && zbody < 0)
                    {
                        depthflag = 0;
                    }
                    Debug.Log(factor);
                }
            }
        }

        /*
         * if( !GameObject.Find("soccerball"))
         * {
         *      var soccerball = Instantiate(soccerball,GameObject.Find("shoot_point").transform.position,Quaternion.identity);
         *
         * }
         */



        // reading text from file to get command
    }
Exemplo n.º 30
0
    // Update is called once per frame
    void Update()
    {
        if (sw.pollSkeleton())
        {
            float currentTime = Time.time;
            this.rightFootPos = sw.bonePos[PlayerId, 19];
            this.leftFootPos  = sw.bonePos[PlayerId, 15];
            this.spinePos     = sw.bonePos[PlayerId, 1];

            if (this.firstTime)
            {
                this.rightFootPosPre = this.rightFootPos;
                this.leftFootPosPre  = this.leftFootPos;
                this.spinePosPre     = this.spinePos;
                this.firstTime       = false;
            }

            this.rightFootVelo = this.rightFootPos - this.rightFootPosPre;
            this.leftFootVelo  = this.leftFootPos - this.leftFootPosPre;
            this.spineVelo     = this.spinePos - this.spinePosPre;

            if (this.rightFootVelo.y > accuracy && Math.Abs(this.rightFootVelo.y) > Math.Abs(this.rightFootVelo.x))
            {
                if (currentRightFootMotion != BodyMotion.RIGHT_FOOT_UP)
                {
                    currentRightFootMotion   = BodyMotion.RIGHT_FOOT_UP;
                    motionRightFootStartTime = currentTime;
                    motionStartRightFootPos  = leftFootPos;
                }
            }
            else
            {
                currentRightFootMotion = BodyMotion.NON;
            }

            if (this.leftFootVelo.y > accuracy && Math.Abs(this.leftFootVelo.y) > Math.Abs(this.leftFootVelo.x))
            {
                if (currentLeftFootMotion != BodyMotion.LEFT_FOOT_UP)
                {
                    currentLeftFootMotion   = BodyMotion.LEFT_FOOT_UP;
                    motionLeftFootStartTime = currentTime;
                    motionStartLeftFootPos  = leftFootPos;
                }
            }
            else
            {
                currentLeftFootMotion = BodyMotion.NON;
            }

            if (this.spineVelo.y > accuracy && Math.Abs(this.spineVelo.y) > Math.Abs(this.spineVelo.x))
            {
                if (currentLeftFootMotion != BodyMotion.LEFT_FOOT_UP)
                {
                    currentSpineMotion     = BodyMotion.BODY_UP;
                    motionSpineStartTime   = currentTime;
                    motionStartLeftFootPos = spinePos;
                }
            }
            else
            {
                currentSpineMotion = BodyMotion.NON;
            }
//			currentRightHandMotion == HandMotion.RIGHT_HAND_WAVE_OUT
//				&& currentTime - motionRightHandStartTime <= detectMotionDuration
//					&& rightHandPos.x - motionStartRightHandPos.x >= detectMotionDistance

            if (currentLeftFootMotion == BodyMotion.LEFT_FOOT_UP &&
                currentRightFootMotion == BodyMotion.RIGHT_FOOT_UP &&
                currentSpineMotion == BodyMotion.BODY_UP &&
                currentTime - motionRightFootStartTime <= detectMotionDuration &&
                currentTime - motionLeftFootStartTime <= detectMotionDuration &&
                currentTime - motionSpineStartTime <= detectMotionDuration &&
                rightFootPos.y - motionStartRightFootPos.y >= detectMotionDistance &&
                leftFootPos.y - motionStartLeftFootPos.y >= detectMotionDistance &&
                spinePos.y - motionStartSpineSPos.y >= detectMotionDistance)
            {
                if (rightFootVelo.y - spineVelo.y >= detectMotionDistance &&
                    leftFootVelo.y - spineVelo.y >= detectMotionDistance)
                {
                    OnBodyMotionDetected(BodyMotion.SUPER_JUMP);
                }
                else
                {
                    OnBodyMotionDetected(BodyMotion.JUMP);
                }

                motionLeftFootStartTime  = currentTime;
                motionRightFootStartTime = currentTime;
                motionSpineStartTime     = currentTime;
                motionStartLeftFootPos   = leftFootPos;
                motionStartRightFootPos  = rightFootPos;
                motionStartSpineSPos     = spinePos;
            }

            rightFootPosPre = rightFootPos;
            leftFootPosPre  = leftFootPos;
            spinePosPre     = spinePos;
        }
    }