public void playerSideAdjuster() { var p1id = _KinectManager.GetUserIdByIndex(0); var p2id = _KinectManager.GetUserIdByIndex(1); //player1.isRight = false;//temporary for testing if (p1id != 0 && p2id != 0) { var p1pos = _KinectManager.GetUserPosition(p1id); var p2pos = _KinectManager.GetUserPosition(p2id); //Debug.Log("p1pos="+p1pos); //Debug.Log("p2pos="+p2pos); if (p1pos.x <= p2pos.x) { player1.isRight = false; player2.isRight = true; player1.gripHandTexture = leftMostHand[0]; player1.releaseHandTexture = leftMostHand[1]; player1.normalHandTexture = leftMostHand[2]; player2.gripHandTexture = RightMostHand[0]; player2.releaseHandTexture = RightMostHand[1]; player2.normalHandTexture = RightMostHand[2]; //player1.playerIndex=0; //player2.playerIndex=1; } else { player1.isRight = true; player2.isRight = false; player2.gripHandTexture = leftMostHand[0]; player2.releaseHandTexture = leftMostHand[1]; player2.normalHandTexture = leftMostHand[2]; player1.gripHandTexture = RightMostHand[0]; player1.releaseHandTexture = RightMostHand[1]; player1.normalHandTexture = RightMostHand[2]; //player1.playerIndex=1; //player2.playerIndex=0; } } }
protected virtual void MovePlayer(Vector3 moveDirection, float moveSpeed) { Vector3 movement = (moveDirection * moveSpeed) * Time.fixedDeltaTime; Vector3 finalPosition; if (directionMethod.Equals(DirectionalMethod.PositionRelativeToKinect)) { if (cameraManager == null) { cameraManager = KinectManager.Instance; } //the offset of the player from the center of the camera float xOffset = cameraManager.GetUserPosition(cameraManager.GetPrimaryUserID()).x; float xPosition = Mathf.Lerp(-2.8f, 2.8f, Mathf.InverseLerp(-0.8f, 0.8f, xOffset)); float xSmooth = Mathf.Lerp(player.position.x, xPosition, verticalMovementSmoothness); finalPosition = new Vector3(xSmooth, player.position.y, movement.z + player.position.z); } else { finalPosition = new Vector3(movement.x + player.position.x, player.position.y, movement.z + player.position.z); } if (player != null && CanMove(bodyPhysics, player.position, finalPosition)) { player.position = finalPosition; } }
// Moves the avatar in 3D space - pulls the tracked position of the spine and applies it to root. // Only pulls positional, not rotational. protected void MoveAvatar(uint UserID) { if (Hooked) { return; } if (bodyRoot == null || kinectManager == null || Hooked) { return; } if (!kinectManager.IsJointTracked(UserID, (int)KinectWrapper.NuiSkeletonPositionIndex.HipCenter)) { return; } // Get the position of the body and store it. Vector3 trans = kinectManager.GetUserPosition(UserID); HipPos = kinectManager.GetJointPosition(UserID, 0); // If this is the first time we're moving the avatar, set the offset. Otherwise ignore it. if (!offsetCalibrated) { offsetCalibrated = true; xOffset = !mirroredMovement ? trans.x * moveRate : -trans.x * moveRate; yOffset = trans.y * moveRate; zOffset = -trans.z * moveRate; if (offsetRelativeToSensor) { Vector3 cameraPos = Camera.main.transform.position; float yRelToAvatar = (offsetNode != null ? offsetNode.transform.position.y : transform.position.y) - cameraPos.y; Vector3 relativePos = new Vector3(trans.x * moveRate, yRelToAvatar, trans.z * moveRate); Vector3 offsetPos = cameraPos + relativePos; if (offsetNode != null) { offsetNode.transform.position = offsetPos; } else { transform.position = offsetPos; } } } // Smoothly transition to the new position Vector3 targetPos = Kinect2AvatarPos(trans, verticalMovement); if (smoothFactor != 0f) { bodyRoot.localPosition = Vector3.Lerp(bodyRoot.localPosition, targetPos, smoothFactor * Time.deltaTime); } else { bodyRoot.localPosition = targetPos; } }
void SpawnMedicin() { KinectManager manager = KinectManager.Instance; if (eggPrefab && manager && manager.IsInitialized() && manager.IsUserDetected()) { long userId = manager.GetPrimaryUserID(); Vector3 posUser = manager.GetUserPosition(userId); int posDrop = Random.Range(0, positionDrop.Length); while (posDrop == oldPos) { posDrop = Random.Range(0, positionDrop.Length); } oldPos = posDrop; float addXPos = positionDrop[posDrop].localPosition.x; Vector3 spawnPos = new Vector3(addXPos, 5f, posUser.z); Transform eggTransform = Instantiate(eggPrefab, spawnPos, Quaternion.identity) as Transform; int a = Random.Range(0, 5); Debug.Log(a + "//" + CheckListCurrent()); count++; if (count >= 4) { if (!CheckListCurrent()) { a = game1Manager.currentDisease; } count = 0; } eggTransform.GetComponent <MedicinTrigger>().Init(a, speed); eggTransform.parent = transform; } }
// Moves the avatar in 3D space - pulls the tracked position of the spine and applies it to root. // Only pulls positional, not rotational. void MoveAvatar(Int64 UserID) { if (!kinectManager || !kinectManager.IsJointTracked(UserID, (int)JointType.SpineBase)) { return; } // Get the position of the body and store it. Vector3 trans = kinectManager.GetUserPosition(UserID); // If this is the first time we're moving the avatar, set the offset. Otherwise ignore it. if (!OffsetCalibrated) { OffsetCalibrated = true; XOffset = !MirroredMovement ? trans.x * MoveRate : -trans.x * MoveRate; YOffset = trans.y * MoveRate; ZOffset = -trans.z * MoveRate; } // Smoothly transition to the new position Vector3 targetPos = Kinect2AvatarPos(trans, VerticalMovement); if (BodyRoot != null && BodyRoot.parent != null) { BodyRoot.parent.localPosition = SmoothFactor != 0f ? Vector3.Lerp(BodyRoot.parent.localPosition, targetPos, SmoothFactor * Time.deltaTime) : targetPos; } else { transform.localPosition = SmoothFactor != 0f ? Vector3.Lerp(transform.localPosition, targetPos, SmoothFactor * Time.deltaTime) : targetPos; } }
public void SpawnBotton() { Vector3 spawn = new Vector3(0, 0, 2); // Instantiate(fruit, spawn, transform.rotation); KinectManager manager = KinectManager.Instance; if (fruitPrefab && manager && manager.IsInitialized() && manager.IsUserDetected()) { int a = Random.Range(0, 100); long userId = manager.GetPrimaryUserID(); Vector3 posUser = manager.GetUserPosition(userId); Debug.Log(posUser); // float addXPos = Random.Range(-6f, 6f); // Vector3 spawnPos = new Vector3(addXPos, 6, posUser.z); // FruitTrigger ft = Instantiate(fruitPrefab, spawnPos, Quaternion.identity); FruitTrigger ft = Instantiate(fruit, spawn, transform.rotation); if (a < percenGood) { //random good object ft.Init(true); } else { //random bad object ft.Init(false); } ft.transform.parent = parrentFruit; } }
void SpawnBalls() { KinectManager manager = KinectManager.Instance; if (ballPrefab && cubePrefab && ballsCount < numberOfObjects && manager && manager.IsInitialized() && manager.IsUserDetected()) { long userId = manager.GetPrimaryUserID(); posUser = userTransform ? userTransform.position : manager.GetUserPosition(userId); float xPos = UnityEngine.Random.Range(-instantiateInRange.x, instantiateInRange.x); float zPos = UnityEngine.Random.Range(-instantiateInRange.z, instantiateInRange.z); Vector3 spawnPos = new Vector3(posUser.x + xPos, posUser.y + instantiateInRange.y, posUser.z + zPos); int ballOrCube = Mathf.RoundToInt(UnityEngine.Random.Range(0f, 1f)); Transform ballTransform = Instantiate(ballOrCube > 0 ? ballPrefab : cubePrefab, spawnPos, Quaternion.identity) as Transform; ballTransform.GetComponent <Renderer>().material.color = new Color(UnityEngine.Random.Range(0.5f, 1f), UnityEngine.Random.Range(0.5f, 1f), UnityEngine.Random.Range(0.5f, 1f), 1f); ballTransform.parent = transform; ballsCount++; if (OnNewObject != null) { OnNewObject(ballTransform); } } }
void Update() { if (manager == null || !manager.IsInitialized()) { return; } userId = manager.GetUserIdByIndex(playerIndex); currentUserPos = manager.GetUserPosition(userId); if (userId != 0 && userId != lastUserId) { lastUserId = userId; // initialUserPos = currentUserPos; } if (userId != 0) { Vector3 deltaUserPos = currentUserPos; // relToInitialPos ? (currentUserPos - initialUserPos) : currentUserPos; Vector3 newPlanePos = initialPlanePos + new Vector3(0f, 0f, deltaUserPos.z); transform.position = Vector3.Lerp(transform.position, newPlanePos, smoothFactor * Time.deltaTime); } else { lastUserId = 0; // initialUserPos = Vector3.zero; transform.position = initialPlanePos; } }
// Moves the avatar in 3D space - pulls the tracked position of the spine and applies it to root. // Only pulls positional, not rotational. void MoveAvatar(uint UserID) { if (Root == null || Root.parent == null || kinectManager == null) { return; } if (!kinectManager.IsJointTracked(UserID, (int)KinectWrapper.SkeletonJoint.HIPS)) { return; } // Get the position of the body and store it. Vector3 trans = kinectManager.GetUserPosition(UserID); // If this is the first time we're moving the avatar, set the offset. Otherwise ignore it. if (!OffsetCalibrated) { OffsetCalibrated = true; XOffset = !MirroredMovement ? trans.x * MoveRate : -trans.x * MoveRate; YOffset = trans.y * MoveRate; ZOffset = -trans.z * MoveRate; } // Smoothly transition to the new position Vector3 targetPos = Kinect2AvatarPos(trans, VerticalMovement); Root.parent.localPosition = Vector3.Lerp(Root.parent.localPosition, targetPos, SmoothFactor * Time.deltaTime); }
void SpawnBalls() { KinectManager kinectManager = KinectManager.Instance; if (ballPrefab && cubePrefab && ballsCount < numberOfObjects && kinectManager && kinectManager.IsInitialized() && kinectManager.IsUserDetected(playerIndex)) { ulong userId = kinectManager.GetUserIdByIndex(playerIndex); Vector3 posUser = kinectManager.GetUserPosition(userId); float xOfs = Random.Range(-1.5f, 1.5f); float zOfs = Random.Range(-2.0f, 1.0f); float yOfs = Random.Range(1.0f, 4.0f); Vector3 spawnPos = new Vector3(posUser.x + xOfs, posUser.y + yOfs, posUser.z + zOfs); int ballOrCube = Mathf.RoundToInt(Random.Range(0f, 1f)); Transform ballTransform = Instantiate(ballOrCube > 0 ? ballPrefab : cubePrefab, spawnPos, Quaternion.identity) as Transform; ballTransform.GetComponent <Renderer>().material.color = new Color(Random.Range(0.5f, 1f), Random.Range(0.5f, 1f), Random.Range(0.5f, 1f), 1f); ballTransform.GetComponent <Rigidbody>().drag = Random.Range(1f, 100f); ballTransform.parent = transform; ballsCount++; } }
void Update() { if (scalerInited && kinectManager && kinectManager.IsInitialized()) { // get the plane rectangle to be used for object overlay if (backgroundPlane && !planeRectSet) { planeRectSet = true; planeRect.width = 10f * Mathf.Abs(backgroundPlane.localScale.x); planeRect.height = 10f * Mathf.Abs(backgroundPlane.localScale.z); planeRect.x = backgroundPlane.position.x - planeRect.width / 2f; planeRect.y = backgroundPlane.position.y - planeRect.height / 2f; } long userId = kinectManager.GetUserIdByIndex(playerIndex); // check user distance and hand positions if (userId != 0 && minUserDistance > 0f) { Vector3 userPos = kinectManager.GetUserPosition(userId); bool lHandTracked = kinectManager.IsJointTracked(userId, (int)KinectInterop.JointType.WristLeft); Vector3 lHandPos = lHandTracked ? kinectManager.GetJointPosition(userId, (int)KinectInterop.JointType.WristLeft) : Vector3.zero; bool rHandTracked = kinectManager.IsJointTracked(userId, (int)KinectInterop.JointType.WristRight); Vector3 rHandPos = rHandTracked ? kinectManager.GetJointPosition(userId, (int)KinectInterop.JointType.WristRight) : Vector3.zero; if (userPos.z < minUserDistance || !lHandTracked || (lHandPos.z - userPos.z) <= -0.3f || !rHandTracked || (rHandPos.z - userPos.z) <= -0.3f) { // don't scale the model userId = 0; //Debug.Log ("Avatar scaling skipped."); } } if (userId != currentUserId) { currentUserId = userId; if (userId != 0) { GetUserBodySize(true, true, true); // if (fixModelHipsAndShoulders) // FixJointsBeforeScale(); ScaleAvatar(0f, true); } } } if (currentUserId != 0 && continuousScaling) { GetUserBodySize(true, true, true); ScaleAvatar(smoothFactor, false); } }
/// <summary> /// 获取用户位置 /// </summary> private void GetUserPos() { if (manager.IsUserDetected()) { long userID = manager.GetPrimaryUserID(); Vector3 userPos = manager.GetUserPosition(userID); } }
// Mueve el avatar en un espacio 3D - saca la posición rastreada de la espina (columna) y la aplica a la raiz. // Sólo saca posición, no rotación. protected void MoveAvatar(uint UserID) { if (bodyRoot == null || kinectManager == null) { return; } if (!kinectManager.IsJointTracked(UserID, (int)KinectWrapper.NuiSkeletonPositionIndex.HipCenter)) { return; } // Obtener la posición del cuerpo y almacenarlo. Vector3 trans = kinectManager.GetUserPosition(UserID); // Si es la primera vez que se mueve el avatar, definir el offset, de resto ignorarlo. if (!offsetCalibrated) { offsetCalibrated = true; // PROBAR MIRROR MOVEMENT (imprimir en log). xOffset = !mirroredMovement ? trans.x * moveRate : -trans.x * moveRate; yOffset = trans.y * moveRate; zOffset = -trans.z * moveRate; if (offsetRelativeToSensor) { Vector3 cameraPos = Camera.main.transform.position; float yRelToAvatar = (offsetNode != null ? offsetNode.transform.position.y : transform.position.y) - cameraPos.y; Vector3 relativePos = new Vector3(trans.x * moveRate, yRelToAvatar, trans.z * moveRate); Vector3 offsetPos = cameraPos + relativePos; if (offsetNode != null) { offsetNode.transform.position = offsetPos; } else { transform.position = offsetPos; } } } // Transicionar de manera suave (Smooth) a nueva posición. Vector3 targetPos = Kinect2AvatarPos(trans, verticalMovement); if (smoothFactor != 0f) { bodyRoot.localPosition = Vector3.Lerp(bodyRoot.localPosition, targetPos, smoothFactor * Time.deltaTime); } else { bodyRoot.localPosition = targetPos; } //abril 3 //cubeman.SendMessage("moveCubeMan", bodyRoot.position); }
// Update the avatar each frame. public void UpdateAvatar(uint UserID) { bodyCtrlData.UserID = UserID; if (!transform.gameObject.activeInHierarchy) { return; } // Get the KinectManager instance if (kinectManager == null) { kinectManager = KinectManager.Instance; } // Get the position of the body and store it. //bodyCtrlData.userPosition = kinectManager.GetUserPosition(UserID); kinectManager.setUserPosition(kinectManager.GetUserPosition(UserID)); for (var boneIndex = 0; boneIndex < bones.Length; boneIndex++) { if (!bones[boneIndex] || boneIndex == 12) { continue; } if (boneIndex2JointMap.ContainsKey(boneIndex)) { KinectWrapper.NuiSkeletonPositionIndex joint = boneIndex2JointMap[boneIndex]; TransformBone(UserID, joint, boneIndex, true); } else { kinectManager.setJointRotation(Quaternion.identity, boneIndex); } } KinectWrapper.NuiSkeletonPositionIndex HandLeftJointPos = boneIndex2JointMap[8]; //bodyCtrlData.HandLeftPos = kinectManager.GetJointPosition(UserID, (int)HandLeftJointPos); //kinectManager.setHandLeftPos(kinectManager.GetJointPosition(UserID, (int)HandLeftJointPos)); KinectWrapper.NuiSkeletonPositionIndex HandRightJointPos = boneIndex2JointMap[13]; //bodyCtrlData.HandRightPos = kinectManager.GetJointPosition(UserID, (int)HandRightJointPos); //kinectManager.setHandRightPos(kinectManager.GetJointPosition(UserID, (int)HandRightJointPos)); }
//decide if the user wants to play as FPS or as TPS by tracking the position of user in real world void SetTPorFP(uint UserID) { if (Root == null || kinectManager == null) { return; } if (!kinectManager.IsJointTracked(UserID, (int)KinectWrapper.SkeletonJoint.HIPS)) { return; } // Get the position of the body and store it. Vector3 trans = kinectManager.GetUserPosition(UserID); if (!OffsetCalibrated) { OffsetCalibrated = true; initialPositionInRealWorld = trans; } if (trans.z - initialPositionInRealWorld.z < -0.05f) { if (Fp) { //move the spine Vector3 tmp = Root.localPosition; tmp.z -= 100; Root.localPosition = tmp; Fp = false; } } if (trans.z - initialPositionInRealWorld.z < 0.05f) { if (!Fp) { //move spine back Vector3 tmp = Root.localPosition; tmp.z += 100; Root.localPosition = tmp; Fp = true; } } }
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()); }
// Moves the avatar in 3D space - pulls the tracked position of the spine and applies it to root. // Only pulls positional, not rotational. protected void MoveAvatar(uint UserID) { if (bodyRoot == null || kinectManager == null) { return; } if (!kinectManager.IsJointTracked(UserID, (int)KinectWrapper.NuiSkeletonPositionIndex.HipCenter)) { return; } // Obtener la posición del cuerpo y almacenarlo. Vector3 trans = kinectManager.GetUserPosition(UserID); // Si es la primera vez que movemos el avatar, establecemos el desplazamiento. De lo contrario ignorarlo. if (!offsetCalibrated) { offsetCalibrated = true; xOffset = !mirroredMovement ? trans.x * moveRate : -trans.x * moveRate; yOffset = trans.y * moveRate; zOffset = -trans.z * moveRate; if (offsetRelativeToSensor) { Vector3 cameraPos = Camera.main.transform.position; float yRelToAvatar = (offsetNode != null ? offsetNode.transform.position.y : transform.position.y) - cameraPos.y; Vector3 relativePos = new Vector3(trans.x * moveRate, yRelToAvatar, trans.z * moveRate); Vector3 offsetPos = cameraPos + relativePos; if (offsetNode != null) { offsetNode.transform.position = offsetPos; } else { transform.position = offsetPos; } } } // Transición suave a la nueva posición Vector3 targetPos = Kinect2AvatarPos(trans, verticalMovement); if (smoothFactor != 0f) { bodyRoot.localPosition = Vector3.Lerp(bodyRoot.localPosition, targetPos, smoothFactor * Time.deltaTime); } else { bodyRoot.localPosition = targetPos; } }
protected void MoveAvatar(uint UserID) { if (bodyRoot == null || _BodyManager == null) { return; } if (!kinectManager.IsJointTracked(UserID, (int)Kinect.JointType.SpineBase)) { return; } Vector3 trans = kinectManager.GetUserPosition(UserID); // If this is the first time we're moving the avatar, set the offset. Otherwise ignore it. if (!offsetCalibrated) { offsetCalibrated = true; xOffset = trans.x * moveRate; yOffset = trans.y * moveRate; zOffset = -trans.z * moveRate; if (offsetRelativeToSensor) { Vector3 cameraPos = Camera.main.transform.position; float yRelToAvatar = (offsetNode != null ? offsetNode.transform.position.y : transform.position.y) - cameraPos.y; Vector3 relativePos = new Vector3(trans.x * moveRate, yRelToAvatar, trans.z * moveRate); Vector3 offsetPos = cameraPos + relativePos; if (offsetNode != null) { offsetNode.transform.position = offsetPos; } else { transform.position = offsetPos; } } } // Smoothly transition to the new position Vector3 targetPos = Kinect2AvatarPos(trans); if (smoothFactor != 0f) { bodyRoot.localPosition = Vector3.Lerp(bodyRoot.localPosition, targetPos, smoothFactor * Time.deltaTime); } else { bodyRoot.localPosition = targetPos; } }
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 updateUserPosition(KinectManager manager, uint userID) { Vector3 userPosition = manager.GetUserPosition(userID); userPosition.x *= -1; if (Vector3.Distance(transform.position, userPosition) < minimumPositionDelta) { transform.position = userPosition; } else { transform.position = Vector3.Lerp(transform.position, userPosition, Time.deltaTime * JointAdjustmentSpeed); } }
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 SpawnEgg() { KinectManager manager = KinectManager.Instance; if (eggPrefab && manager && manager.IsInitialized() && manager.IsUserDetected()) { long userId = manager.GetPrimaryUserID(); Vector3 posUser = manager.GetUserPosition(userId); float addXPos = Random.Range(-10f, 10f); Vector3 spawnPos = new Vector3(addXPos, 10f, posUser.z - 0.2f); Transform eggTransform = Instantiate(eggPrefab, spawnPos, Quaternion.identity) as Transform; eggTransform.parent = transform; } }
void SpawnEgg() { KinectManager kinectManager = KinectManager.Instance; if (eggPrefab && kinectManager && kinectManager.IsInitialized() && kinectManager.IsUserDetected(playerIndex)) { ulong userId = kinectManager.GetUserIdByIndex(playerIndex); Vector3 posUser = kinectManager.GetUserPosition(userId); float addXPos = Random.Range(-2f, 2f); Vector3 spawnPos = new Vector3(addXPos, 5f, posUser.z - 0.1f); Transform eggTransform = Instantiate(eggPrefab, spawnPos, Quaternion.identity) as Transform; eggTransform.parent = transform; } }
private Vector3 GetJointPositionInv(long userId, int jointIndex) { if (manager) { Vector3 userPos = manager.GetUserPosition(userId); Vector3 jointPos = manager.GetJointPosition(userId, jointIndex); Vector3 jointDiff = jointPos - userPos; jointDiff.z = -jointDiff.z; jointPos = userPos + jointDiff; return(jointPos); } return(Vector3.zero); }
void SpawnEgg() { KinectManager manager = KinectManager.Instance; if (eggPrefab && manager && manager.IsInitialized() && manager.IsUserDetected()) { uint userId = manager.GetPlayer1ID(); Vector3 posUser = manager.GetUserPosition(userId); float addXPos = Random.Range(-13f, 15f); Vector3 spawnPos = new Vector3(addXPos, 25f, posUser.z); Transform eggTransform = Instantiate(eggPrefab, spawnPos, Quaternion.Euler(90, 180, 0)) as Transform; eggTransform.parent = transform; } }
private void SetBodyData(string bodyData, float deltaTime) { string[] parsedBodyData = bodyData.Split(DELIMITER); uint playerID = _kinectManager != null?_kinectManager.GetPlayer1ID() : 0; Vector3 posPointMan = _kinectManager.GetUserPosition(playerID); for (int jointIndex = 0; jointIndex < Enum.GetValues(typeof(Bones)).Length; jointIndex++) { float x, y, z; float.TryParse(parsedBodyData[jointIndex * 3], out x); float.TryParse(parsedBodyData[jointIndex * 3 + 1], out y); float.TryParse(parsedBodyData[jointIndex * 3 + 2], out z); if (MirroredMovement) { x = -x; z = -z; } _bones[jointIndex].transform.localPosition = new Vector3(x, y, z); //=================================================================== // Comparison //=================================================================== Vector3 posJoint = _kinectManager.GetJointPosition(playerID, jointIndex); posJoint -= posPointMan; Vector3 parsedJointPos = new Vector3(x, y, z); float distance = (posJoint - parsedJointPos).magnitude; if (distance <= ErrorMargin) { //Debug.Log("distance ok"); _currentScore = ScoreGainPerJoinPerSecond * deltaTime; } else { //Debug.Log("distance not ok (" + distance + ")"); } } UIManager.Instance.PlayUiState.SetScore((int)_currentScore); }
void SpawnEgg() { KinectManager manager = KinectManager.Instance; if (eggPrefab && manager && manager.IsInitialized() && manager.IsUserDetected()) { uint userId = manager.GetPlayer1ID(); Vector3 posUser = manager.GetUserPosition(userId); //Vector3 posUser = manager.GetRawSkeletonJointPos(userId,5); float addXPos = Random.Range(-1.3f, 15.5f); Vector3 spawnPos = new Vector3(addXPos, 10f, posUser.z); //Debug.Log (addXPos+ "10f" + posUser.z); //Debug.Log (addXPos); Transform eggTransform = Instantiate(eggPrefab, spawnPos, Quaternion.identity) as Transform; eggTransform.parent = transform; } }
void SpawnEgg() { KinectManager manager = KinectManager.Instance; if (fruitPrefab && manager && manager.IsInitialized() && manager.IsUserDetected()) { int a = Random.Range(0, 100); long userId = manager.GetPrimaryUserID(); Vector3 posUser = manager.GetUserPosition(userId); //float addXPos = Random.Range(-6f, 6f); //Vector3 spawnPos = new Vector3(addXPos, 6, posUser.z); int posDrop = Random.Range(0, positionDrop.Length); while (posDrop == oldPos) { posDrop = Random.Range(0, positionDrop.Length); } oldPos = posDrop; float addXPos = positionDrop[posDrop].localPosition.x; Vector3 spawnPos = new Vector3(addXPos, 5f, posUser.z); FruitTrigger ft = Instantiate(fruitPrefab, spawnPos, Quaternion.identity); if (a < percenGood) { //random good object ft.Init(true); } else { //random bad object ft.Init(false); } ft.transform.parent = parrentFruit; } }
private void UpdateArms() { kinectUserID = kinectManager.GetUserIdByIndex(0); Vector3 rootPos = kinectManager.GetUserPosition(kinectUserID); Quaternion leftQuat = kinectManager.GetJointOrientation(kinectUserID, (int)KinectInterop.JointType.ElbowLeft, true); //leftQuat = leftQuat; leftQuat = Quaternion.Slerp(leftRoot.localRotation, leftQuat, smoothFactor * Time.deltaTime); leftRoot.localRotation = leftQuat; Quaternion rightQuat = kinectManager.GetJointOrientation(kinectUserID, (int)KinectInterop.JointType.ElbowRight, true); rightQuat = rightQuat * Quaternion.AngleAxis(angleFlipAmt, angleFlipDirection); rightQuat = Quaternion.Slerp(rightRoot.localRotation, rightQuat, smoothFactor * Time.deltaTime); rightRoot.localRotation = rightQuat; /******************************************************/ Vector3 rightPos = kinectManager.GetJointPosition(kinectUserID, (int)KinectInterop.JointType.ElbowRight); rightPos.z = (rightPos.z * -1f) + rootPos.z; rightPos.x = rightPos.x - rootPos.x; rightPos.y = rightPos.y - rootPos.y; rightPos = ((rightPos) * positionScale); rightPos = Vector3.Lerp(rightRoot.localPosition, rightPos, smoothFactor * Time.deltaTime); rightRoot.localPosition = rightPos; Vector3 leftPos = kinectManager.GetJointPosition(kinectUserID, (int)KinectInterop.JointType.ElbowLeft); leftPos.z = (leftPos.z * -1f) + rootPos.z; leftPos.x = leftPos.x - rootPos.x; leftPos.y = leftPos.y - rootPos.y; leftPos = ((leftPos) * positionScale); leftPos = Vector3.Lerp(leftRoot.localPosition, leftPos, smoothFactor * Time.deltaTime); leftRoot.localPosition = leftPos; }
void Update() { if (kinectManager == null || !kinectManager.IsInitialized()) { return; } userId = kinectManager.GetUserIdByIndex(playerIndex); currentUserPos = kinectManager.GetUserPosition(userId); bool bInstantMove = false; if (userId != 0 && userId != lastUserId) { lastUserId = userId; bInstantMove = true; } if (userId != 0) { Vector3 deltaUserPos = currentUserPos; // relToInitialPos ? (currentUserPos - initialUserPos) : currentUserPos; Vector3 newPlanePos = initialPlanePos + new Vector3(0f, 0f, deltaUserPos.z); if (!bInstantMove) { transform.position = Vector3.Lerp(transform.position, newPlanePos, smoothFactor * Time.deltaTime); } else { transform.position = newPlanePos; } } else { lastUserId = 0; transform.position = new Vector3(0f, 0f, -1f); // initialPlanePos; } }
// 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; } }
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); } }