void Update () 
	{
		// get the face-tracking manager instance
		if(faceManager == null)
		{
			kinectManager = KinectManager.Instance;
			faceManager = FacetrackingManager.Instance;
		}
		
		if (kinectManager && faceManager && faceManager.IsTrackingFace ()) {
			// get user-id by user-index
			long userId = kinectManager.GetUserIdByIndex (playerIndex);
			if (userId == 0)
				return;

			// head rotation
			Quaternion newRotation = initialRotation * faceManager.GetHeadRotation (userId, true);
			
			if (smoothFactor != 0f)
				transform.rotation = Quaternion.Slerp (transform.rotation, newRotation, smoothFactor * Time.deltaTime);
			else
				transform.rotation = newRotation;

			// head position
			Vector3 newPosition = faceManager.GetHeadPosition (userId, true);
			//Debug.Log(newPosition.ToString());

			if (verticalOffset != 0f) {
				Vector3 dirHead = new Vector3 (0, verticalOffset, 0);
				dirHead = transform.InverseTransformDirection (dirHead);
				newPosition += dirHead;
			}
			
//			if(smoothFactor != 0f)
//				transform.position = Vector3.Lerp(transform.position, newPosition, smoothFactor * Time.deltaTime);
//			else

			//<----------------------------------------------correct modal position --------------------------------------------->
			//Debug.Log ("new Positionx   "  + newPosition.x.ToString());

			if(newPosition.x > 0f)
				newPosition.x = newPosition.x * 0.8f - deltaX; 
			else if(newPosition.x < 0f)
				newPosition.x = newPosition.x * 0.8f + deltaX;
			//<------------------------------------------------------------------------------------------------------------------>


			transform.position = newPosition;

			//Debug.Log ("transform.position   " + transform.position.x.ToString());
			//Debug.Log(newPosition.ToString());
		} else if (kinectManager && faceManager && !faceManager.IsTrackingFace ()) {
		
			transform.position = -Vector3.one;
		}

	}
Exemple #2
0
    // Update is called once per frame
    void Update()
    {
        KinectManager manager = KinectManager.Instance;

        if (manager && manager.IsInitialized() && foregroundCamera)
        {
            if (facetrackingmanager.IsTrackingFace())
            {
                cube.transform.position = getHDFacePoints.GetAllPoint(11);

                // rotation
                Vector3 targetDir = getHDFacePoints.GetAllPoint(11) - (getHDFacePoints.GetAllPoint(469) + getHDFacePoints.GetAllPoint(1117)) / 2;
                Vector3 oriDir    = new Vector3(0.0f, 0.0f, 1.0f);
                Vector3 newDir    = Vector3.RotateTowards(oriDir, targetDir, 360.0f, 360.0f);

                // set right rotation


                // calculate left or right face   (1297,1293) two side
                Vector3 left_pt        = getHDFacePoints.GetAllPoint(1297);
                Vector3 right_pt       = getHDFacePoints.GetAllPoint(1293);
                Vector3 temp_center_pt = left_pt - right_pt;

                Vector3 cro_out = Vector3.Cross(newDir, temp_center_pt);

                cube.transform.rotation = Quaternion.LookRotation(newDir, cro_out);
            }
        }
    }
Exemple #3
0
    void Update()
    {
        if (facetrackingManager == null)
        {
            facetrackingManager = FacetrackingManager.Instance;
        }

        if (facetrackingManager && facetrackingManager.IsTrackingFace())
        {
            // set head position & rotation
            if (head != null)
            {
                //Vector3 newPosition = HeadInitialPosition + manager.GetHeadPosition();
                //HeadTransform.localPosition = Vector3.Lerp(HeadTransform.localPosition, newPosition, 3 * Time.deltaTime);

                //Quaternion newRotation = HeadInitialRotation * facetrackingManager.GetHeadRotation();
                //head.localRotation = Quaternion.Slerp(head.localRotation, newRotation, 3 * Time.deltaTime);
                //head.localRotation = HeadInitialRotation * facetrackingManager.GetHeadRotation();
                Vector3 targetOrientation = Vector3.zero;
                targetOrientation.x = facetrackingManager.GetHeadRotation().eulerAngles.x;
                targetOrientation.y = facetrackingManager.GetHeadRotation().eulerAngles.y;

                head.localRotation = Quaternion.Euler(targetOrientation);
            }
        }
    }
Exemple #4
0
    public static float GetNeckAngle(FacetrackingManager facetrackingManager, JointName joint)
    {
        float angle = 0;

        if (facetrackingManager == null)
        {
            facetrackingManager = FacetrackingManager.Instance;
        }

        if (facetrackingManager && facetrackingManager.IsTrackingFace())
        {
            switch (joint)
            {
            case JointName.pan:
                angle = facetrackingManager.GetHeadRotation().eulerAngles.y;
                if (angle > 180f)
                {
                    angle = angle - 360f;                   //180도를 넘을리는 없지만 각의 범위를 -180~180로 쓰겠다는 의미
                }
                break;

            case JointName.tilt:
                angle = facetrackingManager.GetHeadRotation().eulerAngles.x;
                if (angle > 180f)
                {
                    angle = angle - 360f;
                }
                break;

            default: break;
            }
        }

        return(angle);
    }
    void Update()
    {
        // get the face-tracking manager instance
        if (faceManager == null)
        {
            kinectManager = KinectManager.Instance;
            faceManager   = FacetrackingManager.Instance;
        }

        // get user-id by user-index
        long userId = kinectManager ? kinectManager.GetUserIdByIndex(playerIndex) : 0;

        if (kinectManager && kinectManager.IsInitialized() && userId != 0 &&
            faceManager && faceManager.IsTrackingFace(userId))
        {
            if (faceManager.GetUserFaceProperties(userId, ref faceProps))
            {
                string sFaceProps = "";
                foreach (string propName in faceProps.Keys)
                {
                    string propValue = faceProps[propName];
                    sFaceProps += propName + "=" + propValue + "\n";
                }

                if (infoText && sFaceProps.Length > 0)
                {
                    //Debug.Log("FaceProps: " + sFaceProps);
                    infoText.text = sFaceProps;
                }
            }
        }
    }
    void Update()
    {
        // get the face-tracking manager instance
        if (faceManager == null)
        {
            kinectManager = KinectManager.Instance;
            faceManager   = FacetrackingManager.Instance;
        }

        // get user-id by user-index
        long userId = kinectManager ? kinectManager.GetUserIdByIndex(playerIndex) : 0;

        if (kinectManager && kinectManager.IsInitialized() && userId != 0 &&
            faceManager && faceManager.IsTrackingFace(userId))
        {
            if (faceManager.GetUserFaceProperties(userId, ref faceProps))
            {
                //NuitrackInterface.FaceLandmarks faceLM = new NuitrackInterface.FaceLandmarks();
                //if(faceProps.ContainsKey("landmarks"))
                //{
                //    faceLM = JsonUtility.FromJson<NuitrackInterface.FaceLandmarks>(faceProps["landmarks"]);
                //    // do something with the face landmarks
                //}

                //Vector2 leftEyePos = Vector2.zero;
                //if (faceProps.ContainsKey("lefteye"))
                //{
                //    leftEyePos = JsonUtility.FromJson<Vector2>(faceProps["lefteye"]);
                //    // do something with the left-eye position
                //}

                //Vector2 rightEyePos = Vector2.zero;
                //if (faceProps.ContainsKey("righteye"))
                //{
                //    rightEyePos = JsonUtility.FromJson<Vector2>(faceProps["righteye"]);
                //    // do something with the right-eye position
                //}

                string sFaceProps = "";
                foreach (string propName in faceProps.Keys)
                {
                    string propValue = faceProps[propName];
                    if (propValue != null && propValue.Length > maxPropLength)
                    {
                        propValue = propValue.Substring(0, maxPropLength) + "...";
                    }

                    sFaceProps += propName + "=" + propValue + "\n";
                }

                if (infoText && sFaceProps.Length > 0)
                {
                    //Debug.Log("FaceProps: " + sFaceProps);
                    infoText.text = sFaceProps;
                }
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (manager && manager.IsInitialized() && foregroundCamera)
        {
            // get the background rectangle (use the portrait background, if available)
            Rect backgroundRect = foregroundCamera.pixelRect;

            // check if face is tracking
            if (facetrackingmanager.IsTrackingFace())
            {
                if (DrawSpecialPointOn)
                {
                    //------------ draw 35 special face point------------
                    //Vector3[] newFacePos = new Vector3[35];

                    //HighDetailFacePoints[] facePoints = (HighDetailFacePoints[])System.Enum.GetValues(typeof(HighDetailFacePoints));

                    //for (int i = 0; i < facePoints.Length; i++)
                    //{
                    //    HighDetailFacePoints point = facePoints[i];
                    //    newFacePos[i] = getHDFacePoints.GetPoint(point);

                    //    //Vector3 temp = manager.GetHDFaceOverlay(newFacePos[i], foregroundCamera, backgroundRect);
                    //    Vector3 temp = newFacePos[i];

                    //    //sphere[i].transform.position = newFacePos[i];
                    //    sphere[i].transform.position = temp;
                    //}

                    //------------ draw all face points------------
                    for (int i = 0; i < 1347; i++)
                    {
                        // draw specific point to white
                        //if (i == 420)
                        //{
                        //    Material m_Material = childGameObject[i].GetComponent<Renderer>().material;
                        //    m_Material.color = UnityEngine.Color.white;
                        //    childGameObject[i].GetComponent<Renderer>().material = m_Material;
                        //}

                        childGameObject[i].transform.position = getHDFacePoints.GetAllPoint(i);
                    }
                }
                else
                {
                    for (int i = 0; i < 1347; i++)
                    {
                        childGameObject[i].transform.position = new Vector3(0.075f, 0, 0);
                    }
                }
            }
        }
    }
Exemple #8
0
    void Update()

    {      // float translation = Time.deltaTime * 10;
        // get the face-tracking manager instance
        if (manager == null)
        {
            manager = FacetrackingManager.Instance;
        }

        if (manager && manager.IsTrackingFace())
        {
            // set head position & rotation
            //	FaceFrameReference faceRef = e.FrameReference;
        }
    }
Exemple #9
0
    private Rect GetHeadJointFaceRect(long userId)
    {
        Rect faceJointRect = new Rect();

        if (useTrackedFaceRect && faceManager &&
            faceManager.IsFaceTrackingInitialized() && faceManager.IsTrackingFace(userId))
        {
            faceJointRect = faceManager.GetFaceColorRect(userId);
            return(faceJointRect);
        }

        if (kinectManager.IsJointTracked(userId, (int)KinectInterop.JointType.Head))
        {
            Vector3 posHeadRaw = kinectManager.GetJointKinectPosition(userId, (int)KinectInterop.JointType.Head);

            if (posHeadRaw != Vector3.zero)
            {
                Vector2 posDepthHead = kinectManager.MapSpacePointToDepthCoords(posHeadRaw);
                ushort  depthHead    = kinectManager.GetDepthForPixel((int)posDepthHead.x, (int)posDepthHead.y);

                Vector3 sizeHalfFace = new Vector3(faceWidth / 2f, faceHeight / 2f, 0f);
                Vector3 posFaceRaw1  = posHeadRaw - sizeHalfFace;
                Vector3 posFaceRaw2  = posHeadRaw + sizeHalfFace;

                Vector2 posDepthFace1 = kinectManager.MapSpacePointToDepthCoords(posFaceRaw1);
                Vector2 posDepthFace2 = kinectManager.MapSpacePointToDepthCoords(posFaceRaw2);

                if (posDepthFace1 != Vector2.zero && posDepthFace2 != Vector2.zero && depthHead > 0)
                {
                    Vector2 posColorFace1 = kinectManager.MapDepthPointToColorCoords(posDepthFace1, depthHead);
                    Vector2 posColorFace2 = kinectManager.MapDepthPointToColorCoords(posDepthFace2, depthHead);

                    if (!float.IsInfinity(posColorFace1.x) && !float.IsInfinity(posColorFace1.y) &&
                        !float.IsInfinity(posColorFace2.x) && !float.IsInfinity(posColorFace2.y))
                    {
                        faceJointRect.x      = posColorFace1.x;
                        faceJointRect.y      = posColorFace2.y;
                        faceJointRect.width  = Mathf.Abs(posColorFace2.x - posColorFace1.x);
                        faceJointRect.height = Mathf.Abs(posColorFace2.y - posColorFace1.y);
                    }
                }
            }
        }

        return(faceJointRect);
    }
    void Update()
    {
        // get the face-tracking manager instance
        if (faceManager == null)
        {
            kinectManager = KinectManager.Instance;
            faceManager   = FacetrackingManager.Instance;
        }

        if (kinectManager && faceManager && faceManager.IsTrackingFace())
        {
            // get user-id by user-index
            long userId = kinectManager.GetUserIdByIndex(playerIndex);
            if (userId == 0)
            {
                return;
            }

            // head rotation
            Quaternion newRotation = initialRotation * faceManager.GetHeadRotation(userId, true);

            if (smoothFactor != 0f)
            {
                transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, smoothFactor * Time.deltaTime);
            }
            else
            {
                transform.rotation = newRotation;
            }

            // head position
            Vector3 newPosition = faceManager.GetHeadPosition(userId, true);

            if (verticalOffset != 0f)
            {
                Vector3 dirHead = new Vector3(horizontalOffset, verticalOffset, zOffset);
                dirHead      = transform.InverseTransformDirection(dirHead);
                newPosition += dirHead;
            }

//			if(smoothFactor != 0f)
//				transform.position = Vector3.Lerp(transform.position, newPosition, smoothFactor * Time.deltaTime);
//			else
            transform.position = newPosition;
        }
    }
Exemple #11
0
    void Update()
    {
        // get the face-tracking manager instance
        if (faceManager == null)
        {
            faceManager = FacetrackingManager.Instance;
        }

        if (faceManager && faceManager.IsTrackingFace())
        {
            // head rotation
            Quaternion newRotation = initialRotation * faceManager.GetHeadRotation(true);

            if (smoothFactor != 0f)
            {
                transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, smoothFactor * Time.deltaTime);
            }
            else
            {
                transform.rotation = newRotation;
            }

            // head position
            Vector3 newPosition = faceManager.GetHeadPosition(true);

            if (verticalOffset != 0f)
            {
                Vector3 dirHead = new Vector3(0, verticalOffset, 0);
                dirHead      = transform.InverseTransformDirection(dirHead);
                newPosition += dirHead;
            }

//			if(smoothFactor != 0f)
//				transform.position = Vector3.Lerp(transform.position, newPosition, smoothFactor * Time.deltaTime);
//			else
            transform.position = newPosition;
        }
    }
    void Update()
    {
        // get the face-tracking manager instance
        if (manager == null)
        {
            manager = FacetrackingManager.Instance;
        }

        if (manager && manager.IsTrackingFace())
        {
            // set head position & rotation
            if (HeadTransform != null)
            {
                // head position
                Vector3 newPosition = HeadInitialPosition + manager.GetHeadPosition(mirroredHeadMovement);

                if (smoothFactor != 0f)
                {
                    HeadTransform.localPosition = Vector3.Lerp(HeadTransform.localPosition, newPosition, smoothFactor * Time.deltaTime);
                }
                else
                {
                    HeadTransform.localPosition = newPosition;
                }

                // head rotation
                Quaternion newRotation = HeadInitialRotation * manager.GetHeadRotation(mirroredHeadMovement);

                if (smoothFactor != 0f)
                {
                    HeadTransform.localRotation = Quaternion.Slerp(HeadTransform.localRotation, newRotation, smoothFactor * Time.deltaTime);
                }
                else
                {
                    HeadTransform.localRotation = newRotation;
                }
            }

            // apply animation units

            // AU0 - Upper Lip Raiser
            // 0=neutral, covering teeth; 1=showing teeth fully; -1=maximal possible pushed down lip
            float fAU0 = manager.GetAnimUnit(KinectInterop.FaceShapeAnimations.LipPucker);
            SetJointRotation(UpperLipLeft, UpperLipLeftAxis, fAU0, UpperLipLeftNeutral, UpperLipLeftUp);
            SetJointRotation(UpperLipRight, UpperLipRightAxis, fAU0, UpperLipRightNeutral, UpperLipRightUp);

            // AU1 - Jaw Lowerer
            // 0=closed; 1=fully open; -1= closed, like 0
            float fAU1 = manager.GetAnimUnit(KinectInterop.FaceShapeAnimations.JawOpen);
            SetJointRotation(Jaw, JawAxis, fAU1, JawNeutral, JawDown);

            // AU2 – Lip Stretcher
            // 0=neutral; 1=fully stretched (joker’s smile); -1=fully rounded (kissing mouth)
            float fAU2_left = manager.GetAnimUnit(KinectInterop.FaceShapeAnimations.LipStretcherLeft);
            fAU2_left = (platform == KinectInterop.DepthSensorPlatform.KinectSDKv2) ? (fAU2_left * 2 - 1) : fAU2_left;
            SetJointRotation(LipLeft, LipLeftAxis, fAU2_left, LipLeftNeutral, LipLeftStretched);

            float fAU2_right = manager.GetAnimUnit(KinectInterop.FaceShapeAnimations.LipStretcherRight);
            fAU2_right = (platform == KinectInterop.DepthSensorPlatform.KinectSDKv2) ? (fAU2_right * 2 - 1) : fAU2_right;
            SetJointRotation(LipRight, LipRightAxis, fAU2_right, LipRightNeutral, LipRightStretched);

            // AU3 – Brow Lowerer
            // 0=neutral; -1=raised almost all the way; +1=fully lowered (to the limit of the eyes)
            float fAU3_left = manager.GetAnimUnit(KinectInterop.FaceShapeAnimations.LefteyebrowLowerer);
            fAU3_left = (platform == KinectInterop.DepthSensorPlatform.KinectSDKv2) ? (fAU3_left * 2 - 1) : fAU3_left;
            SetJointRotation(EyebrowLeft, EyebrowLeftAxis, fAU3_left, EyebrowLeftNeutral, EyebrowLeftLowered);

            float fAU3_right = manager.GetAnimUnit(KinectInterop.FaceShapeAnimations.RighteyebrowLowerer);
            fAU3_right = (platform == KinectInterop.DepthSensorPlatform.KinectSDKv2) ? (fAU3_right * 2 - 1) : fAU3_right;
            SetJointRotation(EyebrowRight, EyebrowRightAxis, fAU3_right, EyebrowRightNeutral, EyebrowRightLowered);

            // AU4 – Lip Corner Depressor
            // 0=neutral; -1=very happy smile; +1=very sad frown
            float fAU4_left = manager.GetAnimUnit(KinectInterop.FaceShapeAnimations.LipCornerDepressorLeft);
            fAU4_left = (platform == KinectInterop.DepthSensorPlatform.KinectSDKv2) ? (fAU4_left * 2) : fAU4_left;
            SetJointRotation(LipCornerLeft, LipCornerLeftAxis, fAU4_left, LipCornerLeftNeutral, LipCornerLeftDepressed);

            float fAU4_right = manager.GetAnimUnit(KinectInterop.FaceShapeAnimations.LipCornerDepressorRight);
            fAU4_right = (platform == KinectInterop.DepthSensorPlatform.KinectSDKv2) ? (fAU4_right * 2) : fAU4_right;
            SetJointRotation(LipCornerRight, LipCornerRightAxis, fAU4_right, LipCornerRightNeutral, LipCornerRightDepressed);

            // AU6, AU7 – Eyelid closed
            // 0=neutral; -1=raised; +1=fully lowered
            float fAU6_left = manager.GetAnimUnit(KinectInterop.FaceShapeAnimations.LefteyeClosed);
            fAU6_left = (platform == KinectInterop.DepthSensorPlatform.KinectSDKv2) ? (fAU6_left * 2 - 1) : fAU6_left;
            SetJointRotation(UpperEyelidLeft, UpperEyelidLeftAxis, fAU6_left, UpperEyelidLeftNeutral, UpperEyelidLeftLowered);
            SetJointRotation(LowerEyelidLeft, LowerEyelidLeftAxis, fAU6_left, LowerEyelidLeftNeutral, LowerEyelidLeftRaised);

            float fAU6_right = manager.GetAnimUnit(KinectInterop.FaceShapeAnimations.RighteyeClosed);
            fAU6_right = (platform == KinectInterop.DepthSensorPlatform.KinectSDKv2) ? (fAU6_right * 2 - 1) : fAU6_right;
            SetJointRotation(UpperEyelidRight, UpperEyelidRightAxis, fAU6_right, UpperEyelidRightNeutral, UpperEyelidRightLowered);
            SetJointRotation(LowerEyelidRight, LowerEyelidRightAxis, fAU6_right, UpperEyelidRightNeutral, LowerEyelidRightRaised);
        }
    }
Exemple #13
0
    void Update()
    {
        // get the face-tracking manager instance
        if (faceManager == null)
        {
            kinectManager = KinectManager.Instance;
            faceManager   = FacetrackingManager.Instance;
        }

        // get user-id by user-index
        long userId = kinectManager ? kinectManager.GetUserIdByIndex(playerIndex) : 0;

        if (kinectManager && kinectManager.IsInitialized() && userId != 0 &&
            faceManager && faceManager.IsTrackingFace(userId) && foregroundCamera)
        {
            // get head position
            Vector3 newPosition = faceManager.GetHeadPosition(userId, true);

            // get head rotation
            Quaternion newRotation = initialRotation * faceManager.GetHeadRotation(userId, true);

            // rotational fix, provided by Richard Borys:
            // The added rotation fixes rotational error that occurs when person is not centered in the middle of the kinect
            Vector3 addedRotation = newPosition.z != 0f ? new Vector3(Mathf.Rad2Deg * (Mathf.Tan(newPosition.y) / newPosition.z),
                                                                      Mathf.Rad2Deg * (Mathf.Tan(newPosition.x) / newPosition.z), 0) : Vector3.zero;

            addedRotation.x = newRotation.eulerAngles.x + addedRotation.x;
            addedRotation.y = newRotation.eulerAngles.y + addedRotation.y;
            addedRotation.z = newRotation.eulerAngles.z + addedRotation.z;

            newRotation = Quaternion.Euler(addedRotation.x, addedRotation.y, addedRotation.z);
            // end of rotational fix

            if (smoothFactorRotation != 0f)
            {
                transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, smoothFactorRotation * Time.deltaTime);
            }
            else
            {
                transform.rotation = newRotation;
            }

            // 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();
            }

            // model position
            newPosition = kinectManager.GetJointPosColorOverlay(userId, (int)KinectInterop.JointType.Head, foregroundCamera, backgroundRect);
            if (newPosition == Vector3.zero)
            {
                // hide the model behind the camera
                newPosition.z = -10f;
            }

            if (verticalOffset != 0f)
            {
                // add the vertical offset
                Vector3 dirHead = new Vector3(0, verticalOffset, 0);
                dirHead      = transform.InverseTransformDirection(dirHead);
                newPosition += dirHead;
            }

            // go to the new position
            if (smoothFactorMovement != 0f && transform.position.z >= 0f)
            {
                transform.position = Vector3.Lerp(transform.position, newPosition, smoothFactorMovement * Time.deltaTime);
            }
            else
            {
                transform.position = newPosition;
            }

            // scale the model if needed
            if (transform.localScale.x != modelScaleFactor)
            {
                transform.localScale = new Vector3(modelScaleFactor, modelScaleFactor, modelScaleFactor);
            }
        }
        else
        {
            // hide the model behind the camera
            if (transform.position.z >= 0f)
            {
                transform.position = new Vector3(0f, 0f, -10f);
            }
        }
    }
Exemple #14
0
    void Update()
    {
        // get the face-tracking manager instance
        if (manager == null)
        {
            manager = FacetrackingManager.Instance;
        }

        if (manager && manager.IsTrackingFace())
        {
            // set head position & rotation
            if (HeadTransform != null)
            {
                Vector3 newPosition = HeadInitialPosition + manager.GetHeadPosition();
                HeadTransform.localPosition = Vector3.Lerp(HeadTransform.localPosition, newPosition, 3 * Time.deltaTime);

                Quaternion newRotation = HeadInitialRotation * manager.GetHeadRotation();
                HeadTransform.localRotation = Quaternion.Slerp(HeadTransform.localRotation, newRotation, 3 * Time.deltaTime);
            }

            // get animation units
            int iAUCount = manager.GetAnimUnitsCount();

            if (iAUCount >= 6)
            {
                // AU0 - Upper Lip Raiser
                // 0=neutral, covering teeth; 1=showing teeth fully; -1=maximal possible pushed down lip
                float fAU0 = manager.GetAnimUnit(0);
                SetJointRotation(UpperLipLeft, UpperLipLeftAxis, fAU0, UpperLipLeftNeutral, UpperLipLeftUp);
                SetJointRotation(UpperLipRight, UpperLipRightAxis, fAU0, UpperLipRightNeutral, UpperLipRightUp);

                // AU1 - Jaw Lowerer
                // 0=closed; 1=fully open; -1= closed, like 0
                float fAU1 = manager.GetAnimUnit(1);
                SetJointRotation(Jaw, JawAxis, fAU1, JawNeutral, JawDown);

                // AU2 – Lip Stretcher
                // 0=neutral; 1=fully stretched (joker’s smile); -1=fully rounded (kissing mouth)
                float fAU2 = manager.GetAnimUnit(2);
                SetJointRotation(LipLeft, LipLeftAxis, fAU2, LipLeftNeutral, LipLeftStretched);
                SetJointRotation(LipRight, LipRightAxis, fAU2, LipRightNeutral, LipRightStretched);

                // AU3 – Brow Lowerer
                // 0=neutral; -1=raised almost all the way; +1=fully lowered (to the limit of the eyes)
                float fAU3 = manager.GetAnimUnit(3);
                SetJointRotation(EyebrowLeft, EyebrowLeftAxis, fAU3, EyebrowLeftNeutral, EyebrowLeftLowered);
                SetJointRotation(EyebrowRight, EyebrowRightAxis, fAU3, EyebrowRightNeutral, EyebrowRightLowered);

                // AU4 – Lip Corner Depressor
                // 0=neutral; -1=very happy smile; +1=very sad frown
                float fAU4 = manager.GetAnimUnit(4);
                SetJointRotation(LipCornerLeft, LipCornerLeftAxis, fAU4, LipCornerLeftNeutral, LipCornerLeftDepressed);
                SetJointRotation(LipCornerRight, LipCornerRightAxis, fAU4, LipCornerRightNeutral, LipCornerRightDepressed);

                // AU5 – Outer Brow Raiser
                // 0=neutral; -1=fully lowered as a very sad face; +1=raised as in an expression of deep surprise
                float fAU5 = manager.GetAnimUnit(5);
                SetJointRotation(OuterBrowLeft, OuterBrowLeftAxis, fAU5, OuterBrowLeftNeutral, OuterBrowLeftRaised);
                SetJointRotation(OuterBrowRight, OuterBrowRightAxis, fAU5, OuterBrowRightNeutral, OuterBrowRightRaised);
            }

            if (iAUCount >= 8)
            {
                // AU6 – Upper Eyelid
                // 0=neutral; -1=raised; +1=fully lowered
                float fAU6 = manager.GetAnimUnit(6);
                SetJointRotation(UpperEyelidLeft, UpperEyelidLeftAxis, fAU6, UpperEyelidLeftNeutral, UpperEyelidLeftLowered);
                SetJointRotation(UpperEyelidRight, UpperEyelidRightAxis, fAU6, UpperEyelidRightNeutral, UpperEyelidRightLowered);

                // AU7 – Lower Eyelid
                // 0=neutral; -1=lowered; +1=fully raised
                float fAU7 = manager.GetAnimUnit(7);
                SetJointRotation(LowerEyelidLeft, LowerEyelidLeftAxis, fAU7, LowerEyelidLeftNeutral, LowerEyelidLeftRaised);
                SetJointRotation(LowerEyelidRight, LowerEyelidRightAxis, fAU7, LowerEyelidRightNeutral, LowerEyelidRightRaised);
            }
        }
    }
    void Update()
    {
        // get the face-tracking manager instance
        if (manager == null)
        {
            manager = FacetrackingManager.Instance;
        }

        if (manager && manager.IsTrackingFace())
        {
            // set head position & rotation
            if (HeadTransform != null)
            {
                // head rotation
                Quaternion newRotation = HeadInitialRotation * manager.GetHeadRotation(mirroredHeadMovement);

                if (smoothFactor != 0f)
                {
                    HeadTransform.rotation = Quaternion.Slerp(HeadTransform.rotation, newRotation, smoothFactor * Time.deltaTime);
                }
                else
                {
                    HeadTransform.rotation = newRotation;
                }

                // head position
                Vector3 newPosition = HeadInitialPosition + manager.GetHeadPosition(mirroredHeadMovement);

                // check for head pos overlay
                if (foregroundCamera)
                {
                    // get the background rectangle (use the portrait background, if available)
                    Rect backgroundRect             = foregroundCamera.pixelRect;
                    PortraitBackground portraitBack = PortraitBackground.Instance;

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

                    KinectManager kinectManager = KinectManager.Instance;

                    if (kinectManager)
                    {
                        long    userId          = kinectManager.GetUserIdByIndex(manager.playerIndex);
                        Vector3 posColorOverlay = kinectManager.GetJointPosColorOverlay(userId, (int)KinectInterop.JointType.Head, foregroundCamera, backgroundRect);

                        if (posColorOverlay != Vector3.zero)
                        {
                            newPosition = posColorOverlay;

//							if(overlayObj)
//							{
//								overlayObj.position = newPosition;
//							}
                        }
                    }
                }

                // vertical offet
                if (verticalOffset != 0f)
                {
                    // add the vertical offset
                    Vector3 dirHead = new Vector3(0, verticalOffset, 0);
                    dirHead      = HeadTransform.InverseTransformDirection(dirHead);
                    newPosition += dirHead;
                }

                // set the position
                if (smoothFactor != 0f)
                {
                    HeadTransform.position = Vector3.Lerp(HeadTransform.position, newPosition, smoothFactor * Time.deltaTime);
                }
                else
                {
                    HeadTransform.position = newPosition;
                }

                // scale factor
                if (HeadTransform.localScale.x != modelScaleFactor)
                {
                    HeadTransform.localScale = new Vector3(modelScaleFactor, modelScaleFactor, modelScaleFactor);
                }
            }

            // apply animation units

            // AU0 - Upper Lip Raiser
            // 0=neutral, covering teeth; 1=showing teeth fully; -1=maximal possible pushed down lip
            float fAU0 = manager.GetAnimUnit(KinectInterop.FaceShapeAnimations.LipPucker);
            SetJointRotation(UpperLipLeft, UpperLipLeftAxis, fAU0, UpperLipLeftNeutral, UpperLipLeftUp);
            SetJointRotation(UpperLipRight, UpperLipRightAxis, fAU0, UpperLipRightNeutral, UpperLipRightUp);

            // AU1 - Jaw Lowerer
            // 0=closed; 1=fully open; -1= closed, like 0
            float fAU1 = manager.GetAnimUnit(KinectInterop.FaceShapeAnimations.JawOpen);
            SetJointRotation(Jaw, JawAxis, fAU1, JawNeutral, JawDown);

            // AU2 – Lip Stretcher
            // 0=neutral; 1=fully stretched (joker’s smile); -1=fully rounded (kissing mouth)
            float fAU2_left = manager.GetAnimUnit(KinectInterop.FaceShapeAnimations.LipStretcherLeft);
            fAU2_left = (platform == KinectInterop.DepthSensorPlatform.KinectSDKv2) ? (fAU2_left * 2 - 1) : fAU2_left;
            SetJointRotation(LipLeft, LipLeftAxis, fAU2_left, LipLeftNeutral, LipLeftStretched);

            float fAU2_right = manager.GetAnimUnit(KinectInterop.FaceShapeAnimations.LipStretcherRight);
            fAU2_right = (platform == KinectInterop.DepthSensorPlatform.KinectSDKv2) ? (fAU2_right * 2 - 1) : fAU2_right;
            SetJointRotation(LipRight, LipRightAxis, fAU2_right, LipRightNeutral, LipRightStretched);

            // AU3 – Brow Lowerer
            // 0=neutral; -1=raised almost all the way; +1=fully lowered (to the limit of the eyes)
            float fAU3_left = manager.GetAnimUnit(KinectInterop.FaceShapeAnimations.LefteyebrowLowerer);
            fAU3_left = (platform == KinectInterop.DepthSensorPlatform.KinectSDKv2) ? (fAU3_left * 2 - 1) : fAU3_left;
            SetJointRotation(EyebrowLeft, EyebrowLeftAxis, fAU3_left, EyebrowLeftNeutral, EyebrowLeftLowered);

            float fAU3_right = manager.GetAnimUnit(KinectInterop.FaceShapeAnimations.RighteyebrowLowerer);
            fAU3_right = (platform == KinectInterop.DepthSensorPlatform.KinectSDKv2) ? (fAU3_right * 2 - 1) : fAU3_right;
            SetJointRotation(EyebrowRight, EyebrowRightAxis, fAU3_right, EyebrowRightNeutral, EyebrowRightLowered);

            // AU4 – Lip Corner Depressor
            // 0=neutral; -1=very happy smile; +1=very sad frown
            float fAU4_left = manager.GetAnimUnit(KinectInterop.FaceShapeAnimations.LipCornerDepressorLeft);
            fAU4_left = (platform == KinectInterop.DepthSensorPlatform.KinectSDKv2) ? (fAU4_left * 2) : fAU4_left;
            SetJointRotation(LipCornerLeft, LipCornerLeftAxis, fAU4_left, LipCornerLeftNeutral, LipCornerLeftDepressed);

            float fAU4_right = manager.GetAnimUnit(KinectInterop.FaceShapeAnimations.LipCornerDepressorRight);
            fAU4_right = (platform == KinectInterop.DepthSensorPlatform.KinectSDKv2) ? (fAU4_right * 2) : fAU4_right;
            SetJointRotation(LipCornerRight, LipCornerRightAxis, fAU4_right, LipCornerRightNeutral, LipCornerRightDepressed);

            // AU6, AU7 – Eyelid closed
            // 0=neutral; -1=raised; +1=fully lowered
            float fAU6_left = manager.GetAnimUnit(KinectInterop.FaceShapeAnimations.LefteyeClosed);
            fAU6_left = (platform == KinectInterop.DepthSensorPlatform.KinectSDKv2) ? (fAU6_left * 2 - 1) : fAU6_left;
            SetJointRotation(UpperEyelidLeft, UpperEyelidLeftAxis, fAU6_left, UpperEyelidLeftNeutral, UpperEyelidLeftLowered);
            SetJointRotation(LowerEyelidLeft, LowerEyelidLeftAxis, fAU6_left, LowerEyelidLeftNeutral, LowerEyelidLeftRaised);

            float fAU6_right = manager.GetAnimUnit(KinectInterop.FaceShapeAnimations.RighteyeClosed);
            fAU6_right = (platform == KinectInterop.DepthSensorPlatform.KinectSDKv2) ? (fAU6_right * 2 - 1) : fAU6_right;
            SetJointRotation(UpperEyelidRight, UpperEyelidRightAxis, fAU6_right, UpperEyelidRightNeutral, UpperEyelidRightLowered);
            SetJointRotation(LowerEyelidRight, LowerEyelidRightAxis, fAU6_right, LowerEyelidRightNeutral, LowerEyelidRightRaised);
        }
    }
Exemple #16
0
    public void measureEngagement()
    {
//		Debug.Log("in measure engagement");
//		Debug.Log("(faceManager.GetFaceTrackingID(p1Index)) = " + (faceManager.GetFaceTrackingID(p1Index)));
//		if(faceManager.IsTrackingFace(faceManager.GetFaceTrackingID(p1Index)))
//			{
//				Debug.Log("is tracking");
//			}
//			else
//			{
//			Debug.Log("isnt tracking");
//			}

        //Debug.Log("faceManager.IsTrackingFace(faceManager.GetFaceTrackingID(p1Index) "+ faceManager.IsTrackingFace(faceManager.GetFaceTrackingID(p1Index))+"faceManager.IsTrackingFace(faceManager.GetFaceTrackingID(p2Index)) "+faceManager.IsTrackingFace(faceManager.GetFaceTrackingID(p2Index))+"_KinectManager.IsUserDetected() "+_KinectManager.IsUserDetected());

        assignIdByPosition();
        if (faceManager.IsTrackingFace(faceManager.GetFaceTrackingID(p1Index)) && faceManager.IsTrackingFace(faceManager.GetFaceTrackingID(p2Index)) && _KinectManager.IsUserDetected())
        {
            Debug.Log("in faceManager.isTrackingFace");
            //process left player
            // allocate storage for the point cloud points in a vector
            //get the face point cloud from the FaceTrackingManager and fill up the vector
            //get the joint position for the left shoulder
            avModelVertices1 = new Vector3[faceManager.GetFaceModelVertexCount(p1Index)];
            faceManager.GetUserFaceVertices(leftId, ref avModelVertices1);
            p1shoulderpos = _KinectManager.GetJointPosition(leftId, 4);
            //get the distance between the chin and the left shoulder
            p1shoulderToChin = Mathf.Abs((((avModelVertices1[4].x) - (p1shoulderpos.x)) * (100f)));
            //get the joint position for the right shoulder
            p1rightShoulderPos = _KinectManager.GetJointPosition(leftId, 8);
            //same as above (left)
            p1leftShoulderPos = _KinectManager.GetJointPosition(leftId, 4);
            //difference of the .z positions for the shoulders (if body turns)
            p1shoulderToShoulder = (p1rightShoulderPos.z - p1leftShoulderPos.z) * 20f;
            //head distance plus shoulder distance
            p1TotalEngagement = p1shoulderToChin + p1shoulderToShoulder;
            Debug.Log("p1TotalEngagement " + p1TotalEngagement);
            // process right player
            p2rightShoulderPos   = _KinectManager.GetJointPosition(rightId, 8);
            p2leftShoulderPos    = _KinectManager.GetJointPosition(rightId, 4);
            p2shoulderToShoulder = ((p2leftShoulderPos.z) - (p2rightShoulderPos.z)) * 20f;
            //get the face point cloud from the FaceTrackingManager and fill up the vector
            avModelVertices2 = new Vector3[faceManager.GetFaceModelVertexCount(p2Index)];
            faceManager.GetUserFaceVertices(rightId, ref avModelVertices2);
            p2shoulderpos     = _KinectManager.GetJointPosition(rightId, 4);
            p2shoulderToChin  = Mathf.Abs((((avModelVertices2[4].x) - (p2shoulderpos.x)) * (100f)));
            p2TotalEngagement = (p2shoulderToChin) - (p2shoulderToShoulder);
            Debug.Log("p2TotalEngagement " + p2TotalEngagement);

            /*
             * p2rightShoulderPos=_KinectManager.GetJointPosition(rightid,8);
             * p2leftShoulderPos=_KinectManager.GetJointPosition(rightid,4);
             * p2shoulderToShoulder=((p2rightShoulderPos.z)-(p2leftShoulderPos.z))*20f;
             * avModelVertices2=new Vector3[faceManagerP2.GetFaceModelVertexCount()];
             * faceManagerP2.GetUserFaceVertices(rightid, ref avModelVertices2);
             * p2shoulderpos=_KinectManager.GetJointPosition(rightid,4);
             * p2shoulderToChin=(((avModelVertices2[4].x)-(p2shoulderpos.x))*(100f));
             * p2TotalEngagement =(p2shoulderToChin)-(p2shoulderToShoulder);
             */
            Debug.Log("p1TotalEngagement" + p1TotalEngagement + "p2TotalEngagement" + p2TotalEngagement);


            //Debug.Log("leftshoulder.z=" +p1leftShoulderPos.z+"rightshoulder.z"+p1rightShoulderPos.z);
            //Debug.Log("leftshoulder-rightshoulder");
            //Debug.Log("p1leftshoulder.z=" +p1leftShoulderPos.z+"p1rightshoulder.z"+p1rightShoulderPos.z);
            //Debug.Log("p2leftshoulder.z=" +p2leftShoulderPos.z+"p1rightshoulder.z"+p2rightShoulderPos.z);
            //Debug.Log("p1engagement= "+ ((p1shoulderToChin)+(p1shoulderToShoulder)));
            //Debug.Log("p2engagment="+((p2shoulderToChin)-(p2shoulderToShoulder)));
            //Debug.Log("leftshoulder-rightshoulder"+(rightShoulderPos.z-leftShoulderPos.z ));
            if (p1TotalEngagement >= 20f && p2TotalEngagement <= 15f)
            {
                //faceMat1.material.SetColor("_Color",Color.green);
                //faceMat2.material.SetColor("_Color",Color.green);

                if (_PecCard.pecStarted)
                {
                    combinedPlayerEngagementsecondHalf++;
                }
                else
                {
                    combinedPlayerEngagement++;
                }
                //engagement.SetActive(true);
                //StartCoroutine(wait());
            }
            if (p1TotalEngagement >= 20f && !(p1TotalEngagement >= 20f && p2TotalEngagement <= 15f))
            {
                //faceMat1.material.SetColor("_Color",Color.blue);
                if (_PecCard.pecStarted)
                {
                    leftPlayerEngagementsecondHalf++;;
                }
                else
                {
                    leftPlayerEngagement++;
                }
            }
            if (!(p1TotalEngagement >= 20f) && !(p1TotalEngagement >= 20f && p2TotalEngagement <= 15f))
            {
                //faceMat1.material.SetColor("_Color",Color.gray);
            }

            if (p2TotalEngagement <= 10f && !(p1TotalEngagement >= 20f && p2TotalEngagement <= 10f))
            {
                //faceMat2.material.SetColor("_Color",Color.blue);
                if (_PecCard.pecStarted)               //second phase of level
                {
                    rightPlayerEngagementsecondHalf++;
                }
                else
                {
                    rightPlayerEngagement++;
                }
            }
            if (!(p2TotalEngagement <= 10f) && !(p1TotalEngagement >= 20f && p2TotalEngagement <= 10f))
            {
                //faceMat2.material.SetColor("_Color",Color.gray);
            }

            //return;
        }

        /*
         * if(faceManagerP1.IsTrackingFace()&&_KinectManager.IsUserDetected())
         *      {
         *      //p1rot=faceManagerP1.GetHeadRotation(leftid,false);//shoulderight=8//shoulderleft=4
         *
         *      avModelVertices1=new Vector3[faceManagerP1.GetFaceModelVertexCount()];
         *       faceManagerP1.GetUserFaceVertices(leftid, ref avModelVertices1);
         *       p1shoulderpos=_KinectManager.GetJointPosition(leftid,4);
         *       p1shoulderToChin=(((avModelVertices1[4].x)-(p1shoulderpos.x))*(100f));
         *       p1rightShoulderPos=_KinectManager.GetJointPosition(leftid,8);
         *       p1leftShoulderPos=_KinectManager.GetJointPosition(leftid,4);
         *       p1TotalEngagement=p1shoulderToChin+p1shoulderToShoulder;
         *       p1shoulderToShoulder=(p1rightShoulderPos.z-p1leftShoulderPos.z)*20f;
         *      if((p1TotalEngagement>=25f))
         *              {
         *              faceMat1.material.SetColor("_Color",Color.blue);
         *              leftPlayerEngagement++;
         *              }
         *      else
         *              {
         *              faceMat1.material.SetColor("_Color",Color.gray);
         *              }
         *      }
         *
         *
         *
         *
         * if(faceManagerP2.IsTrackingFace())
         * {
         *      avModelVertices2=new Vector3[faceManagerP2.GetFaceModelVertexCount()];
         *      faceManagerP2.GetUserFaceVertices(leftid, ref avModelVertices2);
         *      p2shoulderpos=_KinectManager.GetJointPosition(rightid,4);
         *      p2shoulderToChin=(((avModelVertices1[4].x)-(p2shoulderpos.x))*(100f));
         *      p2rightShoulderPos=_KinectManager.GetJointPosition(rightid,8);
         *      p2leftShoulderPos=_KinectManager.GetJointPosition(rightid,4);
         *      //Debug.Log("leftshoulder.z=" +leftShoulderPos.z+"rightshoulder.z"+rightShoulderPos.z);
         *      //Debug.Log("leftshoulder-rightshoulder"+(rightShoulderPos.z-leftShoulderPos.z ));
         *  p2shoulderToShoulder=(p2leftShoulderPos.z-p2rightShoulderPos.z)*20f;
         *      if(((p2shoulderToChin)-(p2shoulderToShoulder))<=12f)
         *      {
         *              faceMat2.material.SetColor("_Color",Color.blue);
         *              rightPlayerEngagement++;
         *      }
         *      else
         *      {
         *              faceMat2.material.SetColor("_Color",Color.gray);
         *      }
         *
         * }
         *
         * }
         *
         * IEnumerator wait() {
         *
         * //yield return new WaitForSeconds(3);
         *
         * engagement.SetActive(true);
         * for(int i=0;i<5;i++)
         * {
         *      stars[i].SetBool("isSpinning",true);
         * }
         * yield return new WaitForSeconds(3);	//Wait 3 Secs
         * engagement.SetActive(false);
         * //engagement.SetActive(false);
         *
         */
    }
Exemple #17
0
    void Update()
    {
        // get the face-tracking manager instance
        if (faceManager == null)
        {
            kinectManager = KinectManager.Instance;
            faceManager   = FacetrackingManager.Instance;
        }

        // get user-id by user-index
        long userId = kinectManager ? kinectManager.GetUserIdByIndex(playerIndex) : 0;

        if (kinectManager && kinectManager.IsInitialized() && userId != 0 &&
            faceManager && faceManager.IsTrackingFace(userId) && foregroundCamera)
        {
            // get head position
            Vector3 newPosition = faceManager.GetHeadPosition(userId, true);

            // get head rotation
            Quaternion newRotation = initialRotation * faceManager.GetHeadRotation(userId, true);

            // rotational fix, provided by Richard Borys:
            // The added rotation fixes rotational error that occurs when person is not centered in the middle of the kinect
            Vector3 addedRotation = newPosition.z != 0f ? new Vector3(Mathf.Rad2Deg * (Mathf.Tan(newPosition.y) / newPosition.z),
                                                                      Mathf.Rad2Deg * (Mathf.Tan(newPosition.x) / newPosition.z), 0) : Vector3.zero;

            addedRotation.x = newRotation.eulerAngles.x + addedRotation.x;
            addedRotation.y = newRotation.eulerAngles.y + addedRotation.y;
            addedRotation.z = newRotation.eulerAngles.z + addedRotation.z;

            newRotation = Quaternion.Euler(addedRotation.x, addedRotation.y, addedRotation.z);
            // end of rotational fix

            if (smoothFactorRotation != 0f)
            {
                transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, smoothFactorRotation * Time.deltaTime);
            }
            else
            {
                transform.rotation = newRotation;
            }

            // 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();
            }

            // model position
            newPosition = kinectManager.GetJointPosColorOverlay(userId, (int)KinectInterop.JointType.Head, foregroundCamera, backgroundRect);
            if (newPosition == Vector3.zero)
            {
                // hide the model behind the camera
                newPosition.z = -10f;
            }

            if (verticalOffset != 0f)
            {
                // add the vertical offset
                Vector3 dirHead = new Vector3(0, verticalOffset, 0);
                dirHead      = transform.InverseTransformDirection(dirHead);
                newPosition += dirHead;
            }

            // go to the new position
            if (smoothFactorMovement != 0f && transform.position.z >= 0f)
            {
                transform.position = Vector3.Lerp(transform.position, newPosition, smoothFactorMovement * Time.deltaTime);
            }
            else
            {
                transform.position = newPosition;
            }

            // scale the model if needed
            if (transform.localScale.x != modelScaleFactor)
            {
                transform.localScale = new Vector3(modelScaleFactor, modelScaleFactor, modelScaleFactor);
            }

            ///Main Routine

            int angle = (int)(transform.eulerAngles.x + KinectManager.Instance.sensorAngle);
            if (angle < 0)
            {
                angle += 360;
            }

            //Face Up/Down
            if (angle > 90)
            {
                int i = 360 - (int)angle;

                if (i > iDeltaUpDown)
                {
                    DriverManager.instance.OutObjList[5].GetComponent <Text>().text = "Face : Up " + i.ToString() + " degrees";
                    DriverManager.instance.OutObjList[5].SetActive(true);
                }
                else
                {
                    DriverManager.instance.OutObjList[5].SetActive(false);
                }
            }
            else
            {
                if (angle > iDeltaUpDown)
                {
                    DriverManager.instance.OutObjList[5].GetComponent <Text>().text = "Face : Down " + angle.ToString() + " degrees";
                    DriverManager.instance.OutObjList[5].SetActive(true);
                }
                else
                {
                    DriverManager.instance.OutObjList[5].SetActive(false);
                }
            }
            ////
            //Face Left/Right

            angle = (int)(transform.eulerAngles.y);

            if (angle >= 180)
            {
                int i = (int)angle - 180;

                if (i > iDeltaLeftRight)
                {
                    DriverManager.instance.OutObjList[6].GetComponent <Text>().text = "Face : Left " + i.ToString() + " degrees";
                    DriverManager.instance.OutObjList[6].SetActive(true);
                }
                else
                {
                    DriverManager.instance.OutObjList[6].SetActive(false);
                }
            }
            else
            {
                int i = 180 - (int)angle;

                if (i > iDeltaLeftRight)
                {
                    DriverManager.instance.OutObjList[6].GetComponent <Text>().text = "Face : Right " + i.ToString() + " degrees";
                    DriverManager.instance.OutObjList[6].SetActive(true);
                }
                else
                {
                    DriverManager.instance.OutObjList[6].SetActive(false);
                }
            }
        }
        else
        {
            DriverManager.instance.OutObjList[5].SetActive(false);
            DriverManager.instance.OutObjList[6].SetActive(false);

            // hide the model behind the camera
            if (transform.position.z >= 0f)
            {
                transform.position = new Vector3(0f, 0f, -10f);
            }
        }
    }
 private void CheckFaceTrackingAvailability(long userId)
 {
     faceTracker = FacetrackingManager.Instance;
     faceTrackingAvailable [userId] = faceTracker != null && faceTracker.IsTrackingFace (userId);
 }
 public bool IsFaceTrackingAvailable(long userId)
 {
     faceTracker = FacetrackingManager.Instance;
     return (userId == firstUserId || userId == secondUserId) && faceTracker.IsTrackingFace (userId);
 }
    void FixedUpdate()
    {      // float translation = Time.deltaTime * 10;
        // get the face-tracking manager instance
        if (manager == null)
        {
            manager = FacetrackingManager.Instance;
        }

        if (manager && manager.IsTrackingFace())
        {
            // set head position & rotation
            if (HeadTransform != null)
            {
                // head position
                Vector3 newPosition = HeadInitialPosition + manager.GetHeadPosition(mirroredHeadMovement);

                if (smoothFactor != 0f)
                {
                    HeadTransform.localPosition = Vector3.Lerp(HeadTransform.localPosition, newPosition, smoothFactor * Time.deltaTime);
                }
                else
                {
                    HeadTransform.localPosition = newPosition;
                }

                // head rotation
                Quaternion newRotation = HeadInitialRotation * manager.GetHeadRotation(mirroredHeadMovement);

                if (smoothFactor != 0f)
                {
                    HeadTransform.localRotation = Quaternion.Slerp(HeadTransform.localRotation, newRotation, smoothFactor * Time.deltaTime);
                }
                else
                {
                    HeadTransform.localRotation = newRotation;
                }
            }
            if (LeftEyeTransform != null)
            {
                // head position
                Vector3 newPosition = LeftEyeInitialPosition + manager.GetHeadPosition(mirroredHeadMovement);

                if (smoothFactor != 0f)
                {
                    LeftEyeTransform.localPosition = Vector3.Lerp(HeadTransform.localPosition, newPosition, smoothFactor * Time.deltaTime);
                }
                else
                {
                    LeftEyeTransform.localPosition = newPosition;
                }

                // head rotation
                Quaternion newRotation = LeftEyeInitialRotation * manager.GetHeadRotation(mirroredHeadMovement);

                if (smoothFactor != 0f)
                {
                    LeftEyeTransform.localRotation = Quaternion.Slerp(LeftEyeTransform.localRotation, newRotation, smoothFactor * Time.deltaTime);
                }
                else
                {
                    LeftEyeTransform.localRotation = newRotation;
                }
            }
            if (RightEyeTransform != null)
            {
                // head position
                Vector3 newPosition = RightEyeInitialPosition + manager.GetHeadPosition(mirroredHeadMovement);

                if (smoothFactor != 0f)
                {
                    RightEyeTransform.localPosition = Vector3.Lerp(HeadTransform.localPosition, newPosition, smoothFactor * Time.deltaTime);
                }
                else
                {
                    RightEyeTransform.localPosition = newPosition;
                }

                // head rotation
                Quaternion newRotation = RightEyeInitialRotation * manager.GetHeadRotation(mirroredHeadMovement);

                if (smoothFactor != 0f)
                {
                    RightEyeTransform.localRotation = Quaternion.Slerp(RightEyeTransform.localRotation, newRotation, smoothFactor * Time.deltaTime);
                }
                else
                {
                    RightEyeTransform.localRotation = newRotation;
                }
            }            // apply animation units

            // AU0 - Upper Lip Raiser
            // 0=neutral, covering teeth; 1=showing teeth fully; -1=maximal possible pushed down lip
            float fAU0 = manager.GetAnimUnit(KinectInterop.FaceShapeAnimations.LipPucker);
            if (fAU0 > Value_Lippucker && isSadMouth == false && isSmillingMouth == false && isOpenMouth == false)
            {
                setBlendShape(100, 4);
                isKissingMouth = true;
            }
            else
            {
                setBlendShape(0, 4);
                isKissingMouth = false;
            }

            //	Debug.Log (fAU0 .ToString ());
            //	setBlendShape1 (fAU0, 5);
            // AU1 - Jaw Lowerer
            // 0=closed; 1=fully open; -1= closed, like 0
            float fAU1 = manager.GetAnimUnit(KinectInterop.FaceShapeAnimations.JawOpen);
            if (fAU1 > Value_JawOpen && isSadMouth == false && isSmillingMouth == false && isKissingMouth == false)
            {
                setBlendShape(100, 8);
                isOpenMouth = true;
            }
            else
            {
                setBlendShape(0, 8);
                isOpenMouth = false;
            }
            //	Debug.Log (fAU1 .ToString ());
            // AU2 – Lip Stretcher
            // 0=neutral; 1=fully stretched (joker’s smile); -1=fully rounded (kissing mouth)
            float fAU2_left = manager.GetAnimUnit(KinectInterop.FaceShapeAnimations.LipStretcherLeft);
            //fAU2_left = (platform == KinectInterop.DepthSensorPlatform.KinectSDKv2) ? (fAU2_left * 2 - 1) : fAU2_left;

            float fAU2_right = manager.GetAnimUnit(KinectInterop.FaceShapeAnimations.LipStretcherRight);
            //	fAU2_right = (platform == KinectInterop.DepthSensorPlatform.KinectSDKv2) ? (fAU2_right * 2 - 1) : fAU2_right;



            if (fAU2_left > Value_Lipstretcher && isSadMouth == false && isKissingMouth == false && isOpenMouth == false)
            {
                setBlendShape(100, 1);
                isSmillingMouth = true;
            }
            else
            {
                //setBlendShape (0, 4);
                setBlendShape(0, 1);
                isSmillingMouth = false;
            }


            //	Debug.Log (fAU2_left .ToString ());
            // AU3 – Brow Lowerer
            // 0=neutral; -1=raised almost all the way; +1=fully lowered (to the limit of the eyes)
            float fAU3_left = manager.GetAnimUnit(KinectInterop.FaceShapeAnimations.LefteyebrowLowerer);
            //fAU3_left = (platform == KinectInterop.DepthSensorPlatform.KinectSDKv2) ? (fAU3_left * 2 - 1) : fAU3_left;


            float fAU3_right = manager.GetAnimUnit(KinectInterop.FaceShapeAnimations.RighteyebrowLowerer);
            //fAU3_right = (platform == KinectInterop.DepthSensorPlatform.KinectSDKv2) ? (fAU3_right * 2 - 1) : fAU3_right;


            if (fAU3_left < -0.1)
            {
                setBlendShape(100f, 3);
            }
            else if (fAU3_left > 0.1)
            {
                setBlendShape(100f, 7);
            }
            else
            {
                setBlendShape(0, 7);
                setBlendShape(0, 3);
            }



            // AU4 – Lip Corner Depressor
            // 0=neutral; -1=very happy smile; +1=very sad frown
            float fAU4_left = manager.GetAnimUnit(KinectInterop.FaceShapeAnimations.LipCornerDepressorLeft);
            //	fAU4_left = (platform == KinectInterop.DepthSensorPlatform.KinectSDKv2) ? (fAU4_left * 2-1) : fAU4_left;

            float fAU4_right = manager.GetAnimUnit(KinectInterop.FaceShapeAnimations.LipCornerDepressorRight);
            //	Debug.Log (fAU4_left.ToString ());

            if (fAU1 < 0.6 && fAU4_left > Value_LipCornerDepressor && isSmillingMouth == false && isKissingMouth == false)
            {
                setBlendShape(100f, 2);
                isSadMouth = true;
            }
            else
            {
                setBlendShape(0f, 2);
                isSadMouth = false;
            }

            Debug.Log(fAU4_left.ToString());
            // AU6, AU7 – Eyelid closed
            // 0=neutral; -1=raised; +1=fully lowered
            float fAU6_left = manager.GetAnimUnit(KinectInterop.FaceShapeAnimations.LefteyeClosed);
            fAU6_left = (platform == KinectInterop.DepthSensorPlatform.KinectSDKv2) ? (fAU6_left * 2 - 1) : fAU6_left;


            float fAU6_right = manager.GetAnimUnit(KinectInterop.FaceShapeAnimations.RighteyeClosed);
            fAU6_right = (platform == KinectInterop.DepthSensorPlatform.KinectSDKv2) ? (fAU6_right * 2 - 1) : fAU6_right;

            /*if (blendShapeCount > 2) {
             *
             * if (blendOne<<100f &&fAU2_left>0f) {
             *      blendOne=1000*fAU2_left;
             *      skinnedMeshRenderer.SetBlendShapeWeight (1, blendOne);
             *      //blendOne += blendSpeed;
             * } else {
             *      //blendOneFinished = true;
             * }
             *
             * if (  blendTwo < 100f) {
             *      skinnedMeshRenderer.SetBlendShapeWeight (2, blendTwo);
             *      blendTwo += blendSpeed;
             * }
             *
             * }*/
        }
    }
    // Update is called once per frame
    void Update()
    {
        KinectManager manager = KinectManager.Instance;

        if (manager && manager.IsInitialized() && foregroundCamera)
        {
            if (facetrackingmanager.IsTrackingFace())   // check if get face
            {
                // ------------------------- start take point -----------------------------
                if (is_getallpoint && edit_status != 0)     // check if point collect && check
                {
                    // ------------- get two point --------------
                    if (Input.GetMouseButtonUp(0) && count_point_num < 2)
                    {
                        if (count_point_num >= 0)
                        {
                            pick_pt[count_point_num] = new Vector2(Input.mousePosition.x + mouse_x_calib, (Input.mousePosition.y + mouse_y_calib));

                            // search the closest face point
                            for (int i = 0; i < 1347; i++)
                            {
                                if (Vector2.Distance(pick_pt[count_point_num], MapColorPt[i]) < min_dis)
                                {
                                    min_dis   = Vector2.Distance(pick_pt[count_point_num], MapColorPt[i]);
                                    min_index = i;
                                }
                            }

                            // record point index
                            pt_index[edit_status - 1, count_point_num] = min_index;

                            // position line point
                            Vector3 temp = FacePointBuffer[min_index];
                            line_pt[count_point_num].transform.position = temp;

                            debugText2.GetComponent <GUIText>().text = "pick point: " + new Vector2(Input.mousePosition.x + mouse_x_calib, Input.mousePosition.y + mouse_y_calib);
                        }
                        count_point_num++;

                        min_dis   = 99999;
                        min_index = -1;
                    }

                    // ------------------- find two point center and the closest to it --------------------
                    if (count_point_num == 2 && is_GetTwoPt == false)
                    {
                        Vector2 centerpt = (MapColorPt[pt_index[edit_status - 1, 0]] + MapColorPt[pt_index[edit_status - 1, 1]]) / 2;

                        // find the smallest
                        for (int i = 0; i < 1347; i++)
                        {
                            if (Vector2.Distance(MapColorPt[i], centerpt) < min_dis_1)
                            {
                                min_dis_1 = Vector2.Distance(MapColorPt[i], centerpt);
                                min_index_1[edit_status - 1] = i;
                            }
                        }

                        // find the second smallest
                        for (int i = 0; i < 1347; i++)
                        {
                            if (Vector2.Distance(MapColorPt[i], centerpt) < min_dis_2 && i != min_index_1[edit_status - 1])
                            {
                                min_dis_2 = Vector2.Distance(MapColorPt[i], centerpt);
                                min_index_2[edit_status - 1] = i;
                            }
                        }

                        is_GetTwoPt = true;
                    }

                    // record two point
                    if (count_point_num == 2)
                    {
                        Vector3 start_pt = FacePointBuffer[pt_index[edit_status - 1, 0]];
                        Vector3 end_pt   = FacePointBuffer[pt_index[edit_status - 1, 1]];
                        Vector3 ct1_pt   = FacePointBuffer[min_index_1[edit_status - 1]];
                        Vector3 ct2_pt   = FacePointBuffer[min_index_2[edit_status - 1]];

                        linegroup[edit_status - 1].transform.position = start_pt;

                        // rotation
                        Vector3 targetDir = end_pt - start_pt;
                        Vector3 oriDir    = new Vector3(0.0f, 0.0f, 1.0f);
                        Vector3 newDir    = Vector3.RotateTowards(oriDir, targetDir, 360.0f, 360.0f);

                        Vector3 v2 = ct1_pt - ct2_pt;

                        // set right rotation
                        Vector3 cro_out = Vector3.Cross(v2, newDir);

                        // calculate left or right face   (1297,1293) two side
                        Vector3 left_pt        = getHDFacePoints.GetAllPoint(1297);
                        Vector3 right_pt       = getHDFacePoints.GetAllPoint(1293);
                        Vector3 temp_center_pt = (left_pt + right_pt) / 2;
                        Vector3 temp_dir_vec   = ct1_pt - temp_center_pt;
                        //Debug.Log(temp_dir_vec.x + ", " + temp_dir_vec.y + ", " + temp_dir_vec.z);

                        if (temp_dir_vec.x < 0) // left face point
                        {
                            if (cro_out.x < 0)
                            {
                                cro_out = Vector3.Cross(newDir, v2);
                            }
                        }
                        else  // right face point
                        {
                            if (cro_out.x > 0)
                            {
                                cro_out = Vector3.Cross(newDir, v2);
                            }
                        }

                        linegroup[edit_status - 1].transform.rotation = Quaternion.LookRotation(newDir, cro_out);      // second parameter indicate upward direction

                        // point position
                        line_pt[0].transform.position = Vector3.zero;
                        line_pt[1].transform.position = Vector3.zero;

                        isLineDone[edit_status - 1] = true;

                        // reset
                        min_dis_1 = 999999;
                        min_dis_2 = 999999;

                        edit_status     = 0;
                        count_point_num = -1;
                        is_GetTwoPt     = false;
                    }
                }

                // ------------------  position line ------------------------
                if (is_conti == true)
                {
                    for (int i = 0; i < 22; i++)
                    {
                        if (isLineDone[i] == true)
                        {
                            Vector3 start_pt = getHDFacePoints.GetAllPoint(pt_index[i, 0]);
                            Vector3 end_pt   = getHDFacePoints.GetAllPoint(pt_index[i, 1]);
                            Vector3 ct1_pt   = getHDFacePoints.GetAllPoint(min_index_1[i]);
                            Vector3 ct2_pt   = getHDFacePoints.GetAllPoint(min_index_2[i]);

                            float pt_dis = Vector3.Distance(start_pt, end_pt);

                            // position
                            linegroup[i].transform.position = start_pt;

                            // rotation
                            Vector3 targetDir = end_pt - start_pt;
                            Vector3 oriDir    = new Vector3(0.0f, 0.0f, 1.0f);
                            Vector3 newDir    = Vector3.RotateTowards(oriDir, targetDir, 360.0f, 360.0f);

                            Vector3 v2 = ct1_pt - ct2_pt;

                            // set right rotation
                            Vector3 cro_out = Vector3.Cross(v2, newDir);

                            // calculate left or right face   (1297,1293) two side
                            Vector3 left_pt        = getHDFacePoints.GetAllPoint(1297);
                            Vector3 right_pt       = getHDFacePoints.GetAllPoint(1293);
                            Vector3 temp_center_pt = (left_pt + right_pt) / 2;
                            Vector3 temp_dir_vec   = ct1_pt - temp_center_pt;
                            //Debug.Log(temp_dir_vec.x + ", " + temp_dir_vec.y + ", " + temp_dir_vec.z);

                            if (temp_dir_vec.x < 0) // left face point
                            {
                                if (cro_out.x < 0)
                                {
                                    cro_out = Vector3.Cross(newDir, v2);
                                }
                            }
                            else  // right face point
                            {
                                if (cro_out.x > 0)
                                {
                                    cro_out = Vector3.Cross(newDir, v2);
                                }
                            }

                            linegroup[i].transform.rotation = Quaternion.LookRotation(newDir, cro_out);      // second parameter indicate upward direction
                        }
                    }
                }
            }
        }
    }