public void Bebop2_OnSpeedChanged(Bebop2 bebop2, Leap.Vector speed) { this.droneSpeedLabel.Invoke(new MethodInvoker(delegate() { this.droneSpeedLabel.Text = string.Format("{0:F2}m/s", speed.MagnitudeSquared); })); }
void AnalyzeBounds(Leap.Vector position) { if (position.x < leftMostX) { leftMostX = position.x; } if (position.y > topMostY) { topMostY = position.y; } if (position.x > rightMostX) { rightMostX = position.x; } if (position.y < bottomMostY) { bottomMostY = position.y; } if (position.z < forwardMostZ) { forwardMostZ = position.z; } if (position.z > backMostZ) { backMostZ = position.z; } }
public void Vector_ints() { Vector thisVector = new Leap.Vector(1, 2, 3); Vector thatVector = new Leap.Vector(1, 2, 3); Assert.True(thisVector.Equals(thatVector), "this.Equals(that) Vector"); //Assert.True (thisVector == thatVector, "this == that Vector"); }
public void Vector_floats() { Vector thisVector = new Leap.Vector(1.111111111111111f, 2.222222222222222f, 3.333333333333333f); Vector thatVector = new Leap.Vector(1.111111111111111f, 2.222222222222222f, 3.333333333333333f); Assert.True(thisVector.Equals(thatVector), "this.Equals(that) Vector"); //Assert.True (thisVector == thatVector, "this == that Vector"); }
public static Leap.Vector RoundToInt(Leap.Vector vector) { int x = Mathf.RoundToInt(vector.x); int y = Mathf.RoundToInt(vector.y); int z = Mathf.RoundToInt(vector.z); return(new Leap.Vector(x, y, z)); }
Vector3 leapToUnity(Leap.Vector v) { Vector3 result = new Vector3(0, 0, 0); result.x = -v.x; result.y = -v.z; result.z = -v.y; return(result); }
public Quaternion QuatrnionBetweenTwoVectors(Leap.Vector v1, Leap.Vector v2) { var v1n = v1.Normalized; var v2n = v2.Normalized; var angle = (float)Math.Acos(v1n.Dot(v2n)); var axis = v1n.Cross(v2n).Normalized; return(Quaternion.FromAxisAngle(new Vector3(-axis.x, axis.y, axis.z), angle)); }
Point GetCanvasPosition(Leap.Vector position) { float percentageX = (position.x - leftMostX) / (rightMostX - leftMostX); float percentageY = (position.y - topMostY) / (bottomMostY - topMostY); float newX = (float)(percentageX * myCanvas.ActualWidth); float newY = (float)(percentageY * myCanvas.ActualHeight); return(new Point(newX, newY)); }
//public void UpdateFingerState(Leap.Vector vecterFingerTip, Leap.Vector vecterPalm, Leap.Finger oFinger) //{ // double dInterval = this.GetVecterDistance(vecterFingerTip, vecterPalm); // if (Max == 0) // { // Max = dInterval; // return; // } // if (dInterval > Max) // { // Max = dInterval; // } // if (dInterval < Sensitive) // { // Sensitive = dInterval; // } // if (dInterval < Sensitive) // dInterval = Sensitive; // double dPercent = (dInterval - Sensitive) / (this.Max - Sensitive); // double dScale = 1 - 0.5 * dPercent; // this.ScaleX = dScale; // this.ScaleY = dScale; //} public void UpdateFingerState(Leap.Vector vecterFingerTip, Leap.Vector vecterPalm, Leap.Finger oFinger) { if (oFinger.Type != Leap.Finger.FingerType.TYPE_THUMB) { double angle = (180 - (oFinger.Hand.Direction.AngleTo(oFinger.Direction) / Math.PI) * 180); if (this.Max == 0) { this.Max = angle; return; } if (angle > this.Max) { this.Max = angle; } if (angle < this.Min) { this.Min = angle; } double dAngleDeviation = 30d * (1 - angle / 180d); double dPercent = (angle - dAngleDeviation - this.Min) / (this.Max - this.Min); double dScale = 1 - 0.5 * dPercent; this.ScaleX = dScale; this.ScaleY = dScale; } else if (oFinger.Type == Leap.Finger.FingerType.TYPE_THUMB) { Leap.Bone bone1 = oFinger.Bone(Leap.Bone.BoneType.TYPE_DISTAL); Leap.Bone bone2 = oFinger.Bone(Leap.Bone.BoneType.TYPE_PROXIMAL); double angle = (180 - (bone1.Direction.AngleTo(bone2.Direction) / Math.PI) * 180); if (this.Max == 0) { this.Max = angle; return; } if (angle > this.Max) { this.Max = angle; } if (angle < this.Min) { this.Min = angle; } double dAngleDeviation = (this.Max - this.Min) * (1 - angle / 180d); double dPercent = (angle - dAngleDeviation - this.Min) / (this.Max - this.Min); double dScale = 1 - 0.5 * dPercent; this.ScaleX = dScale; this.ScaleY = dScale; } }
Vector3 leapVectorToWorld(Leap.Vector v) { Matrix4x4 m = camera.cameraToWorldMatrix; //Vector4 camori = m * new Vector4 (0, 0, 0, 1); Vector3 temp = leapToUnity(v); Vector4 cameravec = m * new Vector4(temp.x, temp.y, temp.z, 0); Vector3 res = new Vector3(cameravec[0], cameravec[1], cameravec[2]); return(res); }
Vector3 leapToWorld(Leap.Vector v) { Matrix4x4 m = camera.cameraToWorldMatrix; Vector3 temp = leapToUnity(v) / 1000.0f; Vector4 cameravec = m * new Vector4(temp.x, temp.y, temp.z, 0); Vector3 res = new Vector3(cameravec[0], cameravec[1], cameravec[2]); res = res + leaporigin; return(res); }
public Vector(Leap.Vector vector) { x = vector.x; y = vector.y; z = vector.z; Pitch = vector.Pitch; Roll = vector.Roll; Yaw = vector.Yaw; Magnitude = vector.Magnitude; MagnitudeSquared = vector.MagnitudeSquared; }
/// <summary> /// Converts by flipping across the Z axis and scaling from mm to m. /// </summary> protected Vector3 LeapToUnityVector(Leap.Vector leapVector) { // convert the raw structure Vector3 unityVector = Leap.Unity.UnityVectorExtension.ToVector3(leapVector); // scale unityVector *= MM_TO_M; // flip over Z unityVector = Vector3.Scale(unityVector, FLIP_Z_AXIS); return(unityVector); }
void UpdateLights() { if (DateTime.Now - LastLightUpdateTime < TimeSpan.FromMilliseconds(MinTimeBetweenUpdatesMs)) { return; } Leap.Vector markPosition = new Leap.Vector(-20.2903f, 445.1746f, 423.4169f); lock (skeletalData2d.world.worldLock) foreach (Hand2d hand2D in skeletalData2d.Hands) { Leap.Vector lightPosition = skeletalData2d.GetLightPosition(hand2D); if (lightPosition != null) { double deltaX = lightPosition.x - markPosition.x; double deltaY = lightPosition.y - markPosition.y; double deltaZ = lightPosition.z - markPosition.z; double distance = Math.Round(Math.Sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ)); // Pythagorean theorem in 3D: // <formula 2; distance = \sqrt{deltaX^2 + deltaY^2 + deltaZ^2}> const int minDistance = 100; const int maxDistance = 350; distance = Math.Max(minDistance, distance); distance = Math.Min(maxDistance, distance); double brightnessMultiplier = 1 - (distance - minDistance) / (maxDistance - minDistance); brightnessMultiplier = Math.Ceiling(5 * brightnessMultiplier) / 5; // isolate to 0.2, 0.4, 0.6, // 250 to about 100 brightnessMultiplier = Math.Max(0.2, brightnessMultiplier); int hueShift = GetHueShiftFromHand(hand2D); if (lightPosition.x < markPosition.x) { ChangeLeftBulbSettings(hueShift, brightnessMultiplier); } else { ChangeRightBulbSettings(hueShift, brightnessMultiplier); } // System.Diagnostics.Debug.WriteLine($"({lightPosition.x}, {lightPosition.y}, {lightPosition.z})"); } } LastLightUpdateTime = DateTime.Now; }
void HandleMouse() { while (_mThreadRunning) { Leap.Vector pointerPos = _gestureMap.PointerPosition; System.Drawing.Rectangle screen = System.Windows.Forms.Screen.PrimaryScreen.Bounds; if (pointerPos.z < 0.1) { System.Drawing.Point pos = new System.Drawing.Point((int)(pointerPos.x * screen.Width), (int)((1 - pointerPos.y) * screen.Height)); Thread.Sleep(5); System.Windows.Forms.Cursor.Position = pos; } } }
public static Leap.Vector RoundToDec(Leap.Vector vector, int decimalPlaces) { int xSz = CountDigitsAfterDecimal(vector.x); int ySz = CountDigitsAfterDecimal(vector.y); int zSz = CountDigitsAfterDecimal(vector.z); //xRounded; float xRounded = xSz - decimalPlaces != 0 ? vector.x * xSz / (xSz - decimalPlaces) : 0; //float yRounded = vector.y * ySz / (ySz-decimalPlaces); //float zRounded = vector.z * zSz / (zSz-decimalPlaces); //discover number of decimal places //multiply by number of decimal places, then divide by that same number minus 2 Leap.Vector vectorRounded = new Leap.Vector(xRounded, xRounded, xRounded); return(vectorRounded); }
private void SendFrame(object source, ElapsedEventArgs e) { if (sbm.GetConnectedStatus()) { SyrusPacket pak = new SyrusPacket(); pak.id = 20; Dispatcher.BeginInvoke(new Action(() => { Leap.Vector v = lpm.GetHandPosition(); Text.Text = "X: " + v.x + " Y: " + v.y + " Z: " + v.z; }), DispatcherPriority.SystemIdle); byte[] arr = lpm.getFrameInfo(); pak.data = arr; pak.n = (byte)pak.data.Length; sbm.SendPacket(pak); } }
public bool GetTargetPoint(Leap.Vector start, Leap.Vector direction, out int x, out int y) { var planeNormal = new Leap.Vector(0, 0, 1); var aPointInPlane = new Leap.Vector(0, 0, 0); start.z += leapOffsetZ_; start.y += leapOffsetY_; start.x += leapOffsetX_; double epsilon = 1e-8; float denom = direction.Dot(planeNormal); if (Math.Abs(denom) < epsilon) { x = 0; y = 0; return(false); } var diff = new Leap.Vector(aPointInPlane.x - start.x, aPointInPlane.y - start.y, aPointInPlane.z - start.z); float distance = diff.Dot(planeNormal) / denom; var v2 = new Leap.Vector(distance * direction.x + start.x, distance * direction.y + start.y, distance * direction.z + start.z); float width = 475; float height = 270; float halfWidth = width / 2; float halfHeight = height / 2; x = millimeterToPixel(v2.x + halfWidth); y = millimeterToPixel(height - v2.y); return(true); }
public LEAP_VECTOR(Leap.Vector leap) { x = leap.x; y = leap.y; z = leap.z; }
public static Vector3 getVector3(Leap.Vector vectorUnity) { Vector3 vectorLeap = new Vector3(vectorUnity.x, vectorUnity.y, vectorUnity.z); return(vectorLeap); }
/// <summary> /// Converts by flipping but not scaling. /// </summary> protected Vector3 LeapToUnityNormal(Leap.Vector leapVector) { Vector3 unityVector = Leap.Unity.UnityVectorExtension.ToVector3(leapVector); return(Vector3.Scale(unityVector, FLIP_Z_AXIS)); }
public static DxLibDLL.DX.VECTOR ToDX(this Leap.Vector vec) { return(DxLibDLL.DX.VGet(vec.x * 1, vec.y * 1, -vec.z * 1)); }
public override Value Evaluate(FSharpList<Value> args) { Leap.Frame frame = (Leap.Frame)((Value.Container)args[0]).Item; if (frame == null) throw new Exception("No Leap Frame."); // Age is optional; Defaults to 1 int age = 1; if (args.Length > 1 && args[1].IsNumber) { age = (int)((Value.Number)args[1]).Item; if (age < 0) throw new Exception("Leap Frame Age must be >= 0"); } Leap.Controller controller = dynLeapController.Controller; if (controller == null) throw new Exception("No Leap Controller node."); Leap.Vector v; Leap.Frame sinceFrame = controller.Frame(age); if (sinceFrame != null && sinceFrame.IsValid) v = frame.Translation(sinceFrame); else v = new Leap.Vector(); return Value.NewContainer(new XYZ(v.x, v.y, v.z)); }
public static void Convert(this Leap.Vector p_src, ref GlmSharp.vec3 p_dst) { p_dst.x = p_src.x; p_dst.y = p_src.y; p_dst.z = p_src.z; }
void CompositionTarget_Rendering( object sender, EventArgs e ) { // 最新のフレームを取得する var frame = leap.Frame(); // カメラ画像を取得する var images = frame.Images; if ( images.Count == 0 ) { return; } // 画像データをビットマップにする var left = images[0]; ImageLeap.Source = BitmapSource.Create( left.Width, left.Height, 96, 96, PixelFormats.Gray8, null, left.Data, left.Width ); CanvasFinger.Children.Clear(); // 右手を探す var hand = frame.Hands.FirstOrDefault( h => h.IsRight ); if ( hand ==null ) { isPinch = isGrab = false; return; } // 手と指の位置を取得する var handPosition = GetFingerPositionForRawImage( left, hand.StabilizedPalmPosition ); var fingers = GetFingerPositionForRawImage( left, hand.Fingers ); // 手と指の位置を描画する AddEllipse( left, handPosition, 30 ); foreach ( var finger in fingers ) { AddEllipse( left, finger, 10 ); } // グラブ if ( hand.GrabStrength >= 0.95 ) { ProcessGrab( handPosition ); // 手の座標を保存する prevPosition = handPosition; } // ピンチ else if ( hand.PinchStrength >= 0.95 ) { // 親指を探す var finger = hand.Fingers.FirstOrDefault( f => f.Type() == Leap.Finger.FingerType.TYPE_THUMB ); if ( finger == null ) { isPinch = false; return; } // 指の座標をカメラ画像に合わせる var fingerPosition = GetFingerPositionForRawImage( left, finger.StabilizedTipPosition ); // ピンチ処理 ProcessPinch( fingerPosition ); // 指の座標を保存する prevPosition = fingerPosition; } else { isPinch = isGrab = false; } }
public static Vector ToSerialiableVector(this Leap.Vector vector) { return(new Vector(vector.x, vector.y, vector.z)); }
public static Vector3D ToVector3D(this Leap.Vector v) => new Vector3D(v.x, v.y, v.z);
public override void OnFrame(Leap.Controller controller) { Leap.Frame frame = controller.Frame(); Leap.InteractionBox interactionBox = frame.InteractionBox; _pointerPosition = interactionBox.NormalizePoint(frame.Pointables.Frontmost.TipPosition); _standardGestures = frame.Gestures(); foreach (Leap.Gesture gesture in _standardGestures) { if (gesture.State.Equals(Leap.Gesture.GestureState.STATESTOP)) { if (gesture.Type.Equals(Leap.Gesture.GestureType.TYPESWIPE)) { Print("Finger Swipe Detected"); Leap.SwipeGesture swipe = new Leap.SwipeGesture(gesture); Events.FingerSwipeEvent swipeEvent = new Events.FingerSwipeEvent(swipe); OnFingerSwipeDetected(swipeEvent); } if (gesture.Type.Equals(Leap.Gesture.GestureType.TYPE_CIRCLE)) { Print("Circle Gesture Detected"); Leap.CircleGesture circle = new Leap.CircleGesture(gesture); Events.CircleEvent circleEvent = new Events.CircleEvent(circle); OnCircleDetected(circleEvent); } if (gesture.Type.Equals(Leap.Gesture.GestureType.TYPE_SCREEN_TAP)) { Print("Screen Tap Detected"); Leap.ScreenTapGesture screenTap = new Leap.ScreenTapGesture(gesture); Events.ScreenTapEvent screenTapEvent = new Events.ScreenTapEvent(screenTap); OnScreenTapDetected(screenTapEvent); } } } Gestures.HandSwipe handSwipe = Gestures.HandSwipe.IsHandSwipe(frame); if (handSwipe != null) { if (handSwipe.State.Equals(Gestures.GestureState.END)) { Print("Hand Swipe Detected"); Events.HandSwipeEvent swipeEvent = new Events.HandSwipeEvent(handSwipe); OnHandSwipeDetected(swipeEvent); } } Gestures.ZoomIn zoomIn = Gestures.ZoomIn.IsZoomIn(frame); if (zoomIn != null) { if (zoomIn.State.Equals(Gestures.GestureState.END)) { Print("ZoomIn Detected"); Events.ZoomInEvent zoomInEvent = new Events.ZoomInEvent(zoomIn); OnZoomInDetected(zoomInEvent); } } Gestures.ZoomOut zoomOut = Gestures.ZoomOut.IsZoomOut(frame); if (zoomOut != null) { if (zoomOut.State.Equals(Gestures.GestureState.END)) { Print("ZoomOut Detected"); Events.ZoomOutEvent zoomOutEvent = new Events.ZoomOutEvent(zoomOut); OnZoomOutDetected(zoomOutEvent); } } }
private double GetVecterDistance(Leap.Vector vecter1, Leap.Vector vecter2) { return(Math.Sqrt((vecter1.x - vecter2.x) * (vecter1.x - vecter2.x) + (vecter1.y - vecter2.y) * (vecter1.y - vecter2.y) + (vecter1.z - vecter2.z) * (vecter1.z - vecter2.z))); }