// Update is called once per frame void Update() { if (NuitrackManager.NumUsers > 0) { if (timer <= waitTime) { timer += Time.deltaTime; BoneScalingProgress.text = "Bone Scaling: In Progress..."; } else if (timer >= waitTime) { BoneScalingProgress.text = "Bone Scaling: Completed"; } // get ID of user nuitrack.User[] users = NuitrackManager.Users; nuitrack.User CurrentUser = users[0]; int CurrentUserID = CurrentUser.ID; foreach (var riggedJoint in jointsRigged) { //Get joint from the Nuitrack nuitrack.Joint joint = NuitrackManager.SkeletonData.GetSkeletonByID(CurrentUserID).GetJoint(riggedJoint.Key); if (joint.Confidence > 0.5) //Currently, there are only two values of confidence: 0 (Nuitrack thinks that this isn't a joint) and 0.75 (a joint). { ModelJoint modeljoint = riggedJoint.Value; //get modelJoint nuitrack.Joint parentjoint = NuitrackManager.SkeletonData.GetSkeletonByID(CurrentUserID).GetJoint(modeljoint.parentJointType); Vector3 newPos = 0.001f * joint.ToVector3(); //given in mm Vector3 parentPos = 0.001f * parentjoint.ToVector3(); // Coinvert nuitrack joint orientation to quaternion Quaternion jointOrient = joint.ToQuaternion(); // Update Model joint to tracked orientation modeljoint.bone.rotation = jointOrient * modeljoint.baseRotOffset; // perform bone scaling for 5 seconds at the start maybe? if (modeljoint.parentBone != null && timer <= waitTime) { Debug.Log("BONE SCALING PERFORMED..........."); // take the transform of the parent bone //Transform parentBone = modeljoint.parentBone; // calculate how many times the distance between the child bone and its parent bone has changed compared to the base distances (which was recorded at the start) float scaleDif = modeljoint.baseDistanceToParent / Vector3.Distance(newPos, parentPos); // change the size of the bone to the resulting value modeljoint.parentBone.localScale = Vector3.one / scaleDif; } } } } }
private void RefreshJointRotation(nuitrack.Skeleton skeleton) { foreach (var riggedJoint in jointsRigged) { nuitrack.Joint joint = skeleton.GetJoint(riggedJoint.Key); ModelJoint modelJoint = riggedJoint.Value; Quaternion jointOrient = Quaternion.Inverse(CalibrationInfo.SensorOrientation) * (joint.ToQuaternion()) * modelJoint.baseRotOffset; modelJoint.bone.rotation = jointOrient; } }
private void CheckForInput() { if ((Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(0)) && Grounded) { _jump = true; } if ((Input.GetKey(KeyCode.Space) || Input.GetMouseButton(0)) && !Grounded) { _glide = true; } if (Input.GetKeyUp(KeyCode.Space) || Input.GetMouseButtonUp(0)) { _glide = false; } if (Input.GetKey(KeyCode.LeftControl)) { _crouch = true; } if (Input.GetKeyUp(KeyCode.LeftControl)) { _crouch = false; } if (UseNuitrack) { if (_gameManager.GameState == GameManager.GameStateType.EndGame) { if (CheckForTPose()) { if (_currentTimer > 0.0f) { _currentTimer -= Time.deltaTime; } else { _currentTimer = _startTimer; _gameManager.RestartLevel(); } } } if (_gameManager.GameState == GameManager.GameStateType.Playing && _userDetected) { if (Grounded && (_rightHipJoint.ToVector3().y > _rightHipStartingPosition.y + JumpThreshold * _playerHeight || _leftHipJoint.ToVector3().y > _leftHipStartingPosition.y + JumpThreshold * _playerHeight)) { if (!_jump) { _jump = true; _scoreManager.NumberOfJumps++; } } if (!Grounded && (_rightShoulderJoint.ToQuaternion().eulerAngles.z > 270 && _rightShoulderJoint.ToQuaternion().eulerAngles.z < 360) || (_rightShoulderJoint.ToQuaternion().eulerAngles.z >= 0 && _rightShoulderJoint.ToQuaternion().eulerAngles.z < 60)) { if ((_leftShoulderJoint.ToQuaternion().eulerAngles.z > 0 && _leftShoulderJoint.ToQuaternion().eulerAngles.z < 90) || (_leftShoulderJoint.ToQuaternion().eulerAngles.z <= 360 && _leftShoulderJoint.ToQuaternion().eulerAngles.z > 300)) { if (!_glide) { _scoreManager.NumberOfGlides++; } _glide = true; } } if ((_rightShoulderJoint.ToQuaternion().eulerAngles.z <= 270 && _rightShoulderJoint.ToQuaternion().eulerAngles.z > 60) || (_leftShoulderJoint.ToQuaternion().eulerAngles.z >= 90 && _leftShoulderJoint.ToQuaternion().eulerAngles.z <= 300)) { _glide = false; } if (_rightHipJoint.ToVector3().y < _rightHipStartingPosition.y - CrouchThreshold * _playerHeight || _leftHipJoint.ToVector3().y < _leftHipStartingPosition.y - CrouchThreshold * _playerHeight) { if (!_crouch) { _scoreManager.NumberOfSquats++; } _crouch = true; } else { _crouch = false; } } //print("LEFT: " + _leftShoulderJoint.ToQuaternion().eulerAngles.z + " , RIGHT: " + _rightShoulderJoint.ToQuaternion().eulerAngles.z); } }