public List <Vector3>[] GetHandPositions() { int arrayLength = target.GetLeapHand().Fingers.Count + 1; List <Vector3>[] indexedArray = new List <Vector3> [arrayLength]; int i = 0; //Fingers foreach (var finger in target.GetLeapHand().Fingers) { List <Vector3> positions = new List <Vector3>(); for (int j = 0; j < 4; j++) { int key = getFingerJointIndex((int)finger.Type, j); Vector3 position = finger.Bone((Bone.BoneType)j).NextJoint.ToVector3(); positions.Add(position); } indexedArray[i++] = positions; } //Palm List <Vector3> palmPositions = new List <Vector3>(); Vector3 palmPosition = target.GetLeapHand().PalmPosition.ToVector3(); palmPositions.Add(palmPosition); indexedArray[i] = palmPositions; return(indexedArray); }
// Update is called once per frame void Update() { if (attachedObject != null) { Debug.Log(hand.GetLeapHand().PalmPosition.ToVector3()); attachedObject.transform.position = hand.GetLeapHand().PalmPosition.ToVector3() + positionOffset; attachedObject.transform.rotation = hand.GetLeapHand().Rotation.ToQuaternion() * rotationOffset; } }
// Update is called once per frame void Update() { if (!isThrown) //check whether it is the throw action or drag action { if (isDragged) { CapsuleHand capsuleHand = m_Hand.GetComponentInChildren <CapsuleHand> (); if (capsuleHand) { m_HandModel = capsuleHand.GetLeapHand(); transform.position += (m_HandModel.PalmPosition.ToVector3() - initPalmPos); initPalmPos = m_HandModel.PalmPosition.ToVector3(); } } } else { if (collided) //if the time to wait to reset the ball { m_TimeAfterCollision += Time.deltaTime; if (m_TimeAfterCollision >= m_TimeToWait) { m_MiniGameController.ResetBall(); } } } }
public void ReleaseBall() { if (!isThrown) //get the throw distance from the initial hand position and the position after grabbing { CapsuleHand capsuleHand = m_Hand.GetComponentInChildren <CapsuleHand> (); if (capsuleHand) { m_HandModel = capsuleHand.GetLeapHand(); endPos = m_HandModel.PalmPosition.ToVector3(); Rigidbody rb = GetComponent <Rigidbody> (); Vector3 displacement = initPos - endPos; Vector3 throwDirection = displacement.normalized; //This is very finally the throw happenes if (displacement.sqrMagnitude > minDispThrow) // give the thrown ball falling speed with gravity { isThrown = true; rb.velocity = throwDirection * displacement.magnitude * m_SpeedScale; rb.useGravity = true; } else { transform.position = ballInitPos; } } isDragged = false; } }
public void GrabBall(GameObject hand) { m_Hand = hand; if (!isThrown) //get the hand initial position if it is not the throw action { CapsuleHand capsuleHand = m_Hand.GetComponentInChildren <CapsuleHand> (); m_HandModel = capsuleHand.GetLeapHand(); initPos = m_HandModel.PalmPosition.ToVector3(); initPalmPos = m_HandModel.PalmPosition.ToVector3(); isDragged = true; } }
void Update() { if (capsuleHand && gameObject.activeSelf) { if (hand == null) { hand = capsuleHand.GetLeapHand(); } else { //menuPlane.transform.position = hand.PalmPosition.ToVector3(); menuPlane.transform.SetPositionAndRotation(hand.PalmPosition.ToVector3() + menuPlanePositionInPalm, hand.Rotation.ToQuaternion()); } } }
void Update() { Transform camera = Camera.main.transform; Ray ray = new Ray(camera.position, Vector3.Normalize(camera.rotation * Vector3.forward)); RaycastHit hit; mount_panel.text = setMountPanel(); if (cubeCanvas != null && geometryTargetObj != null) { cubeCanvas.transform.rotation = Quaternion.identity; cubeCanvas.transform.position = geometryTargetObj.transform.position; cubeCanvas.transform.Translate(0, 0, -0.05f); } if (left_hand.isActiveAndEnabled && right_hand.isActiveAndEnabled) { if (left_hand.GetLeapHand().GrabStrength > 0.99 && right_hand.GetLeapHand().GrabStrength > 0.99) { grabMode = GrabMode.Both; } else if (left_hand.GetLeapHand().GrabStrength > 0.99) { grabMode = GrabMode.LeftOnly; } else if (right_hand.GetLeapHand().GrabStrength > 0.99) { grabMode = GrabMode.RightOnly; } else { grabMode = GrabMode.Empty; } } switch (grabMode) { case GrabMode.Empty: if (Physics.Raycast(ray, out hit)) // Hit { if (hitObject == hit.collider.gameObject) // 같은 블럭 { if (grabMode == GrabMode.Empty) { hitObject.transform.localScale = new Vector3(1f, 1f, 1f); } if (!cubeAlphaObj.activeSelf) { countdown = timeToSelect; cubeAlphaObj.SetActive(true); } else { countdown -= Time.deltaTime; if (countdown < 0.0f) { cubeCanvas.SetActive(true); countdown = timeToSelect; } } } else if (hitObject != null) // 다른 블럭 { if (blockToggle.isOn) { //nothing } else { cubeAlphaObj.SetActive(false); cubeCanvas.SetActive(false); cubeAlphaObj = null; cubeCanvas = null; blockToggle = null; hitObject = hit.collider.gameObject; cubeAlphaObj = hitObject.transform.GetChild(6).gameObject; cubeCanvas = hitObject.transform.GetChild(7).gameObject; blockToggle = cubeCanvas.transform.GetChild(0).GetChild(0).GetComponent <Toggle>(); } } else // null 블럭 { hitObject = hit.collider.gameObject; cubeAlphaObj = hitObject.transform.GetChild(6).gameObject; cubeCanvas = hitObject.transform.GetChild(7).gameObject; blockToggle = cubeCanvas.transform.GetChild(0).GetChild(0).GetComponent <Toggle>(); } } else // no Hit { hitObject.transform.localScale = new Vector3(1f, 1f, 1f); if (hitObject != null) // previous hit block exist { if (blockToggle.isOn) { //nothing } else { //hitObject = null, effect = false&null hitObject = null; cubeAlphaObj.SetActive(false); cubeCanvas.SetActive(false); cubeAlphaObj = null; cubeCanvas = null; } } else { } } break; case GrabMode.LeftOnly: Debug.Log("left"); if (Vector3.Distance(hitObject.gameObject.transform.position, UnityVectorExtension.ToVector3(left_hand.GetLeapHand().Fingers[0].TipPosition)) < 0.15f && !blockToggle.isOn) { hitObject.transform.localScale = new Vector3(0.8f, 0.8f, 0.8f); Vector3 newPosition = UnityVectorExtension.ToVector3(left_hand.GetLeapHand().Fingers[0].TipPosition); hitObject.transform.position = new Vector3(truncate(newPosition.x), truncate(newPosition.y), truncate(newPosition.z)); } break; case GrabMode.RightOnly: Debug.Log("right"); if (Vector3.Distance(hitObject.gameObject.transform.position, UnityVectorExtension.ToVector3(right_hand.GetLeapHand().Fingers[0].TipPosition)) < 0.15f && !blockToggle.isOn) { hitObject.transform.localScale = new Vector3(0.8f, 0.8f, 0.8f); Vector3 newPosition = UnityVectorExtension.ToVector3(right_hand.GetLeapHand().Fingers[0].TipPosition); hitObject.transform.position = new Vector3(truncate(newPosition.x), truncate(newPosition.y), truncate(newPosition.z)); } break; case GrabMode.Both: if (Vector3.Dot(UnityVectorExtension.ToVector3(left_hand.GetLeapHand().PalmNormal), Vector3.up) > 0 && Vector3.Dot(UnityVectorExtension.ToVector3(right_hand.GetLeapHand().PalmNormal), Vector3.up) > 0) { block_panel.SetActive(true); } //float palm_distance = Vector3.Distance(UnityVectorExtension.ToVector3(left_hand.GetLeapHand().PalmPosition), UnityVectorExtension.ToVector3(right_hand.GetLeapHand().PalmPosition)); //hitObject.transform.localScale = new Vector3(truncate(palm_distance), truncate(palm_distance), truncate(palm_distance)); break; } }
private void Awake() { //missiles = new List<GameObject>(); rb = GetComponent <Rigidbody>(); hand = capsule.GetLeapHand(); }
// Update is called once per frame void Update() { if (handLeft == null) { leftHandModel = GameObject.FindGameObjectWithTag("LeftHandInteraction"); if (leftHandModel != null) { if ((capsuleHandLeft = leftHandModel.GetComponent <CapsuleHand>()) != null) { handLeft = capsuleHandLeft.GetLeapHand(); if (handLeft.IsRight) { handRight = handLeft; handLeft = null; } if (handRight == handLeft) { handLeft = null; } } } } if (handRight == null) { rightHandModel = GameObject.FindGameObjectWithTag("RightHandInteraction"); if (rightHandModel != null) { if ((capsuleHandRight = rightHandModel.GetComponent <CapsuleHand>()) != null) { handRight = capsuleHandRight.GetLeapHand(); if (handRight.IsLeft) { handLeft = handRight; handRight = null; } if (handRight == handLeft) { handRight = null; } } } } // movement and rotation if (handLeft != null && handRight != null) { CheckMovementRotation(); DoMovementRotation(); } // allow game space extension by right hand fist gesture if (allowGameSpaceExtension && GameObject.FindGameObjectWithTag("RightHandInteraction") == null) { isFistThumbUp = false; handRight = null; } else if (gameSpaceExtension != null && handRight != null) { isFistThumbUp = CheckFistThumbUp(handRight); } if (gameSpaceExtension != null) { Debug.Log("LeapMovement: isFist = " + isFistThumbUp + " allowGameSpaceExtension=" + allowGameSpaceExtension); if (isFistThumbUp && !allowGameSpaceExtension) { gameSpaceExtension.SetAllowGameSpaceExtension(true); allowGameSpaceExtension = true; } if (!isFistThumbUp && allowGameSpaceExtension) { gameSpaceExtension.SetAllowGameSpaceExtension(false); allowGameSpaceExtension = false; } } }
// It controls ALL the movements. The trigger is actionated by the Master for each pressed trigger done by the user // To every task completly, it has to start in point Z (InitialStatus Object). The process as follow // Stage starts at 0. // If hand in initialstatus and trigger. Initialstatus object dissapears, the object to pick shows up. Stage = 0 // When object picked, Second trigger shadow for next movement appears. Stage = 1 // when object realeased, then trigger, shadows dissapear for pioint zero and appears in starts position. Stage = 2 // When object in initial position and trigger objects dissapears and user move hand back to point zero. Stage = 3 // When hand in initial position and trigger, movements ends. Stage = -1 public void reGoal() { if (conditionsToProceed(stage)) { if (stage == -1) { initialPoint.SetActive(true); stage = 0; } else if (stage == 0) // Hand in point Zero. Pre. No object to pick. Pos Object showed up initial position. { int nGoal; while ((nGoal = Random.Range(0, 2)) == goal) { ; } goal = nGoal; //goal = 0; this.propContr = props[goal].GetComponent <PropController>(); //TODO trackers. How mannage 3 trackers. This part should dissapear since all trackers should be in the scene so we should not need to look for the tracker everytime /* GameObject tracker1 = GameObject.Find("Tracker1"); * if(tracker1 != null) * { * HydraTracker hTracker = tracker1.GetComponent<HydraTracker>(); * if(hTracker != null) * { * //hTracker.attach(propContr); * hTracker.PositionReference = this.propContr; * if (masterController.currentStage != MasterController.EXP_STAGE.PROP_MATCHING_PLUS_RETARGETING) * { * hTracker.attach(); * } * * } * }*/ GameObject PositionReference = propContr.positionReference; targetedController.starShifting(PositionReference.transform.position, capsuleHand.GetLeapHand().PalmPosition.ToVector3()); //Capsulehand has a simplified methos for giving the hand. does not work here? if (masterController.currentStage == MasterController.EXP_STAGE.PROP_MATCHING_PLUS_RETARGETING || masterController.currentStage == MasterController.EXP_STAGE.PROP_NOT_MATCHING_PLUS_RETARGETING) { props[goal].transform.position = targetedController.retargetedPosition.transform.position; } else { props[goal].transform.position = PositionReference.transform.position; } StartCoroutine(pairTracker(1, this.propContr)); persistanceManager.trackedObject = this.propContr; //props[goal].SetActive(true); persistanceManager.startDocking(stage); initialPoint.SetActive(false); stage = 1; } else if (stage == 1) // Hand in object Maybe should check the coliders are overlapped. Pre No shadow in scene. Pos shadow in point Z { persistanceManager.saveDocking(); propContr.dockProp.SetActive(true); persistanceManager.startDocking(stage); stage = 2; } else if (stage == 2) // Object moved in desired position i point Z. Pre Shadow in point Z. Pos shadow in initial position { persistanceManager.saveDocking(); propContr.movePropDock(false); persistanceManager.startDocking(stage); stage = 3; } else if (stage == 3) // Object moved to initial position in desired orientation. Pre. Shadow on, initial status off. Pos Shadow off, initial position on { persistanceManager.saveDocking(); propContr.dockProp.SetActive(false); initialPoint.SetActive(true); persistanceManager.startDocking(stage); /* * GameObject tracker1 = GameObject.Find("Tracker1"); * if (tracker1 != null) * { * HydraTracker hTracker = tracker1.GetComponent<HydraTracker>(); * if (hTracker != null) * { * //hTracker.attach(propContr); * hTracker.PositionReference = this.propContr; * if (masterController.currentStage != MasterController.EXP_STAGE.PROP_MATCHING_PLUS_RETARGETING) * { * hTracker.detach(); * } * * } * } */ capsuleHand.canDraw = true; propContr.hydraTracker.detach(); propContr.gameObject.SetActive(false); stage = 4; } else if (stage == 4) // Hand moves to point z { persistanceManager.saveDocking(); persistanceManager.startDocking(stage); initialPoint.SetActive(false); capsuleHand.canDraw = true; stage = -1; propContr.hydraTracker.detach(); if (!masterController.isDemo) { if (propContr.angleNumber == 2) { notificationsMannager.registerGoal(); } } } notificationsMannager.lightStepNotification(stage + 2); } }
// Update is called once per frame void Update() { leftScore = Mathf.Max(0, leftScore - .016f); rightScore = Mathf.Max(0, rightScore - .032f); // left right should be no more than 30 deg // Check if both hands are tracked Locked = leftHand.IsTracked && rightHand.IsTracked; // Up/down should be no more than 15 deg // Check up down angle if (leftHand.Handedness == Chirality.Left && leftHand.IsTracked && leftHand.GetLeapHand() != null) { //leftHand; Leap.Hand hand = leftHand.GetLeapHand(); var arm = hand.Arm; Vector3 right = arm.Basis.xBasis.ToVector3() * arm.Width * 0.7f * 0.5f; Vector3 wrist = arm.WristPosition.ToVector3(); Vector3 elbow = arm.ElbowPosition.ToVector3(); float armLength = Vector3.Distance(wrist, elbow); wrist -= arm.Direction.ToVector3() * armLength * 0.05f; Vector3 thumbBase = leftHand.getThumbBase(); Vector3 mockThumbBase = leftHand.getMockThumbBase(); Vector3 leftArmFrontRight = wrist + right; Vector3 leftArmFrontLeft = wrist - right; leftLeft = Vector3.Distance(leftArmFrontRight, mockThumbBase); leftRight = Vector3.Distance(leftArmFrontLeft, thumbBase); leftOrientation = Mathf.Rad2Deg * (hand.Direction.AngleTo(arm.Direction)); // Get up/down Vector3 leftPalmNorm = -hand.PalmNormal.ToVector3(); Vector3 leftArm = hand.Arm.Direction.ToVector3(); angleL = Vector3.Angle(leftArm, leftPalmNorm); } if (rightHand.Handedness == Chirality.Right && rightHand.IsTracked && rightHand.GetLeapHand() != null) { //leftHand; Leap.Hand hand = rightHand.GetLeapHand(); var arm = hand.Arm; Vector3 right = arm.Basis.xBasis.ToVector3() * arm.Width * 0.7f * 0.5f; Vector3 wrist = arm.WristPosition.ToVector3(); Vector3 elbow = arm.ElbowPosition.ToVector3(); float armLength = Vector3.Distance(wrist, elbow); wrist -= arm.Direction.ToVector3() * armLength * 0.05f; Vector3 thumbBase = rightHand.getThumbBase(); Vector3 mockThumbBase = rightHand.getMockThumbBase(); Vector3 rightArmFrontRight = wrist + right; Vector3 rightArmFrontLeft = wrist - right; rightLeft = Vector3.Distance(rightArmFrontRight, mockThumbBase); rightRight = Vector3.Distance(rightArmFrontLeft, thumbBase); // Get up/down Vector3 leftPalmNorm = -hand.PalmNormal.ToVector3(); Vector3 leftArm = hand.Arm.Direction.ToVector3(); angleR = Vector3.Angle(leftArm, leftPalmNorm); rightOrientation = Mathf.Rad2Deg * (hand.Direction.AngleTo(arm.Direction)); } if (Locked) { //Debug.Log(leftLeft + " " + leftRight + "::" + rightLeft+" " + rightRight); badL = 0; badR = 0; if (useServer) { if (sent) { HandFeature data = _connector.getData(); if (data != null) { badL = data.badL; badR = data.badR; sent = false; } } else { _connector.sendData(angleL, angleR, leftLeft, leftRight, rightLeft, rightRight, leftOrientation, rightOrientation, Locked, badL, badR); sent = true; } } else { if ((Mathf.Abs(angleL - target) > tolerance || (leftOrientation >= 35))) { //Debug.Log(leftOrientation + " " + rightOrientation + " bad"); badL = 1; //Debug.Log("Bad"); } if ((Mathf.Abs(angleR - target) > tolerance || (rightOrientation >= 35))) { //Debug.Log(leftOrientation + " " + rightOrientation + " bad"); badR = 1; //Debug.Log("Bad"); } } leftScore = Mathf.Min(100, leftScore + ((float)badL) / 20); rightScore = Mathf.Min(100, rightScore + ((float)badR) / 25); try { leftHand.updateMatColor(colorScale.Evaluate(leftScore)); rightHand.updateMatColor(colorScale.Evaluate(rightScore)); } catch (MissingComponentException) { } } else { badL = 0; badR = 0; } if (badL == 1 || badR == 1) { // Some visual if (Time.time - lastErr >= timeout) { lastErr = Time.time; if (badStuff != null) { badStuff.Play(); } } } //Debug.Log(badL + " " + badR); rowDataLeft[0] = "" + angleL; rowDataLeft[1] = "" + leftLeft; rowDataLeft[2] = "" + leftRight; rowDataLeft[3] = "" + leftOrientation; rowDataLeft[4] = "" + badL; rowDataLeft[5] = "" + Locked; rowDataRight[0] = "" + angleR; rowDataRight[1] = "" + rightLeft; rowDataRight[2] = "" + rightRight; rowDataRight[3] = "" + rightOrientation; rowDataRight[4] = "" + badR; rowDataRight[5] = "" + Locked; string delimiter = ","; StringBuilder sbL = new StringBuilder(); StringBuilder sbR = new StringBuilder(); for (int index = 0; index < rowDataLeft.Length; index++) { sbL.AppendLine(string.Join(delimiter, rowDataLeft[index])); sbR.AppendLine(string.Join(delimiter, rowDataRight[index])); } string filePathL = "C:\\Users\\Vinay\\Documents\\WristWatcher\\Assets\\WristWatcher\\Left.csv"; string filePathR = "C:\\Users\\Vinay\\Documents\\WristWatcher\\Assets\\WristWatcher\\Right.csv"; // Create a file to write to. System.IO.File.AppendAllText(filePathL, sbL.ToString() + "\n"); System.IO.File.AppendAllText(filePathR, sbR.ToString() + "\n"); //Debug.Log(filePath); //Debug.Log("Left Angle:" + angleL + " Right Angle:" + angleR); }
void FixedUpdate() { if (directConnect) { //追従対象の手がないときは非アクティブにする palm.gameObject.SetActive(capsuleHand.gameObject.activeSelf); for (int f = 0; f < fingers.Length; ++f) { if (fingers [f] != null) { fingers [f].gameObject.SetActive(capsuleHand.gameObject.activeSelf); } } //追従対象がないときは何もしない if (!capsuleHand.gameObject.activeSelf) { return; } Hand leapHand = capsuleHand.GetLeapHand(); palm.position = leapHand.PalmPosition.ToVector3(); palm.rotation = leapHand.Rotation.ToQuaternion(); if (recorder.recording) { string[] data = { palm.position.x.ToString(), palm.position.y.ToString(), palm.position.z.ToString(), palm.rotation.x.ToString(), palm.rotation.y.ToString(), palm.rotation.z.ToString(), palm.rotation.w.ToString() }; recorder.Record(data); } for (int f = 0; f < fingers.Length; ++f) { if (fingers [f] != null) { fingers [f].FixedUpdateBones(leapHand.Fingers [f]); } } } else { //再生してないときは非アクティブにする palm.gameObject.SetActive(player.playing); for (int f = 0; f < fingers.Length; ++f) { if (fingers [f] != null) { fingers [f].gameObject.SetActive(player.playing); } } if (!player.playing) { return; } float[] data = player.OnFixedUpdate(); if (data == null) { return; } palm.position = new Vector3(data [0], data [1], data [2]); palm.rotation = new Quaternion(data [3], data [4], data [5], data [6]); for (int f = 0; f < fingers.Length; ++f) { if (fingers [f] != null) { fingers [f].FixedUpdateBones(); } } } }