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