private void MoveXY() { // Calc rotation angle Vector2 camDir = new Vector2(Camera.main.transform.forward.x, Camera.main.transform.forward.z); float ang = Vector2.Angle(refOrigin, camDir); if (Vector3.Cross(refOrigin, camDir).z > 0) { ang = 360 - ang; } // Translate real world vector to game vector Vector3 armVec = kin.GetJointPos(KinectWrapper.Joints.HAND_RIGHT) - kin.GetJointPos(KinectWrapper.Joints.ELBOW_RIGHT); Vector3 translatedArm = new Vector3(armVec.x, -armVec.y, -armVec.z); translatedArm = Quaternion.Euler(0, ang, 0) * translatedArm.normalized; // rotate // Calc new look at vector Vector3 worldExtension = transform.position + translatedArm; if (this.pointTo == null) { this.pointTo = worldExtension; } else { this.pointTo = pointTo + (worldExtension - pointTo) * movementSpeed * Time.deltaTime; } // Look at this.transform.LookAt(this.pointTo, new Vector3(0, 1, 0)); }
// Update is called once per frame void Update() { if (!debugMode) { //Choose center Vector3 center = Kinect.GetJointPos(KinectWrapper.Joints.SHOULDER_CENTER); //Release any non-fixated directions if (!fixateX) { center.x = 0; } if (!fixateY) { center.y = 0; } if (!fixateZ) { center.z = 0; } if (easyMode) { var temp = Vector3.Scale(Kinect.GetJointPos(JointToTrack) - center, new Vector3(1, 1, -1)); var tempX = temp.x; var tempY = temp.y; transform.localPosition = new Vector3(tempX, tempY, 0); } else { //Position this object according to chosen joint, but do it relative to the ShoulderCenter position transform.localPosition = Vector3.Scale(Kinect.GetJointPos(JointToTrack) - center, new Vector3(1, 1, -1)); } } else { position = Input.mousePosition; if (mirrored) { position = new Vector3( -MapValue(position.x, 0, 1800, -20, 20), MapValue(position.y, 0, 1000, -15, 15), 0); } else { position = new Vector3( MapValue(position.x, 0, 1800, -20, 20), MapValue(position.y, 0, 1000, -15, 15), 0); } transform.localPosition = position; } }
public static bool KinectLeft(KUInterface kin) { if (kin == null) return false; bool val = false; Vector3 leftWrist = kin.GetJointPos(KinectWrapper.Joints.WRIST_LEFT); Vector3 leftElbow = kin.GetJointPos(KinectWrapper.Joints.ELBOW_LEFT); if (Math.Abs(leftWrist.x - leftElbow.x) > Vector3.Distance(leftWrist, leftElbow) * 0.9) val = true; return val; }
public static bool KinectRight(KUInterface kin) { if (kin == null) return false; bool val = false; Vector3 rightWrist = kin.GetJointPos(KinectWrapper.Joints.WRIST_RIGHT); Vector3 rightElbow = kin.GetJointPos(KinectWrapper.Joints.ELBOW_RIGHT); if (Math.Abs(rightWrist.x - rightElbow.x) > Vector3.Distance(rightWrist, rightElbow) * 0.9) val = true; return val; }
// Update is called once per frame void Update() { if (!isInitialized) { return; } Vector3 pos1 = kin.GetJointPos(KinectWrapper.Joints.SHOULDER_LEFT); Vector3 pos2 = kin.GetJointPos(KinectWrapper.Joints.ELBOW_LEFT); Vector3 vec = pos2 - pos1; vec.z = -1 * vec.z; transform.LookAt((transform.position + vec.normalized), new Vector3(0, 1, 0)); }
public static bool KinectLeft(KUInterface kin) { if (kin == null) return false; bool val = false; Vector3 shoulderCenter = kin.GetJointPos(KinectWrapper.Joints.SHOULDER_CENTER); Vector3 hipCenter = kin.GetJointPos(KinectWrapper.Joints.HIP_CENTER); Vector3 upperBody = shoulderCenter - hipCenter; if (upperBody.normalized.x < -0.15) val = true; return val; }
// Update is called once per frame void Update() { if (!isInitialized) { return; } Vector3 elbowPos = kin.GetJointPos(KinectWrapper.Joints.ELBOW_LEFT); Vector3 handPos = kin.GetJointPos(KinectWrapper.Joints.HAND_LEFT); Vector3 handVector = handPos - elbowPos; handVector.z = -1 * handVector.z; transform.LookAt((transform.position + handVector.normalized), new Vector3(0, 1, 0)); }
public static bool KinectBack(KUInterface kin) { if (kin == null) return false; bool val = false; Vector3 rightAnkle = kin.GetJointPos(KinectWrapper.Joints.ANKLE_RIGHT); Vector3 leftAnkle = kin.GetJointPos(KinectWrapper.Joints.ANKLE_LEFT); Vector3 leftFoot = kin.GetJointPos(KinectWrapper.Joints.FOOT_LEFT); if (leftAnkle.z - rightAnkle.z < -Vector3.Distance(leftAnkle, leftFoot)) { val = true; } return val; }
// Update is called once per frame void Update() { if (!isInitialized) { return; } //Vector3 handVector = new Vector3(10, -150, 0); Vector3 leftHandPos = kin.GetJointPos(KinectWrapper.Joints.HAND_LEFT); Vector3 rightHandPos = kin.GetJointPos(KinectWrapper.Joints.HAND_RIGHT); float distance = Vector3.Distance(leftHandPos, rightHandPos) / 1000; //Vector3 shoulderCenterPos = kin.GetJointPos(KinectWrapper.Joints.SHOULDER_CENTER); //float handstoShoulderCenterDistance = Vector3.Distance(rightHandPos,shoulderCenterPos) / 1000; //Debug.Log(distance); if (distance < 5f) { Vector3 difference = rightHandPos - leftHandPos; Vector3 negZDifference = new Vector3(difference.x, difference.y, difference.z); negZDifference.z = -1 * negZDifference.z; Vector3 bothHandsPos = transform.position + negZDifference.normalized; Vector3 diffHandsPos = bothHandsPos - lastHandPos; transform.LookAt(lastHandPos + 0.3f * diffHandsPos, new Vector3(0, 1, 0)); lastHandPos = lastHandPos + 0.3f * diffHandsPos; Debug.Log(Vector3.Magnitude(diffHandsPos)); if (Vector3.Magnitude(diffHandsPos) > 0.45) { audio.PlayOneShot(SaberMove); } Vector3 centerHands = rightHandPos - 0.5f * difference; Vector3 shoulderCenterPos = kin.GetJointPos(KinectWrapper.Joints.SHOULDER_CENTER); centerHands.y = 0; shoulderCenterPos.y = 0; Vector3 shoulderToHands = centerHands - shoulderCenterPos; shoulderToHands.z = -shoulderToHands.z; transform.localPosition = 0.75f * shoulderToHands.normalized; //Debug.Log( transform.localPosition + " " + transform.position + " " + shoulderToHands.normalized ); } }
public static bool KinectHeadRightTilt(KUInterface kin) { if (kin == null) { return(false); } bool val = false; Vector3 neck = kin.GetJointPos(KinectWrapper.Joints.HEAD) - kin.GetJointPos(KinectWrapper.Joints.SHOULDER_CENTER); if (neck.normalized.x > 0.15) { val = true; } return(val); }
public static bool KinectRight(KUInterface kin) { if (kin == null) { return(false); } bool val = false; Vector3 rightWrist = kin.GetJointPos(KinectWrapper.Joints.WRIST_RIGHT); Vector3 rightElbow = kin.GetJointPos(KinectWrapper.Joints.ELBOW_RIGHT); if (Math.Abs(rightWrist.x - rightElbow.x) > Vector3.Distance(rightWrist, rightElbow) * 0.9) { val = true; } return(val); }
public static bool KinectLeft(KUInterface kin) { if (kin == null) { return(false); } bool val = false; Vector3 leftWrist = kin.GetJointPos(KinectWrapper.Joints.WRIST_LEFT); Vector3 leftElbow = kin.GetJointPos(KinectWrapper.Joints.ELBOW_LEFT); if (Math.Abs(leftWrist.x - leftElbow.x) > Vector3.Distance(leftWrist, leftElbow) * 0.9) { val = true; } return(val); }
// Update is called once per frame void Update() { if (!isInitialized) { return; } Vector3 pos1 = kin.GetJointPos(KinectWrapper.Joints.SHOULDER_LEFT); Vector3 pos2 = kin.GetJointPos(KinectWrapper.Joints.SHOULDER_RIGHT); Vector3 vec = pos2 - pos1; //vec.z = -1 * vec.z; vec.y = 0; vec = Vector3.Cross(Vector3.up, vec); vec.z = -1 * vec.z; //Debug.Log( vec.normalized + new Vector3(0, 1, 0)); transform.LookAt((transform.position + vec.normalized), new Vector3(0, 1, 0)); }
public static bool StartKinect(KUInterface kin) { if (kin == null) return false; bool val = false; if (kin.GetJointPos(KinectWrapper.Joints.HEAD).z > 30) val = true; return val; }
public static bool KinectBack(KUInterface kin) { if (kin == null) { return(false); } bool val = false; Vector3 rightAnkle = kin.GetJointPos(KinectWrapper.Joints.ANKLE_RIGHT); Vector3 leftAnkle = kin.GetJointPos(KinectWrapper.Joints.ANKLE_LEFT); Vector3 leftFoot = kin.GetJointPos(KinectWrapper.Joints.FOOT_LEFT); if (leftAnkle.z - rightAnkle.z < -Vector3.Distance(leftAnkle, leftFoot)) { val = true; } return(val); }
// Update is called once per frame void Update() { if (!isInitialized) { return; } Vector3 pos1 = kin.GetJointPos(KinectWrapper.Joints.SHOULDER_RIGHT); Vector3 pos2 = kin.GetJointPos(KinectWrapper.Joints.ELBOW_RIGHT); Vector3 vec = pos2 - pos1; vec.z = -1 * vec.z; vec = vec.normalized; Vector3 diffHandsPos = vec - lastVec; transform.LookAt((transform.position + lastVec + 0.3f * diffHandsPos), new Vector3(0, 1, 0)); lastVec = vec; }
// Update is called once per frame void Update() { if (!isInitialized) { return; } Vector3 elbowPos = kin.GetJointPos(KinectWrapper.Joints.ELBOW_RIGHT); Vector3 handPos = kin.GetJointPos(KinectWrapper.Joints.HAND_RIGHT); handVector = handPos - elbowPos; handVector.z = -1 * handVector.z; handVector = handVector.normalized; Vector3 diffHandsPos = handVector - lastHandVec; transform.LookAt((transform.position + lastHandVec + 0.3f * diffHandsPos), new Vector3(0, 1, 0)); lastHandVec = handVector; }
public static bool KinectLeft(KUInterface kin) { if (kin == null) { return(false); } bool val = false; Vector3 shoulderCenter = kin.GetJointPos(KinectWrapper.Joints.SHOULDER_CENTER); Vector3 hipCenter = kin.GetJointPos(KinectWrapper.Joints.HIP_CENTER); Vector3 upperBody = shoulderCenter - hipCenter; if (upperBody.normalized.x < -0.15) { val = true; } return(val); }
private void CameraRotate() { if (this.kin == null) { return; } Vector3 rotateSpine = kin.GetJointPos(KinectWrapper.Joints.SHOULDER_CENTER) - kin.GetJointPos(KinectWrapper.Joints.HIP_CENTER); Vector3 rotateShoulder = kin.GetJointPos(KinectWrapper.Joints.SHOULDER_LEFT) - kin.GetJointPos(KinectWrapper.Joints.SHOULDER_RIGHT); float xRot = (float)Math.Asin(rotateSpine.normalized.z); float yRot = (float)Math.Asin(rotateShoulder.normalized.z); Quaternion target = Quaternion.Euler(new Vector3(-(float)(180.0f / Math.PI * xRot), this.rotationAngle - (float)(180.0f / Math.PI * yRot), 0)); //if ((gRec.rightArm == GestureRecognizer.ARM_STATE.AS_NEG_Y && gRec.leftArm == GestureRecognizer.ARM_STATE.AS_NEG_Y)) Vector3 leftHip = kin.GetJointPos(KinectWrapper.Joints.HIP_LEFT); Vector3 leftHand = kin.GetJointPos(KinectWrapper.Joints.HAND_LEFT); Vector3 rightHip = kin.GetJointPos(KinectWrapper.Joints.HIP_RIGHT); Vector3 rightHand = kin.GetJointPos(KinectWrapper.Joints.HAND_RIGHT); if (leftHand.y < leftHip.y && rightHand.y < rightHip.y) { this.transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * cameraSmoothing); } //else //{ //this.transform.eulerAngles = new Vector3(0, reOrigin, 0); //} }
private void Update() { // return; if (!kin.isReady) { return; } if (!this._isInitialized) { InitializeKinect(); } if (sizeCount < MAXSIZE) { this._feet.Add(kin.GetJointPos(KinectWrapper.Joints.FOOT_LEFT) - kin.GetJointPos(KinectWrapper.Joints.FOOT_RIGHT)); sizeCount++; } //else //{ // this._feet.RemoveAt(0); // this._feet.Add(kin.GetJointPos(KinectWrapper.Joints.FOOT_LEFT) - kin.GetJointPos(KinectWrapper.Joints.FOOT_RIGHT)); //} }
// Update is called once per frame void Update() { //Choose center Vector3 center = Kinect.GetJointPos(KinectWrapper.Joints.SHOULDER_CENTER); //Release any non-fixated directions if (!fixateX) { center.x = 0; } if (!fixateY) { center.y = 0; } if (!fixateZ) { center.z = 0; } //Positions of from and to -objects. Notice we use the "ShoulderCenter" as our origo. Vector3 fromPos = Kinect.GetJointPos(FromJoint) - center; Vector3 toPos = Kinect.GetJointPos(ToJoint) - center; //Compute direction and length Vector3 direction = (toPos - fromPos); float armLength = direction.magnitude; //Place in the middle between the two points transform.localPosition = fromPos + direction * 0.5f; //Orient so that we point from one object to the other (Convert from local to world coordinates) transform.LookAt(transform.position + 0.5f * direction); //Scale so we reach the points transform.localScale = new Vector3(1, 1, armLength); }
public static bool StartKinect(KUInterface kin) { if (kin == null) { return(false); } bool val = false; if (kin.GetJointPos(KinectWrapper.Joints.HEAD).z > 30) { val = true; } return(val); }
public static bool KinectCrouch(KUInterface kin) { if (kin == null) { return(false); } bool val = false; Vector3 lowerLeftLeg = kin.GetJointPos(KinectWrapper.Joints.ANKLE_LEFT) - kin.GetJointPos(KinectWrapper.Joints.KNEE_LEFT); Vector3 upperLeftLeg = kin.GetJointPos(KinectWrapper.Joints.HIP_LEFT) - kin.GetJointPos(KinectWrapper.Joints.KNEE_LEFT); Vector3 lowerRightLeg = kin.GetJointPos(KinectWrapper.Joints.ANKLE_RIGHT) - kin.GetJointPos(KinectWrapper.Joints.KNEE_RIGHT); Vector3 upperRighLeg = kin.GetJointPos(KinectWrapper.Joints.HIP_RIGHT) - kin.GetJointPos(KinectWrapper.Joints.KNEE_RIGHT); if (Vector3.Angle(lowerLeftLeg, upperLeftLeg) < crouchAngle && Vector3.Angle(lowerRightLeg, upperRighLeg) < crouchAngle) { val = true; } return(val); }
public static bool KinectJump(KUInterface kin) { if (kin == null) { return(false); } bool val = false; Vector3 lowerLeftLeg = kin.GetJointPos(KinectWrapper.Joints.ANKLE_LEFT) - kin.GetJointPos(KinectWrapper.Joints.KNEE_LEFT); Vector3 lowerRightLeg = kin.GetJointPos(KinectWrapper.Joints.ANKLE_RIGHT) - kin.GetJointPos(KinectWrapper.Joints.KNEE_RIGHT); Vector3 upperRighLeg = kin.GetJointPos(KinectWrapper.Joints.HIP_RIGHT) - kin.GetJointPos(KinectWrapper.Joints.KNEE_RIGHT); if (Vector3.Angle(lowerRightLeg, upperRighLeg) < jumpKneeAngle && kin.GetJointPos(KinectWrapper.Joints.ANKLE_RIGHT).y - kin.GetJointPos(KinectWrapper.Joints.ANKLE_LEFT).y > Vector3.Magnitude(lowerLeftLeg) * 0.6) { val = true; } return(val); }
public static bool KinectFly(KUInterface kin) { if (kin == null) { return(false); } bool val = false; Vector3 leftLowerArm = kin.GetJointPos(KinectWrapper.Joints.WRIST_LEFT) - kin.GetJointPos(KinectWrapper.Joints.ELBOW_LEFT); Vector3 rightLowerArm = kin.GetJointPos(KinectWrapper.Joints.WRIST_RIGHT) - kin.GetJointPos(KinectWrapper.Joints.ELBOW_RIGHT); Vector3 leftHand = kin.GetJointPos(KinectWrapper.Joints.HAND_LEFT); Vector3 head = kin.GetJointPos(KinectWrapper.Joints.HEAD); if (leftLowerArm.normalized.y > 0.9 && rightLowerArm.normalized.y < -0.9 && leftHand.y > head.y) { val = true; } return(val); }
public static bool KinectFly(KUInterface kin) { if (kin == null) return false; bool val = false; Vector3 leftLowerArm = kin.GetJointPos(KinectWrapper.Joints.WRIST_LEFT) - kin.GetJointPos(KinectWrapper.Joints.ELBOW_LEFT); Vector3 rightLowerArm = kin.GetJointPos(KinectWrapper.Joints.WRIST_RIGHT) - kin.GetJointPos(KinectWrapper.Joints.ELBOW_RIGHT); Vector3 leftHand = kin.GetJointPos(KinectWrapper.Joints.HAND_LEFT); Vector3 head = kin.GetJointPos(KinectWrapper.Joints.HEAD); if (leftLowerArm.normalized.y > 0.9 && rightLowerArm.normalized.y < -0.9 && leftHand.y > head.y) val = true; return val; }
public static bool KinectHeadRightTilt(KUInterface kin) { if (kin == null) return false; bool val = false; Vector3 neck = kin.GetJointPos(KinectWrapper.Joints.HEAD) - kin.GetJointPos(KinectWrapper.Joints.SHOULDER_CENTER); if (neck.normalized.x > 0.15) val = true; return val; }
public static bool KinectJump(KUInterface kin) { if (kin == null) return false; bool val = false; Vector3 lowerLeftLeg = kin.GetJointPos(KinectWrapper.Joints.ANKLE_LEFT) - kin.GetJointPos(KinectWrapper.Joints.KNEE_LEFT); Vector3 lowerRightLeg = kin.GetJointPos(KinectWrapper.Joints.ANKLE_RIGHT) - kin.GetJointPos(KinectWrapper.Joints.KNEE_RIGHT); Vector3 upperRighLeg = kin.GetJointPos(KinectWrapper.Joints.HIP_RIGHT) - kin.GetJointPos(KinectWrapper.Joints.KNEE_RIGHT); if (Vector3.Angle(lowerRightLeg, upperRighLeg) < jumpKneeAngle && kin.GetJointPos(KinectWrapper.Joints.ANKLE_RIGHT).y - kin.GetJointPos(KinectWrapper.Joints.ANKLE_LEFT).y > Vector3.Magnitude(lowerLeftLeg) * 0.6) val = true; return val; }
// Update is called once per frame void Update() { if (!isInitialized) { return; } //kin.AddToGrammar("destroy"); //Debug.Log(kin.GetLastRecoResult()); // Check for lightning Vector3 rightHand = kin.GetJointPos(KinectWrapper.Joints.HAND_RIGHT); Vector3 rightShoulder = kin.GetJointPos(KinectWrapper.Joints.SHOULDER_RIGHT); Vector3 rightVec = rightHand - rightShoulder; rightVec.z = -1 * rightVec.z; if (rightVec.z / rightVec.magnitude > STATE_THRESHOLD) { rightArm = ARM_STATE.AS_POS_Z; } else if (rightVec.z / rightVec.magnitude < -STATE_THRESHOLD) { rightArm = ARM_STATE.AS_NEG_Z; } else if (rightVec.x / rightVec.magnitude < -STATE_THRESHOLD) { rightArm = ARM_STATE.AS_NEG_X; } else if (rightVec.x / rightVec.magnitude > STATE_THRESHOLD) { rightArm = ARM_STATE.AS_POS_X; } else if (rightVec.y / rightVec.magnitude < -STATE_THRESHOLD) { rightArm = ARM_STATE.AS_NEG_Y; } else if (rightVec.y / rightVec.magnitude > STATE_THRESHOLD) { rightArm = ARM_STATE.AS_POS_Y; } else { rightArm = ARM_STATE.AS_NONE; } Vector3 leftHand = kin.GetJointPos(KinectWrapper.Joints.HAND_LEFT); Vector3 leftShoulder = kin.GetJointPos(KinectWrapper.Joints.SHOULDER_LEFT); Vector3 leftVec = leftHand - leftShoulder; leftVec.z = -1 * leftVec.z; if (leftVec.z / leftVec.magnitude > STATE_THRESHOLD) { leftArm = ARM_STATE.AS_POS_Z; } else if (leftVec.z / leftVec.magnitude < -STATE_THRESHOLD) { leftArm = ARM_STATE.AS_NEG_Z; } else if (leftVec.x / leftVec.magnitude < -STATE_THRESHOLD) { leftArm = ARM_STATE.AS_NEG_X; } else if (leftVec.x / leftVec.magnitude > STATE_THRESHOLD) { leftArm = ARM_STATE.AS_POS_X; } else if (leftVec.y / leftVec.magnitude < -STATE_THRESHOLD) { leftArm = ARM_STATE.AS_NEG_Y; } else if (leftVec.y / leftVec.magnitude > STATE_THRESHOLD) { leftArm = ARM_STATE.AS_POS_Y; } else { leftArm = ARM_STATE.AS_NONE; } Vector3 rightfoot = kin.GetJointPos(KinectWrapper.Joints.FOOT_RIGHT); Vector3 leftfoot = kin.GetJointPos(KinectWrapper.Joints.FOOT_LEFT); float DisBetweenFoots = rightfoot.z - leftfoot.z; float DisToJump = Mathf.Abs(leftfoot.y) - Mathf.Abs(rightfoot.y); if (DisBetweenFoots > LEG_THRESHOLD) { rightLeg = LEG_STATE.AS_BACKWORD; } else if (DisBetweenFoots < -LEG_THRESHOLD) { rightLeg = LEG_STATE.AS_FORWORD;; } else { rightLeg = LEG_STATE.AS_NONE; } if (DisToJump > 90) { rightLegJump = JUMP_STATE.AS_JUMP; } else { rightLegJump = JUMP_STATE.AS_NONE; } Vector3 headVec = kin.GetJointPos(KinectWrapper.Joints.HEAD); Vector3 kneeVec = kin.GetJointPos(KinectWrapper.Joints.KNEE_LEFT); float DisBetweenHeadAndKnee = headVec.y - kneeVec.y; if (DisBetweenHeadAndKnee < DUCK_THRESHOLD) { headKneeLeft = DUCK_STATE.AS_DUCK; } else { headKneeLeft = DUCK_STATE.AS_NONE; } //Debug.Log(headKneeLeft + ": " + DisBetweenHeadAndKnee); }
// Update is called once per frame void Update() { if (!isInitialized) { return; } // Check for lightning Vector3 rightHand = kin.GetJointPos(KinectWrapper.Joints.HAND_RIGHT); Vector3 rightShoulder = kin.GetJointPos(KinectWrapper.Joints.SHOULDER_RIGHT); Vector3 rightVec = rightHand - rightShoulder; rightVec.z = -1 * rightVec.z; if (rightVec.z / rightVec.magnitude > STATE_THRESHOLD) { rightArm = ARM_STATE.AS_POS_Z; } else if (rightVec.z / rightVec.magnitude < -STATE_THRESHOLD) { rightArm = ARM_STATE.AS_NEG_Z; } else if (rightVec.x / rightVec.magnitude < -STATE_THRESHOLD) { rightArm = ARM_STATE.AS_NEG_X; } else if (rightVec.x / rightVec.magnitude > STATE_THRESHOLD) { rightArm = ARM_STATE.AS_POS_X; } else if (rightVec.y / rightVec.magnitude < -STATE_THRESHOLD) { rightArm = ARM_STATE.AS_NEG_Y; } else if (rightVec.y / rightVec.magnitude > STATE_THRESHOLD) { rightArm = ARM_STATE.AS_POS_Y; } else { rightArm = ARM_STATE.AS_NONE; } Vector3 leftHand = kin.GetJointPos(KinectWrapper.Joints.HAND_LEFT); Vector3 leftShoulder = kin.GetJointPos(KinectWrapper.Joints.SHOULDER_LEFT); Vector3 leftVec = leftHand - leftShoulder; leftVec.z = -1 * leftVec.z; if (leftVec.z / leftVec.magnitude > STATE_THRESHOLD) { leftArm = ARM_STATE.AS_POS_Z; } else if (leftVec.z / leftVec.magnitude < -STATE_THRESHOLD) { leftArm = ARM_STATE.AS_NEG_Z; } else if (leftVec.x / leftVec.magnitude < -STATE_THRESHOLD) { leftArm = ARM_STATE.AS_NEG_X; } else if (leftVec.x / leftVec.magnitude > STATE_THRESHOLD) { leftArm = ARM_STATE.AS_POS_X; } else if (leftVec.y / leftVec.magnitude < -STATE_THRESHOLD) { leftArm = ARM_STATE.AS_NEG_Y; } else if (leftVec.y / leftVec.magnitude > STATE_THRESHOLD) { leftArm = ARM_STATE.AS_POS_Y; } else { leftArm = ARM_STATE.AS_NONE; } //Debug.Log(leftVec + " " + leftArm + " " + rightArm + " " + rightVec); }
public static bool KinectCrouch(KUInterface kin) { if (kin == null) return false; bool val = false; Vector3 lowerLeftLeg = kin.GetJointPos(KinectWrapper.Joints.ANKLE_LEFT) - kin.GetJointPos(KinectWrapper.Joints.KNEE_LEFT); Vector3 upperLeftLeg = kin.GetJointPos(KinectWrapper.Joints.HIP_LEFT) - kin.GetJointPos(KinectWrapper.Joints.KNEE_LEFT); Vector3 lowerRightLeg = kin.GetJointPos(KinectWrapper.Joints.ANKLE_RIGHT) - kin.GetJointPos(KinectWrapper.Joints.KNEE_RIGHT); Vector3 upperRighLeg = kin.GetJointPos(KinectWrapper.Joints.HIP_RIGHT) - kin.GetJointPos(KinectWrapper.Joints.KNEE_RIGHT); if (Vector3.Angle(lowerLeftLeg, upperLeftLeg) < crouchAngle && Vector3.Angle(lowerRightLeg, upperRighLeg) < crouchAngle) val = true; return val; }