/// <summary> /// Triggered when the Leap Motion OnFrame event occurs, handles the cursor control and events. /// </summary> protected void UpdateFrame(Controller con) { // Grab the frame and the nearest pointer Frame frame = con.Frame(); Pointable pointable = frame.Pointables.Frontmost; Leap.Vector stabilizedPos = pointable.StabilizedTipPosition; // Calculate the position in screen space InteractionBox iBox = con.Frame().InteractionBox; Leap.Vector normalizedPosition = iBox.NormalizePoint(stabilizedPos); double tx = normalizedPosition.x * screenWidth; double ty = screenHeight - normalizedPosition.y * screenHeight; // Allows use of mouse normally if (pointable.TouchZone != Pointable.Zone.ZONENONE) { Mouse.HandleFrame(tx, ty); } // record current position //Win32Services.POINT pt = Win32Services.GetCursorPosition(); //xPos = pt.x; //yPos = pt.y; }
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; } } } }
protected void DrawLeapPoint(Leap.Frame frame) { this.InkCanvas_LeapPaint.Strokes.Clear(); windowHeight = (float)this.MainWindow1.Height; windowWidth = (float)this.MainWindow1.Width; InteractionBox interactionBox = frame.InteractionBox; foreach (Pointable pointable in frame.Pointables.Extended()) { // InteractionBox を利用した座標変換 Leap.Vector normalizedPosition = interactionBox.NormalizePoint(pointable.StabilizedTipPosition); double tx = normalizedPosition.x * windowWidth; double ty = windowHeight - normalizedPosition.y * windowHeight; StylusPoint touchPoint = new StylusPoint(tx, ty); StylusPointCollection tips = new StylusPointCollection(new StylusPoint[] { touchPoint }); // ホバー状態 if (normalizedPosition.z > TouchBorder) { Stroke touchStroke = new Stroke(tips, pointIndicator); this.InkCanvas_LeapPaint.Strokes.Add(touchStroke); } } }
void Update() { Frame frame = controller.Frame(); FingerCount = frame.Fingers.Count; InteractionBox interactionBox = frame.InteractionBox; Pointable pointable = frame.Pointables.Frontmost; //Debug.Log(interactionBox.NormalizePoint(pointable.TipPosition)); Vector normalizedPosition = interactionBox.NormalizePoint(pointable.TipPosition); normalizedPosition *= 200; normalizedPosition.z = -normalizedPosition.z; FrontMost.transform.localPosition = ToVector3(normalizedPosition); /* * for ( int i = 0; i < FingerObjects.Length; i++ ) { * var leapFinger = frame.Fingers[i]; * var unityFinger = FingerObjects[i]; * SetVisible( unityFinger, leapFinger.IsValid ); * if ( leapFinger.IsValid ) { * Vector normalizedPosition = interactionBox.NormalizePoint(leapFinger.TipPosition ); * normalizedPosition *= 10; * normalizedPosition.z = -normalizedPosition.z; * unityFinger.transform.localPosition = ToVector3( normalizedPosition ); * } * } */ }
private void handDetect(Frame frame) { Hand hand = frame.Hands[0]; // Check if the hand has any fingers FingerList fingers = hand.Fingers; if (!fingers.IsEmpty) { // Calculate the hand's average finger tip position Vector avgPos = Vector.Zero; foreach (Finger finger in fingers) { avgPos += finger.TipPosition; } avgPos /= fingers.Count; InteractionBox iBox = controller.Frame().InteractionBox; Vector normalizedPosition = iBox.NormalizePoint(avgPos); var screen = System.Windows.Forms.Screen.PrimaryScreen.Bounds; var width = screen.Width; var height = screen.Height; float x = normalizedPosition.x * width; float y = normalizedPosition.y * height; int xCoordinate = (int)Math.Round(x); int yCoordinate = (int)Math.Round(y); Cursor.Position = new Point(xCoordinate, height - yCoordinate); } }
protected void DrawLeapTouch(Leap.Frame frame) { InteractionBox interactionBox = frame.InteractionBox; if (frame.Pointables.Extended().Count != 1) { return; } Pointable pointable = frame.Pointables.Extended()[0]; // InteractionBox を利用した座標変換 Leap.Vector normalizedPosition = interactionBox.NormalizePoint(pointable.StabilizedTipPosition); double tx = normalizedPosition.x * windowWidth; double ty = windowHeight - normalizedPosition.y * windowHeight; StylusPoint touchPoint = new StylusPoint(tx, ty); StylusPointCollection tips = new StylusPointCollection(new StylusPoint[] { touchPoint }); // タッチ状態 if (normalizedPosition.z <= TouchBorder) { Stroke touchStroke = new Stroke(tips, touchIndicator); this.InkCanvas_LeapPaintLine.Strokes.Add(touchStroke.Clone()); } }
/// <summary> /// /// </summary> /// <returns>A normalized coordinate to be multiplied with the actual width and height of the screen</returns> public float[] getCoordinate() { float[] coordinates = new float[2]; Frame frame = _controller.Frame(); if (!frame.Hands.IsEmpty) { // Get the first hand Hand hand = frame.Hands[0]; // Check if the hand has any fingers FingerList fingers = hand.Fingers; if (!fingers.IsEmpty) { // Calculate the hand's average finger tip position Vector avgPos = Vector.Zero; foreach (Finger finger in fingers) { avgPos += finger.TipPosition; } avgPos /= fingers.Count; InteractionBox iBox = _controller.Frame().InteractionBox; Vector normalizedPosition = iBox.NormalizePoint(avgPos); coordinates[0] = normalizedPosition.x; coordinates[1] = normalizedPosition.y; return(coordinates); } } return(null); }
Leap.Vector leapToWorld(Leap.Vector leapPoint, InteractionBox iBox) { leapPoint.z *= -1.0f; //right-hand to left-hand rule Leap.Vector normalized = iBox.NormalizePoint(leapPoint, false); normalized += new Leap.Vector(0.5f, 0f, 0.5f); //recenter origin return(normalized * 100.0f); //scale }
// Update is called once per frame void Update() { Frame frame = controller.Frame(); FingerCount = frame.Fingers.Count; //指が有効であればInteractionBoxオブジェクトを使ってLeapMotionの座標系をディスプレイ座標系に変換する InteractionBox interactionBox = frame.InteractionBox; Hand hand = frame.Hands.Rightmost; float strength = hand.GrabStrength; // Debug.Log (strength); for (int i = 0; i < FingerObjects.Length; i++) { var leapFinger = frame.Fingers[i]; var unityFinger = FingerObjects[i]; SetVisible(unityFinger, leapFinger.IsValid); if (leapFinger.IsValid) { Vector normalizedPosition = interactionBox.NormalizePoint(leapFinger.TipPosition); normalizedPosition *= 10; normalizedPosition.z = -normalizedPosition.z; unityFinger.transform.localPosition = ToVector3(normalizedPosition); } } }
protected void DrawLeapLine(Controller leap, Leap.Frame frame) { FingerList allFingers = frame.Fingers.Extended(); if (allFingers.Count != 2 || leap.Frame(10).Fingers.Extended().Count != 2) { return; } Finger finger1 = allFingers.Leftmost; Finger finger2 = allFingers.Rightmost; InteractionBox interactionBox = frame.InteractionBox; Leap.Vector normalizedPosition1 = interactionBox.NormalizePoint(finger1.StabilizedTipPosition); Leap.Vector normalizedPosition2 = interactionBox.NormalizePoint(finger2.StabilizedTipPosition); double tx1 = normalizedPosition1.x * windowWidth; double ty1 = windowHeight - normalizedPosition1.y * windowHeight; double tx2 = normalizedPosition2.x * windowWidth; double ty2 = windowHeight - normalizedPosition2.y * windowHeight; StylusPointCollection tips = new StylusPointCollection(); tips.Add(new StylusPoint(tx1, ty1)); tips.Add(new StylusPoint(tx2, ty2)); Stroke stroke = new Stroke(tips, lineIndicator); this.InkCanvas_LeapPaint.Strokes.Add(stroke); }
// Update is called once per frame void Update() { Frame frame = controller.Frame(); FingerList fingers = frame.Fingers; PointableList pointables = frame.Pointables; InteractionBox interactionBox = frame.InteractionBox; foreach (var pointable in frame.Pointables) { foreach (var finger in frame.Fingers) { Leap.Vector normalizedPosition = interactionBox.NormalizePoint(pointable.StabilizedTipPosition); float tx = normalizedPosition.x * UnityEngine.Screen.width; float ty = UnityEngine.Screen.height - normalizedPosition.y * UnityEngine.Screen.height; // 末端骨(指先の骨) var bone = finger.Bone(Bone.BoneType.TYPE_METACARPAL); if (finger.Type() == Finger.FingerType.TYPE_THUMB) { Debug.Log("tx : " + tx + " ty : " + ty + " 距離 : " + pointable.TouchDistance + " 種類 : " + bone.Type); } int alpha = 255; // ホバー状態 if (pointable.TouchDistance > 0 && pointable.TouchZone != Pointable.Zone.ZONENONE) { alpha = 255 - (int)(255 * pointable.TouchDistance); // touchIndicator.Color = Color.FromArgb((byte)alpha, 0x0, 0xff, 0x0); } } } }
//async void webSocketSetup() //{ // Debug.Log("Setting up websocket"); // w = new MessageWebSocket(); // //In this case we will be sending/receiving a string so we need to set the MessageType to Utf8. // w.Control.MessageType = SocketMessageType.Utf8; // //Add the MessageReceived event handler. // w.MessageReceived += WebSock_MessageReceived; // //Add the Closed event handler. // w.Closed += WebSock_Closed; // Uri serverUri = new Uri(WEBSOCKET_URI_REMOTE); // try // { // //Connect to the server. // Debug.Log("Before Connect to Server"); // await w.ConnectAsync(serverUri); // Debug.Log("Connect to Server"); // //Send a message to the server. // await WebSock_SendMessage(w, flag); // await WebSock_SendMessage(w, GET_FOCUS); // } // catch (Exception ex) // { // //Add code here to handle any exceptions // Debug.Log(ex.StackTrace); // } //} ////Send a message to the server. //private async Task WebSock_SendMessage(MessageWebSocket webSock, string message) //{ // DataWriter messageWriter = new DataWriter(webSock.OutputStream); // messageWriter.WriteString(message); // await messageWriter.StoreAsync(); //} //private void WebSock_Closed(IWebSocket sender, WebSocketClosedEventArgs args) //{ // IsConnected = true; // LeapHandController.SetActive(false); //} ////The MessageReceived event handler. //private void WebSock_MessageReceived(MessageWebSocket sender, MessageWebSocketMessageReceivedEventArgs args) //{ // DataReader messageReader = args.GetDataReader(); // res = messageReader.ReadString(messageReader.UnconsumedBufferLength); // Dictionary<string, object> frameData = (Dictionary<string, object>)Json.Deserialize(res); // Debug.Log(frameData); // if (frameData.ContainsKey("id")) // { // frame = createFrame(frameData); // if (IsConnected != true) // { // LeapHandController.SetActive(true); // IsConnected = true; // } // } //} private Frame createFrame(Dictionary <string, object> frameData) { long id = (long)frameData["id"]; //timestamp long timestamp = (long)frameData["timestamp"]; //FrameRate Double fps = (Double)frameData["currentFrameRate"]; //Interaction Box Object Dictionary <String, object> box = (Dictionary <String, object>)frameData["interactionBox"]; List <object> centerList = (List <object>)box["center"]; List <object> sizeList = (List <object>)box["size"]; Vector center = creatVector(centerList); Vector size = creatVector(sizeList); InteractionBox interactionBox = new InteractionBox(center, size); //HandObject List <object> handsobject = (List <object>)frameData["hands"]; List <Hand> hands = new List <Hand>(); List <object> pointables = (List <object>)frameData["pointables"]; foreach (var item in handsobject) { //Debug.Log(item); hands.Add(creatHand(id, item, pointables)); } return(new Frame(id, timestamp, (float)fps, interactionBox, hands)); }
public FrameData(long frameID, long frameTimeStamp, float frameFPS, InteractionBox frameIBox, List <Hand> frameHands) { id = frameID; timestamp = frameTimeStamp; fps = frameFPS; iBox = frameIBox; hands = frameHands; }
public static Vector3 leapVectorToWorld(Leap.Vector leapPoint, InteractionBox iBox) { Leap.Vector normalized = iBox.NormalizePoint(leapPoint, false); var v1 = new Vector3(UnityEngine.Screen.width / 2, UnityEngine.Screen.height / 2, Camera.main.nearClipPlane); Vector3 v = Camera.main.ScreenToWorldPoint(v1); normalized += new Leap.Vector(v.x, v.y, v.z); //recenter origin return(new Vector3(normalized.x, normalized.y, normalized.z)); }
Leap.Vector LeapToWorld(Leap.Vector lv) { lv.z *= 0.1f; InteractionBox iBox = frame.InteractionBox; Leap.Vector normalized = iBox.NormalizePoint(lv); normalized += new Leap.Vector(0, 0, 0); Debug.Log(normalized); return(normalized * leapToWorldMultiplier); }
void Update_old() { Frame frame = controller.Frame(); // controller is a Controller object InteractionBox iBox = frame.InteractionBox; if (frame.Hands.Count > 0) { List <Hand> hands = frame.Hands; Hand firstHand = hands [0]; transform.position = leapToWorld(firstHand.PalmPosition, iBox).ToVector3(); } }
void Hand() { InteractionBox iBox = controller.Frame().InteractionBox; frame = controller.Frame(); List <Hand> handlist = new List <Hand>(); for (int h = 0; h < frame.Hands.Count; h++) { Hand leapHand = frame.Hands[h]; handlist.Add(leapHand); } index = frame.Hands[0].Fingers[(int)Finger.FingerType.TYPE_INDEX]; if (index.IsExtended) { Vector fingPos = index.StabilizedTipPosition; Vector norm = iBox.NormalizePoint(fingPos, false); appX = norm.x * appWidth; appY = -1 * (1 - norm.y) * appHeight; imageX = t.transform.position.x; imageY = t.transform.position.y; ballX = ball.transform.position.x; ballY = ball.transform.position.y; float distanceX = ballX - imageX; float distanceY = ballY - imageY; if (Mathf.Abs(distanceX) < 50 && Mathf.Abs(distanceY) < 50) { //moveCheck = true; countBegining = 1; //ballX = imageX; //ballY = imageY; //ball.transform.position = t.transform.position; //ball.transform.parent = t.transform; } //if (Mathf.Abs (distanceX) < 100 && Mathf.Abs (distanceY) < 100) { //} Vector3 fPos = new Vector3(appX, appY); Plane objPlane = new Plane(Camera.main.transform.forward * -1, ball.transform.position); Ray mRay = Camera.main.ScreenPointToRay(fPos); float rayDistance; if (objPlane.Raycast(mRay, out rayDistance)) { ball.transform.position = mRay.GetPoint(rayDistance); float d = Vector3.Distance(t.transform.position, ball.transform.position); if (d < 50) { ball.transform.position = t.transform.position; GoodCount++; } } } }
protected void Update(object sender, EventArgs e) { paintCanvas.Strokes.Clear(); windowWidth = (float)this.Width; windowHeight = (float)this.Height; Frame frame = leap.Frame(); InteractionBox interactionBox = leap.Frame().InteractionBox; Debug.WriteLine("Count = " + leap.Frame().Pointables.Count); ioControl(leap.Frame().Pointables.Count); //String str = ""; //foreach (Pointable pointable in leap.Frame().Pointables) //{ // str = str + " " + pointable.Id; //} //Debug.WriteLine(str); foreach (Pointable pointable in leap.Frame().Pointables) { Leap.Vector normalizedPosition = interactionBox.NormalizePoint(pointable.StabilizedTipPosition); float tx = normalizedPosition.x * windowWidth; float ty = windowHeight - normalizedPosition.y * windowHeight; int alpha = 255; // ホバー状態 if (pointable.TouchDistance > 0 && pointable.TouchZone != Pointable.Zone.ZONENONE) { alpha = 255 - (int)(255 * pointable.TouchDistance); touchIndicator.Color = Color.FromArgb((byte)alpha, 0x0, 0xff, 0x0); } // タッチ状態 else if (pointable.TouchDistance <= 0) { alpha = -(int)(255 * pointable.TouchDistance); touchIndicator.Color = Color.FromArgb((byte)alpha, 0xff, 0x0, 0x0); } // タッチ対象外 else { alpha = 50; touchIndicator.Color = Color.FromArgb((byte)alpha, 0x0, 0x0, 0xff); } StylusPoint touchPoint = new StylusPoint(tx, ty); StylusPointCollection tips = new StylusPointCollection(new StylusPoint[] { touchPoint }); Stroke touchStroke = new Stroke(tips, touchIndicator); paintCanvas.Strokes.Add(touchStroke); } }
protected override bool OnItemDroppedOnInteractionBox(InteractionBox box, GameObject obj, HandManager hand) { if (relic == null) { return(false); } if (obj != relic.gameObject) { return(false); } if (!(box is BankAlter)) { return(false); } if (debug) { Debug.Log("PlayerRelicManager Client: Player relic dropped onto a bank alter."); } /* Get the bank alter */ BankAlter alter = (BankAlter)box; /* Is this alter occupied? */ if (alter.IsOccupied()) { if (debug) { Debug.LogWarning("PlayerRelicManager Client: This alter is occupied!"); } return(false); } /* Attempt to attach our relic to the bank alter */ if (!relic.ClientReattach(alter)) { Debug.LogError("PlayerRelicManager Client: Failed to attach relic to alter socket!"); return(false); } /* Open the relic in bank config */ if (!relic.ClientOpenBank()) { Debug.LogError("PlayerRelicManager Client: Failed to open relic in bank configuration!"); return(false); } /* We consumed this event */ return(true); }
// Merge frames from a list of frames public Frame mergeFrames(List <Frame> listOfFrames, long frameID) { List <Hand> listOfHands = new List <Hand>(); for (int i = 0; i < listOfFrames.Count; i++) { for (int j = 0; j < listOfFrames[i].Hands.Count; j++) { int newHandID = listOfFrames.Count * listOfFrames[i].Hands[j].Id + i; Hand newHand = changeHandID(listOfFrames[i].Hands[j], frameID, newHandID); listOfHands.Add(newHand); } } float minX = 10000000, minY = 10000000, minZ = 10000000, maxX = -1, maxY = -1, maxZ = -1; for (int i = 0; i < listOfFrames.Count; i++) { minX = Math.Min(minX, listOfFrames[i].InteractionBox.Center.x - listOfFrames[i].InteractionBox.Width / 2); minY = Math.Min(minY, listOfFrames[i].InteractionBox.Center.y - listOfFrames[i].InteractionBox.Height / 2); minZ = Math.Min(minZ, listOfFrames[i].InteractionBox.Center.z - listOfFrames[i].InteractionBox.Depth / 2); maxX = Math.Max(maxX, listOfFrames[i].InteractionBox.Center.x - listOfFrames[i].InteractionBox.Width / 2); maxY = Math.Max(maxY, listOfFrames[i].InteractionBox.Center.y - listOfFrames[i].InteractionBox.Height / 2); maxZ = Math.Max(maxZ, listOfFrames[i].InteractionBox.Center.z - listOfFrames[i].InteractionBox.Depth / 2); } Vector newSize = new Vector(maxX - minX, maxY - minY, maxZ - minZ); InteractionBox newBox = new InteractionBox(listOfFrames[0].InteractionBox.Center, newSize); long newTimeStamp = listOfFrames[0].Timestamp; for (int i = 1; i < listOfFrames.Count; i++) { newTimeStamp = Math.Max(newTimeStamp, listOfFrames[i].Timestamp); } Frame mergedFrame = new Frame(frameID, newTimeStamp, listOfFrames[0].CurrentFramesPerSecond, newBox, listOfHands); return(mergedFrame); }
public Point toScreenCoor(Leap.Vector LVector) { ibox = controller.Frame().InteractionBox; Leap.Vector normalizedPoint = ibox.NormalizePoint(LVector, true); float appX = normalizedPoint.x * (float)(Image.Width); float appY = (1 - normalizedPoint.y) * (float)(Image.Height); float appX2 = LVector.x; float appY2 = LVector.y; return(new Point(appX, appY)); // return new Point(appX2, appY2); }
protected void Update(object sender, EventArgs e) { paintCanvas.Strokes.Clear(); windowWidth = (float)this.Width; windowHeight = (float)this.Height; Frame frame = leap.Frame(); InteractionBox interactionBox = leap.Frame().InteractionBox; foreach (Pointable pointable in leap.Frame().Pointables) { // InteractionBox を利用した座標変換 Leap.Vector normalizedPosition = interactionBox.NormalizePoint(pointable.StabilizedTipPosition); // Intersect Point を利用した座標変換 //Leap.Vector normalizedPosition = locatedScreen.Intersect( pointable, true ); // Projection Point を利用した座標変換 //Leap.Vector normalizedPosition = locatedScreen.Project( pointable.TipPosition, false ); float tx = normalizedPosition.x * windowWidth; float ty = windowHeight - normalizedPosition.y * windowHeight; int alpha = 255; // ホバー状態 if (pointable.TouchDistance > 0 && pointable.TouchZone != Pointable.Zone.ZONENONE) { alpha = 255 - (int)(255 * pointable.TouchDistance); touchIndicator.Color = Color.FromArgb((byte)alpha, 0x0, 0xff, 0x0); } // タッチ状態 else if (pointable.TouchDistance <= 0) { alpha = -(int)(255 * pointable.TouchDistance); touchIndicator.Color = Color.FromArgb((byte)alpha, 0xff, 0x0, 0x0); } // タッチ対象外 else { alpha = 50; touchIndicator.Color = Color.FromArgb((byte)alpha, 0x0, 0x0, 0xff); } StylusPoint touchPoint = new StylusPoint(tx, ty); StylusPointCollection tips = new StylusPointCollection(new StylusPoint[] { touchPoint }); Stroke touchStroke = new Stroke(tips, touchIndicator); paintCanvas.Strokes.Add(touchStroke); } }
void Update() { if (collisionFlag && collisionCounter > 0) { collisionCounter--; } Frame frame = controller.Frame(); FingerCount = frame.Fingers.Count; InteractionBox interactionBox = frame.InteractionBox; for (int i = 0; i < FingerObjects.Length; i++) { var leapFinger = frame.Fingers[i]; var unityFinger = FingerObjects[i]; SetVisible(unityFinger, leapFinger.IsValid); if (leapFinger.IsValid) { Vector normalizedPosition = interactionBox.NormalizePoint(leapFinger.TipPosition); normalizedPosition *= 10; //normalizedPosition.z = -normalizedPosition.z; //オキュラス合体用座標変換 float theta = 2 * Mathf.PI / 8; normalizedPosition.y = -normalizedPosition.y; float Y = Mathf.Cos(theta) * normalizedPosition.y - Mathf.Sin(theta) * normalizedPosition.z; float Z = Mathf.Sin(theta) * normalizedPosition.y + Mathf.Cos(theta) * normalizedPosition.z; normalizedPosition.x = -normalizedPosition.x; normalizedPosition.z = Z; GameObject v = GameObject.Find("OVRCameraController"); float beta = 2 * Mathf.PI * (v.transform.eulerAngles.y + 70) / 360; float X = Mathf.Cos(beta) * normalizedPosition.x - Mathf.Sin(beta) * normalizedPosition.z; Z = Mathf.Sin(beta) * normalizedPosition.x + Mathf.Cos(beta) * normalizedPosition.z; normalizedPosition.x = X; normalizedPosition.y = Y + 8; normalizedPosition.z = -Z; //合体用終了 unityFinger.transform.position = ToVector3(normalizedPosition); } } }
protected void Update(object sender, EventArgs e) { paintCanvas.Strokes.Clear(); windowWidth = (float)this.Width; windowHeight = (float)this.Height; Leap.Frame frame = leap.Frame(); InteractionBox interactionBox = leap.Frame().InteractionBox; try { Leap.Image image = frame.Images[0]; this.DrawRawImages_WriteableBitmap(image.Data, image.Width, image.Height); } catch { } foreach (Pointable pointable in leap.Frame().Pointables) { Finger oFinger = new Finger(pointable); Leap.Vector normalizedPosition = interactionBox.NormalizePoint(pointable.StabilizedTipPosition); float tx = normalizedPosition.x * windowWidth; float ty = windowHeight - normalizedPosition.y * windowHeight; int alpha = 255; if (pointable.TouchDistance > 0 && pointable.TouchZone != Pointable.Zone.ZONENONE) { alpha = 255 - (int)(255 * pointable.TouchDistance); touchIndicator.Color = Color.FromArgb((byte)alpha, 0x0, 0xff, 0x0); } else if (pointable.TouchDistance <= 0) { alpha = -(int)(255 * pointable.TouchDistance); touchIndicator.Color = Color.FromArgb((byte)alpha, 0xff, 0x0, 0x0); } else { alpha = 50; touchIndicator.Color = Color.FromArgb((byte)alpha, 0x0, 0x0, 0xff); } StylusPoint touchPoint = new StylusPoint(tx, ty); StylusPointCollection tips = new StylusPointCollection(new StylusPoint[] { touchPoint }); Stroke touchStroke = new Stroke(tips, touchIndicator); paintCanvas.Strokes.Add(touchStroke); } }
//This is the main method for parsing the data returned from the framedata. private Frame createFrame(Dictionary <string, object> frameData) { long id = (long)frameData["id"]; //timestamp long timestamp = (long)frameData["timestamp"]; //FrameRate Double fps = (Double)frameData["currentFrameRate"]; //Interaction Box Object Dictionary <String, object> box = (Dictionary <String, object>)frameData["interactionBox"]; List <object> centerList = (List <object>)box["center"]; List <object> sizeList = (List <object>)box["size"]; Vector center = creatVector(centerList); Vector size = creatVector(sizeList); InteractionBox interactionBox = new InteractionBox(center, size); //HandObject List <object> handsobject = (List <object>)frameData["hands"]; List <Hand> hands = new List <Hand>(); //Creating the hands objects. List <object> pointables = (List <object>)frameData["pointables"]; if (handsobject.Count == 1) { //If there is one hand hasHand = true; hands.Add(creatHand(id, handsobject[0], pointables)); } else if (handsobject.Count == 2) { // If there are two hands hasHand = true; hands.Add(creatHand(id, handsobject[0], pointables.GetRange(0, 5))); hands.Add(creatHand(id, handsobject[1], pointables.GetRange(5, 5))); } else { hasHand = false; } return(new Frame(id, timestamp, (float)fps, interactionBox, hands)); }
public override void UpdateHand() { if (palm != null) { palm.position = GetPalmPosition(); palm.rotation = GetPalmRotation() * Reorientation(); InteractionBox interactionBox = controller_.GetFrame().InteractionBox; int count = 0; foreach (Finger finger in controller_.GetFrame().Hands[0].Fingers) { if (finger.IsExtended) { count++; } } if (count == 0) { Vector normalPoint = interactionBox.NormalizePoint(controller_.GetFrame().Hands[0].PalmPosition); if (normalPoint.y > 0.75f) { GameObject canvasCube = GameObject.Find("EaselCube"); //print(canvasCube.transform.position); } } //print(controller_.GetFrame().Hands[0].Fingers[0].TipPosition); RaycastHit rayHit; if (Physics.Raycast(controller_.transform.TransformPoint(controller_.GetFrame().Hands[0].Fingers[0].TipPosition.ToUnityScaled()), controller_.transform.TransformDirection(controller_.GetFrame().Hands[0].Fingers[0].Direction.ToUnity()), out rayHit)) { UnityStandardAssets.Characters.FirstPerson.HandleInput.drawBrush(rayHit); } } if (forearm != null) { forearm.rotation = GetArmRotation() * Reorientation(); } for (int i = 0; i < fingers.Length; ++i) { if (fingers[i] != null) { fingers[i].fingerType = (Finger.FingerType)i; fingers[i].UpdateFinger(); } } }
protected void Update(object sender, EventArgs e) { paintCanvas.Strokes.Clear(); windowWidth = (float)this.Width; windowHeight = (float)this.Height; Leap.Frame frame = leap.Frame(); InteractionBox interactionBox = leap.Frame().InteractionBox; foreach (Pointable pointable in leap.Frame().Pointables) { // ここから追加 // 伸びている指、ツール以外は無視する //if ( !pointable.IsExtended ) { // continue; //} // ここまで追加 Leap.Vector normalizedPosition = interactionBox.NormalizePoint(pointable.StabilizedTipPosition); float tx = normalizedPosition.x * windowWidth; float ty = windowHeight - normalizedPosition.y * windowHeight; int alpha = 255; if ((pointable.TouchDistance > 0 && pointable.TouchZone != Pointable.Zone.ZONENONE)) { alpha = 255 - (int)(255 * pointable.TouchDistance); touchIndicator.Color = Color.FromArgb((byte)alpha, 0x0, 0xff, 0x0); } else if (pointable.TouchDistance <= 0) { alpha = -(int)(255 * pointable.TouchDistance); touchIndicator.Color = Color.FromArgb((byte)alpha, 0xff, 0x0, 0x0); } else { alpha = 50; touchIndicator.Color = Color.FromArgb((byte)alpha, 0x0, 0x0, 0xff); } StylusPoint touchPoint = new StylusPoint(tx, ty); StylusPointCollection tips = new StylusPointCollection(new StylusPoint[] { touchPoint }); Stroke touchStroke = new Stroke(tips, touchIndicator); paintCanvas.Strokes.Add(touchStroke); } }
void Update() { frame = controller.Frame(); interactionBox = frame.InteractionBox; Hand hand = frame.Hands[0]; plamCount = frame.Hands.Count; debugFingerCount = frame.Fingers.Count; Vector plamPos = interactionBox.NormalizePoint(hand.PalmPosition); int scale = 4; //感知する領域を広げる x = scale * (plamPos.x - 0.5f); y = 7 * plamPos.y; z = scale * (plamPos.z - 0.5f); if (plamCount <= 1) //片手の場合 { if (hand.IsValid == false && existPlamFlag) { existPlamFlag = false; Destroy(plam); } if (!existPlamFlag) { if (hand.IsValid) { existPlamFlag = true; plam = (GameObject)Instantiate(Resources.Load("Title/Plam"), ToVector3(new Vector(x, y, -z)), Quaternion.identity); plam.transform.SetParent(GameObject.Find("MainCamera/LeapPos").transform); plam.GetComponent <Renderer>().enabled = hand.IsValid; plam.GetComponent <Collider>().enabled = hand.IsValid; } } else { plam.transform.localPosition = ToVector3(new Vector(x, y, -z)); } HoldDecision(hand); } else if (plamCount >= 2) //両手の場合 { existPlamFlag = false; Destroy(plam); BothHandsGesture(); } }
// Update is called once per frame void Update() { Frame f = m_leapController.Frame(); Hand h = GetFrontHand(f); if (h == null) { return; } InteractionBox box = f.InteractionBox; Vector3 handPos = h.PalmPosition.ToUnityScaled(); transform.position = handPos; RaycastHit hit; Vector3 screenPos = Camera.main.WorldToScreenPoint(transform.position); screenPos.z = 0.0f; Ray r = Camera.main.ScreenPointToRay(screenPos); GameObject [] items = GameObject.FindGameObjectsWithTag("Item"); for (int i = 0; i < items.Length; ++i) { if (items[i] == m_selectedObject) { items[i].renderer.material.color = m_selected; } else { items[i].renderer.material.color = m_hover; } } if (Physics.Raycast(r, out hit)) { if (hit.collider.tag == "Item") { if (h.PinchStrength > 0.6f) { m_selectedObject = hit.collider.gameObject; } } } }
private void DrawFingerBones(Leap.Finger oFinger, InteractionBox interactionBox, DrawingContext drawingContext) { Bone bone; foreach (Bone.BoneType boneType in (Bone.BoneType[])Enum.GetValues(typeof(Bone.BoneType))) { bone = oFinger.Bone(boneType); Leap.Vector startPosition = interactionBox.NormalizePoint(bone.PrevJoint); Leap.Vector endPosition = interactionBox.NormalizePoint(bone.NextJoint); Point posStart = this.ToScreen(startPosition); Point posEnd = this.ToScreen(endPosition); double dX1 = posStart.X; double dY1 = posStart.Y; double dX2 = posEnd.X; double dY2 = posEnd.Y; drawingContext.DrawLine(new Pen() { Brush = new SolidColorBrush(Colors.Blue), Thickness = 1 }, new Point(dX1, dY1), new Point(dX2, dY2)); Pen oPen = new Pen(); if (boneType == Bone.BoneType.TYPE_PROXIMAL) { drawingContext.DrawEllipse(new SolidColorBrush(Colors.Gold), oPen, new Point(dX1, dY1), 6, 6); } else if (boneType == Bone.BoneType.TYPE_METACARPAL) { drawingContext.DrawEllipse(new SolidColorBrush(Colors.Black), oPen, new Point(dX1, dY1), 6, 6); } else if (boneType == Bone.BoneType.TYPE_INTERMEDIATE) { drawingContext.DrawEllipse(new SolidColorBrush(Colors.DarkGreen), oPen, new Point(dX1, dY1), 6, 6); } else if (boneType == Bone.BoneType.TYPE_DISTAL) { drawingContext.DrawEllipse(new SolidColorBrush(Colors.Red), oPen, new Point(dX1, dY1), 6, 6); drawingContext.DrawEllipse(new SolidColorBrush(Colors.Red), oPen, new Point(dX2, dY2), 12, 12); } } }