private void Update() { if (Target != null) { if (Target.isActiveAndEnabled) { _palmPosition = Target.GetLeapHand().PalmPosition.ToVector3(); _palmNormal = Target.GetLeapHand().PalmNormal.ToVector3(); if (!(_palmPosition != null | _palmNormal != null)) { return; } if (showGizmos) { Debug.DrawRay(_palmPosition, _palmNormal); } transform.position = _palmPosition + (_palmNormal * PalmNormalPercent); transform.LookAt(_palmPosition + _palmNormal); Vector3 correctedVector3 = transform.position + positionCorrection; transform.SetPositionAndRotation(correctedVector3, transform.rotation); } } else { _palmPosition = Vector3.forward; _palmNormal = Vector3.forward; } }
/// <summary> /// 判断合掌 /// </summary> /// <param name="frame"></param> private void HeZhang(Frame frame) { if (frame.Hands.Count < 2) { return; } foreach (Hand hand in frame.Hands) { //左手张开 if (hand.IsLeft) { if (!isOpenFullHand(hand)) { return; } } //右手张开 if (hand.IsRight) { if (!isOpenFullHand(hand)) { return; } } Hand LeftHand = leftHandModel.GetLeapHand(); Hand RightHand = rightHandModel.GetLeapHand(); if (RightHand.PalmPosition.x - LeftHand.PalmPosition.x < Palm_Mix_Distance) { LogText.text = "合掌——变小"; Vector3 value = transform.localScale; value -= new Vector3(value.x * 0.01f, value.y * 0.01f, value.z * 0.01f); // Debug.Log(value); transform.localScale = value; } if (RightHand.PalmPosition.x - LeftHand.PalmPosition.x > Palm_Max_Distance) { LogText.text = "合掌——变大"; Vector3 value = transform.localScale; value += new Vector3(value.x * 0.01f, value.y * 0.01f, value.z * 0.01f); // Debug.Log(value); transform.localScale = value; } } }
private void CastSelectRay(bool act) { if (rightHandModel.IsTracked) { Hand rightHand = rightHandModel.GetLeapHand(); if (act == select) { Debug.DrawRay(rightHand.Fingers[1].TipPosition.ToVector3(), 1000 * rightHand.Fingers[1].Direction.ToVector3(), Color.red); } if (act == delete) { Debug.DrawRay(rightHand.Fingers[1].TipPosition.ToVector3(), 1000 * rightHand.Fingers[1].Direction.ToVector3(), Color.green); } Ray ray = new Ray(rightHand.Fingers[1].TipPosition.ToVector3(), rightHand.Fingers[1].Direction.ToVector3()); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { Debug.Log("this is a string in once hit happens"); if (hit.transform.tag == "Selectable") { if (select) { Debug.Log("select hit");/*hit.transform.gameObject.GetComponent<ChangeColor>().SetColor();*/ } if (delete) { Debug.Log("delete hit");/*hit.transform.gameObject.GetComponent<ChangeColor>().ResetColor();*/ } } } } }
void FixedUpdate() { hand = HandModel.GetLeapHand(); if (HandModel != null && HandModel.IsTracked) { //hand.PalmPosition.ToVector3() = position of the camera; hand is a child of the camera height = (hand.PalmPosition.y - controller.transform.position.y) * 100; // Debug.Log("height = " + height); leftRightDistance = (hand.PalmPosition.x - controller.transform.position.x) * 100; // Debug.Log("leftRightDistance = " + leftRightDistance); // if(playGroundTouched && height > 20f && leftRightDistance < 0) { // // player.transform.eulerAngles = new Vector3(player.transform.eulerAngles.x, 180, player.transform.eulerAngles.z); // rbPlayer.velocity = new Vector3(0f, 7f, 0f); // playGroundTouched = false; // } if (playGroundTouched && height > 20f) { // player.transform.eulerAngles = new Vector3(player.transform.eulerAngles.x, 180, player.transform.eulerAngles.z); rbPlayer.velocity = new Vector3(0f, 8f, 0f); // rbPlayer.AddForce(4f, 8f, 0f); playGroundTouched = false; } if (leftRightDistance < 0) { player.transform.eulerAngles = new Vector3(player.transform.eulerAngles.x, -90, player.transform.eulerAngles.z); player.transform.position += Vector3.left * speed * Time.fixedDeltaTime; } if (leftRightDistance > 0) { player.transform.eulerAngles = new Vector3(player.transform.eulerAngles.x, 90, player.transform.eulerAngles.z); player.transform.position += Vector3.right * speed * Time.fixedDeltaTime; } } }
// Update is called once per frame void Update() { ToggleLeftHandLabels(_leftHand.IsTracked); ToggleRightHandLabels(_rightHand.IsTracked); if (_leftHand.IsTracked) { Hand leapHand = _leftHand.GetLeapHand(); string handRotationInfo = MakeHandRotationInfo(leapHand, false); Debug.Log(handRotationInfo); _leftLabel.position = leapHand.PalmPosition.ToVector3(); int n = leapHand.Fingers.Count; for (int i = 0; i < n; i++) { Finger leapFinger = leapHand.Fingers[i]; _leftFingerLabel[i].position = leapFinger.TipPosition.ToVector3(); } } if (_rightHand.IsTracked) { Hand leapHand = _rightHand.GetLeapHand(); string handRotationInfo = MakeHandRotationInfo(leapHand, true); Debug.Log(handRotationInfo); _rightLabel.position = leapHand.PalmPosition.ToVector3(); int n = leapHand.Fingers.Count; for (int i = 0; i < n; i++) { Finger leapFinger = leapHand.Fingers[i]; _rightFingerLabel[i].position = leapFinger.TipPosition.ToVector3(); } } }
// Update is called once per frame void Update() { Leap.LeapQuaternion lq = hand.GetLeapHand().Rotation; float z = new Quaternion(lq.x, lq.y, lq.z, lq.w).eulerAngles.z; transform.rotation = Quaternion.Euler(0, 0, z); }
bool updateLeapHands() { leftHand = leftHandBase.GetLeapHand(); rightHand = rightHandBase.GetLeapHand(); return(leftHand != null && rightHand != null); }
// Update is called once per frame void Update() { if (rightHandModel.IsTracked) { Hand rightHand = rightHandModel.GetLeapHand(); // float twoFingerDistance = 0.07f; if ((rightHand.Fingers[1].TipPosition - new Vector(0, 0, 0)).Magnitude < twoFingerDistance) { Debug.Log("rightHand.Fingers[0].TipPosition" + rightHand.Fingers[0].TipPosition); GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Cube); obj.transform.position = new Vector3(0.25f, 10, 0.25f); obj.transform.localScale = new Vector3(0.05f, 0.05f, 0.05f); obj.AddComponent <Rigidbody>().useGravity = true; obj.AddComponent <InteractionBehaviour>(); print("Pinch detected!"); } } for (int i = 0; i < meshCreateControlPoints.interactCP.Count; i++) { meshCreateControlPoints.interactCP[i].OnContactBegin = () => { var selection = hit; Debug.Log("Leap hand touched with a CP! " + hit); }; } }
public void FixedUpdate() { hand = HandModel.GetLeapHand(); if (HandModel != null && HandModel.IsTracked) { //hand.PalmPosition.ToVector3() = position of the camera; hand is a child of the camera height = (hand.PalmPosition.y - controller.transform.position.y) * 100; Debug.Log("height = " + height); leftRightDistance = (hand.PalmPosition.x - controller.transform.position.x) * 100; Debug.Log("leftRightDistance = " + leftRightDistance); if (playGroundTouched && height > 20f) { Debug.Log("jump height = " + height); rbPlayer.velocity = new Vector3(0f, 4f, 0f); rbPlayer.AddForce(0, 0, speed * Time.fixedDeltaTime); playGroundTouched = false; } if (leftRightDistance < 0 && playGroundTouched) { rbPlayer.AddForce(-5 * Time.fixedDeltaTime, 0, 0, ForceMode.VelocityChange); } else if (leftRightDistance > 0 && playGroundTouched) { rbPlayer.AddForce(5 * Time.fixedDeltaTime, 0, 0, ForceMode.VelocityChange); } } }
void Dynamic_Gestures() { Frame frame = provider.CurrentFrame; // controller is a Controller object //移除list的開頭數據,在無判斷到手勢的時候一直刷新list judge_LeftHanddown.RemoveAt(0); judge_LeftHandup.RemoveAt(0); //偵測不到手的模型時將false塞入list裡 if (!leftHandModel.IsTracked) { judge_LeftHanddown.Add(false); judge_LeftHandup.Add(false); return; } Hand leftHand = leftHandModel.GetLeapHand(); Hand RightHand = RightHandModel.GetLeapHand(); //手部的旋轉角度 float Pitch = leftHand.Direction.Pitch; float yaw = leftHand.Direction.Yaw; float roll = leftHand.Direction.Roll; //print(yaw); //判斷到手部模型並判斷有下滑手勢時,將true塞入list裡 if (IsMoveDown(leftHand)) { judge_LeftHanddown.Add(true); //print("下滑"); } else { judge_LeftHanddown.Add(false); } if (IsMoveUp(leftHand)) { judge_LeftHandup.Add(true); //print("上滑"); } else { judge_LeftHandup.Add(false); } }
private IEnumerator leftHandWatcher() { while (true) { if (leftHandModel != null) { leftHand = leftHandModel.GetLeapHand(); if (leftHand != null) { //if (leftHand.GrabStrength >= 0.85f) Debug.Log("Left Grabbing"); if (leftHandState != 0 && leftHand.PinchStrength >= pinchStrengthForce) { //Debug.Log("Left Pinching"); leftHandState = 1; } else if (leftHand.GrabStrength <= grabStrengthForce) { //Debug.Log("Left AllExtend"); leftHandState = 2; } else { offset = Vector3.zero; leftHandState = 0; if (workstationActivated) { dynamicUI.GetComponent <WorkstationBehaviourExample>().DeactivateWorkstation(); workstationActivated = false; } } if (leftHandState == 2) { if (leftHand.PalmVelocity.z >= onoffVelocity) { //Debug.Log("Left Window TurnOff"); leftHandState = 3; } else if (leftHand.PalmVelocity.z <= -onoffVelocity) { //Debug.Log("Left Window TurnOn"); leftHandState = 4; } if (leftHand.PalmVelocity.x <= -onoffVelocity) { leftHandState = 5; //Debug.Log("Left"); } else if (leftHand.PalmVelocity.x >= onoffVelocity) { leftHandState = 6; } } } } yield return(new WaitForSeconds(0.1f)); } }
// Update is called once per frame void Update() { if (leftHandModel.IsTracked) { Hand leftHand = leftHandModel.GetLeapHand(); if ((leftHand.Fingers[0].TipPosition - leftHand.Fingers[1].TipPosition).Magnitude < twoFingerDistance) { print("LeftHand"); } } if (leftHandModel.IsTracked) { Hand leftHand = leftHandModel.GetLeapHand(); if ((leftHand.Fingers[0].TipPosition - leftHand.Fingers[1].TipPosition).Magnitude > twoFingerDistance) { print("Grasp"); } } if (leftHandModel.IsTracked) { Hand leftHand = leftHandModel.GetLeapHand(); if ((leftHand.Fingers[0].TipPosition - leftHand.Fingers[1].TipPosition).Magnitude > twoFingerDistance && (leftHand.Fingers[0].TipPosition - leftHand.Fingers[2].TipPosition).Magnitude > twoFingerDistance && (leftHand.Fingers[0].TipPosition - leftHand.Fingers[3].TipPosition).Magnitude > twoFingerDistance && (leftHand.Fingers[0].TipPosition - leftHand.Fingers[4].TipPosition).Magnitude > twoFingerDistance) { print("Close to Palm"); } } if (rightHandModel.IsTracked) { Hand rightHand = rightHandModel.GetLeapHand(); if ((rightHand.Fingers[0].TipPosition - rightHand.Fingers[1].TipPosition).Magnitude < twoFingerDistance) { print("RightHandï¼?"); } } }
// Update is called once per frame void FixedUpdate() { if (!leftHandModel.IsTracked) { return; } Hand leftHand = leftHandModel.GetLeapHand(); //if (IsMoveLeft(leftHand)) //{ // print("Move to Left"); //} //if (IsMoveRight(leftHand)) //{ // print("Move to Right"); //} //if (IsMoveUp(leftHand)) //{ // print("Move to Up"); //} //if (IsMoveDown(leftHand)) //{ // print("Move to Down"); //} if (IsCloseHand(leftHand)) { anim.SetBool("bloom", false); // print("play anim"); } //if (IsOpenFullHand(leftHand)) //{ // print("Open Full Hand"); // anim.Play("roll"); //} //if (IsOpenFullHand(leftHand)) //{ // print("IsOpenFullHand"); //} //if (CheckFingerCloseToHand(leftHand)) //{ // print("CheckFingerCloseToHand"); //} /* if (CheckFingerOpenToHand(leftHand,arr)) * { * print("ok"); * point_light.SetActive(false); * * } * if (IsOpenFullHand(leftHand)) * { * print("open"); * anim.Play("roll"); * }*/ }
private IEnumerator rightHandWatcher() { while (true) { if (rightHandModel != null) { rightHand = rightHandModel.GetLeapHand(); if (rightHand != null) { //Debug.Log(rightProximityDetector.CurrentObject); //if (rightHand.GrabStrength >= 0.85f) Debug.Log("Right Grabbing"); if (rightHand.PinchStrength >= 0.85f) { Debug.Log("Right Pinching"); if (!rightPinch && rightProximityDetector.CurrentObject != null) { offset = rightProximityDetector.CurrentObject.transform.position - rightHand.PalmPosition.ToVector3(); rightPinch = true; } rightExtend = false; } else if (rightHand.GrabStrength <= 0.15f) { Debug.Log("Right AllExtend"); rightPinch = false; rightExtend = true; } else { offset = Vector3.zero; rightPinch = false; rightExtend = false; } if (rightExtend) { if (rightHand.PalmVelocity.z >= 0.6f) { Debug.Log("Right Window TurnOff"); rightWindow = false; } else if (rightHand.PalmVelocity.z <= -0.6f) { Debug.Log("Right Window TurnOn"); rightWindow = true; } } } } yield return(new WaitForSeconds(0.1f)); } }
void Update()// decay hiss so it stops if no button is pressed. { Debug.Log("gug"); if (hiss != null) { hiss.volume *= 0.9f; } HandDetails cd = dc.receiveHandDetails(); if (cd != null) { hand.SetLeapHand(cd.hand); hand.UpdateHand(); Debug.Log("werwr"); laserBeam.SetActive(beamActive); if (beamActive) { Debug.Log("activeandgesture"); Finger f = hand.GetLeapHand().Fingers[(int)Finger.FingerType.TYPE_INDEX];// index finger. Bone b = f.Bone(Bone.BoneType.TYPE_DISTAL); Vector3 bCenter = new Vector3(b.Center.x, b.Center.y, b.Center.z); Vector3 bDirection = new Vector3(b.Direction.x, b.Direction.y, b.Direction.z); laserBeam.transform.position = bCenter; laserBeam.transform.forward = bDirection; // Raycast, inflate, explode. RaycastHit hit; if ((Physics.Raycast(bCenter, bDirection, out hit, Mathf.Infinity)) && (hit.collider.gameObject.tag == "Inflatable")) { // Inflate the objectby manipulating scale hit.collider.gameObject.transform.localScale *= 1.0f + (inflationRate * Time.deltaTime); // Play the inflation sound. if (hiss != null) { hiss.volume = 1.0f; if (!hiss.isPlaying) { hiss.Play(); } } // Pop the object if it gets too big. if (hit.collider.gameObject.transform.localScale.magnitude > 1.5) { Destroy(hit.collider.gameObject); if (pop != null) { pop.Play(); } } } } } }
// Update is called once per frame protected override void Update() { base.Update(); if (!IsPinching) { BlackHole.transform.position = hand.GetLeapHand().GetPinchPosition(); } if (DidStartPinch) { TouchpointObject = Instantiate(TouchpointPrefab, Camera.main.transform, false); TouchpointObject.transform.position = BlackHole.transform.position; } if (DidEndPinch) { Destroy(TouchpointObject); } }
private void Update() { //swipe hands to change level SwipeChangeLevel(); //get hands if (leftHandModel.IsTracked || rightHandModel.IsTracked) { leftHand = leftHandModel.GetLeapHand(); rightHand = rightHandModel.GetLeapHand(); } //if selection list changed, compute the barycenter of the selection list if (selectionlistCount != treatSelectionManager.selectionList.Count) { selectionlistCount = treatSelectionManager.selectionList.Count; ComputeBaryenter(treatSelectionManager.selectionList); } if (checkSegment /*a condition that make FindSegment run once*/) { //check if the CPs belong to a segment that is touched by left hand FindSegment(); checkSegment = false; } // Allow to move(deform) the mesh of the model if the mesh(corresponding to the selected control points) is grasped by hand if (graspDetect) { MoveObject(); } //check if scale model is allowed, if yes, scale the model if (voiceChangeScale) { Scale(); } }
// Update is called once per frame void Update() { if (PointerHand.isActiveAndEnabled & Cam != null) { Vector3 fingerTip = PointerHand.GetLeapHand().GetIndex().TipPosition.ToVector3(); Vector3 screenVector3 = Cam.WorldToScreenPoint(fingerTip); float xPos = MapToRange(screenVector3.x, 0, Cam.pixelWidth, 0, DebugScreenWidth); float yPos = MapToRange(Cam.pixelHeight - screenVector3.y, 0, Cam.pixelHeight, 0, DebugScreenHeight); SetCursorPos((int)xPos, (int)yPos); // Call this when you want to set the mouse position if (screenVector3.z >= OnDepth) { Activate(); } if (screenVector3.z < OffDepth) { Deactivate(); } } }
protected override void UpdateHandStatus() { IsActive = m_leapRiggedHand.IsTracked; Leap.Hand hand = m_leapRiggedHand.GetLeapHand(); if (!IsActive || hand == null) { return; } Vector3 indexTip = hand.Fingers[1].TipPosition.ToVector3(); Vector3 middleTip = hand.Fingers[2].TipPosition.ToVector3(); if (Vector3.Distance(indexTip, middleTip) < 0.05f) { InteractionPointMode = InteractionPointModes.Palm; Position = hand.PalmPosition.ToVector3(); } else { InteractionPointMode = InteractionPointModes.Index; Position = hand.Fingers[1].TipPosition.ToVector3(); } }
private IEnumerator rightHandWatcher() { while (true) { if (rightHandModel != null) { rightHand = rightHandModel.GetLeapHand(); if (rightHand != null) { if (rightHand.Fingers[1].IsExtended) { if (leftHand != null) { if (Vector3.Distance(leftHand.PalmPosition.ToVector3(), rightHand.Fingers[1].TipPosition.ToVector3()) < buttonDistance) { LeanTween.move(dynamicUI, leftHand.PalmPosition.ToVector3(), 0.2f); if (!workstationActivated) { dynamicUI.GetComponent <WorkstationBehaviourExample>().ActivateWorkstation(); workstationActivated = true; } } } } if (rightHandState != 0 && rightHand.PinchStrength >= pinchStrengthForce) { //Debug.Log("Right Pinching"); rightHandState = 1; rightHandTrail.emitting = true; } else if (rightHand.GrabStrength <= grabStrengthForce) { //Debug.Log("Right AllExtend"); rightHandState = 2; rightHandTrail.emitting = false; } else { offset = Vector3.zero; rightHandState = 0; rightHandTrail.emitting = false; } if (rightHandState == 2) { if (rightHand.PalmVelocity.z >= onoffVelocity) { //Debug.Log("Right Window TurnOff"); rightHandState = 3; } else if (rightHand.PalmVelocity.z <= -onoffVelocity) { //Debug.Log("Right Window TurnOn"); rightHandState = 4; } if (rightHand.PalmVelocity.x <= -onoffVelocity) { rightHandState = 5; //Debug.Log("Left"); } else if (rightHand.PalmVelocity.x >= onoffVelocity) { rightHandState = 6; } } } } yield return(new WaitForSeconds(0.1f)); } }
// Update is called once per frame void Update() { //CheckTrianglePosition(); //CheckCirclePosition(); if (useMouse) { if (!MousePressed) { if (Input.GetMouseButtonDown(0)) { if (HasIntersection()) { MousePressed = true; CheckTrianglePosition(); CheckCirclePosition(); return; } } } else { if (Input.GetMouseButtonUp(0) || !Input.GetMouseButton(0) || !HasIntersection()) { MousePressed = false; StopDrag(); return; } if (!DragCircle) { CheckTrianglePosition(); } if (!DragTriangle) { CheckCirclePosition(); } return; } } else { if (HandModel != null && HandModel.IsTracked) { Finger finger = HandModel.GetLeapHand().Fingers[1]; // 1 For Index Vector3 fingerDirection = finger.Bone(Bone.BoneType.TYPE_DISTAL).Direction.ToVector3(); Ray ray = new Ray(finger.TipPosition.ToVector3(), finger.Direction.ToVector3()); RaycastHit hit; if (Physics.Raycast(ray, out hit, 0.01f)) { if (HasIntersection(ray)) { print("here"); CheckTrianglePosition(); CheckCirclePosition(); gameManager.ChangeColor(TheColor); //Gizmos.color = Color.white; //Gizmos.DrawRay(ray); } else { StopDrag(); if (!DragCircle) { CheckTrianglePosition(); } if (!DragTriangle) { CheckCirclePosition(); } } } else { StopDrag(); } //else //{ // if (!HasIntersection()) // { // MousePressed = false; // StopDrag(); // return; // } // if (!DragCircle) // CheckTrianglePosition(); // if (!DragTriangle) // CheckCirclePosition(); // return; //} Debug.DrawRay(finger.TipPosition.ToVector3(), finger.Direction.ToVector3(), Color.black); } } }
public HandDetails(HandModelBase handBase) { id = getID(); hand = handBase.GetLeapHand(); }
bool UpdateHand() { rightHand = rightHandModelBase.GetLeapHand(); return(rightHand != null); }
void Update() { selectedObject = GameObject.FindWithTag("Selected"); if (selectedObject != null) { //Multiply scales of all parents of the selectedTargetObject scaleParents = selectedObject.transform.localScale; Transform tranformParent = selectedObject.transform.parent; while (tranformParent != null) { scaleParents = Vector3.Scale(scaleParents, tranformParent.localScale); tranformParent = tranformParent.parent; } /// When index finger is extended move the selectedObject following /// the finger movement if (extendedFingerDetectorR != null && extendedFingerDetectorR.IsActive) { if (time > gestureWaitingTime) { /// When the gesture is avtive disable the scripts for the hand menu appearance to disambiguate the functionalities. //GameObject.Find("Attachment Hands").GetComponent<HandMenuAppearance>().enabled = false; //GameObject.Find("CenterEyeAnchor").GetComponent<Gaze>().enabled = false; selectedObject.gameObject.GetComponent <InteractionBehaviour>().ignoreGrasping = true; //Store index position indexPosition = HandModel_R.GetLeapHand().Fingers[1].TipPosition.ToVector3(); /// If it is the first frame in which there is the extended index (again) set "lastIndexPosition" /// equals to "indexPosition" in order to have, at first, deltaIndexPosition=0 and not to move the /// object at the first time according to the last index position. if (_extendedIndexActive == false) { var assemblies = GameObject.Find("Assemblies"); var soundPath = @"Audio/activation"; //FeedBack.AudioPlay(assemblies, soundPath); lastIndexPosition = indexPosition; // Save in a list the selectedObject and its transform before each transformation ( for the UNDO operation) var position = new Vector3(); var rotation = new Quaternion(); var scale = new Vector3(); position = selectedObject.transform.localPosition; scale = selectedObject.transform.localScale; rotation = selectedObject.transform.localRotation; TransformGameObject transformSelectedObject = new TransformGameObject(selectedObject, position, rotation, scale); //VoiceController.transformationsFlow.Add(transformSelectedObject); //VoiceController.positionSelectedObject.Add(position); //VoiceController.scaleSelectedObject.Add(scale); //VoiceController.rotationSelectedObject.Add(rotation); } Vector3 deltaIndexPosition = indexPosition - lastIndexPosition; // Change the position of the object //Vector3 translation = Vector3.Scale(scaleParents, deltaIndexPosition); selectedObject.transform.position = selectedObject.transform.position + deltaIndexPosition; lastIndexPosition = indexPosition; _extendedIndexActive = true; } } else { _extendedIndexActive = false; selectedObject.gameObject.GetComponent <InteractionBehaviour>().ignoreGrasping = false; //GameObject.Find("Attachment Hands").GetComponent<HandMenuAppearance>().enabled = true; //GameObject.Find("CenterEyeAnchor").GetComponent<Gaze>().enabled = true; time = 0.0f; } time += Time.deltaTime; } }
private void Update() { if (HandModel == null || !HandModel.IsTracked) { return; } Hand hand = HandModel.GetLeapHand(); if (hand == null) { return; } int selectedFinger = SelectedFingerOrdinal(); Vector3 currentPosition = hand.Fingers[selectedFinger].TipPosition.ToVector3(); switch (direction) { case SwipeDirection.Up: if (!(currentPosition.y >= _previousPosition.y)) { _currentDistance = 0; break; } _currentDistance += Math.Abs(currentPosition.y - _previousPosition.y); break; case SwipeDirection.Down: if (!(currentPosition.y <= _previousPosition.y)) { _currentDistance = 0; break; } _currentDistance += Math.Abs(currentPosition.y - _previousPosition.y); break; case SwipeDirection.Left: if (!(currentPosition.x <= _previousPosition.x)) { _currentDistance = 0; break; } _currentDistance += Math.Abs(currentPosition.x - _previousPosition.x); break; case SwipeDirection.Right: if (!(currentPosition.x >= _previousPosition.x)) { _currentDistance = 0; break; } _currentDistance += Math.Abs(currentPosition.x - _previousPosition.x); break; } if (_currentDistance >= minimumDistance) { Activate(); } else { Deactivate(); } _previousPosition = currentPosition; }
// Update is called once per frame void Update() { // if (Input.GetKeyUp(KeyCode.Return)) //{ // reCallibrate(); //} if (callibrating) { bool setUp = false; if (callibrationTimer > 0) { callibrationTimer -= Time.deltaTime; } else { callibrationState++; setUp = true; Debug.Log(callibrationState); } if (forPassenger) { handCenterPosition = passangerCenter.position; } else { handCenterPosition = steeringWheelCenter.position; } if (callibrationState == 1) { if (setUp) { callibrationTimer = 0; } transform.position = OriginalPosition; InputTracking.Recenter(); //Quaternion rotation = Quaternion.(.eulerAngles, headPose.parent.transform.forward); ; Quaternion rotation = Quaternion.FromToRotation(headPose.forward, transform.parent.forward); headPose.parent.transform.Rotate(new Vector3(0, rotation.eulerAngles.y, 0)); //headPose.parent.transform.rotation = transform.parent.rotation; //transform.rotation = transform.parent.rotation; } else if (callibrationState == 2) { if (handTrackin) { if (setUp) { callibrationTimer = 10; // Debug.Break(); } if (HandModelL.IsTracked && HandModelR.IsTracked) { Vector3 A = HandModelL.GetLeapHand().PalmPosition.ToVector3(); Vector3 B = HandModelR.GetLeapHand().PalmPosition.ToVector3(); Vector3 AtoB = B - A; Debug.DrawLine(A, B); if (steeringWheelCenter != null) { Vector3 transformDifference = (A + (AtoB * 0.5f)) - handCenterPosition; Debug.DrawLine(transform.position, handCenterPosition); offset = transformDifference; transform.position -= transformDifference; // Quaternion rot = Quaternion.FromToRotation(AtoB, -steeringWheelCenter.right); // rotOld = rot; //Debug.Log(rot); // transform.RotateAround(handCenterPosition, Vector3.up, rot.eulerAngles.y); } } else { callibrationTimer += Time.deltaTime; } } } else if (callibrationState == 3) { if (arTracking) { if (markerPose.GetComponent <extArRotation>().setCallibrate()) {/// if we find a usable marker we use it if not we reset and look for it the next second initalARRotation = headPose.rotation * Quaternion.Inverse(markerPose.rotation); callibrationTimer = 0; } else { callibrationTimer = 1; } } } else { callibrationTimer = 0; callibrating = false; callibrationState = 0; } } else { // driftCorrection = initalARRotation * Quaternion.Inverse(myReceiver.marker * Quaternion.Inverse(headPose.rotation));\ ///Adjusing the rotation over time isdifficult with markers as there is a long dela. It would be better to find adifferent solution. ///One approache we could explore is too look at the actual headset motion and have based on that two modes. ///either we are measuring the drifft that happend ///or ///we are corrrecting for the drifft all based on the speed of the motion from the headset. if (arTracking) { if (myReceiver.markerUsable) { driftCorrection = (initalARRotation * markerPose.rotation) * Quaternion.Inverse(headPose.rotation); float temp = driftCorrection.eulerAngles.y; if (temp > 180) { temp -= 360; } if (accumelatedYError > 30 && !runCorrection) { runCorrection = true; prevCorrectRotation = headPose.parent.rotation.eulerAngles.y; prevRot = headPose.parent.rotation; rotationTimer = 0; } else { yRotationCorrectio = temp * 0.8f + 0.2f * yRotationCorrectio; accumelatedYError = Mathf.Abs(temp) * 0.1f + 0.9f * accumelatedYError; } if (runCorrection) { rotationTimer += Time.deltaTime * 0.1f; // Vector3 blub = new Vector3(headPose.parent.rotation.eulerAngles.x, Mathf.Lerp(prevCorrectRotation, yRotationCorrectio, rotationTimer), headPose.parent.rotation.eulerAngles.z); //headPose.parent.Rotate(0, yRotationCorrectio, 0); headPose.parent.rotation = Quaternion.Euler(headPose.parent.rotation.eulerAngles.x, Mathf.LerpAngle(headPose.parent.rotation.eulerAngles.y, headPose.parent.rotation.eulerAngles.y + yRotationCorrectio, rotationTimer), headPose.parent.rotation.eulerAngles.z); //Quaternion.Lerp(prevRot, prevRot * Quaternion.Euler(0,yRotationCorrectio,0), rotationTimer); //= Quaternion.Lerp(prevCorrectRotation, prevCorrectRotation * Quaternion.Euler(0, yRotationCorrectio, 0), rotationTimer); //headPose.parent.Rotate(0f, yRotationCorrectio * .05f, 0f); } if (rotationTimer > 1) { runCorrection = false; } } //driftCorrection = initalARRotation * (myReceiver.marker * Quaternion.Inverse(headPose.rotation*Quaternion.Inverse(transform.parent.rotation))); //driftCorrection.eulerAngles.Set(driftCorrection.eulerAngles.x, driftCorrection.eulerAngles.y-180f,driftCorrection.eulerAngles.z); //headPose.parent.Rotate(0f, Quaternion.Lerp(headPose.parent.rotation, driftCorrection, 0.10f).eulerAngles.y, 0f); } if (continuesHandTracking) { if (HandModelL.IsTracked && HandModelR.IsTracked) { Vector3 A = HandModelL.GetLeapHand().PalmPosition.ToVector3(); Vector3 B = HandModelR.GetLeapHand().PalmPosition.ToVector3(); Vector3 AtoB = B - A; Debug.DrawLine(A, B, Color.green); if (steeringWheelCenter != null) { Vector3 transformDifference = (A + (AtoB * 0.5f)) - handCenterPosition; Vector3 carForward = transform.parent.forward; carForward.y = 0; Vector3 handForward = ((A + (AtoB * 0.5f)) - transform.position); handForward.y = 0; Debug.DrawLine(transform.position, transform.position + carForward * 2, Color.red); Debug.DrawLine(transform.position, transform.position + handForward * 2, Color.green); float Rot = Quaternion.FromToRotation(carForward, handForward).eulerAngles.y; if (Rot > 180) { Rot -= 360; } yRotationCorrectio = Rot; headPose.parent.Rotate(new Vector3(0, -Rot / 10f, 0)); // Debug.Log(Rot.eulerAngles.y); //Debug.Break(); } } } } }