// Update is called once per frame void Update() { // get kinect status from bodysourceview script bool kinectActive = BodySourceView.kinectActive; // based on kinect status... if (kinectActive) { // get hand position Vector3 hand = BodySourceView.hand; inputMove = hand; // get hand state handState = BodySourceView.handState; // based on gesture, toggle rotation speed if (handState == Kinect.HandState.Closed || handState == Kinect.HandState.Lasso) target = speed; else target = 0f; } else { // gets mouse position and converts to world units Vector2 mousePos = Input.mousePosition; Vector3 mouseWorldPos = Camera.main.ScreenToWorldPoint(new Vector3(mousePos.x, mousePos.y, camZ)); // get mouse position inputMove = mouseWorldPos; // based on mouse press, toggle rotation speed if (Input.GetButtonDown("Fire1")) target = speed; else if (Input.GetButtonUp("Fire1")) { target = 0f; } } // easing formula for rotation speed transition float targetAngle = target; float t = targetAngle - angle; // Mathf.Abs is absolute value // https://en.wikipedia.org/wiki/Absolute_value if (Mathf.Abs(t) > 0) { angle += t * easing; } // rotate object towards position tr.RotateAround(tr.position, new Vector3(inputMove.y * direction, -inputMove.x * direction, 0.0f), angle); }
private int CheckRightHandState(Kinect.HandState handState2) { int result = 0; switch (handState2) { //Normal case Kinect.HandState.Closed: rightHandActive = false; result = 0; break; //Shoot case Kinect.HandState.Open: signalStart = true; rightHandActive = false; result = 0; break; //Flip case Kinect.HandState.Lasso: rightHandActive = true; result = 1; break; default: result = 0; break; } return(result); }
private int CheckLeftHandState(Kinect.HandState handState1) { int result = 0; switch (handState1) { //Normal case Kinect.HandState.Closed: leftHandActive = false; result = 0; break; //Shoot case Kinect.HandState.Open: leftHandActive = false; result = 3; break; //Flip case Kinect.HandState.Lasso: leftHandActive = true; result = 1; break; default: result = 0; break; } return(result); }
public void update(float timeDelta, Kinect.HandState nextState) { bool nextNextIsClosed; switch (nextState) { case Kinect.HandState.Open: nextNextIsClosed = false; break; case Kinect.HandState.Closed: nextNextIsClosed = true; break; default: return; } if (nextIsClosed == nextNextIsClosed) { heldTime += timeDelta; if (heldTime > threshold) { isClosed = nextIsClosed; } } else { heldTime = 0; nextIsClosed = nextNextIsClosed; } }
private int CheckHandState(Kinect.HandState handState) { int result = 0; switch (handState) { //Normal case Kinect.HandState.Closed: result = 0; break; //Shoot case Kinect.HandState.Open: result = 0; break; //Flip case Kinect.HandState.Lasso: result = 1; break; default: result = 0; break; } return(result); }
/// <summary> /// Refreshes the current body updating /// the position of each of the limbs /// </summary> /// <param name="body">The Body to Update</param> /// <param name="bodyObject">The Body object holding all the pieces</param> private void RefreshBodyObject(Kinect.Body body, GameObject bodyObject) { rightHandState = body.HandRightState; leftHandState = body.HandLeftState; if (rightHandState == Kinect.HandState.Closed && body.HandRightConfidence == Kinect.TrackingConfidence.High) { if (leftHandState == Kinect.HandState.Closed && body.HandLeftConfidence == Kinect.TrackingConfidence.High) { if (!handCheckCooldown) { StartCoroutine(ReturnToMenu()); } } } }
private void RefreshHandState(Kinect.Body body) { rightHandState = body.HandRightState; leftHandState = body.HandLeftState; if (handCursor != null) { currentLetter = FindCurrentLetter(); } if (currentLetter != null) { if (currentLetter.transform.Find("Cube").GetComponent <MeshRenderer>().material != hoverLetterMaterial) { currentLetter.transform.Find("Cube").GetComponent <MeshRenderer>().material = hoverLetterMaterial; } } if (rightHandState == Kinect.HandState.Closed && body.HandRightConfidence == Kinect.TrackingConfidence.High) { if (currentLetter != null && !letterEnterCooldown) { if (currentLetter.name == "Submit") { gm._PlayerName.text = playerName.text; SaveLastUserName(playerName.text); camAnim.SetTrigger("nametomenu"); return; } StartCoroutine(EnterLetter(currentLetter.transform.Find("Cube").GetComponent <MeshRenderer>())); playerName.text += currentLetter.name.ToString(); } } else if (leftHandState == Kinect.HandState.Closed && body.HandLeftConfidence == Kinect.TrackingConfidence.High) { if (!letterEnterCooldown) { StartCoroutine(DeleteLetter()); } } }
private static Color GetColorForState(Kinect.HandState state) { switch (state) { case Kinect.HandState.Open: return(Color.green); case Kinect.HandState.Lasso: return(Color.yellow); case Kinect.HandState.NotTracked: return(Color.black); case Kinect.HandState.Closed: return(Color.blue); default: return(Color.red); } }
void CheckRightHandState(Kinect.HandState handState) { switch (handState) { //Normal case Kinect.HandState.Closed: break; //Shoot case Kinect.HandState.Open: break; //Flip case Kinect.HandState.Lasso: rightHandActive = true; Debug.LogError("Right"); break; } }
void CheckLeftHandState(Kinect.HandState handState) { switch (handState) { //Normal case Kinect.HandState.Closed: break; //Shoot case Kinect.HandState.Open: leftHandActive = false; break; //Flip case Kinect.HandState.Lasso: leftHandActive = true; Debug.LogError("left"); break; } }
void Update() { Kinect.Body[] data = mBodySourceManager.GetData(); //check to see if kenect is returning data if (data == null) { return; } //all tracking ids that the kinect can see List <ulong> trackedIds = new List <ulong>(); foreach (var body in data) { //check to see if data isnt a body if (body == null) { continue; } //if body is currently being tracked add it to trackedIds list if (body.IsTracked) { trackedIds.Add(body.TrackingId); } } //the keys of the bodies dictionary List <ulong> knownIds = new List <ulong>(mBodies.Keys); foreach (ulong trackingId in knownIds) { //if trackedIds list does not contain the tracking id from know ids delete from scene if (!trackedIds.Contains(trackingId)) { Destroy(mBodies[trackingId]); mBodies.Remove(trackingId); //reset bool tests resetTest(); } } int counter = 0; //create bodies foreach (var body in data) { //if no body, skip if (body == null) { continue; } //body.TrackingId == trackedIds[0] ie/ if the bodys tracking ID is the first body that was tracked, creater and update it if (body.IsTracked && body.TrackingId == trackedIds[0]) { chosenBody = body; //if body doesnt exist, create it if (!mBodies.ContainsKey(body.TrackingId)) { mBodies[body.TrackingId] = CreateBodyObject(body.TrackingId); } UpdateBodyObject(body, mBodies[body.TrackingId]); //update position counter++; if (collisionManager.CheckHandsShowing()) { //MAKE rightState be grabbed from BodySourceView as body is not defined here. Kinect.HandState rightState = chosenBody.HandRightState; if (rightState == Kinect.HandState.Closed) { rightCloseFlag = true; GameObject.Find("HandRight").GetComponent <SpriteRenderer>().sprite = mClosedRight; //drop.DragOrPickUp(); } if (rightState == Kinect.HandState.Open) { rightCloseFlag = false; GameObject.Find("HandRight").GetComponent <SpriteRenderer>().sprite = mOpenRight; //drop.DropItem(); } //left hand Kinect.HandState leftState = chosenBody.HandLeftState; if (leftState == Kinect.HandState.Closed) { leftCloseFlag = true; GameObject.Find("HandLeft").GetComponent <SpriteRenderer>().sprite = mClosedLeft; } if (leftState == Kinect.HandState.Open) { leftCloseFlag = false; GameObject.Find("HandLeft").GetComponent <SpriteRenderer>().sprite = mOpenLeft; } } } } }
private void RefreshBodyObject(Kinect.Body body, GameObject bodyObject) { for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++) { Kinect.Joint sourceJoint = body.Joints[jt]; Kinect.Joint? targetJoint = null; if (_BoneMap.ContainsKey(jt)) { targetJoint = body.Joints[_BoneMap[jt]]; } Transform jointObj = bodyObject.transform.FindChild(jt.ToString()); jointObj.localPosition = GetVector3FromJoint(sourceJoint); // reference left hand position if (jt == joint) { hand = jointObj.position; handState = body.HandLeftState; } } }
// Update is called once per frame void Update () { if (bodySourceManager == null) { return; } bodyManager = bodySourceManager.GetComponent<BodySourceManager>(); if(bodyManager == null) { return; } // get data from kinect Kinect.Body[] data = bodyManager.GetData(); if(data == null) { return; } // get list of currently tracked bodies Kinect.Body potentialNewTrackedBody = null; bool stillTrackingPreviousBody = false; // check if the previously tracked body is still there foreach(Kinect.Body body in data) { if(body == null) { continue; } if (body.IsTracked) { // no body being track, get the first body found if (currentTrackedObject == null) { currentTrackedObject = body; } // the previous body may already disappearred, save the first body found just in case if (potentialNewTrackedBody == null) { potentialNewTrackedBody = body; } // still tracking previous body if (body.TrackingId == currentTrackedObject.TrackingId) { stillTrackingPreviousBody = true; break; } } } // // the previously tracked body have disappear, get the new trackid found if(!stillTrackingPreviousBody) { currentTrackedObject = potentialNewTrackedBody; } if(currentTrackedObject == null) { return; } ////////////////////////////////////////// // Everything after this is getting data of the body and manipulate the world ScoreManager.ready = true; // if holding something and left hand is closed, move the object according to hand movement if (currentTrackedObject.HandLeftState == Kinect.HandState.Closed && grabbed) { Debug.Log("Holding Object"); DragObject(); } // if not holding anything and left hand is closed, attempt to grab the object in the desired direction else if (!grabbed && currentTrackedObject.HandLeftState == Kinect.HandState.Closed) { Debug.Log("Trying to Grab Object"); GrabObject(); } // release hand while holding something will initiate throw else if (currentTrackedObject.HandLeftState == Kinect.HandState.Open && grabbed) { Debug.Log("Throwing Object"); ThrowObject(); } // shoot wave bullet if two hand open else if (currentTrackedObject.HandLeftState == Kinect.HandState.Open && currentTrackedObject.HandRightState == Kinect.HandState.Open) { Debug.Log("Wave Attack"); UpdateAimTarget(); GetComponent<Shooting>().Shoot(waveBullet, aimTarget.transform.position, aimTarget.transform.rotation); } // shoot wave bullet if left hand open and not holding anything else if (currentTrackedObject.HandLeftState == Kinect.HandState.Open) { Debug.Log("Bullet Attack"); UpdateAimTarget(); GetComponent<Shooting>().Shoot(lightBullet, aimTarget.transform.position, aimTarget.transform.rotation); } // other action should reset holding state else { //currentlyGrabbedObj = null; Debug.Log("Unknow Action"); grabbed = false; } //Debug.Log(currentTrackedObject.HandRightState); //Debug.Log(previousHandState); previousHandState = currentTrackedObject.HandRightState; SaberControl(); }
/// <summary> /// Refreshes the current body updating /// the position of each of the limbs /// </summary> /// <param name="body">The Body to Update</param> /// <param name="bodyObject">The Body object holding all the pieces</param> private void UpdateHandInput(Kinect.Body body, GameObject bodyObject) { if (!initialized) { handCursor = Instantiate(handCursorObj); playerSpawnPosition.localEulerAngles = new Vector3(playerSpawnPosition.localEulerAngles.x - 90, 0, 0); initialized = true; } Kinect.Joint rh = body.Joints[Kinect.JointType.HandRight]; Transform currentJointObj = bodyObject.transform.Find(Kinect.JointType.HandRight.ToString()); /// Find the Vector3 Position of this joint Vector3 currentJointPosition = BodySourceManager.GetVector3FromJoint(rh); currentJointObj.localPosition = new Vector3(currentJointPosition.x * -1, currentJointPosition.y, currentJointPosition.z); handState = body.HandRightState; Vector3 handPos = (currentJointObj.position - perspectiveObj.position) * 0.5f + perspectiveObj.position; handCursor.transform.position = new Vector3(handPos.x, 2, handPos.z); Vector3 dir = new Vector3(perspectiveObj.position.x - currentJointObj.position.x, perspectiveObj.position.y - currentJointObj.position.y, perspectiveObj.position.z - currentJointObj.position.z); Debug.DrawRay(currentJointObj.position, dir, Color.cyan, 2); int menuMask = 1 << 13; RaycastHit hit; if (Physics.Raycast(currentJointObj.position, dir, out hit, Mathf.Infinity, menuMask)) { Vector3 selected = new Vector3(1.1f, 1.1f, 1); if (hit.collider.tag == "PlayButton") { if (!playSelected) { hit.collider.transform.localScale = selected; playButton = hit.collider.transform.gameObject; if (highScoresButton != null) { highScoresButton.transform.localScale = Vector3.one; } if (enterNameButton != null) { enterNameButton.transform.localScale = Vector3.one; } SoundManager.instance.PlaySound("menu_hover"); playSelected = true; highscoreSelected = false; enterNameSelected = false; } } else if (hit.collider.tag == "HighButton") { if (!highscoreSelected) { hit.collider.transform.localScale = selected; highScoresButton = hit.collider.transform.gameObject; if (playButton != null) { playButton.transform.localScale = Vector3.one; } if (enterNameButton != null) { enterNameButton.transform.localScale = Vector3.one; } SoundManager.instance.PlaySound("menu_hover"); highscoreSelected = true; playSelected = false; enterNameSelected = false; } } else if (hit.collider.tag == "NameButton") { if (!enterNameSelected) { hit.collider.transform.localScale = selected; enterNameButton = hit.collider.transform.gameObject; if (highScoresButton != null) { highScoresButton.transform.localScale = Vector3.one; } if (playButton != null) { playButton.transform.localScale = Vector3.one; } SoundManager.instance.PlaySound("menu_hover"); enterNameSelected = true; playSelected = false; highscoreSelected = false; } } if (handState == Kinect.HandState.Closed && body.HandRightConfidence == Kinect.TrackingConfidence.High && !selectionMade) { if (hit.collider.tag == "PlayButton") { camAnim.SetTrigger("menutogame"); selectionMade = true; } else if (hit.collider.tag == "HighButton") { camAnim.SetTrigger("menutohigh"); selectionMade = true; } else if (hit.collider.tag == "NameButton") { camAnim.SetTrigger("menutoname"); selectionMade = true; } } } }
// Update is called once per frame void Update() { if (myCam == null) { myCam = Camera.main; } if (_sensor != null) { IsAvailable = _sensor.IsAvailable; } if (_bodyFrameReader != null) { var frame = _bodyFrameReader.AcquireLatestFrame(); if (frame != null) { frame.GetAndRefreshBodyData(_bodies); if (bodyTracked) { if (_bodies[bodyIndex].IsTracked) { body = _bodies[bodyIndex]; } else { bodyTracked = false; } } if (setupBody || !bodyTracked) { closestDistance = 0; for (int i = 0; i < _bodies.Length; ++i) { float thisDistance = _bodies[i].Joints[JointType.Head].Position.Z; if (closestDistance == 0 || thisDistance != 0 && thisDistance <= closestDistance) { closestDistance = thisDistance; bodyIndex = i; } } if (_bodies[bodyIndex].IsTracked) { bodyTracked = true; } } if (body != null && bodyTracked && body.IsTracked) { IsAvailable = true; if (PlayerHand.Equals("HandRight")) { HandState = body.HandRightState; } else { HandState = body.HandLeftState; } HandClosed = (HandState == HandState.Closed); HandOpen = (HandState == HandState.Open); CameraSpacePoint newPos = body.Joints[MainHand].Position; newPos.X = newPos.X * sensitivityX; newPos.Y = newPos.Y * sensitivityY; MoveHand(newPos); if (!HandAwaken) { ShakeHand(); } if (checkWave) { WaveSegments(); } } frame.Dispose(); frame = null; } //foreach (var body in _bodies.Where(b => b.IsTracked)) // { // //if (body.HandRightConfidence == TrackingConfidence.High && body.HandRightState == HandState.Lasso) // } } }