Beispiel #1
0
 /// <summary>
 /// Adds the received <see cref="GenericDeviceData"/> to the listeners list.
 /// </summary>
 /// <param name="newListener">The <see cref="GenericDeviceData"/> to be added to the listeners list.</param>
 public void AddListener(GenericDeviceData newListener)
 {
     lock (_listenersLock)
     {
         if (_listeners.Contains(newListener) == false)
         {
             _listeners.Add(newListener);
         }
     }
 }
        /// <summary>
        /// Updates The eyetracking panel in the GUI according to its <see cref="GenericDeviceUnity.GenericDeviceData"/> data
        /// </summary>
        private void UpdateEyeTrackGuiPanel()
        {
            var screenHeight = Screen.currentResolution.height;
            var screenWidth  = Screen.currentResolution.width;

            var parentHeight = TrackerScreen.GetComponent <RectTransform>().rect.height;
            var parentWidth  = TrackerScreen.GetComponent <RectTransform>().rect.width;

            var eyePosX = GenericDeviceData.GetFloat(emotiv.eyelocationx.ToString());
            var eyePosY = GenericDeviceData.GetFloat(emotiv.eyelocationy.ToString());

            var newHeightPos = parentHeight * eyePosY / screenHeight;
            var newWidthPos  = parentWidth * eyePosX / screenWidth;

            TrackerPoint.transform.localPosition = new Vector3(newWidthPos, newHeightPos);
        }
Beispiel #3
0
        /// <summary>
        /// Updates the avatar joints values (position and rotation) according to its <see cref="GenericDeviceUnity.GenericDeviceData"/>
        /// </summary>
        public void UpdateAvatar()
        {
            if (_kinectData == null)
            {
                _kinectData = (KinectData)GenericDeviceData;
            }

            //Body.transform.localPosition = _kinectData.GetPosition(KinectBones.waist.ToString());

            if (Head != null)
            {
                Head.transform.rotation = Body.transform.rotation *                                    //reference object
                                          GenericDeviceData.GetRotation(KinectBones.head.ToString()) * //rotation that comes from kinect (world rotation)
                                          _initialRotations[(int)KinectBones.head];                    //initial rotation of the head inside unity
            }
            if (Neck != null)
            {
                Neck.transform.rotation = Body.transform.rotation *
                                          GenericDeviceData.GetRotation(KinectBones.neck.ToString()) *
                                          _initialRotations[(int)KinectBones.neck];
            }

            if (Torso != null)
            {
                Torso.transform.rotation = Body.transform.rotation *
                                           GenericDeviceData.GetRotation(KinectBones.torso.ToString()) *
                                           _initialRotations[(int)KinectBones.torso];
            }

            if (Waist != null)
            {
                Waist.transform.rotation = Body.transform.rotation *
                                           GenericDeviceData.GetRotation(KinectBones.waist.ToString()) *
                                           _initialRotations[(int)KinectBones.waist];
            }

            if (LeftShoulder != null)
            {
                LeftShoulder.transform.rotation = Body.transform.rotation *
                                                  GenericDeviceData.GetRotation(KinectBones.leftshoulder.ToString()) *
                                                  _initialRotations[(int)KinectBones.leftshoulder];
            }

            if (LeftElbow != null)
            {
                LeftElbow.transform.rotation = Body.transform.rotation *
                                               GenericDeviceData.GetRotation(KinectBones.leftelbow.ToString()) *
                                               _initialRotations[(int)KinectBones.leftelbow];
            }

            if (LeftWrist != null)
            {
                LeftWrist.transform.rotation = Body.transform.rotation *
                                               GenericDeviceData.GetRotation(KinectBones.leftwrist.ToString()) *
                                               _initialRotations[(int)KinectBones.leftwrist];
            }

            if (RightShoulder != null)
            {
                RightShoulder.transform.rotation = Body.transform.rotation *
                                                   GenericDeviceData.GetRotation(KinectBones.rightshoulder.ToString()) *
                                                   _initialRotations[(int)KinectBones.rightshoulder];
            }

            if (RightElbow != null)
            {
                RightElbow.transform.rotation = Body.transform.rotation *
                                                GenericDeviceData.GetRotation(KinectBones.rightelbow.ToString()) *
                                                _initialRotations[(int)KinectBones.rightelbow];
            }

            if (RightWrist != null)
            {
                RightWrist.transform.rotation = Body.transform.rotation *
                                                GenericDeviceData.GetRotation(KinectBones.rightwrist.ToString()) *
                                                _initialRotations[(int)KinectBones.rightwrist];
            }

            if (LeftHip != null)
            {
                LeftHip.transform.rotation = Body.transform.rotation *
                                             GenericDeviceData.GetRotation(KinectBones.lefthip.ToString()) *
                                             _initialRotations[(int)KinectBones.lefthip];
            }

            if (LeftKnee != null)
            {
                LeftKnee.transform.rotation = Body.transform.rotation *
                                              GenericDeviceData.GetRotation(KinectBones.leftknee.ToString()) *
                                              _initialRotations[(int)KinectBones.leftknee];
            }

            if (LeftAnkle != null)
            {
                LeftAnkle.transform.rotation = Body.transform.rotation *
                                               GenericDeviceData.GetRotation(KinectBones.leftankle.ToString()) *
                                               _initialRotations[(int)KinectBones.leftankle];
            }

            if (RightHip != null)
            {
                RightHip.transform.rotation = Body.transform.rotation *
                                              GenericDeviceData.GetRotation(KinectBones.righthip.ToString()) *
                                              _initialRotations[(int)KinectBones.righthip];
            }

            if (RightKnee != null)
            {
                RightKnee.transform.rotation = Body.transform.rotation *
                                               GenericDeviceData.GetRotation(KinectBones.rightknee.ToString()) *
                                               _initialRotations[(int)KinectBones.rightknee];
            }

            if (RightAnkle != null)
            {
                RightAnkle.transform.rotation = Body.transform.rotation *
                                                GenericDeviceData.GetRotation(KinectBones.rightankle.ToString()) *
                                                _initialRotations[(int)KinectBones.rightankle];
            }
        }
Beispiel #4
0
 /// <summary>
 /// Adds a <see cref="GenericDeviceData"/> to the list of <see cref="_notifier"/>
 /// </summary>
 /// <param name="genericDeviceData"></param>
 public void AddListener(GenericDeviceData genericDeviceData)
 {
     _notifier.AddListener(genericDeviceData);
 }
Beispiel #5
0
        /// <summary>
        /// Updates the hand joints rotation values according to its <see cref="GenericDeviceUnity.GenericDeviceData"/>
        /// </summary>
        public void UpdateHandRotation()
        {
            if (Arm != null)
            {
                Arm.transform.rotation =
                    HandGameobject.transform.rotation *                                 //reference object gameobject (inthis case the hand)
                    GenericDeviceData.GetRotation(LeapMotionBones.forearm.ToString()) * //rotation that comes from leapmotion (world rotation)
                    _initialRotations[(int)LeapMotionBones.forearm];                    //initial rotation of the forearm inside unity
            }
            if (Hand != null)
            {
                Hand.transform.rotation =
                    HandGameobject.transform.rotation *
                    GenericDeviceData.GetRotation(LeapMotionBones.palm.ToString()) *
                    _initialRotations[(int)LeapMotionBones.palm];
            }

            if (ThumbFingerBone1 != null)
            {
                ThumbFingerBone1.transform.rotation =
                    HandGameobject.transform.rotation *
                    GenericDeviceData.GetRotation(LeapMotionBones.thumb_bone1.ToString()) *
                    _initialRotations[(int)LeapMotionBones.thumb_bone1];
            }

            if (ThumbFingerBone2 != null)
            {
                ThumbFingerBone2.transform.rotation =
                    HandGameobject.transform.rotation *
                    GenericDeviceData.GetRotation(LeapMotionBones.thumb_bone2.ToString()) *
                    _initialRotations[(int)LeapMotionBones.thumb_bone2];
            }

            if (ThumbFingerBone3 != null)
            {
                ThumbFingerBone3.transform.rotation =
                    HandGameobject.transform.rotation *
                    GenericDeviceData.GetRotation(LeapMotionBones.thumb_bone3.ToString()) *
                    _initialRotations[(int)LeapMotionBones.thumb_bone3];
            }

            if (IndexFingerBone1 != null)
            {
                IndexFingerBone1.transform.rotation =
                    HandGameobject.transform.rotation *
                    GenericDeviceData.GetRotation(LeapMotionBones.index_bone1.ToString()) *
                    _initialRotations[(int)LeapMotionBones.index_bone1];
            }

            if (IndexFingerBone2 != null)
            {
                IndexFingerBone2.transform.rotation =
                    HandGameobject.transform.rotation *
                    GenericDeviceData.GetRotation(LeapMotionBones.index_bone2.ToString()) *
                    _initialRotations[(int)LeapMotionBones.index_bone2];
            }

            if (IndexFingerBone3 != null)
            {
                IndexFingerBone3.transform.rotation =
                    HandGameobject.transform.rotation *
                    GenericDeviceData.GetRotation(LeapMotionBones.index_bone3.ToString()) *
                    _initialRotations[(int)LeapMotionBones.index_bone3];
            }

            if (MiddleFingerBone1 != null)
            {
                MiddleFingerBone1.transform.rotation =
                    HandGameobject.transform.rotation *
                    GenericDeviceData.GetRotation(LeapMotionBones.middle_bone1.ToString()) *
                    _initialRotations[(int)LeapMotionBones.middle_bone1];
            }

            if (MiddleFingerBone2 != null)
            {
                MiddleFingerBone2.transform.rotation =
                    HandGameobject.transform.rotation *
                    GenericDeviceData.GetRotation(LeapMotionBones.middle_bone2.ToString()) *
                    _initialRotations[(int)LeapMotionBones.middle_bone2];
            }

            if (MiddleFingerBone3 != null)
            {
                MiddleFingerBone3.transform.rotation =
                    HandGameobject.transform.rotation *
                    GenericDeviceData.GetRotation(LeapMotionBones.middle_bone3.ToString()) *
                    _initialRotations[(int)LeapMotionBones.middle_bone3];
            }

            if (PinkyFingerBone1 != null)
            {
                PinkyFingerBone1.transform.rotation =
                    HandGameobject.transform.rotation *
                    GenericDeviceData.GetRotation(LeapMotionBones.pinky_bone1.ToString()) *
                    _initialRotations[(int)LeapMotionBones.pinky_bone1];
            }

            if (PinkyFingerBone2 != null)
            {
                PinkyFingerBone2.transform.rotation =
                    HandGameobject.transform.rotation *
                    GenericDeviceData.GetRotation(LeapMotionBones.pinky_bone2.ToString()) *
                    _initialRotations[(int)LeapMotionBones.pinky_bone2];
            }

            if (PinkyFingerBone3 != null)
            {
                PinkyFingerBone3.transform.rotation =
                    HandGameobject.transform.rotation *
                    GenericDeviceData.GetRotation(LeapMotionBones.pinky_bone3.ToString()) *
                    _initialRotations[(int)LeapMotionBones.pinky_bone3];
            }

            if (RingFingerBone1 != null)
            {
                RingFingerBone1.transform.rotation =
                    HandGameobject.transform.rotation *
                    GenericDeviceData.GetRotation(LeapMotionBones.ring_bone1.ToString()) *
                    _initialRotations[(int)LeapMotionBones.ring_bone1];
            }

            if (RingFingerBone2 != null)
            {
                RingFingerBone2.transform.rotation =
                    HandGameobject.transform.rotation *
                    GenericDeviceData.GetRotation(LeapMotionBones.ring_bone2.ToString()) *
                    _initialRotations[(int)LeapMotionBones.ring_bone2];
            }

            if (RingFingerBone3 != null)
            {
                RingFingerBone3.transform.rotation =
                    HandGameobject.transform.rotation *
                    GenericDeviceData.GetRotation(LeapMotionBones.ring_bone3.ToString()) *
                    _initialRotations[(int)LeapMotionBones.ring_bone3];
            }
        }
Beispiel #6
0
 /// <summary>
 /// Updates the hand joints position values according to its <see cref="GenericDeviceUnity.GenericDeviceData"/>
 /// </summary>
 private void UpdateHandPosition()
 {
     HandGameobject.transform.localPosition = GenericDeviceData.GetPosition(LeapMotionBones.forearm.ToString());
 }
        /// <summary>
        /// Updates the values of each emotiv signal according to its <see cref="GenericDeviceUnity.GenericDeviceData"/> data
        /// </summary>
        private void UpdateGuiValues()
        {
            BarLongTermExc.fillAmount = GenericDeviceData.GetFloat(emotiv.longtermexcitement.ToString()) /
                                        GenericDeviceData.GetFloat("max_" + emotiv.longtermexcitement);

            BarShortTermExc.fillAmount = GenericDeviceData.GetFloat(emotiv.shorttermexcitement.ToString()) /
                                         GenericDeviceData.GetFloat("max_" + emotiv.shorttermexcitement);
            BarMeditation.fillAmount = GenericDeviceData.GetFloat(emotiv.meditation.ToString()) /
                                       GenericDeviceData.GetFloat("max_" + emotiv.meditation);
            BarFrustration.fillAmount = GenericDeviceData.GetFloat(emotiv.frustration.ToString()) /
                                        GenericDeviceData.GetFloat("max_" + emotiv.frustration);
            BarBoredom.fillAmount = GenericDeviceData.GetFloat(emotiv.boredom.ToString()) /
                                    GenericDeviceData.GetFloat("max_" + emotiv.boredom);
            BarEyebrowExtent.fillAmount = GenericDeviceData.GetFloat(emotiv.eyebrowextent.ToString()) /
                                          GenericDeviceData.GetFloat("max_" + emotiv.eyebrowextent);
            BarSmileValue.fillAmount = GenericDeviceData.GetFloat(emotiv.smileextent.ToString()) /
                                       GenericDeviceData.GetFloat("max_" + emotiv.smileextent);
            BarUpperFacePower.fillAmount = GenericDeviceData.GetFloat(emotiv.upperfacepower.ToString()) /
                                           GenericDeviceData.GetFloat("max_" + emotiv.upperfacepower);
            BarLowerFacePower.fillAmount = GenericDeviceData.GetFloat(emotiv.lowerfacepower.ToString()) /
                                           GenericDeviceData.GetFloat("max_" + emotiv.lowerfacepower);

            LongTermExcitementValue.text =
                GenericDeviceData.GetFloat(emotiv.longtermexcitement.ToString()).ToString();
            ShortTermExcitementValue.text =
                GenericDeviceData.GetFloat(emotiv.shorttermexcitement.ToString()).ToString();
            MeditationValue.text =
                GenericDeviceData.GetFloat(emotiv.meditation.ToString()).ToString();
            FrustrationValue.text =
                GenericDeviceData.GetFloat(emotiv.frustration.ToString()).ToString();
            BoredomValue.text =
                GenericDeviceData.GetFloat(emotiv.boredom.ToString()).ToString();
            EyebrowExtentValue.text =
                GenericDeviceData.GetFloat(emotiv.eyebrowextent.ToString()).ToString();
            SmileValue.text =
                GenericDeviceData.GetFloat(emotiv.smileextent.ToString()).ToString();
            UpperFacePowerValue.text =
                GenericDeviceData.GetFloat(emotiv.upperfacepower.ToString()).ToString();
            LowerFacePowerValue.text =
                GenericDeviceData.GetFloat(emotiv.lowerfacepower.ToString()).ToString();


            CounterValue.text = GenericDeviceData.GetFloat(emotiv.counter.ToString()).ToString();
            AF4Value.text     = GenericDeviceData.GetFloat(emotiv.af4.ToString()).ToString();
            F3Value.text      = GenericDeviceData.GetFloat(emotiv.f3.ToString()).ToString();
            F4Value.text      = GenericDeviceData.GetFloat(emotiv.f4.ToString()).ToString();
            F7Value.text      = GenericDeviceData.GetFloat(emotiv.f7.ToString()).ToString();
            F8Value.text      = GenericDeviceData.GetFloat(emotiv.f8.ToString()).ToString();
            FC5Value.text     = GenericDeviceData.GetFloat(emotiv.fc5.ToString()).ToString();
            FC6Value.text     = GenericDeviceData.GetFloat(emotiv.fc6.ToString()).ToString();
            T7Value.text      = GenericDeviceData.GetFloat(emotiv.t7.ToString()).ToString();
            T8Value.text      = GenericDeviceData.GetFloat(emotiv.t8.ToString()).ToString();
            P7Value.text      = GenericDeviceData.GetFloat(emotiv.p7.ToString()).ToString();
            P8Value.text      = GenericDeviceData.GetFloat(emotiv.p8.ToString()).ToString();
            O1Value.text      = GenericDeviceData.GetFloat(emotiv.o1.ToString()).ToString();
            O2Value.text      = GenericDeviceData.GetFloat(emotiv.o2.ToString()).ToString();

            var gyro =
                GenericDeviceData.GetRotation(emotiv.gyro.ToString());

            GyroPosValue.text = string.Format("X: {0}; Y: {1}; Z: {2}", gyro.x, gyro.y, gyro.z);

            EyePosValue.text = string.Format("X: {0}; Y: {1};", emotiv.eyelocationy, emotiv.eyelocationy);

            BlinkValue.text        = GenericDeviceData.GetBoolean(emotiv.blink.ToString()) ? "TRUE" : "FALSE";
            LookingUpValue.text    = GenericDeviceData.GetBoolean(emotiv.lookingup.ToString()) ? "TRUE" : "FALSE";
            LookingDownValue.text  = GenericDeviceData.GetBoolean(emotiv.lookingdown.ToString()) ? "TRUE" : "FALSE";
            LookingLeftValue.text  = GenericDeviceData.GetBoolean(emotiv.lookingleft.ToString()) ? "TRUE" : "FALSE";
            LookingRightValue.text = GenericDeviceData.GetBoolean(emotiv.lookingright.ToString()) ? "TRUE" : "FALSE";
        }