Exemple #1
0
        /// <summary> 終了処理 </summary>
        private void Uninitialize()
        {
            if (senseManager != null)
            {
                senseManager.Dispose();
                senseManager = null;
            }
            if (projection != null)
            {
                projection.Dispose();
                projection = null;
            }
            if (handData != null)
            {
                handData.Dispose();
                handData = null;
            }

            if (handAnalyzer != null)
            {
                handAnalyzer.Dispose();
                handAnalyzer = null;
            }
            if (config != null)
            {
                config.UnsubscribeGesture(OnFiredGesture);
                config.Dispose();
            }
        }
        private void Uninitialize()
        {
            if (senseManager != null)
            {
                senseManager.Dispose();
                senseManager = null;
            }

            if (projection != null)
            {
                projection.Dispose();
                projection = null;
            }

            if (handData != null)
            {
                handData.Dispose();
                handData = null;
            }

            if (handAnalyzer != null)
            {
                handAnalyzer.Dispose();
                handAnalyzer = null;
            }
        }
Exemple #3
0
        private void Uninitialize()
        {
            if (senseManager != null)
            {
                senseManager.Dispose();
                senseManager = null;
            }

            if (handConfig != null)
            {
                handConfig.Dispose();
                handConfig = null;
            }

            if (handData != null)
            {
                handData.Dispose();
                handData = null;
            }

            if (handAnalyzer != null)
            {
                handAnalyzer.Dispose();
                handAnalyzer = null;
            }
        }
 private void OnDisable()
 {
     if (handAnalyzer != null)
     {
         handAnalyzer.Dispose();
     }
     if (SenseToolkitManager.Instance.SenseManager != null)
     {
         SenseToolkitManager.Instance.SenseManager.Dispose();
     }
 }
Exemple #5
0
        private void Uninitialize()
        {
            // リソースを解放する
            if (senseManager != null)
            {
                senseManager.Dispose();
                senseManager = null;
            }

            if (handData != null)
            {
                handData.Dispose();
                handData = null;
            }

            if (handAnalyzer != null)
            {
                handAnalyzer.Dispose();
                handAnalyzer = null;
            }
        }
    void OnDisable()
    {
        /* Dispose hand data instance*/
        if (hand_data != null)
        {
            hand_data.Dispose();
            hand_data = null;
        }

        /* Dispose hand module instance*/
        if (hand != null)
        {
            hand.Dispose();
            hand = null;
        }

        /* Dispose sense manager instance*/
        if (sm != null)
        {
            sm.Dispose();
            sm = null;
        }
    }
    //Called every frame when in manual mode
    private void UpdateFreeMovementState()
    {

        if (!manualEnabled)
            return;

        if (gesture.Equals("fist"))
        {
            GetComponent<Rigidbody>().AddForce(1 * transform.forward * forceMultiplier);
        }
        else if (gesture.Equals("v_sign"))
        {
            GetComponent<Rigidbody>().AddTorque(-1 * transform.up * forceMultiplier * rotateFactor);
            gesture = "";
        }
        else if (gesture.Equals("thumb_down"))
        {
            GetComponent<Rigidbody>().AddTorque(1 * transform.up * forceMultiplier * rotateFactor);
            gesture = "";
        }


        /* Retrieve hand tracking Module Instance */
        handAnalyzer = sm.QueryHand();

        /* Retrieve hand tracking Data */
        PXCMHandData _handData = handAnalyzer.CreateOutput();

        if (_handData != null)
        {
            _handData.Update();
        }

        handAnalyzer.Dispose();
        sm.ReleaseFrame();

    }
        // Update is called once per frame
        void Update()
        {
            if (session == null)
                return;

            // For accessing hand data
            handAnalyzer = session.QueryHand();
            faceAnalyzer = session.QueryFace();

            if (handAnalyzer != null)
            {
                PXCMHandData handData = handAnalyzer.CreateOutput();
                if (handData != null)
                {
                    handData.Update();

                    PXCMHandData.IHand IHAND; // Ihand instance for accessing future data
                 //   Int32 IhandData; // for QueryOpenness Value
                //    PXCMPoint3DF32 location; // Stores hand tracking position

                    //Fills IHAND with information to later be grabbed and used for tracking + openness
                    handData.QueryHandData(PXCMHandData.AccessOrderType.ACCESS_ORDER_NEAR_TO_FAR, 0, out IHAND);

                    // If there is data in Ihand
                    if (IHAND != null)
                    {

                        // Debug.DrawLine(transform.position, hit.point, Color.red);

                        // Inits hand tracking from the center of the hand.
                //        location = IHAND.QueryMassCenterWorld();
                  //      if (mCurrentDart != null)
                    //    {
                      //      Vector3 locationUnity = new Vector3(location.x, location.y, location.z);
                      //      mCurrentDart.transform.localPosition = locationUnity * RSScale;
                       // }

                    }

                }
                handAnalyzer.Dispose();
                session.ReleaseFrame();

            }

            if (faceAnalyzer != null)
            {

                PXCMFaceData facedata = faceAnalyzer.CreateOutput();
                if (facedata != null)
                {
                    Int32 nfaces = facedata.QueryNumberOfDetectedFaces();
                    for (Int32 i = 0; i < nfaces; i++)
                    {

                        // Retrieve the face landmark data instance

                        PXCMFaceData.Face face = facedata.QueryFaceByIndex(i);

                        PXCMFaceData.PoseData pdata = face.QueryPose();

                        // retrieve the pose information

                        PXCMFaceData.PoseEulerAngles angles;

                        pdata.QueryPoseAngles(out angles);
                        Debug.Log("Eular Angles yaw : " + angles.yaw);
                        Debug.Log("Eular Angles pitch: " + angles.pitch);
                        Debug.Log("Eular Angles Roll: " + angles.roll);
                        angles.pitch = gameObject.transform.rotation.z;
                        angles.yaw = gameObject.transform.rotation.y;

                    }

                    // device is a PXCMCapture.Device instance

                }
            }
        }
Exemple #9
0
	// Update is called once per frame
	void Update () {
		/* Make sure SenseManager Instance is valid */
		if (senseManager == null)
			return;
		
		/* Wait until any frame data is available */
		if (senseManager.AcquireFrame (false) != pxcmStatus.PXCM_STATUS_NO_ERROR)
			return;
		
		/* Retrieve hand tracking Module Instance */
		handAnalyzer = senseManager.QueryHand ();
		
		try
		{
			if (handAnalyzer != null) {
				/* Retrieve hand tracking Data */
				PXCMHandData _handData = handAnalyzer.CreateOutput ();
				if (_handData != null) {
					_handData.Update ();

					PXCMHandData.IHand[] _iHand = new PXCMHandData.IHand[MaxHands];
					NumOfHands = _handData.QueryNumberOfHands ();

					hands.isLeft = false;
					hands.isRight = false;

					/* Retrieve all joint Data */
					if (_handData.QueryHandData (PXCMHandData.AccessOrderType.ACCESS_ORDER_LEFT_HANDS, 0, out _iHand[0]) == pxcmStatus.PXCM_STATUS_NO_ERROR) {
						/*Identify left/right hand */
						gesture[0].isExist = true;
						hands.isLeft = true;

						for (int i = 0; i <  _handData.QueryFiredGesturesNumber(); i++){
							//Debug.Log (i.ToString());
							if (_handData.QueryFiredGestureData (i, out gesture[0].gestureData) == pxcmStatus.PXCM_STATUS_NO_ERROR)
								Debug.Log (gesture[0].gestureData.name);
								//continue;//If you want to use this gesture info, you need to realize a SEND function here.
						}
						for (int j = 0; j < MaxJoints; j++) {
							if (_iHand[0].QueryTrackedJoint ((PXCMHandData.JointType)j, out hands.jointData [0] [j]) != pxcmStatus.PXCM_STATUS_NO_ERROR)					
								hands.jointData [0] [j] = null;
						/*	hands.smoothPosition[0][j].AddSample(hands.jointData[0][j].positionWorld);
							hands.smoothLocalRotation[0][j].AddSample(((Quaternion)hands.jointData[0][j].localRotation).eulerAngles);
							hands.smoothGlobalRotation[0][j].AddSample(((Quaternion)hands.jointData[0][j].globalOrientation).eulerAngles);
						*/}

						if (!handList.ContainsKey (_iHand[0].QueryUniqueId ()))
							handList.Add (_iHand[0].QueryUniqueId (), _iHand[0].QueryBodySide ());
					}else{
						gesture[0].isExist = false;
					}

					if (_handData.QueryHandData (PXCMHandData.AccessOrderType.ACCESS_ORDER_RIGHT_HANDS, 0, out _iHand[1]) == pxcmStatus.PXCM_STATUS_NO_ERROR) {
						/*Identify left/right hand */	
						gesture[1].isExist = true;
						hands.isRight = true;

						for (int i = 0; i < _handData.QueryFiredGesturesNumber(); i++)
							if (_handData.QueryFiredGestureData (i, out gesture[1].gestureData) == pxcmStatus.PXCM_STATUS_NO_ERROR)
								continue;//If you want to use this gesture info, you need to realize a SEND function here.

						for (int j = 0; j < MaxJoints; j++) {
							if (_iHand[1].QueryTrackedJoint ((PXCMHandData.JointType)j, out hands.jointData [1] [j]) != pxcmStatus.PXCM_STATUS_NO_ERROR)					
								hands.jointData [1] [j] = null;
						}
						
						if (!handList.ContainsKey (_iHand[1].QueryUniqueId ()))
							handList.Add (_iHand[1].QueryUniqueId (), _iHand[1].QueryBodySide ());
					}else{
						gesture[1].isExist = false;
					}
				}
				_handData.Dispose ();
			}
		}
		catch (IOException ex)
		{
			Console.WriteLine("An IOException has been thrown!");
			Console.WriteLine(ex.ToString());
			Console.ReadLine();
			return;
		}
		handAnalyzer.Dispose ();
		senseManager.ReleaseFrame ();
	}
    // Update is called once per frame
    void Update()
    {
        /* Make sure SenseManager Instance is valid */
        if (sm == null)
        {
            return;
        }

        /* Wait until any frame data is available */
        if (sm.AcquireFrame(false) != pxcmStatus.PXCM_STATUS_NO_ERROR)
        {
            return;
        }

        /* Retrieve hand tracking Module Instance */
        handAnalyzer = sm.QueryHand();

        if (handAnalyzer != null)
        {
            /* Retrieve hand tracking Data */
            PXCMHandData _handData = handAnalyzer.CreateOutput();
            if (_handData != null)
            {
                _handData.Update();

                /* Retrieve Gesture Data to manipulate GUIText */
                PXCMHandData.GestureData gestureData;
                for (int i = 0; i < _handData.QueryFiredGesturesNumber(); i++)
                {
                    if (_handData.QueryFiredGestureData(i, out gestureData) == pxcmStatus.PXCM_STATUS_NO_ERROR)
                    {
                        DisplayGestures(gestureData);
                    }
                }


                /* Retrieve Alert Data to manipulate GUIText */
                PXCMHandData.AlertData alertData;
                for (int i = 0; i < _handData.QueryFiredAlertsNumber(); i++)
                {
                    if (_handData.QueryFiredAlertData(i, out alertData) == pxcmStatus.PXCM_STATUS_NO_ERROR)
                    {
                        ProcessAlerts(alertData);
                    }
                }

                /* Retrieve all joint Data */
                for (int i = 0; i < _handData.QueryNumberOfHands(); i++)
                {
                    PXCMHandData.IHand _iHand;
                    if (_handData.QueryHandData(PXCMHandData.AccessOrderType.ACCESS_ORDER_FIXED, i, out _iHand) == pxcmStatus.PXCM_STATUS_NO_ERROR)
                    {
                        for (int j = 0; j < MaxJoints; j++)
                        {
                            if (_iHand.QueryTrackedJoint((PXCMHandData.JointType)j, out jointData[i][j]) != pxcmStatus.PXCM_STATUS_NO_ERROR)
                            {
                                jointData[i][j] = null;
                            }
                        }
                        if (!handList.ContainsKey(_iHand.QueryUniqueId()))
                        {
                            handList.Add(_iHand.QueryUniqueId(), _iHand.QueryBodySide());
                        }
                    }
                }

                /* Smoothen and Display the Data - Joints and Bones*/
                DisplayJoints();
            }
            handAnalyzer.Dispose();
        }


        sm.ReleaseFrame();

        RotateCam();
    }
        // Update is called once per frame
        void Update()
        {
            if (session == null)
            {
                return;
            }

            // For accessing hand data
            handAnalyzer = session.QueryHand();
            faceAnalyzer = session.QueryFace();


            if (handAnalyzer != null)
            {
                PXCMHandData handData = handAnalyzer.CreateOutput();
                if (handData != null)
                {
                    handData.Update();

                    PXCMHandData.IHand IHAND; // Ihand instance for accessing future data
                    //   Int32 IhandData; // for QueryOpenness Value
                    //    PXCMPoint3DF32 location; // Stores hand tracking position

                    //Fills IHAND with information to later be grabbed and used for tracking + openness
                    handData.QueryHandData(PXCMHandData.AccessOrderType.ACCESS_ORDER_NEAR_TO_FAR, 0, out IHAND);


                    // If there is data in Ihand
                    if (IHAND != null)
                    {
                        // Debug.DrawLine(transform.position, hit.point, Color.red);


                        // Inits hand tracking from the center of the hand.
                        //        location = IHAND.QueryMassCenterWorld();
                        //      if (mCurrentDart != null)
                        //    {
                        //      Vector3 locationUnity = new Vector3(location.x, location.y, location.z);
                        //      mCurrentDart.transform.localPosition = locationUnity * RSScale;
                        // }
                    }
                }
                handAnalyzer.Dispose();
                session.ReleaseFrame();
            }


            if (faceAnalyzer != null)
            {
                PXCMFaceData facedata = faceAnalyzer.CreateOutput();
                if (facedata != null)
                {
                    Int32 nfaces = facedata.QueryNumberOfDetectedFaces();
                    for (Int32 i = 0; i < nfaces; i++)
                    {
                        // Retrieve the face landmark data instance

                        PXCMFaceData.Face face = facedata.QueryFaceByIndex(i);

                        PXCMFaceData.PoseData pdata = face.QueryPose();



                        // retrieve the pose information

                        PXCMFaceData.PoseEulerAngles angles;

                        pdata.QueryPoseAngles(out angles);
                        Debug.Log("Eular Angles yaw : " + angles.yaw);
                        Debug.Log("Eular Angles pitch: " + angles.pitch);
                        Debug.Log("Eular Angles Roll: " + angles.roll);
                        angles.pitch = gameObject.transform.rotation.z;
                        angles.yaw   = gameObject.transform.rotation.y;
                    }

                    // device is a PXCMCapture.Device instance
                }
            }
        }
    // Update is called once per frame
    void Update()
    {
        /* Make sure SenseManager Instance is valid */
        if (sm == null)
            return;

        /* Wait until any frame data is available */
        if (sm.AcquireFrame (false) != pxcmStatus.PXCM_STATUS_NO_ERROR)
            return;

        /* Retrieve hand tracking Module Instance */
        handAnalyzer = sm.QueryHand ();

        if (handAnalyzer != null) {
            /* Retrieve hand tracking Data */
            PXCMHandData _handData = handAnalyzer.CreateOutput ();
            if (_handData != null) {
                _handData.Update ();

                /* Retrieve Gesture Data to manipulate GUIText */
                PXCMHandData.GestureData gestureData;
                for (int i = 0; i < _handData.QueryFiredGesturesNumber(); i++)
                    if (_handData.QueryFiredGestureData (i, out gestureData) == pxcmStatus.PXCM_STATUS_NO_ERROR)
                        DisplayGestures (gestureData);

                /* Retrieve Alert Data to manipulate GUIText */
                PXCMHandData.AlertData alertData;
                for (int i=0; i<_handData.QueryFiredAlertsNumber(); i++)
                    if (_handData.QueryFiredAlertData (i, out alertData) == pxcmStatus.PXCM_STATUS_NO_ERROR)
                        ProcessAlerts (alertData);

                /* Retrieve all joint Data */
                for (int i = 0; i < _handData.QueryNumberOfHands (); i++) {
                    PXCMHandData.IHand _iHand;
                    if (_handData.QueryHandData (PXCMHandData.AccessOrderType.ACCESS_ORDER_FIXED, i, out _iHand) == pxcmStatus.PXCM_STATUS_NO_ERROR) {
                        for (int j = 0; j < MaxJoints; j++) {
                            if (_iHand.QueryTrackedJoint ((PXCMHandData.JointType)j, out jointData [i] [j]) != pxcmStatus.PXCM_STATUS_NO_ERROR)
                                jointData [i] [j] = null;
                        }
                        if (!handList.ContainsKey (_iHand.QueryUniqueId ()))
                            handList.Add (_iHand.QueryUniqueId (), _iHand.QueryBodySide ());
                    }
                }

                /* Smoothen and Display the Data - Joints and Bones*/
                DisplayJoints ();

            }
            _handData.Dispose ();
        }

        handAnalyzer.Dispose ();

        sm.ReleaseFrame ();

        RotateCam ();
    }
Exemple #13
0
    // Update is called once per frame
    void Update()
    {
        /* Make sure SenseManager Instance is valid */
        if (sm == null)
        {
            return;
        }

        /* Wait until any frame data is available */
        if (sm.AcquireFrame(false) != pxcmStatus.PXCM_STATUS_NO_ERROR)
        {
            return;
        }

        /* Retrieve hand tracking Module Instance */
        handAnalyzer = sm.QueryHand();

        if (handAnalyzer != null)
        {
            /* Retrieve hand tracking Data */
            PXCMHandData _handData = handAnalyzer.CreateOutput();
            if (_handData != null)
            {
                _handData.Update();

                /* Retrieve all joint Data */
                bool[] someJointsDetected = { false, false };
                for (int i = 0; i < _handData.QueryNumberOfHands(); i++)
                {
                    PXCMHandData.IHand _iHand;
                    if (_handData.QueryHandData(PXCMHandData.AccessOrderType.ACCESS_ORDER_FIXED, i, out _iHand) == pxcmStatus.PXCM_STATUS_NO_ERROR)
                    {
                        for (int j = 0; j < MaxJoints; j++)
                        {
                            if (_iHand.QueryTrackedJoint((PXCMHandData.JointType)j, out jointData[i, j]) != pxcmStatus.PXCM_STATUS_NO_ERROR)
                            {
                                jointData[i, j] = null;
                            }
                            else if (jointData[i, j].confidence == 100)
                            {
                                someJointsDetected[i] = true;
                            }
                        }
                        if (!handList.ContainsKey(_iHand.QueryUniqueId()))
                        {
                            handList.Add(_iHand.QueryUniqueId(), _iHand.QueryBodySide());
                        }
                    }
                }

                for (int i = 0; i < MaxHands; i++)
                {
                    if (!someJointsDetected[i] && handWasTracked[i])
                    {
                        for (int j = 0; j < MaxJoints; j++)
                        {
                            Joint joint = myJoints[i, j];
                            if (joint == null)
                            {
                                continue;
                            }
                            joint.transform.position = joint.originalPosition;
                            joint.transform.rotation = joint.originalRotation;

                            foreach (Joint e in joint.extensions)
                            {
                                e.transform.position = e.originalPosition;
                                e.transform.rotation = e.originalRotation;
                            }
                        }
                    }
                    else
                    {
                        if (!handWasTracked[i])
                        {
                            if (myJoints[i, 0] == null || jointData[i, 0] == null || jointData[i, 0].confidence < 100)
                            {
                                break;
                            }
                            PXCMPoint3DF32 smoothedPoint  = smoother3D[i, 0].SmoothValue(jointData[i, 0].positionWorld);
                            Vector3        targetPosition = new Vector3(-1 * smoothedPoint.x, smoothedPoint.y, smoothedPoint.z);
                            trackingOffset[i] = targetPosition - myJoints[i, 0].originalPosition;
                        }
                        /* Smooth the data and move the joints*/
                        MoveJoints(i);
                    }
                    handWasTracked[i] = someJointsDetected[i];
                }
            }
            handAnalyzer.Dispose();
        }


        sm.ReleaseFrame();

        RotateCam();
    }