void Update() { //Vaisseau.avancer(); this.gameObject.transform.Translate(Vector3.back * speed * Time.deltaTime); j++; if (manager != null && KinectManager.IsKinectInitialized() && manager.GetPlayer1ID() > 0) { uint userId = manager.GetPlayer1ID(); Vector3 screenNormalPos = Vector3.zero; if (manager.GetGestureProgress(userId, KinectWrapper.Gestures.TournerADroite) >= 0.1f) { this.gameObject.transform.Rotate(Vector3.up * 1.5f, Space.World); } if (manager.GetGestureProgress(userId, KinectWrapper.Gestures.TournerAGauche) >= 0.1f) { this.gameObject.transform.Rotate(Vector3.down * 1.5f, Space.World); } //*/ if (manager.GetGestureProgress(userId, KinectWrapper.Gestures.Accelerer) >= 0.1f) { if (!fast) { fast = true; speed *= 5; } } //*/ else if (manager.GetGestureProgress(userId, KinectWrapper.Gestures.Ralentir) <= 0.1f) { if (fast) { fast = false; speed /= 5; } } //*/ if (manager.GetGestureProgress(userId, KinectWrapper.Gestures.TirDroite) >= 0.1f) { if ((j % 10) == 0) { canonDroite.GetComponent <CanonJoueur>().shoot = true; } } //*/ if (manager.GetGestureProgress(userId, KinectWrapper.Gestures.TirGauche) >= 0.1f) { if ((j % 10) == 0) { canonGauche.GetComponent <CanonJoueur>().shoot = true; } } //*/ } }
private void getUserGestureValue() { if (manager.IsUserDetected()) { DirectionBetweenJoints = new List <Vector3>(); AngleBetweenJoints = new List <float>(); uint p1 = manager.GetPlayer1ID(); //uint jointLength = 20; UserOrientation = manager.GetUserOrientation(p1, flip); /*for (int i = 0; i < jointLength; i++) * { * JointPosition[i] = manager.GetJointPosition(p1, i); * JointLocalPosition[i] = manager.GetJointLocalPosition(p1, i); * JointOrientation[i] = manager.GetJointOrientation(p1, i, flip); * JointLocalOrientation[i] = manager.GetJointLocalOrientation(p1, i, flip); * }*/ ElbowToShoulder_L = manager.GetDirectionBetweenJoints(p1, (int)Joint.Elbow_Left, (int)Joint.Shoulder_Left, flip, flip); ElbowToShoulder_R = manager.GetDirectionBetweenJoints(p1, (int)Joint.Elbow_Right, (int)Joint.Shoulder_Right, flip, flip); ElbowToWrist_L = manager.GetDirectionBetweenJoints(p1, (int)Joint.Elbow_Left, (int)Joint.Wrist_Left, flip, flip); ElbowToWrist_R = manager.GetDirectionBetweenJoints(p1, (int)Joint.Elbow_Right, (int)Joint.Wrist_Right, flip, flip); KneeToHip_L = manager.GetDirectionBetweenJoints(p1, (int)Joint.Knee_Left, (int)Joint.Hip_Left, flip, flip); KneeToHip_R = manager.GetDirectionBetweenJoints(p1, (int)Joint.Knee_Right, (int)Joint.Hip_Right, flip, flip); KneeToAnkle_L = manager.GetDirectionBetweenJoints(p1, (int)Joint.Knee_Left, (int)Joint.Ankle_Left, flip, flip); KneeToAnkle_R = manager.GetDirectionBetweenJoints(p1, (int)Joint.Knee_Right, (int)Joint.Ankle_Right, flip, flip); DirectionBetweenJoints.Add(ElbowToShoulder_L); DirectionBetweenJoints.Add(ElbowToWrist_L); DirectionBetweenJoints.Add(ElbowToShoulder_R); DirectionBetweenJoints.Add(ElbowToWrist_R); DirectionBetweenJoints.Add(KneeToHip_L); DirectionBetweenJoints.Add(KneeToAnkle_L); DirectionBetweenJoints.Add(KneeToHip_R); DirectionBetweenJoints.Add(KneeToAnkle_R); for (int i = 0; i < DirectionBetweenJoints.Count; i++) { DirectionBetweenJoints[i].Normalize(); } for (int i = 0; i < DirectionBetweenJoints.Count; i += 2) { AngleBetweenJoints.Add(Vector3.Angle(DirectionBetweenJoints[i], DirectionBetweenJoints[i + 1])); } //Debug.Log("Get Gesture Value Complete."); } }
private void FindPosition(KinectManager manager, KinectWrapper.NuiSkeletonPositionIndex TrackedJoint , ref Vector3 positionInWorldSpace) { int iJointIndex = (int)TrackedJoint; uint userId = manager.GetPlayer1ID(); if (manager.IsJointTracked(userId, iJointIndex)) { Vector3 posJoint = manager.GetRawSkeletonJointPos(userId, iJointIndex); if (posJoint != Vector3.zero) { // 3d position to depth Vector2 posDepth = manager.GetDepthMapPosForJointPos(posJoint); // depth pos to color pos Vector2 posColor = manager.GetColorMapPosForDepthPos(posDepth); //(scaleX, scaleY, distanceToCamera) == viewportPoint float scaleX = (float)posColor.x / KinectWrapper.Constants.ColorImageWidth; float scaleY = 1.0f - (float)posColor.y / KinectWrapper.Constants.ColorImageHeight; positionInWorldSpace = Camera.main.ViewportToWorldPoint(new Vector3(scaleX, scaleY, 0)); } } }
void Update() { KinectManager manager = KinectManager.Instance; if (manager && manager.IsInitialized()) { if (manager.IsUserDetected()) { uint userId = manager.GetPlayer1ID(); if (manager.IsJointTracked(userId, (int)KinectWrapper.NuiSkeletonPositionIndex.ShoulderLeft) && manager.IsJointTracked(userId, (int)KinectWrapper.NuiSkeletonPositionIndex.ShoulderRight)) { Vector3 posLeftShoulder = manager.GetJointPosition(userId, (int)KinectWrapper.NuiSkeletonPositionIndex.ShoulderLeft); Vector3 posRightShoulder = manager.GetJointPosition(userId, (int)KinectWrapper.NuiSkeletonPositionIndex.ShoulderRight); posLeftShoulder.z = -posLeftShoulder.z; posRightShoulder.z = -posRightShoulder.z; Vector3 dirLeftRight = posRightShoulder - posLeftShoulder; dirLeftRight -= Vector3.Project(dirLeftRight, Vector3.up); Quaternion rotationShoulders = Quaternion.FromToRotation(Vector3.right, dirLeftRight); transform.rotation = rotationShoulders; } } } }
private void Update() { KinectManager manager = KinectManager.Instance; if (!manager || !manager.IsInitialized() || !manager.IsUserDetected()) { return; } int iJointIndex = (int)TrackedJoint; if (manager.IsUserDetected()) { uint userId = manager.GetPlayer1ID(); if (manager.IsJointTracked(userId, iJointIndex)) { Vector3 posJoint = manager.GetRawSkeletonJointPos(userId, iJointIndex); if (posJoint != Vector3.zero) { if (posJoint.x <= rangMax && posJoint.x >= rangMin) { SceneManager.LoadScene("Interaccio"); } } } } }
// Update is called once per frame void Update() { uint playerID = manager != null?manager.GetPlayer1ID() : 0; if (playerID > 0) { getPosJoint(playerID); if (RightHandControlMouse()) { float mouseX = Mathf.Lerp(-cavX, cavX, Mathf.InverseLerp(-oldX, oldX, posJoint[1].x - posJoint[0].x)); float mouseY = Mathf.Lerp(-cavY, cavY, Mathf.InverseLerp(-oldY, oldY, posJoint[1].y - posJoint[0].y)); transform.position = new Vector2(mouseX, mouseY); } else { float mouseX = Mathf.Lerp(-cavX, cavX, Mathf.InverseLerp(-oldX, oldX, posJoint[3].x - posJoint[2].x)); float mouseY = Mathf.Lerp(-cavY, cavY, Mathf.InverseLerp(-oldY, oldY, posJoint[3].y - posJoint[2].y)); transform.position = new Vector2(mouseX, mouseY); } } else { float mouseX = Mathf.Lerp(-cavX, cavX, Mathf.InverseLerp(0, 1920, Input.mousePosition.x)); float mouseY = Mathf.Lerp(-cavY, cavY, Mathf.InverseLerp(0, 1080, Input.mousePosition.y)); transform.position = new Vector2(mouseX, mouseY); } }
// Update is called once per frame void Update() { // get the joint position if (manager == null) { manager = KinectManager.Instance; } if (manager && manager.IsInitialized()) { if (manager.IsUserDetected()) { uint userId = manager.GetPlayer1ID(); if (manager.IsJointTracked(userId, (int)joint)) { // output the joint position for easy tracking Vector3 jointPos = manager.GetJointPosition(userId, (int)joint); //aumentar tamanho do movimento e rapides jointPos.Set(jointPos.x * 2, jointPos.y * 2, jointPos.z); transform.localPosition = jointPos; } } } }
void Update() { KinectManager manager = KinectManager.Instance; if (manager && manager.IsInitialized()) { //backgroundImage.renderer.material.mainTexture = manager.GetUsersClrTex(); if (backgroundImage && (backgroundImage.texture == null)) { backgroundImage.texture = manager.GetUsersClrTex(); } // Vector3 vRight = BottomRight - BottomLeft; // Vector3 vUp = TopLeft - BottomLeft; if (manager.IsUserDetected()) { uint userId = manager.GetPlayer1ID(); foreach (GameObject joint in this.OverlayObjects) { KinectWrapper.NuiSkeletonPositionIndex skelton = joint.GetComponent <SkeltonPosIndexName>().getSkelton(); int iJointIndex = this.TrackedJoints.IndexOf(skelton); Debug.Log("Pos : " + iJointIndex); if (manager.IsJointTracked(userId, iJointIndex)) { Vector3 posJoint = manager.GetRawSkeletonJointPos(userId, (int)skelton); if (posJoint != Vector3.zero) { // 3d position to depth Vector2 posDepth = manager.GetDepthMapPosForJointPos(posJoint); // depth pos to color pos Vector2 posColor = manager.GetColorMapPosForDepthPos(posDepth); float scaleX = (float)posColor.x / KinectWrapper.Constants.ColorImageWidth; float scaleY = 1.0f - (float)posColor.y / KinectWrapper.Constants.ColorImageHeight; // Vector3 localPos = new Vector3(scaleX * 10f - 5f, 0f, scaleY * 10f - 5f); // 5f is 1/2 of 10f - size of the plane // Vector3 vPosOverlay = backgroundImage.transform.TransformPoint(localPos); //Vector3 vPosOverlay = BottomLeft + ((vRight * scaleX) + (vUp * scaleY)); if (debugText) { debugText.GetComponent <GUIText> ().text = "Tracked user ID: " + userId; // new Vector2(scaleX, scaleY).ToString(); } if (OverlayObjects[0]) { Vector3 vPosOverlay = Camera.main.ViewportToWorldPoint(new Vector3(scaleX, scaleY, distanceToCamera)); OverlayObjects[iJointIndex].transform.position = Vector3.Lerp(OverlayObjects[iJointIndex].transform.position, vPosOverlay, smoothFactor * Time.deltaTime); } } } } } } }
// joint の処理 IEnumerator GetJoint() { while (true) { KinectManager manager = KinectManager.Instance; if (manager && manager.IsInitialized() && manager.IsUserDetected()) { // userIdを取得 uint userId = manager.GetPlayer1ID(); // 感知したかどうか SetIsDetected(true); // jointが動いたかどうか if (manager.IsJointTracked(userId, JointKinectNumber)) { JointPosObjUpdate(manager, userId); // 関節のpositionを更新 } } else { // 感知したかどうか SetIsDetected(false); } yield return(new WaitForSeconds(TimeDiff)); } }
// Update is called once per frame void Update() { if (manager == null) { manager = KinectManager.Instance; } // get the users texture if (manager && manager.IsInitialized()) { //foregroundTex = manager.GetUsersLblTex(); if (backgroundImage && (backgroundImage.sprite == null)) { //backgroundImage.texture = manager.GetUsersClrTex(); backgroundImage.sprite = Sprite.Create(manager.GetUsersClrTex(), new Rect(0, 0, manager.GetUsersClrTex().width, manager.GetUsersClrTex().height), Vector2.zero); backgroundImage.rectTransform.sizeDelta = new Vector2(manager.GetUsersClrTex().width, manager.GetUsersClrTex().height); } } if (manager.IsUserDetected()) { uint[] userId = new uint[2] { manager.GetPlayer1ID(), manager.GetPlayer2ID() }; // update colliders int numColliders = (int)KinectWrapper.NuiSkeletonPositionIndex.Count; for (int j = 0; j < 2; j++) { for (int i = 0; i < numColliders; i++) { if (manager.IsJointTracked(userId[j], i)) { Vector3 posJoint = manager.GetRawSkeletonJointPos(userId[j], i); if (posJoint != Vector3.zero) { // convert the joint 3d position to depth 2d coordinates Vector2 posDepth = manager.GetDepthMapPosForJointPos(posJoint); float scaledX = posDepth.x * foregroundRect.width / KinectWrapper.Constants.DepthImageWidth; float scaledY = posDepth.y * -foregroundRect.height / KinectWrapper.Constants.DepthImageHeight; float screenX = foregroundOfs.x + scaledX; float screenY = Camera.main.pixelHeight - (foregroundOfs.y + scaledY); float zDistance = posJoint.z - Camera.main.transform.position.z; Vector3 posScreen = new Vector3(screenX, screenY, zDistance); Vector3 posCollider = Camera.main.ScreenToWorldPoint(posScreen); jointColliders[i + j * numColliders].transform.position = posCollider; } } } } } }
//------------------------------------------------------------------------ void Awake() { UserId = manager.GetPlayer1ID(); //choose current Model according to gender changeGenderModel(); numRecord = 1; newPos = new Vector3[_numJoints]; newRot = new Quaternion[_numJoints]; }
void Update() { if (manager == null) { manager = KinectManager.Instance; } // get the users texture if (manager && manager.IsInitialized()) { foregroundTex = manager.GetUsersLblTex(); //foregroundTex = manager.GetUsersClrTex(); } if (manager.IsUserDetected()) { uint userId = manager.GetPlayer1ID(); // update colliders int numColliders = (int)KinectWrapper.NuiSkeletonPositionIndex.Count; for (int i = 0; i < numColliders; i++) { if (manager.IsJointTracked(userId, i)) { Vector3 posJoint = manager.GetRawSkeletonJointPos(userId, i); if (posJoint != Vector3.zero) { // convert the joint 3d position to depth 2d coordinates Vector2 posDepth = manager.GetDepthMapPosForJointPos(posJoint); float scaledX = posDepth.x * foregroundRect.width / KinectWrapper.Constants.DepthImageWidth; float scaledY = posDepth.y * -foregroundRect.height / KinectWrapper.Constants.DepthImageHeight; float screenX = foregroundOfs.x + scaledX; float screenY = Camera.main.pixelHeight - (foregroundOfs.y + scaledY); float zDistance = posJoint.z - Camera.main.transform.position.z; Vector3 posScreen = new Vector3(screenX, screenY, zDistance); Vector3 posCollider = Camera.main.ScreenToWorldPoint(posScreen); jointColliders[i].transform.position = posCollider; } } } } else { // update colliders int numColliders = (int)KinectWrapper.NuiSkeletonPositionIndex.Count; for (int i = 0; i < numColliders; i++) { jointColliders[i].transform.position = new Vector2(-1000f, -1000f); } } }
Vector3 GetVectorBetween(JointIndex joint1, JointIndex joint2)//순서 중요 { uint playerID = manager != null?manager.GetPlayer1ID() : 0; Vector3 pos1 = manager.GetJointPosition(playerID, (int)joint1); Vector3 pos2 = manager.GetJointPosition(playerID, (int)joint2); return(pos2 - pos1); }
public static Vector3 GetVectorBetween(JointIndex joint1, JointIndex joint2, KinectManager manager)//순서 중요 | joint1->joint2 { uint playerID = manager != null?manager.GetPlayer1ID() : 0; Vector3 pos1 = manager.GetJointPosition(playerID, (int)joint1); Vector3 pos2 = manager.GetJointPosition(playerID, (int)joint2); return(pos2 - pos1); }
// Make the defenders jump on the server side. public void Jump(uint userId, int usersCount) { KinectManager Manager = KinectManager.Instance; uint user1Id = Manager.GetPlayer1ID(); uint user2Id = Manager.GetPlayer2ID(); if (usersCount == 2) { if (userId == user1Id) { if (networkObject == null) { for (int i = 0; i < 2; i++) { defendersOffline[i].GetComponent <DefenderMovement>().Jump(); } } else { for (int i = 0; i < 2; i++) { defenders[i].gameObject.GetComponent <DefenderMovement>().Jump(); } } } else { if (networkObject == null) { for (int i = 2; i < 4; i++) { defendersOffline[i].GetComponent <DefenderMovement>().Jump(); } } else { for (int i = 2; i < 4; i++) { defenders[i].gameObject.GetComponent <DefenderMovement>().Jump(); } } } } else { foreach (DefenderBehavior d in defenders) { d.gameObject.GetComponent <DefenderMovement>().Jump(); } foreach (GameObject d in defendersOffline) { d.GetComponent <DefenderMovement>().Jump(); } } }
// Update is called once per frame void Update() { KinectManager manager = KinectManager.Instance; if (manager && manager.IsInitialized()) { // Kinectが利用可能 int iJointIndex = (int)TrackedJoint; if (manager.IsUserDetected()) { // 人物を認識 // 人物を一人に固定 uint userId = manager.GetPlayer1ID(); if (manager.IsJointTracked(userId, iJointIndex)) { // 特定のユーザーのジョイント(手)を認識 Vector3 posJoint = manager.GetRawSkeletonJointPos(userId, iJointIndex); if (posJoint != Vector3.zero) { // ジョイントの位置が0でない // 3次元座標を深度に変換 Vector2 posDepth = manager.GetDepthMapPosForJointPos(posJoint); // 3次元座標を色情報に変換 Vector2 posColor = manager.GetColorMapPosForDepthPos(posJoint); // 座標変換(Y座標については仕様上反転している) float scaleX = (float)posColor.x / KinectWrapper.Constants.ColorImageWidth; float scaleY = 1.0f - (float)posColor.y / KinectWrapper.Constants.ColorImageHeight; if (HandPointObject) { // 座標系を変換しなめらかに移動 Vector3 vPosHandPoint = Camera.main.ViewportToWorldPoint(new Vector3(scaleX, scaleY, distanceToCamera)); HandPointObject.transform.position = Vector3.Lerp(HandPointObject.transform.position, vPosHandPoint, smoothFactor * Time.deltaTime); } } } else { Debug.Log("Hand lost"); } } else { Debug.Log("Human lost"); } } else { Debug.Log("Kinect is unavailavle"); } }
private string GetBodyData() { KinectManager kinectManager = KinectManager.Instance; StringBuilder result = new StringBuilder(); uint playerID = kinectManager.GetPlayer1ID(); if (playerID <= 0) { Debug.Log("player1Id not found!"); return(null); } Vector3 posPointMan = kinectManager.GetUserPosition(playerID); //********************** for (int joint = 0; joint < Enum.GetValues(typeof(Bones)).Length; joint++) { if (kinectManager.IsJointTracked(playerID, joint)) { Vector3 posJoint = kinectManager.GetJointPosition(playerID, joint); //Quaternion rotJoint = kinectManager.GetJointOrientation(playerID, joint, false); //rotJoint = initialRotation * rotJoint; posJoint -= posPointMan; //bones[i].transform.localPosition = posJoint; //bones[i].transform.rotation = rotJoint; result.AppendFormat("{0:F3}", posJoint.x).Append(DELIMITER); result.AppendFormat("{0:F3}", posJoint.y).Append(DELIMITER); result.AppendFormat("{0:F3}", posJoint.z).Append(DELIMITER); } else { result.AppendFormat("{0:F3}", 0).Append(DELIMITER); result.AppendFormat("{0:F3}", 0).Append(DELIMITER); result.AppendFormat("{0:F3}", 0).Append(DELIMITER); } } //********************** // remove the last delimiter if (result.Length > 0 && result[result.Length - 1] == DELIMITER) { result.Remove(result.Length - 1, 1); } return(result.ToString()); }
//get current joint position and store them in _joints void getJointPosition() { UserId = manager.GetPlayer1ID(); for (int i = 0; i < _numJoints; i++) { if (manager.IsJointTracked(UserId, i)) { playerJoints[i] = manager.GetJointPosition(UserId, i); } } }
void Update() { KinectManager manager = KinectManager.Instance; if (manager && manager.IsInitialized()) { //backgroundImage.renderer.material.mainTexture = manager.GetUsersClrTex(); if (backgroundImage && (backgroundImage.texture == null)) { backgroundImage.texture = manager.GetUsersClrTex(); } // Vector3 vRight = BottomRight - BottomLeft; // Vector3 vUp = TopLeft - BottomLeft; int iJointIndex = (int)TrackedJoint; if (manager.IsUserDetected()) { uint userId = manager.GetPlayer1ID(); if (manager.IsJointTracked(userId, iJointIndex)) { Vector3 posJoint = manager.GetRawSkeletonJointPos(userId, iJointIndex); if (posJoint != Vector3.zero) { // 3d position to depth Vector2 posDepth = manager.GetDepthMapPosForJointPos(posJoint); // depth pos to color pos Vector2 posColor = manager.GetColorMapPosForDepthPos(posDepth); float scaleX = (float)posColor.x / KinectWrapper.Constants.ColorImageWidth; float scaleY = 1.0f - (float)posColor.y / KinectWrapper.Constants.ColorImageHeight; if (debugText) { debugText.GetComponent <GUIText>().text = "Tracked user ID: " + userId; // new Vector2(scaleX, scaleY).ToString(); } if (OverlayObject) { Vector3 vPosOverlay = Camera.main.ViewportToWorldPoint(new Vector3(scaleX, scaleY, distanceToCamera)); OverlayObject.transform.position = Vector3.Lerp(OverlayObject.transform.position, vPosOverlay, smoothFactor * Time.deltaTime); } } } } } }
void Update() { if (isSaving) { // create the file, if needed if (!File.Exists(saveFilePath)) { using (StreamWriter writer = File.CreateText(saveFilePath)) { // csv file header string sLine = "time;joint;pos_x;pos_y;poz_z"; writer.WriteLine(sLine); Debug.Log(sLine); } } // check the start time if (saveStartTime < 0f) { saveStartTime = Time.time; } } // get the joint position KinectManager manager = KinectManager.Instance; if (manager && manager.IsInitialized()) { if (manager.IsUserDetected()) { uint userId = manager.GetPlayer1ID(); if (manager.IsJointTracked(userId, (int)joint)) { // output the joint position for easy tracking Vector3 jointPos = manager.GetJointPosition(userId, (int)joint); outputPosition = jointPos; if (isSaving) { if ((secondsToSave == 0f) || ((Time.time - saveStartTime) <= secondsToSave)) { using (StreamWriter writer = File.AppendText(saveFilePath)) { string sLine = string.Format("{0:F3};{1};{2:F3};{3:F3};{4:F3}", Time.time, (int)joint, jointPos.x, jointPos.y, jointPos.z); writer.WriteLine(sLine); } } } } } } }
void Update() { KinectManager manager = KinectManager.Instance; if (manager && manager.IsInitialized()) { // this.renderer.material.mainTexture = manager.GetUsersClrTex(); Vector3 vRight = BottomRight - BottomLeft; Vector3 vUp = TopLeft - BottomLeft; int iJointIndex = (int)TrackedJoint; if (manager.IsUserDetected()) { uint userId = manager.GetPlayer1ID(); if (manager.IsJointTracked(userId, iJointIndex)) { GameObject obstacle = GameObject.Find("Obstacle"); obstacle.renderer.enabled = true; Vector3 posJoint = manager.GetRawSkeletonJointPos(userId, iJointIndex); // 3d position to depth Vector2 posDepth = manager.GetDepthMapPosForJointPos(posJoint); // depth pos to color pos Vector2 posColor = manager.GetColorMapPosForDepthPos(posDepth); float scaleX = (float)posColor.x / Camera.main.pixelWidth; float scaleY = 1.0f - (float)posColor.y / Camera.main.pixelHeight; Vector3 vOverlayPosition = BottomLeft + ((vRight * scaleX) + (vUp * scaleY)); Debug.Log(Mathf.Abs(obstacle.transform.position.y - vOverlayPosition.y)); if (Mathf.Abs(obstacle.transform.position.y - vOverlayPosition.y) < 6) { obstacle.transform.position = new Vector3( vOverlayPosition.y * -1f, 2.5f, 0 ); } } } else { GameObject.Find("Obstacle").renderer.enabled = false; } } }
void Update() { if (Input.GetKeyDown(KeyCode.F)) { Screen.fullScreen = !Screen.fullScreen; } KinectManager manager = KinectManager.Instance; if (manager && manager.IsInitialized()) { int iJointIndex = (int)TrackedJoint; if (manager.IsUserDetected()) { uint userId = manager.GetPlayer1ID(); if (manager.IsJointTracked(userId, iJointIndex)) { Vector3 posJoint = manager.GetRawSkeletonJointPos(userId, iJointIndex); // Ignore positions too close to the Kinect if (posJoint.z < 0.5f) { return; } // Smooth signal by using averaging Vector3 meanLastPosition = getPositionsMean(lastHeadPositions, 4); if (lastHeadPositions.Count > 8 && Vector3.Distance(meanLastPosition, posJoint) > 0.8f) { // Handle outlier } // Save the most recent head coordinates lastHeadPositions.Add(posJoint); if (lastHeadPositions.Count >= 10) { lastHeadPositions.RemoveAt(0); } Vector3 camPos = posJoint; camPos.z = (camPos.z * 10.0f - (17.5f * (2.0f / distanceFromKinectInMeters))) * zFactor; Camera.main.transform.position = new Vector3(camPos.x * xFactor * (-1.0f) * cameraHeightFactor, cameraHeight, camPos.z * (-1.0f) * cameraHeightFactor); changePerspective(); } } } }
// Update is called once per frame void Update() { KinectManager manager = KinectManager.Instance; if (manager && manager.IsInitialized()) { int HeadIndex = (int)TrackedHead; if (manager.IsUserDetected()) { if (rawImage) { rawImage.texture = manager.GetUsersClrTex(); } long userId = manager.GetPlayer1ID(); if (manager.IsJointTracked(userId, HeadIndex)) { Vector3 posJoint = manager.GetRawSkeletonJointPos(userId, HeadIndex); if (posJoint != Vector3.zero) { // print ("posJoint"); // 3d position to depth Vector2 posDepth = manager.GetDepthMapPosForJointPos(posJoint); // depth pos to color pos Vector2 posColor = manager.GetColorMapPosForDepthPos(posDepth); float scaleX = (float)posColor.x / KinectWrapper.Constants.ColorImageWidth; float scaleY = (float)posColor.y / KinectWrapper.Constants.ColorImageHeight; scaleX -= HeadImageWidth / 2.5f; scaleY -= HeadImageHeight / 5f; // Vector3 localPos = new Vector3(scaleX * 10f - 5f, 0f, scaleY * 10f - 5f); // 5f is 1/2 of 10f - size of the plane // Vector3 vPosOverlay = backgroundImage.transform.TransformPoint(localPos); //Vector3 vPosOverlay = BottomLeft + ((vRight * scaleX) + (vUp * scaleY)); if (rawImage) { // print ("rawInage"); rawImage.uvRect = new Rect(Mathf.Lerp(rawImage.uvRect.x, scaleX, smoothFactor * Time.deltaTime), Mathf.Lerp(rawImage.uvRect.y, scaleY, smoothFactor * Time.deltaTime), HeadImageHeight, HeadImageWidth); // Vector3 vPosOverlay = Camera.main.ViewportToWorldPoint(new Vector3(scaleX, scaleY, distanceToCamera)); // OverlayObject.transform.position = Vector3.Lerp(OverlayObject.transform.position, vPosOverlay, smoothFactor * Time.deltaTime); } } } } } }
void Update() { KinectManager manager = KinectManager.Instance; if (manager && manager.IsInitialized()) { // Vector3 vRight = BottomRight - BottomLeft; // Vector3 vUp = TopLeft - BottomLeft; int b = (int)TrackedJoint; int a = (int)TrackedJoint2; if (manager.IsUserDetected()) { uint userId = manager.GetPlayer1ID(); if (manager.IsJointTracked(userId, b) && manager.IsJointTracked(userId, a)) { Vector3 B = manager.GetRawSkeletonJointPos(userId, b); Vector3 A = manager.GetRawSkeletonJointPos(userId, a); Vector3 posJoint = new Vector3(4.3f * A.x - 3.3f * B.x, 4.3f * A.y - 3.3f * B.y, 4.3f * A.z - 3.3f * B.z); if (posJoint != Vector3.zero) { // 3d position to depth Vector2 posDepth = manager.GetDepthMapPosForJointPos(posJoint); // depth pos to color pos Vector2 posColor = manager.GetColorMapPosForDepthPos(posDepth); float scaleX = ((float)posColor.x / KinectWrapper.Constants.ColorImageWidth); float scaleY = 0.85f * (1.0f - (float)posColor.y / KinectWrapper.Constants.ColorImageHeight); float scaleX2 = ((float)posColor.x / KinectWrapper.Constants.ColorImageWidth); float scaleY2 = 0.85f * (1.0f - (float)posColor.y / KinectWrapper.Constants.ColorImageHeight); // Vector3 localPos = new Vector3(scaleX * 10f - 5f, 0f, scaleY * 10f - 5f); // 5f is 1/2 of 10f - size of the plane // Vector3 vPosOverlay = backgroundImage.transform.TransformPoint(localPos); //Vector3 vPosOverlay = BottomLeft + ((vRight * scaleX) + (vUp * scaleY)); if (Sphere2 && Sphere) { Vector3 vPosOverlay = Camera.main.ViewportToWorldPoint(new Vector3(scaleX, scaleY, distanceToCamera)); Vector3 vPosOverlay2 = Camera.main.ViewportToWorldPoint(new Vector3(scaleX2, scaleY2, distanceToCamera2)); Sphere.transform.position = Vector3.Lerp(Sphere.transform.position, vPosOverlay, smoothFactor * Time.deltaTime); Sphere2.transform.position = Vector3.Lerp(Sphere2.transform.position, vPosOverlay2, smoothFactor * Time.deltaTime); } } } } } }
void DepthPlacement() { KinectManager manager = KinectManager.Instance; if (musicInterface && manager && manager.IsInitialized() && manager.IsUserDetected()) { uint userId = manager.GetPlayer1ID(); Vector3 posUser = manager.GetUserPosition(userId); zPos = posUser.z; } }
private void WaitForPlayers() { uint P1ID = manager.GetPlayer1ID(); uint P2ID = manager.GetPlayer2ID(); if (P1ID != 0 && P2ID != 0) { _state = GameStateEn.Starting; } else { Debug.Log("Waiting for Players"); } }
void Update() { KinectManager manager = KinectManager.Instance; if (manager && manager.IsInitialized()) { int iJointIndex = (int)TrackedJoint; if (manager.IsUserDetected()) { uint userId = manager.GetPlayer1ID(); if (manager.IsJointTracked(userId, iJointIndex)) { Vector3 posJoint = manager.GetRawSkeletonJointPos(userId, iJointIndex); if (posJoint != Vector3.zero) { //posJoint is in meters, so first convert to feet posJoint = posJoint * 3.28084f + new Vector3(0.0f, -15.0f / 12.0f, 69.0f / 12.0f); // (0,0,0) for the kinect seems to actually be 1 meter in the Z direction... if (SceneCamera) { Vector3 vPosOverlay = Quaternion.AngleAxis(25, Vector3.left) * posJoint; vPosOverlay.z = -vPosOverlay.z; if (debugText) { debugText.guiText.text = vPosOverlay.ToString(); } SceneCamera.transform.localPosition = vPosOverlay; // Vector3.Lerp(OverlayObject.transform.position, vPosOverlay, smoothFactor * Time.deltaTime); if (RealCamera) { RealCamera.transform.localPosition = vPosOverlay; } if (LookAtObject) { SceneCamera.transform.LookAt(LookAtObject.transform.position); if (RealCamera) { RealCamera.transform.localRotation = SceneCamera.transform.localRotation; } } } } } } } }
void Update() { //Right hand joint that holds saber Vector3 rightHand = km.GetJointPosition(km.GetPlayer1ID(), 11); //Activate saber after 3 secs timeLeft -= Time.deltaTime; if (timeLeft < 0) { saber.GetComponent <LaserSwordScript>().Activate(); } rotateSaber(rightHand); }
void SetBasketPos() { //checar si no hubi problemas de inicializacion if (manager != null && manager.IsUserDetected()) { uint userID = manager.GetPlayer1ID(); Vector3 posUser = manager.GetUserPosition(userID); transform.position = new Vector3(posUser.x * speed, transform.position.y, posUser.z); } else { StartCoroutine(CheckIfPlayerDetected()); } }
void Update() { manager = KinectManager.Instance; if (manager && manager.IsInitialized()) { if (manager.IsUserDetected()) { uint userId = manager.GetPlayer1ID(); //firstButterfly.GetComponent<firstButterflyMove>().setTarget (firstTrackObject.transform.position); //firstButterfly.GetComponent<firstButterflyMove>().moveDistance = false; if (manager.IsJointTracked(userId, (int)firstTrackId)) { Vector3 posJoint = manager.GetRawSkeletonJointPos(userId, (int)firstTrackId); Vector3 firstMapPosition = getPosition(posJoint); firstButterfly.GetComponent <ButterflyMove>().setTarget(firstTrackObject.transform.position); firstButterfly.GetComponent <ButterflyMove>().roamAround = false; if (firstMapPosition != Vector3.zero) { firstTrackObject.transform.position = Vector3.Lerp(firstTrackObject.transform.position, firstMapPosition, smoothFactor * Time.deltaTime); } } if (manager.IsJointTracked(userId, (int)secondTrackId)) { Vector3 posJoint = manager.GetRawSkeletonJointPos(userId, (int)secondTrackId); Vector3 secondMapPosition = getPosition(posJoint); secondButterfly.GetComponent <ButterflyMove>().setTarget(secondTrackObject.transform.position); secondButterfly.GetComponent <ButterflyMove>().roamAround = false; if (secondMapPosition != Vector3.zero) { secondTrackObject.transform.position = Vector3.Lerp(secondTrackObject.transform.position, secondMapPosition, smoothFactor * Time.deltaTime); } } } else { firstButterfly.GetComponent <ButterflyMove>().roamAround = true; secondButterfly.GetComponent <ButterflyMove>().roamAround = true; } } }
// Update is called once per frame void Update() { km = KinectManager.Instance; string trackedJointsString = "Tracked Joints:"; if (km != null) { if (km.IsUserDetected()) { uint userId = km.GetPlayer1ID(); /*trackedJointsString += "\nchecking joints"; if(km.IsJointTracked(userId, (int)rightHand)) trackedJointsString += "\nRight hand"; if(km.IsJointTracked(userId, (int)rightWrist)) trackedJointsString += "\nRight wrist"; if(km.IsJointTracked(userId, (int)centreHip)) trackedJointsString += "\nCentre Hip"; if(km.IsJointTracked(userId, (int)leftShoulder)) trackedJointsString += "\nLeft shoulder"; if(km.IsJointTracked(userId, (int)centreShoulder)) trackedJointsString += "\nCentre shoulder"; if(km.IsJointTracked(userId, (int)rightShoulder)) trackedJointsString += "\nRight shoulder"; trackedJointsString += "\ndone checking joints";*/ if (km.IsJointTracked(userId, (int)rightHand) && km.IsJointTracked(userId, (int)rightShoulder)) wristVector = km.GetJointPosition(userId, (int)rightHand) - km.GetJointPosition(userId, (int)rightShoulder); if (km.IsJointTracked(userId, (int)rightShoulder) && km.IsJointTracked(userId, (int)leftShoulder)) shouldersVector = km.GetJointPosition(userId, (int)rightShoulder) - km.GetJointPosition(userId, (int)leftShoulder); if (km.IsJointTracked(userId, (int)centreShoulder) && km.IsJointTracked(userId, (int)centreHip)) backVector = km.GetJointPosition(userId, (int)centreShoulder) - km.GetJointPosition(userId, (int)centreHip); //GramSchmidt Orthonormal Space Vector3 e2 = backVector.normalized; Vector3 e1 = (shouldersVector - Vector3.Dot (shouldersVector,e2) * e2).normalized; wristVectorInPlane = new Vector2(Vector3.Dot(e1, wristVector), Vector3.Dot(e2, wristVector)); } } trackedJointsText.text = trackedJointsString; CheckPointingTopRight(); }
void Update() { kinectManager = KinectManager.Instance; if (kinectManager != null) { uint playerID = kinectManager.GetPlayer1ID(); Vector3 realWorldUserPosition = kinectManager.GetUserPosition(playerID); Vector2 inGameUserPosition; if (!usingQuadForLocation) { inGameUserPosition = new Vector2 ( 0.5f - Mathf.InverseLerp (leftMostRealWorldX, rightMostRealWorldX, realWorldUserPosition.x), Mathf.InverseLerp (closestRealWorldZ, furthestRealWorldZ, realWorldUserPosition.z)); } else { inGameUserPosition = ProjectRealWorldOntoSquare (new Vector2 (realWorldUserPosition.x, realWorldUserPosition.z)); } SetUserLocation (inGameUserPosition); } }
void Update() { kinectManager = GetComponentInChildren<KinectManager>(); uint playerID = kinectManager != null ? kinectManager.GetPlayer1ID() : 0; //Change the name of the spawned Player gameObject --> Move this to start or awake if ((transform.name == "" || transform.name == "Player(Clone)")) { transform.name = playerUniqueIdentity; } if (kinectManager != null && kinectManager.AllPlayersCalibrated1) { MoveCube(playerID); } else { transform.position = MatrixFunk.ExtractTranslationFromMatrix(ref kinectManager.kinectToWorld); transform.rotation = MatrixFunk.ExtractRotationFromMatrix(ref kinectManager.kinectToWorld); } }
// Update is called once per frame void Update() { if (Input.GetKeyDown (KeyCode.Space)) { calibrationPoints = new Vector2[] { new Vector2(0.6950065f,1.96167f), new Vector2(-0.8923265f,2.011135f), new Vector2(-1.026978f,3.05445f), new Vector2(1.254533f,3.204662f) }; demoInstructionText.text = ""; Application.LoadLevel (postSetupLevelName); progress = calibrationProgress.Left_Calibration; } kinectManager = KinectManager.Instance; uint playerID = kinectManager != null ? kinectManager.GetPlayer1ID() : 0; switch (progress) { case calibrationProgress.One_Started: case calibrationProgress.Two_Started: case calibrationProgress.Three_Started: case calibrationProgress.Four_Started: { Vector3 realWorldUserPosition = kinectManager.GetUserPosition(playerID); realWorldCalPointSum += Time.deltaTime * (new Vector2(realWorldUserPosition.x,realWorldUserPosition.z)); } break; } }