private void UpdateGestureFromTouchInfo() { // Clear the gesture list. GestureList.Clear(); switch (state) { // User has not put finger on touch pad. case State.WAITING: HandleWaitingState(); break; // User has not started a gesture (by moving out of slop). case State.TOUCHING: HandleDetectingState(); break; // User is scrolling on touchpad. case State.SCROLLING: HandleScrollingState(); break; default: Debug.LogFormat("Wrong gesture detector state: {0}", state); break; } }
public void detectGesture(Leap.Frame frame) { GestureList gestures = frame.Gestures(); //Return a list of gestures for (int i = 0; i < gestures.Count(); i++) // enumerate all the gestures detected in a frame { Gesture gesture = gestures[i]; switch (gesture.Type) { case Gesture.GestureType.TYPE_CIRCLE: richTextBox1.AppendText("Circle detected!" + Environment.NewLine); this.Unlocked = true; this.UnlockGestureTimer.Stop(); this.UnlockGestureTimer.Start(); break; case Gesture.GestureType.TYPE_KEY_TAP: FanController.WindLevel(); richTextBox1.AppendText("Key Tap detected!" + Environment.NewLine); break; case Gesture.GestureType.TYPE_SWIPE: FanController.PowerOff(); richTextBox1.AppendText("Swipe detected!" + Environment.NewLine); break; case Gesture.GestureType.TYPE_SCREEN_TAP: FanController.LightOn(); richTextBox1.AppendText("Screen Tap detected!" + Environment.NewLine); break; } } }
private void detectGesture(Leap.Frame frame) { GestureList gestures = frame.Gestures(); for (int i = 0; i < gestures.Count(); i++) { Gesture gesture = gestures[i]; switch (gesture.Type) { case Gesture.GestureType.TYPE_CIRCLE: //richTextBox1.AppendText("Movement detected!" + Environment.NewLine); break; case Gesture.GestureType.TYPE_KEY_TAP: //richTextBox1.AppendText("Movement detected!" + Environment.NewLine); break; case Gesture.GestureType.TYPE_SWIPE: // richTextBox1.AppendText("Translation detected!" + Environment.NewLine); break; case Gesture.GestureType.TYPE_INVALID: //richTextBox1.AppendText("NO MOVEMENT "); break; } } }
//method to detect hand and creates the frame object public void detectGesture(Leap.Frame frame) { // creates an object GestureList gestures = frame.Gestures(); //returns list of gestures for (int i = 0; i < gestures.Count(); i++) { Gesture gesture = gestures[i]; //switch using gesture.type as a flag, when it gets the type of gesture it will go to its respective case switch (gesture.Type) { //these are the cases and prints out the detected gesture case Gesture.GestureType.TYPE_CIRCLE: Debug.WriteLine("Circle"); break; case Gesture.GestureType.TYPE_KEY_TAP: Debug.WriteLine("Key Tap"); break; case Gesture.GestureType.TYPE_SWIPE: Debug.WriteLine("Swipe"); break; case Gesture.GestureType.TYPE_SCREEN_TAP: Debug.WriteLine("Screen Tap"); break; } } }
void objectOperationWithLeapMotion() { Frame frame = controller.Frame(); FingerCount = frame.Fingers.Count; GestureList gestures = frame.Gestures(); InteractionBox interactionBox = frame.InteractionBox; if (frame.Fingers[0].IsValid) { for (int n = 0; n < gestures.Count; n++) { Gesture gesture = gestures[n]; Debug.Log(gesture.Type); switch (gesture.Type) { case Gesture.GestureType.TYPEKEYTAP: KeyTapGesture keytapGesture = new KeyTapGesture(gesture); Debug.Log("KeyTap"); break; case Gesture.GestureType.TYPESCREENTAP: ScreenTapGesture screenTapGesture = new ScreenTapGesture(gesture); Debug.Log("ScreenTap"); break; default: break; } } } }
// Update is called once per frame void Update() { Debug.Log("UPDATE"); Frame frame = Controller.Frame(); GestureList gestures = frame.Gestures(); Debug.Log(" gestures: " + gestures.Count.ToString()); for (int i = 0; i < gestures.Count; i++) { Gesture gesture = gestures[0]; switch (gesture.Type) { case Gesture.GestureType.TYPECIRCLE: Debug.Log("Circle"); break; case Gesture.GestureType.TYPEKEYTAP: Debug.Log("keytap"); break; case Gesture.GestureType.TYPESWIPE: Debug.Log("swipe"); break; case Gesture.GestureType.TYPE_SCREEN_TAP: Debug.Log("screen tap"); break; default: Debug.Log("Bad gesture type"); break; } } }
void CheckCustomGestures() { GestureList gestures = controller.GetCustomGestures(); for (int i = 0; i < gestures.Count; i++) { Gesture gesture = gestures[i]; switch (gesture.Type) { case Gesture.GestureType.TYPESCREENTAP: MoveFoward(); break; case Gesture.GestureType.TYPEKEYTAP: KeyTapGesture keyTapGesture = new KeyTapGesture(gesture); Vector3 vector = keyTapGesture.Position.ToUnityScaled(); hudScript.PressButton(controller.transform.TransformPoint(vector)); break; case Gesture.GestureType.TYPESWIPE: SwipeGesture swipeGesture = new SwipeGesture(gesture); Rotate90(swipeGesture.Direction.x); break; default: break; } } }
private void TapGestures() { GestureList gestures = controller.GetCustomGestures(); for (int i = 0; i < gestures.Count; i++) { Gesture gesture = gestures[i]; Vector3 vect = new Vector3(); if (gesture.Type == ScreenTapGesture.ClassType()) { //Debug.Log ("tap"); ScreenTapGesture screenTapGesture = new ScreenTapGesture(gesture); vect = screenTapGesture.Position.ToUnityScaled(); } if (gesture.Type == KeyTapGesture.ClassType()) { //Debug.Log ("key"); KeyTapGesture screenTapGesture = new KeyTapGesture(gesture); vect = screenTapGesture.Position.ToUnityScaled(); } vect = controller.transform.TransformPoint(vect); foreach (Button button in buttons) { Vector3[] corners = new Vector3 [4]; RectTransform rectTrans = button.gameObject.GetComponent <RectTransform>(); rectTrans.GetWorldCorners(corners); if (ContainInWorld(corners, vect)) { button.onClick.Invoke(); } } } }
/// <summary> /// Processes the leap input. /// </summary> public override void processLeapInput() { // Gets current frame Data Frame currentFrame = LeapInput.Frame; if (currentFrame.IsValid) { // Gets current list of gestures GestureList leapGestures = currentFrame.Gestures(); // Iterates trhough all the gestures found in the current frame foreach (Gesture gesture in leapGestures) { SwipeGesture swipeGesture = new SwipeGesture(gesture); switch (swipeGesture.State) { case SwipeGesture.GestureState.STATESTART: storeInitialSwipeValues(swipeGesture); break; case SwipeGesture.GestureState.STATESTOP: storeFinalSwipeValues(swipeGesture); processSwipeGesture(); break; } } } }
// funzione per la rotazione tramite la circle gesture void PinchRotation() { string clockwiseness = null; if (LeftHand.IsValid && RightHand.IsValid) { GestureList gesture = frame.Gestures(); for (int i = 0; i < gesture.Count; i++) { CircleGesture circle = new CircleGesture(gesture [i]); string state = circle.State.ToString(); if (state.Equals("STATE_UPDATE")) { if (circle.Pointable.Direction.AngleTo(circle.Normal) <= Math.PI / 2) { //clockwiseness transform.Rotate(Vector3.up, Time.deltaTime * -90f, Space.World); } else { //clockwiseness transform.Rotate(Vector3.up, Time.deltaTime * 90f, Space.World); } } } } }
// Update is called once per frame void Update() { gestureTimeout -= Time.deltaTime; if (gestureTimeout > 0.0f) { return; } Frame frame = cont.Frame(); GestureList gestures = frame.Gestures(); foreach (Gesture gesture in gestures) { if (gesture.Type == Gesture.GestureType.TYPE_CIRCLE) { CircleGesture circle = new CircleGesture(gesture); if (testCircle(circle)) { gestureTimeout = 0.5f; break; } } else if (gesture.State == Gesture.GestureState.STATE_STOP) { SwipeGesture swipe = new SwipeGesture(gesture); if (testGesture(swipe)) { gestureTimeout = 0.5f; break; } } } }
private void OpenFile() { var fileDialog = new System.Windows.Forms.OpenFileDialog() { FileName = Path.GetFileName(EyeGestureFile) }; var result = fileDialog.ShowDialog(); switch (result) { case System.Windows.Forms.DialogResult.OK: EyeGestureFile = fileDialog.FileName; break; case System.Windows.Forms.DialogResult.Cancel: default: break; } xmlEyeGestures = XmlEyeGestures.ReadFromFile(EyeGestureFile); EyeGesture = GestureList != null && GestureList.Any() ? GestureList[0] : null; if (GestureList.Any()) { DisableAll(); } }
void OnGestureMade(GestureList gestures) { foreach (var gesture in gestures) { GameModel.GestureMade = LeapGestures.GestureTypesLookUp[gesture.Type]; } }
void checkForGestures() { if (!leap_hand.IsLeft) { return; } Debug.Log(selectedObject); Frame frame = LEAPcontroller.Frame(); GestureList gesturesInFrame = frame.Gestures(); if (!gesturesInFrame.IsEmpty) { foreach (Gesture gesture in gesturesInFrame) { switch (gesture.Type) { //CIRCLE = GROW/SHRINK case Gesture.GestureType.TYPECIRCLE: CircleGesture circleGesture = new CircleGesture(gesture); float turns = circleGesture.Progress / 1000; //grow if rotating clockwise if (circleGesture.Pointable.Direction.AngleTo(circleGesture.Normal) <= Mathf.PI / 2) { if (targetScale <= 10.0f) { targetScale += turns; } } else { if (targetScale >= 1.0f) { targetScale -= turns; } } v3Scale = new Vector3(targetScale, targetScale, targetScale); selectedObject.transform.localScale = Vector3.Lerp(selectedObject.transform.localScale, v3Scale, Time.deltaTime * shrinkSpeed); break; case Gesture.GestureType.TYPESWIPE: SwipeGesture swipe = new SwipeGesture(gesture); Vector swipeDirection = swipe.Direction; //left swipe if (swipeDirection.x > 0) { Debug.Log("rightSwipe"); selectedObject.transform.GetComponent <MeshRenderer> ().material.color = previousColour; selectedObject = null; } break; } } } }
// Update is called once per frame void Update() { Ray ray; Frame frame = controller.Frame(); fingerCount = frame.Fingers.Count; Debug.Log(fingerCount); GestureList gestures = frame.Gestures(); for (int i = 0; i < gestures.Count; i++) { Gesture gesture = gestures[i]; if (gesture.Type == Gesture.GestureType.TYPESWIPE) { SwipeGesture swipe = new SwipeGesture(gesture); Vector swipeDirection = swipe.Direction; if (swipeDirection.y < 0) { Debug.Log("Down Gesture"); buttons.SetActive(true); iTween.MoveTo(buttons, iTween.Hash("path", iTweenPath.GetPath("mainMenu"), "time", 1f, "easetype", "easeInCubic" )); } else if (swipeDirection.y > 0) { Debug.Log("Up Gesture"); buttons.SetActive(false); } } } }
public void detectGesture(Leap.Frame frame) //Función publica de detección de gesto con los frames recibidos del Leap Motion { GestureList gestures = frame.Gestures(); //Intanciación del objeto gestos con la llamada de frames for (int i = 0; i < gestures.Count(); i++) //Bucle for para recorrer la cantidad de gestos recibidos { Gesture gesture = gestures[i]; //Aignación de las posiciones del array segun se recorre el array de gestos switch (gesture.Type) //Switch de caos del tipo de gesto { case Gesture.GestureType.TYPE_CIRCLE: //Si se recibe el gesto de circulo richTextBox1.AppendText("Circle detected!" + Environment.NewLine); //Se muestra el texto por pantalla y se pasa a la siguiente linea del cuadro de muestras de texto por pantalla break; //Salida case Gesture.GestureType.TYPE_SCREEN_TAP: //Si se recibe el gesto de screen tap richTextBox1.AppendText("Screen tap!" + Environment.NewLine); //Se muestra el texto por pantalla y se pasa a la siguiente linea del cuadro de muestras de texto por pantalla break; //Salida case Gesture.GestureType.TYPE_KEY_TAP: //Si se recibe el gesto de key tap richTextBox1.AppendText("Key tap!" + Environment.NewLine); //Se muestra el texto por pantalla y se pasa a la siguiente linea del cuadro de muestras de texto por pantalla break; //Salida case Gesture.GestureType.TYPE_SWIPE: //Si se recibe el gesto de swipe richTextBox1.AppendText("Swipe detected!" + Environment.NewLine); //Se muestra el texto por pantalla y se pasa a la siguiente linea del cuadro de muestras de texto por pantalla break; //Salida } } }
//Función encargada de tratar los gestos detectados virtual protected void DeteccionGestos(GestureList gesturesInFrame) { if (!gesturesInFrame.IsEmpty) { foreach (Gesture gesture in gesturesInFrame) { switch (gesture.Type) { case Gesture.GestureType.TYPECIRCLE: //si hemos detectado un gesto del tipo círculo if (EventSystem.current.currentSelectedGameObject != null) { GameObject ObjetoBoton = EventSystem.current.currentSelectedGameObject; Button boton = ObjetoBoton.GetComponent <Button> (); if (ObjetoBoton.tag == "BotonInterfaz") { boton.onClick.Invoke(); } } break; } } } }
public override void OnFrame(Controller controller) { // Get the most recent frame and report some basic information Frame frame = controller.Frame(); // Get gestures // Only handles swipe gesture for now... GestureList gestures = frame.Gestures(); for (int i = 0; i < gestures.Count; i++) { Gesture gesture = gestures[i]; switch (gesture.Type) { case Gesture.GestureType.TYPE_SWIPE: SwipeGesture swipe = new SwipeGesture(gesture); OnGesture("swipe", swipe.Id, swipe.State.ToString(), swipe.Position.ToFloatArray(), swipe.Direction.ToFloatArray()); break; case Gesture.GestureType.TYPECIRCLE: CircleGesture circle = new CircleGesture(gesture); OnCircleGesture("circle", circle.Id, circle.State.ToString(), circle.Progress, circle.Normal, circle.Pointable); break; } } }
public override void OnFrame(Controller controller) { // Get the most recent frame and report some basic information Frame frame = controller.Frame(); // Get gestures GestureList gestures = frame.Gestures(); for (int i = 0; i < gestures.Count; i++) { Gesture gesture = gestures[i]; switch (gesture.Type) { case Gesture.GestureType.TYPEKEYTAP: soundPlayer.Play(); break; case Gesture.GestureType.TYPESCREENTAP: soundPlayer.Stop(); break; default: break; } } }
void Update() { Frame frame = m_controller.Frame(); // update the pointer controller ToolList tools = frame.Tools; if (m_pointerController) { if (tools.Count > 0) { Tool tool = tools[0]; // leap motion uses different object for vectors Vector3 positionVector = new Vector3(tool.TipPosition.x, tool.TipPosition.y, tool.TipPosition.z); m_pointerController.ToolMoved(positionVector); } // do something with the tracking data in the frame... GestureList gestures = frame.Gestures(); if (gestures.Count > 0) { foreach (Gesture gesture in gestures) { if (gesture.State == Gesture.GestureState.STATESTOP) { m_pointerController.Gesture(gesture); Debug.Log(gesture.Type + " : " + gesture.Duration); } } } } }
public override void OnFrame(Controller controller) { using (Frame frame = controller.Frame()) { if (frame != null) { GestureList gestures = frame.Gestures(); if (gestures != null && gestures.Count > 0) { foreach (var gesture in gestures) { if (GestureRecognized != null) { GestureRecognized(this, new LeapMotionEventArgs { Controller = controller, Frame = frame, Gesture = gesture }); } } } if (FrameReady != null) { FrameReady(this, new LeapMotionEventArgs { Controller = controller, Frame = frame }); } } } }
/// <summary> /// Updates gestures with data from receiving gestureList /// </summary> /// <param name="gestures">list of recognized gestures</param> /// <returns></returns> public bool UpdateData(GestureList gestures) { if (gestures == null) throw new ArgumentNullException(nameof(gestures)); if (gestures.Count == 0) _activeGesture = false; try { foreach (Gesture gesture in gestures) { switch (gesture.Type) { case Gesture.GestureType.TYPE_CIRCLE: PreCircle(gesture); break; case Gesture.GestureType.TYPE_SWIPE: PreSwipe(gesture); break; case Gesture.GestureType.TYPE_KEY_TAP: PreKeyTap(gesture); break; case Gesture.GestureType.TYPE_SCREEN_TAP: PreScreenTap(gesture); break; } } return true; } catch (Exception) { return false; } }
public void detectGesture(Leap.Frame frame) { GestureList gestures = frame.Gestures(); //Return a list of gestures for (int i = 0; i < gestures.Count(); i++) // enumerate all the gestures detected in a frame { Gesture gesture = gestures[i]; switch (gesture.Type) { case Gesture.GestureType.TYPE_CIRCLE: richTextBox1.AppendText("Circle detected!" + Environment.NewLine); break; case Gesture.GestureType.TYPE_KEY_TAP: richTextBox1.AppendText("Key Tap detected!" + Environment.NewLine); break; case Gesture.GestureType.TYPE_SWIPE: richTextBox1.AppendText("Swipe detected!" + Environment.NewLine); break; case Gesture.GestureType.TYPE_SCREEN_TAP: richTextBox1.AppendText("Screen Tap detected!" + Environment.NewLine); break; } } }
protected void DetectLeapGesture(Controller leap, Leap.Frame frame) { GestureList gestures = frame.Gestures(); foreach (Gesture gesture in gestures) { if (gesture.State != Gesture.GestureState.STATESTOP) { continue; } switch (gesture.Type) { case Gesture.GestureType.TYPESWIPE: SwipeGesture swipe = new SwipeGesture(gesture); if (swipe.StartPosition.x < 0 && swipe.Direction.x > 0) { TurnSlide(-1); } else if (swipe.StartPosition.x > 0 && swipe.Direction.x < 0) { TurnSlide(+1); } break; default: break; } } }
void FixedUpdate() { // ___________________________________________________________________________________手势swipe模块 this.currentFrame = hc.GetFrame(); Frame frame = hc.GetFrame(); Frame lastframe = hc.getlastframe(); GestureList gestures = this.currentFrame.Gestures(); Vector swipedirection = null; foreach (Gesture g in gestures) { if (g.Type == Gesture.GestureType.TYPE_SWIPE) { SwipeGesture swipe = new SwipeGesture(g); swipedirection = swipe.Direction; //Debug.Log("direction is "+swipedirection); } } if (swipedirection.x > 0) { Debug.Log("right"); mark = 1; } if (swipedirection.x < 0) { Debug.Log("left"); mark = -1; } checkmark(mark); // ———————————————————————————————————————————————————————————————————————————————————————————————————————————— }
// Update is called once per frame void Update() { if (tiempoentregestos == 350) { cerrarapp = 0; tiempoentregestos = 0; } frameActual = controller.Frame(); //obtengo la informacion del leap de un frame GestureList gestos = frameActual.Gestures(); if (frameActual.Hands.Count > 0) { HandList hands = frameActual.Hands; firstHand = hands[0]; } FingerList dedos = frameActual.Fingers; //obtengo todos los dedos detectados en un frame int dedos_extendidos = 0; for (int i = 0; i < dedos.Extended().Count; i++) { dedos_extendidos++; //cuento todos los dedos que estan extendidos de la FingerList dedos } if (dedos_extendidos == 5) { switch (boton) { case "BodyMotion": break; case "EarthMotion": SceneManager.LoadScene(0); break; case "VisualMotion": SceneManager.LoadScene(1); break; case "RollingRoshakazu": SceneManager.LoadScene(4); break; } } for (int i = 0; i < gestos.Count; i++) { if (gestos [i].Type == Gesture.GestureType.TYPECIRCLE && dedos_extendidos == 1) { if (cerrarapp == 5) { UnityEditor.EditorApplication.isPlaying = false; } cerrarapp++; tiempoentregestos = 0; } } tiempoentregestos++; }
void Update() { Frame frame = controller.Frame(); //Obtener los gestos que ha detectado LM GestureList gesturesInFrame = frame.Gestures(); DeteccionGestos(gesturesInFrame); }
protected void OnPropertyChanged() { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(null)); if (xmlEyeGestures != null && GestureList != null && GestureList.Count > 1) { GestureList = new ObservableCollection <EyeGesture>(GestureList.OrderBy(g => g.Name)); } }
private void DeleteGesture() { if (GestureList != null && GestureList.Contains(EyeGesture)) { GestureList.Remove(EyeGesture); } EyeGesture = GestureList != null && GestureList.Any() ? GestureList[0] : null; }
private void FixedUpdate() { currentFrame = leapMotionController.Frame(); gestures = currentFrame.Gestures(); hands = currentFrame.Hands; fingers = currentFrame.Fingers; tools = currentFrame.Tools; }
private void Load() { EyeGesturesEnabled = Settings.Default.EyeGesturesEnabled; EyeGestureFile = Settings.Default.EyeGestureFile; EyeGestureString = Settings.Default.EyeGestureString; xmlEyeGestures = XmlEyeGestures.ReadFromString(EyeGestureString); EyeGesture = GestureList != null && GestureList.Any() ? GestureList[0] : null; }
private static void DispatchGestureEvents(Frame frame) { GestureList gestures = frame.Gestures(); if (gestures.Count > 0) { GestureDetected(gestures); } }
void Update() { Frame frame = controller.Frame(); gestures = frame.Gestures(); FingerCount = frame.Fingers.Count; InteractionBox interactionBox = frame.InteractionBox; for (int i = 0; i < FingerCount; ++i) { var finger = frame.Fingers[i]; var obj = fingerObj[i]; Vector normPos = interactionBox.NormalizePoint(finger.TipPosition); normPos *= 10; normPos.z = -normPos.z; obj.transform.localPosition = new UnityEngine.Vector3(normPos.x, normPos.y, normPos.z); } ChangeColor(); }
void FixedUpdate() { HandList hands = controller.Frame().Hands; Frame frame = controller.Frame(); gestures = frame.Gestures(); foreach(Gesture gesture in gestures){ if (gesture.Type == Gesture.GestureType.TYPE_SWIPE) { SwipeGesture swipe = new SwipeGesture(gesture); Vector swipeDirection = swipe.Direction; float swipe_dot = swipeDirection.Dot(Vector.Left); if (swipe_dot < -0.9) rb.rotation *= Quaternion.AngleAxis(-6, Vector3.up); else if (swipe_dot > 0.9) rb.rotation *= Quaternion.AngleAxis(6, Vector3.up); } } if (hands.Count != 0) { Transform camera_transform = Camera.main.transform; Vector3 direction = camera_transform.forward; if (hands.Count == 2) { direction *= 0; } direction.y = 0; direction.Normalize(); direction.y = rb.velocity.y / speed; rb.velocity = direction * speed; } }
public virtual void CheckGesture() { this._lastFrame = this._leap_controller.Frame(0); this.Hands = this._lastFrame.Hands; this._gestures = this._lastFrame.Gestures(); foreach(Hand hand in Hands) { tempHand = hand; _fingers = hand.Fingers; if (WhichSide.IsEnableGestureHand(this)) { this._fingers = hand.Fingers; foreach (Gesture gesture in _gestures) { if ((gesture.Type == Gesture.GestureType.TYPE_KEY_TAP) && WhichSide.capturedSide(hand, _useArea, _mountType)) { _keytab_gesture = new KeyTapGesture(gesture); this.GetDirection(); this.GetPointable(); this.GestureInvokePosition(); this._isChecked = true; break; } } } if (this._isChecked) break; } if (this._isChecked) { DoAction(); } }
//Load all gestures from the new frame void addGestures() { gestures = m_Frame.Gestures(); }
private void OnGestureDetected(GestureList gestures) { foreach (Gesture g in gestures) { switch (g.Type) { case Gesture.GestureType.TYPECIRCLE: if (g.State == Gesture.GestureState.STATESTOP) { if (showInstructions) { StartCoroutine(webCamPics.StartPlayback()); snapshotCountdown = snapshotWaitTime; LeapInputEx.Controller.EnableGesture(Gesture.GestureType.TYPECIRCLE, false); showInstructions = false; } } break; case Gesture.GestureType.TYPESWIPE: if (g.State == Gesture.GestureState.STATESTOP) { if (webCamPics.snapshotTaken && !webCamPics.scattered) { StartCoroutine(webCamPics.Scatter()); } } break; case Gesture.GestureType.TYPEKEYTAP: if ((selected && selected.GetComponent<Switch>()) || (selectionMethod == SelectionMethod.Tap && g.State == Gesture.GestureState.STATESTOP)) { if (selected) { TriggerSelected(); } else if (selectedPiece) { // Allow for a selected piece to be de-selected even if we are not inside the collision volume selectedPiece = null; } } break; } } }
//Virtual method for gesture checking. public virtual void CheckGesture() { _lastFrame = _leap_controller.Frame(0); Hands = _lastFrame.Hands; _gestures = _lastFrame.Gestures(); foreach(Hand hand in Hands) { tempHand = hand; _fingers = hand.Fingers; if (WhichSide.IsEnableGestureHand(this)) { foreach (Gesture gesture in _gestures) { _fingers = hand.Fingers; if (gesture.Type == Gesture.GestureType.TYPE_CIRCLE) { _circle_gesture = new CircleGesture(gesture); if (!_isPlaying && (gesture.State == Gesture.GestureState.STATE_START) && WhichSide.capturedSide(hand, _useArea, _mountType)) { _isPlaying = !_isPlaying; this._startProgress = _circle_gesture.Progress; } if (_isPlaying && gesture.State == Gesture.GestureState.STATE_STOP) { int direc = PropertyGetter.IsClockWise(this); this._endProgress = _circle_gesture.Progress; if (this._endProgress >= this.MinProgress && direc == _useDirection) { this._isChecked = true; this._isPlaying = !this._isPlaying; } this._state = gesture.State; break; } this._state = gesture.State; } } if (_isPlaying && _state == Gesture.GestureState.STATE_UPDATE) { int direc = this.IsClockWise(); this._endProgress = _circle_gesture.Progress; if (this._endProgress >= this.MinProgress && direc == _useDirection) { this._isChecked = true; this._isPlaying = !this._isPlaying; } } } if (this._isChecked) break; } if (_isChecked) { DoAction(); } }
//----------------------------------------------------- // Function for check gesture occur every frame. public virtual void CheckGesture() { _lastFrame = _leap_controller.Frame(); Hands = _lastFrame.Hands; _gestures = _lastFrame.Gestures(); foreach(Hand hand in Hands) { tempHand = hand; _fingers = hand.Fingers; if (WhichSide.IsEnableGestureHand(this)) { foreach (Gesture gesture in _gestures) { if (gesture.Type == Gesture.GestureType.TYPE_SWIPE) { _swipe_gestrue = new SwipeGesture(gesture); if (!_isPlaying && gesture.State == Gesture.GestureState.STATE_START && WhichSide.capturedSide(hand, _useArea, this._mountType)) { _isPlaying = true; _startPoint = hand.PalmPosition; } if (_isPlaying && gesture.State == Gesture.GestureState.STATE_STOP) { _endPoint = hand.PalmPosition; switch (UseAxis) { case 'x': if (((_endPoint.x - _startPoint.x) * _useDirection) > Sensitivity) { this._isChecked = true; _isPlaying = !_isPlaying; break; } _state = gesture.State; break; case 'y': if (((_endPoint.y - _startPoint.y) * _useDirection) > Sensitivity) { this._isChecked = true; _isPlaying = !_isPlaying; break; } _state = gesture.State; break; case 'z': if (_startPoint.y < this._maxY && _endPoint.y < this._maxY && ((_endPoint.z - _startPoint.z) * _useDirection) > Sensitivity) { this._isChecked = true; _isPlaying = !_isPlaying; _state = gesture.State; break; } _state = gesture.State; break; default: break; } } if (!this._isPlaying || this._isChecked) { break; } _state = gesture.State; } } if (_isPlaying && _state == Gesture.GestureState.STATE_UPDATE && WhichSide.capturedSide(hand, _useArea, this.MountType)) { _endPoint = hand.PalmPosition; switch (UseAxis) { case 'x': if (((_endPoint.x - _startPoint.x) * _useDirection) > Sensitivity) { this._isChecked = true; _isPlaying = !_isPlaying; break; } break; case 'y': if (((_endPoint.y - _startPoint.y) * _useDirection) > Sensitivity) { this._isChecked = true; _isPlaying = !_isPlaying; break; } break; case 'z': if (_startPoint.y < this._maxY && _endPoint.y < this._maxY && ((_endPoint.z - _startPoint.z) * _useDirection) > Sensitivity) { this._isChecked = true; _isPlaying = !_isPlaying; break; } else { _isPlaying = !_isPlaying; } break; default: break; } } } } // -------------------- // If Gesture is captured, call the handler function 'DoAction()' if (_isChecked) { DoAction(); } //--------------------- }
/* private void EnteredTriggerVolume(GameObject go) { // Trigger a selection //selected = go; Debug.Log("line ~200. EnteredTriggerVolume"); } private void ExitedTriggerVolume(GameObject go) { if (selected == go) { selected = null; } Debug.Log("line ~215. ExitedTriggerVolume"); }*/ private void OnGestureDetected(GestureList gestures) { foreach (Gesture g in gestures) { switch (g.Type) { case Gesture.GestureType.TYPEKEYTAP: Debug.Log("x: " + position.x.ToString() + " norm: " + position.normalized.x.ToString() + ", " + position.normalized.y.ToString() + ", " + position.normalized.z.ToString()); position = pointables[0].transform.position; //s. System.Type t = rigidbody.GetType(); foreach (Rigidbody rb in Rigidbody.FindObjectsOfType(t)){ if (rb.name.ToString() == attack.ToString()){ GetComponent<shoot>().projecticle = rb; } } GetComponent<shoot>().shootAttack(attack, position, pointables[0].transform.rotation); //Instantiate(gameObject.particleSystem); Ray r = Camera.main.ScreenPointToRay(position); RaycastHit hit; if (Physics.Raycast(r, out hit, 500)){ Debug.Log(hit.transform.position.ToString() + ", norm: " + hit.normal); //Vector3 hitPoint = hit.transform.position + hit.normal; //Instantiate(currentBlock, hitPoint, Quaternion.identity); } /* if (selectionMethod == SelectionMethod.Tap && g.State == Gesture.GestureState.STATESTOP) { if (pointables[0].activeSelf){ position = pointables[0].transform.position; Debug.Log("asdf!"); //if(pointables[0].TouchDistance <= 0){Debug.LogWarning("warning");} //Leap.Frame } }*/ break; default: Debug.Log("gesture " + g.Type.ToString() + " detected."); break; } } }
/* * */ void Update() { // LEAP stuff frame = controller.Frame (); // hand check // (hand check? what is this high school? thanks mom) if(frame.Hands.Count > 0) { // update variables hand = frame.Hands[0]; fingers = hand.Fingers.Count; palm = hand.PalmPosition.ToUnity(); // ToUnity() is called from Plugins/LeapUnityExtensions.cs gestures = frame.Gestures (); leftOrRight = palm.y; upOrDown = palm.x * -2; handRotation = hand.Direction.Yaw; if(showControls) IdleMode(); else { if(tut.guiActive) Tutorial(); else { if(gui.activeGUI) GUITalk(); Swim(); } } // make sure controls.png is hidden controlsTimer = 0f; } else { clownfish.LevelOff(); hud.direction = 0; controlsTimer += Time.deltaTime; if (controlsTimer > controlsTimeLimit) { showControls = true; tut.Reset(); } } // end hand check // for easy debugging WASDInput (); }
private void OnGestureDetected(GestureList gestures) { foreach (Gesture g in gestures) { if (!g.IsValid) continue; switch (g.Type) { case Gesture.GestureType.TYPESWIPE: allowCircleGestureTime = Time.time + circleWaitTime; switch (g.State) { case Gesture.GestureState.STATESTART: // Average the points for the start position swipeStart = Vector3.zero; foreach (Pointable p in g.Pointables) { swipeStart += p.TipPosition.ToUnityTranslated(); } swipeStart *= 1f / g.Pointables.Count; break; case Gesture.GestureState.STATEUPDATE: // For some reason we sometimes get gestures w/ no pointables if (g.Pointables.Count > 0) { swipeEnd = Vector3.zero; foreach (Pointable p in g.Pointables) { swipeEnd += p.TipPosition.ToUnityTranslated(); } swipeEnd *= 1f / g.Pointables.Count; } break; case Gesture.GestureState.STATESTOP: // A swipe is used to dismiss the refresh prompt if (showRefreshPrompt) { showRefreshPrompt = false; break; } Vector3 startPx = Camera.main.WorldToScreenPoint(swipeStart); Vector3 endPx = Camera.main.WorldToScreenPoint(swipeEnd); Vector3 swipe = endPx - startPx; print(Vector3.Dot(swipe.normalized, Vector3.forward)); // Check major axis to determine if it is a swipe up/down or left/right if (Mathf.Abs(Vector3.Dot(swipe.normalized, Vector3.up)) > 0.9f) { if (showTray >= 1f && !showRefreshPrompt) { trayScrollSpeed = swipe.y * scrollSpeedSwipeMultiplier; } } else if (Mathf.Abs(Vector3.Dot(swipe.normalized, Vector3.forward)) > 0.9f) { if (swipe.x < 0f) { StartCoroutine("ShowTray"); } else if (swipe.x > 0f) { StartCoroutine("HideTray"); } } break; } break; case Gesture.GestureType.TYPESCREENTAP: // Debug.Log("TAP"); trayScrollSpeed = 0f; StartCoroutine(ShowLarge(index)); break; case Gesture.GestureType.TYPECIRCLE: if (Time.time > allowCircleGestureTime && g.State == Gesture.GestureState.STATESTOP) { // Debug.Log("CIRCLE " + g.Id + " " + g.State + " on frame " + Time.frameCount); if (!showRefreshPrompt) { showRefreshPrompt = true; // Delay the next circle gesture, so that it doesn't trigger an automatic refresh allowCircleGestureTime = Time.time + circleWaitTime; } else { if (!IsInvoking("LoadFlickrFeed")) { StartCoroutine("LoadFlickrFeed"); // Delay the next circle gesture, so that it doesn't trigger another prompt allowCircleGestureTime = Time.time + circleWaitTime; } showRefreshPrompt = false; } } break; } } }
/// <summary> /// Allows the game component to update itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> public override void Update(GameTime gameTime) { // TODO: Add your update code here if (controller.IsConnected) { //clear fingers fingerPoints.Clear(); var frame = controller.Frame(); debugLine = ""; SafeWriteLine("Frame id: " + frame.Id + ", timestamp: " + frame.Timestamp + ", hands: " + frame.Hands.Count + ", fingers: " + frame.Fingers.Count + ", tools: " + frame.Tools.Count + ", gestures: " + frame.Gestures().Count); if (!(frame.Hands.Count() == 0 )) { // Get the first hand hand = frame.Hands[0]; firstHandLoc = new Vector2(NormalizeWidth(hand.SphereCenter.x), NormalizeHeight( hand.SphereCenter.y)); // Check if the hand has any fingers fingers = hand.Fingers; if (!(fingers.Count() == 0)) { // Calculate the hand's average finger tip position Vector avgPos = Vector.Zero; foreach (Finger finger in fingers) { fingerPoints.Add(new Vector2( NormalizeWidth(finger.TipPosition.x), NormalizeHeight(finger.TipPosition.y) ) ); avgPos += finger.TipPosition; } avgPos /= fingers.Count; SafeWriteLine("Hand has " + fingers.Count + " fingers, average finger tip position: " + avgPos); } // Get the hand's sphere radius and palm position SafeWriteLine("Hand sphere radius: " + hand.SphereRadius.ToString("n2") + " mm, palm position: " + hand.PalmPosition); // Get the hand's normal vector and direction Vector normal = hand.PalmNormal; Vector direction = hand.Direction; // Calculate the hand's pitch, roll, and yaw angles SafeWriteLine("Hand pitch: " + direction.Pitch * 180.0f / (float)Math.PI + " degrees, " + "roll: " + normal.Roll * 180.0f / (float)Math.PI + " degrees, " + "yaw: " + direction.Yaw * 180.0f / (float)Math.PI + " degrees"); } // Get gestures gestures = frame.Gestures(); Gesture gesture; for (int i = 0; i < gestures.Count; i++) { gesture = gestures[i]; switch (gesture.Type) { case Gesture.GestureType.TYPECIRCLE: CircleGesture circle = new CircleGesture(gesture); // Calculate clock direction using the angle between circle normal and pointable String clockwiseness; if (circle.Pointable.Direction.AngleTo(circle.Normal) <= Math.PI / 4) { //Clockwise if angle is less than 90 degrees clockwiseness = "clockwise"; } else { clockwiseness = "counterclockwise"; } float sweptAngle = 0; // Calculate angle swept since last frame if (circle.State != Gesture.GestureState.STATESTART) { CircleGesture previousUpdate = new CircleGesture(controller.Frame(1).Gesture(circle.Id)); sweptAngle = (circle.Progress - previousUpdate.Progress) * 360; } SafeWriteLine("Circle id: " + circle.Id + ", " + circle.State + ", progress: " + circle.Progress + ", radius: " + circle.Radius + ", angle: " + sweptAngle + ", " + clockwiseness); break; case Gesture.GestureType.TYPESWIPE: SwipeGesture swipe = new SwipeGesture(gesture); SafeWriteLine("Swipe id: " + swipe.Id + ", " + swipe.State + ", position: " + swipe.Position + ", direction: " + swipe.Direction + ", speed: " + swipe.Speed); break; case Gesture.GestureType.TYPEKEYTAP: KeyTapGesture keytap = new KeyTapGesture(gesture); SafeWriteLine("Tap id: " + keytap.Id + ", " + keytap.State + ", position: " + keytap.Position + ", direction: " + keytap.Direction); break; case Gesture.GestureType.TYPESCREENTAP: ScreenTapGesture screentap = new ScreenTapGesture(gesture); SafeWriteLine("Tap id: " + screentap.Id + ", " + screentap.State + ", position: " + screentap.Position + ", direction: " + screentap.Direction); break; default: SafeWriteLine("Unknown gesture type."); break; } } if (!(frame.Hands.Count() == 0) || !(frame.Gestures().Count ==0)) { //SafeWriteLine(""); } } base.Update(gameTime); }
void OnGestureMade(GestureList gestures) { foreach (var gesture in gestures) GameModel.GestureMade = LeapGestures.GestureTypesLookUp[gesture.Type]; }
private void SecondaryUpdate() { try { frame = controller.Frame(); controller.EnableGesture(Gesture.GestureType.TYPESWIPE); gestLst = frame.Gestures(); foreach (Gesture ges in gestLst) { /*getting the SWIPE GESTURE */ if((ges.Type == Gesture.GestureType.TYPESWIPE)&&(piece.rigidbody.isKinematic == false)) { // respawn(); } } if ((!frame.Hands.Empty)) { hand = frame.Hands[0]; hand1 = frame.Hands[1]; //actualCordX = ((((100 - (float)hand.PalmPosition.x) / 100) * BOARD_WIDTH_X) - (BOARD_WIDTH_X/2)); // actualCordZ = ((((100 - (float)hand.PalmPosition.z) / 100) * BOARD_LENGTH_Z) - (BOARD_LENGTH_Z/2)); actualCordX = (hand.PalmPosition.x / 100) * -2.38f; actualCordZ = (hand.PalmPosition.z / 100) * -2.4f; //Debug.Log(hand.PalmNormal.x.ToString()); actualCordY = (hand.PalmPosition.y/40) - 5; #region for incase it need to move the piece discreatly on the board //if (piece.rigidbody.velocity.y == 0.0f) //{ // piece.transform.position = gpArray[getPlaneSlote(pla.transform.position.x, pla.transform.position.z)].X_center; //} #endregion //pla.transform.position = gpArray[getPlaneSlote(actualCordX, -actualCordZ)].X_center; ////////////////////////// codition when palm is open //////////////////////////// if (hand.Fingers.Count > 2) { piece.rigidbody.isKinematic = false; if (!isHandOpen) { virtualHand.animation.Play("release"); //isHandOpen = true; } isHandOpen = true; if (grabbed == true) { stablePieceposition = gpArray[getPlaneSlote(piece.transform.position.x, piece.transform.position.z)].X_center; stableVelocity = ((new Vector3(stablePieceposition.x, 0, stablePieceposition.z) - new Vector3(piece.transform.position.x, 0, piece.transform.position.z))); //piece.rigidbody.velocity = stableVelocity*2; //piece.rigidbody.MovePosition(); Debug.Log("Only once on releasing the piece!!!"); } //else //{ // stablePieceposition = piece.transform.position; //} grabbed = false; endPointTrigger = false; motionForward = true; pla.renderer.material.color = Color.green; } //////////////// codition when palm is closed///////////////////// else if (hand.Fingers.Count < 3) { if (isHandOpen) { virtualHand.animation.Play("handsSkin"); } isHandOpen = false; pla.renderer.material = Resources.Load("n", typeof(Material)) as Material; if ((pla.transform.position.x == piece.transform.position.x) && ((pla.transform.position.z == piece.transform.position.z)) && (grabbed == false)) { grabbed = true; if (!endPointTrigger) { startPoint = virtualHand.transform.position; endPoint = new Vector3(piece.transform.position.x-0.3f,-1.8f,piece.transform.position.z); endPointTrigger = true; transitionComplete = false; } piece.rigidbody.isKinematic = true; } if (grabbed == true) { if ((!motionForward && transitionComplete )||(motionForward && transitionComplete)) { //piece.transform.position = virtualHand.transform.position - new Vector3(-0.4f, 1.15f, 0.5f); } } } //pla.transform.position = gpArray[getPlaneSlote(actualCordX, -actualCordZ)].X_center; DrawPlane(); DrawPiece(); DrawHand(); piece.animation.Play(GetAnimationStringPiece()); } else { virtualHand.transform.position = new Vector3(80,80,80); } } catch(Exception e) {} }