示例#1
0
        private void PollLeap()
        {
            Task.Factory.StartNew(async() =>
            {
                while (true)
                {
                    await Task.Delay(100);

                    var frame = LeapHardware.LeapController.Frame();

                    if (frame.Fingers.Count > 0 && frame.Hands.Count > 0 && frame.IsValid)
                    {
                        if (!LeapHardware.RequestMovement)
                        {
                            RequestSetMovement(true);
                        }

                        LeapHardware.RequestMovement = true;

                        HandList hands = frame.Hands;

                        var leftmost  = hands.FirstOrDefault(h => h.IsLeft);
                        var rightmost = hands.FirstOrDefault(h => h.IsRight);

                        //var travelDirection = rightmost?.Direction;

                        //Debug.WriteLine($"Direction {travelDirection}");

                        if (rightmost != null)
                        {
                            var asdf = rightmost.Fingers[0].Type;

                            float pitch = rightmost.PalmNormal.Pitch;
                            float yaw   = rightmost.Direction.Yaw;
                            float roll  = rightmost.PalmNormal.Roll;

                            //Debug.WriteLine("-----------------------------");

                            //Debug.WriteLine($"Pitch {pitch}");

                            if (pitch < minPitch)
                            {
                                minPitch = pitch;
                                Debug.WriteLine($"min pitch {minPitch}");
                            }

                            if (pitch > maxPitch)
                            {
                                maxPitch = pitch;
                                Debug.WriteLine($"max pitch {maxPitch}");
                            }

                            if (roll < minRoll)
                            {
                                minRoll = roll;
                                Debug.WriteLine($"min roll {minRoll}");
                            }

                            if (roll > maxRoll)
                            {
                                maxRoll = roll;
                                Debug.WriteLine($"max roll {maxRoll}");
                            }

                            if (yaw < minYaw)
                            {
                                minYaw = yaw;
                                Debug.WriteLine($"min yaw {minYaw}");
                            }

                            if (yaw > maxYaw)
                            {
                                maxYaw = yaw;
                                Debug.WriteLine($"max yaw {maxYaw}");
                            }

                            //Debug.WriteLine($"Yaw {yaw}");
                            //Debug.WriteLine($"Roll {roll}");

                            var mPitch = Map(pitch, minPitch, maxPitch, -6, 6);
                            var mYaw   = Map(yaw, minYaw, maxYaw, -6, 6);
                            var mRoll  = Map(roll, minRoll, maxRoll, -6, 6);

                            Debug.WriteLine($"Mapped yaw {mYaw}");
                            Debug.WriteLine($"Mapped pitch {mPitch}");
                            Debug.WriteLine($"Mapped roll {mRoll}");
                        }
                    }
                    else
                    {
                        LeapHardware.RequestMovement = false;
                        RequestSetMovement(false);
                    }
                }
            });
        }
示例#2
0
        public override void OnFrame(Controller controller)
        {
            var frame = controller.Frame();

            if (frame.Fingers.Count > 0 && frame.Hands.Count > 0 && frame.IsValid)
            {
                if (!isEnabled)
                {
                    _requestSetMovement(true);
                }

                isEnabled = true;

                HandList hands = frame.Hands;

                var leftmost  = hands.FirstOrDefault(h => h.IsLeft);
                var rightmost = hands.FirstOrDefault(h => h.IsRight);

                var travelDirection = rightmost?.Direction;

                //Debug.WriteLine($"Direction {travelDirection}");

                if (rightmost != null)
                {
                    var asdf = rightmost.Fingers[0].Type;

                    float pitch = rightmost.PalmNormal.Pitch;
                    float yaw   = rightmost.Direction.Yaw;
                    float roll  = rightmost.PalmNormal.Roll;

                    //Debug.WriteLine("-----------------------------");

                    //Debug.WriteLine($"Pitch {pitch}");

                    if (pitch < minPitch)
                    {
                        minPitch = pitch;
                        Debug.WriteLine($"min pitch {minPitch}");
                    }

                    if (pitch > maxPitch)
                    {
                        maxPitch = pitch;
                        Debug.WriteLine($"max pitch {maxPitch}");
                    }

                    if (roll < minRoll)
                    {
                        minRoll = roll;
                        Debug.WriteLine($"min roll {minRoll}");
                    }

                    if (roll > maxRoll)
                    {
                        maxRoll = roll;
                        Debug.WriteLine($"max roll {maxRoll}");
                    }

                    if (yaw < minYaw)
                    {
                        minYaw = yaw;
                        Debug.WriteLine($"min yaw {minYaw}");
                    }

                    if (yaw > maxYaw)
                    {
                        maxYaw = yaw;
                        Debug.WriteLine($"max yaw {maxYaw}");
                    }

                    //Debug.WriteLine($"Yaw {yaw}");
                    //Debug.WriteLine($"Roll {roll}");

                    var mPitch = Map(pitch, minPitch, maxPitch, -6, 6);
                    var mYaw   = Map(yaw, minYaw, maxYaw, -6, 6);
                    var mRoll  = Map(roll, minRoll, maxRoll, -6, 6);

                    Debug.WriteLine($"Mapped yaw {mYaw}");
                    Debug.WriteLine($"Mapped pitch {mPitch}");
                    Debug.WriteLine($"Mapped roll {mRoll}");
                }
            }
            else
            {
                isEnabled = false;
                _requestSetMovement(false);
            }
        }