Esempio n. 1
1
        /// <summary>
        /// Write the data of each frame in the file.
        /// </summary>
        /// <param name="controller">Controller that represent the device.</param>
        /// <param name="path">Path of the file where the data will be write.<br/>
        /// If one already exist it will be deleted and a new empty on is created.</param>
        public void RecordData(Controller controller, String path)
        {
            if (Directory.Exists(path) == true)
            {
                String destination = path + "leapMotion.data";
                try
                {
                    if (File.Exists(destination) == true)
                        File.Delete(destination);
                    file = File.Create(destination);
                }
                catch (ArgumentException e)
                {
                    throw e;
                }
            }
            else
                throw new System.ArgumentException("Destination path doesn't exist", "path");

            BinaryWriter writer = new BinaryWriter(file);
            for (int f = 9; f >= 0; f--)
            {
                Frame frameToSerialize = controller.Frame(f);
                byte[] serialized = frameToSerialize.Serialize;
                Int32 length = serialized.Length;
                writer.Write(length);
                writer.Write(serialized);
            }
        }
Esempio n. 2
0
 private void InitLeapSensorAndRegisterToEvents()
 {
     _listener = new MotionListener();
     _controller = new Controller();
     _controller.AddListener(_listener);
     _listener.OnHandMoveOn += _listener_OnHandMoveOn;
 }
        // 現在のフレームと、直前の5フレームを取得する
        static void GetBeforeFrame()
        {
            Controller leap = new Controller();
            long previousFrameId = -1;

            while ( true ) {
                // 最新のフレームを取得する(leap.Frame( 0 ) と同じ)
                var currentFrame = leap.Frame();
                if ( previousFrameId == currentFrame.Id ) {
                    continue;
                }

                previousFrameId = currentFrame.Id;

                // 直前の5フレームを取得する
                Console.Write( currentFrame.Id + ", " );
                for ( int i = 1; i <= 5; ++i ) {
                    var previousFrame = leap.Frame( i );
                    Console.Write( previousFrame.Id + ", " );
                }

                Console.WriteLine();
            }

            // 終了処理(onExit()相当)
        }
 private Program(string fileName)
 {
     _c = new Controller();
     _serializer = new LeapFrameSerializer();
     _file = new FileStream(fileName, FileMode.OpenOrCreate);
     _c.FrameReady += WriteFrames;
 }
Esempio n. 5
0
    private LeapManager manager; //This provides access to leap data

    #endregion Fields

    #region Methods

    // Use this for initialization
    void Start()
    {
        manager = Camera.main.GetComponent<LeapManager>();							//This links to some leap data
        listener   = new Leap.Listener ();											//initializes the listener
        controller = new Leap.Controller ();										//Initializes the controler
        controller.AddListener (listener);											//Pipes the listener stream into the controler
    }
 public override void OnInit(Controller controller)
 {
     /**call the LeapEventNotification method in the eventDelegate interface.
        If the event is activated, the event name can be reported to LeapEventNotification
      */
     this.eventDelegate.LeapEventNotification("onInit");
 }
Esempio n. 7
0
        public override void OnFrame(Controller leapController)
        {
            Frame currentFrame = leapController.Frame();

            if (handsLastFrame == 0 && currentFrame.Hands.Count > 0 && LeapRegisterFingers != null)
                LeapRegisterFingers(true);
            else if (handsLastFrame > 0 && currentFrame.Hands.Count == 0 && LeapRegisterFingers != null)
                LeapRegisterFingers(false);
            handsLastFrame = currentFrame.Hands.Count;

            if (currentFrame.Hands.Count > 0 &&
                currentFrame.Hands[0].Fingers.Count > 0 &&
                LeapSwipe != null)
            {
                GestureList gestures = currentFrame.Gestures();
                foreach (Gesture gesture in gestures)
                {
                    SwipeGesture swipe = new SwipeGesture(gesture);
                    if (Math.Abs(swipe.Direction.x) > Math.Abs(swipe.Direction.y)) // Horizontal swipe
                    {
                        if (swipe.Direction.x > 0)
                            LeapSwipe(SwipeDirection.Right);
                        else
                            LeapSwipe(SwipeDirection.Left);
                    }
                    else // Vertical swipe
                    {
                        if (swipe.Direction.y > 0)
                            LeapSwipe(SwipeDirection.Up);
                        else
                            LeapSwipe(SwipeDirection.Down);
                    }
                }
            }
        }
 void Awake() {
   leap_controller_ = new Controller();
   if (leap_controller_.IsConnected) {
     InitializeFlags();
   }
   leap_controller_.Device += HandleControllerConnect;
 }
Esempio n. 9
0
        public override void OnFrame(Controller controller)
        {
            Pointable pointable = FindPointable(controller);

            // use the pointable movement to move the mouse
            if (null != pointable)
            {
                //SafeWriteLine("pointable: " + pointable.Id + ", " + GetPosition(pointable).ToString());

                if (HasPrevTipPosition)
                {
                    Vector tipMovement = GetPosition(pointable) - PrevTipPosition;
                    //Vector tipMovement = pointable.TipVelocity; // too noisy; need better precision for this

                    Vector mouseMovement = LeapTransform.TransformToScreenSpace(tipMovement);
                    mouseMovement.x *= MouseSensitivityX;
                    mouseMovement.y *= MouseSensitivityY;

                    // there are discontinuities in the data we get back; ignore them and only perform reasonably small movements
                    if (mouseMovement.Magnitude < 300)
                    {
                        MouseWrapper.MoveMouse((int)mouseMovement.x, (int)mouseMovement.y);
                    }
                }

                HasPrevTipPosition = true;
                PrevPointableId = pointable.Id;
                PrevTipPosition = GetPosition(pointable);
            }
            else
            {
                SafeWriteLine("No pointable");

                HasPrevTipPosition = false;
                PrevPointableId = int.MinValue;
                PrevTipPosition = null;
            }

            // convert keyboard presses into mouse clicks. We only want to do this with certain presses,
            // where the key combination would not normally cause anything to happen.  We assume that no
            // one actually presses the right shift key. :)
            if ((KeyboardWrapper.IsKeyDown(Keys.LControlKey)) && (KeyboardWrapper.IsKeyDown(Keys.Space)) && (FrameSinceLastClick > 20))
            {
                MouseWrapper.LeftClick();
                FrameSinceLastClick = 0;
            }
            else if ((KeyboardWrapper.IsKeyDown(Keys.RControlKey)) && (KeyboardWrapper.IsKeyDown(Keys.Space) && (FrameSinceLastClick > 20)))
            {
                MouseWrapper.RightClick();
                FrameSinceLastClick = 0;
            }
            else
            {
                FrameSinceLastClick += 1;
                if (FrameSinceLastClick < 0)
                {
                    FrameSinceLastClick = 20;
                }
            }
        }
 // Use this for initialization
 void Start()
 {
     //enable gestures you need to use here
     controller = new Controller();
     controller.EnableGesture(Gesture.GestureType.TYPESWIPE);
     //controller.EnableGesture(Gesture.GestureType.TYPECIRCLE);
 }
Esempio n. 11
0
        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;
                }
            }
        }
        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;
                }
            }
        }
Esempio n. 13
0
        public void connect()
        {
            if (connected)
            {
                // Remove the listener
                controller.RemoveListener(listener);
                controller.Dispose();
                connected = false;
                connectbutton.Text = "Connect";
                fps_label.Text = "disconnected";
            }
            else
            {
                // Create listener and controller
                listener = new SampleListener();
                listener.form = this;
                controller = new Controller();

                if (controller.IsConnected)
                {
                    controller.AddListener(listener);
                    connectbutton.Text = "Disconnect";
                    connected = true;
                }
            }
        }
Esempio n. 14
0
 public void OnInitial(Controller controller,Cursor palmCursor,Form targetForm)
 {
     
     this.palmCursor = palmCursor;
     this.targetForm = targetForm;
     this.targetForm = targetForm;
 }
Esempio n. 15
0
 public LeapListener()
 {
     this.LeapInfo = new LeapFrame();
     this.controller = new Controller();
     this.listener = new LeapEventListener(this);
     controller.AddListener(listener);
 }
Esempio n. 16
0
 public MainWindow()
 {
     InitializeComponent();
     this.controller = new Controller();
     this.listener = new LeapEventListener(this);
     controller.AddListener(listener);
 }
Esempio n. 17
0
        public override void OnFrame(Controller controller)
        {
            // Get the most recent frame and report some basic information
            var frame = controller.Frame();

            try
            {
                // Update all registered items
                lock (_FrameUpdateItems)
                {
                    var item = _FrameUpdateItems.First;
                    while (item != null)
                    {
                        var next = item.Next;
                        if (!item.Value.Update(frame))
                            _FrameUpdateItems.Remove(item);
                        item = next;
                    }
                }
            }
            catch (Exception e)
            {
                _LogAction("Exception: " + e.GetType().FullName + "\n" + e.Message + "\n" + e.StackTrace);
            }
        }
Esempio n. 18
0
        public StillLife()
        {
            InitializeComponent();

            ConfigFile config = new ConfigFile(@"config.ini");
            speedUpDown = config.SettingGroups["Movement"].Settings["SpeedUpDown"].GetValueAsFloat();
            speedLeftRight = config.SettingGroups["Movement"].Settings["SpeedLeftRight"].GetValueAsFloat();
            idleTexturePosition.Width = config.SettingGroups["Idle"].Settings["IdleX"].GetValueAsInt();
            idleTexturePosition.Height = config.SettingGroups["Idle"].Settings["IdleY"].GetValueAsInt();
            timeTillIdle = config.SettingGroups["Idle"].Settings["IdleAfter"].GetValueAsFloat();
            idleSpeed = config.SettingGroups["Idle"].Settings["IdleSpeed"].GetValueAsFloat();

            leapController = new Controller();
            leapListener = new LeapListener();
            leapController.AddListener(leapListener);
            leapListener.LeapSwipe += new LeapListener.SwipeEvent(OnSwipe);
            leapListener.LeapRegisterFingers += new LeapListener.RegisterFingers(OnRegisterFingers);

            CalculateColumnsRows();
            InitializeIdleValues();

            stopWatch.Start();
            updateThread = new Thread(UpdateThread);
            updateThread.Start();
        }
 public override void OnConnect(Controller controller)
 {
     controller.EnableGesture(Gesture.GestureType.TYPE_CIRCLE);
     controller.EnableGesture(Gesture.GestureType.TYPE_KEY_TAP);
     controller.EnableGesture(Gesture.GestureType.TYPE_SCREEN_TAP);
     controller.EnableGesture(Gesture.GestureType.TYPE_SWIPE);
 }
Esempio n. 20
0
 public Form1()
 {
     InitializeComponent();
     oCamera = new InventorCamera();
     controller = new Controller();
     InitializeTexBox();
     AddToLog("Component initialization.");
     Thread.Sleep(100); // wait for connection
     if (controller.Devices.IsEmpty)
     {
         AddToLog("ERROR: No connection to Leap Motion service.");
         AddToLog("ERROR: Connect device and restart application.");
         return;
     }
     else
     {
         AddToLog("Connected to Leap Motion service.");
         controller.EnableGesture(Gesture.GestureType.TYPE_SWIPE);
         controller.EnableGesture(Gesture.GestureType.TYPE_CIRCLE);
         listener = new LeapEventListener(this);
         controller.SetPolicyFlags(Controller.PolicyFlag.POLICY_BACKGROUND_FRAMES);
         controller.AddListener(listener);
     }
     if (!oCamera.IsStarted())
         AddToLog("ERROR: Inventor instance not found.");
     else
         AddToLog("Iventor instance found. ");
     if (!oCamera.IsOpened())
         AddToLog("ERROR: Assembly, part or presentation document not found.");
     else
         AddToLog(oCamera.GetDocType() + " document found.");
 }
Esempio n. 21
0
 public override void OnConnect(Controller leapController)
 {
     leapController.Config.SetFloat("Gesture.Swipe.MinLength", 10);
     leapController.Config.SetFloat("Gesture.Swipe.MinVelocity", 100);
     leapController.Config.Save();
     leapController.EnableGesture(Gesture.GestureType.TYPESWIPE);
 }
        public override void OnFrame(Controller controller)
        {
            Frame frame = controller.Frame();
            // Get the first hand
            Hand hand = frame.Hands[0];

            // Check if the hand has any fingers
            FingerList fingers = hand.Fingers;
            if (!fingers.Empty)
            {
                // Calculate the hand's average finger tip position
                Vector avgPos = Vector.Zero;
                Vector avgVelocity = Vector.Zero;
                foreach (Finger finger in fingers)
                {
                    avgPos += finger.TipPosition;
                    avgVelocity += finger.TipVelocity;
                }
                avgPos /= fingers.Count;
                avgVelocity /= fingers.Count;
                List<Gesture.Direction> directions = new List<Gesture.Direction>();

                if (avgVelocity.y > 1500)
                {
                    directions.Add(Gesture.Direction.Up);
                }
                else if (avgVelocity.y < -1500)
                {
                    directions.Add(Gesture.Direction.Down);
                }

                if (avgVelocity.x > 1500)
                {
                    directions.Add(Gesture.Direction.Left);
                }
                else if (avgVelocity.x < -1500)
                {
                    directions.Add(Gesture.Direction.Right);
                }

                if (avgVelocity.z > 1500)
                {
                    directions.Add(Gesture.Direction.Forward);
                }
                else if (avgVelocity.z < -1500)
                {
                    directions.Add(Gesture.Direction.Backward);
                }

                if (directions.Count > 0)
                {
                    Gesture gesture = new Gesture(directions.ToArray(), fingers.Count);
                    onGesture(gesture);
                }

                //Console.WriteLine("Hand has " + fingers.Count
                //            + " fingers, average finger tip Velocity: " + avgVelocity);
            }
        }
Esempio n. 23
0
 //public Frame frame_read = new Frame();
 public FrameDataForm()
 {
     InitializeComponent();
     this.controller = new Controller();
     this.listener = new LeapEventListener(this);
     controller.AddListener(listener);
     this.controller.SetPolicy (Controller.PolicyFlag.POLICY_IMAGES);
 }
 public override void OnConnect(Controller controller)
 {
     SafeWriteLine("Leap Connected");
     controller.EnableGesture(Gesture.GestureType.TYPE_CIRCLE);
     controller.EnableGesture(Gesture.GestureType.TYPE_KEY_TAP);
     controller.EnableGesture(Gesture.GestureType.TYPE_SCREEN_TAP);
     controller.EnableGesture(Gesture.GestureType.TYPE_SWIPE);
 }
Esempio n. 25
0
 public override void OnInit(Controller controller)
 {
     controller.EnableGesture(Gesture.GestureType.TYPECIRCLE);
     controller.EnableGesture(Gesture.GestureType.TYPEKEYTAP);
     controller.EnableGesture(Gesture.GestureType.TYPESCREENTAP);
     controller.EnableGesture(Gesture.GestureType.TYPESWIPE);
     controller.SetPolicyFlags(Controller.PolicyFlag.POLICYBACKGROUNDFRAMES);
 }
Esempio n. 26
0
 //public bool scratch;
 // Use this for initialization
 void Start()
 {
     print("Inizializzo controller");
     listener = new Leap.Listener();
     controller = new Leap.Controller();
     controller.AddListener(listener);
     angle=0.0683f;
 }
Esempio n. 27
0
 public override void OnFrame(Controller con)
 {
     // If a method is set to the event, fire it
     if (FrameReady != null)
     {
         FrameReady(con);
     }
 }
Esempio n. 28
0
 // Use this for initialization
 void Start()
 {
     leapController = new Leap.Controller();
     leapController.EnableGesture(Leap.Gesture.GestureType.TYPECIRCLE, true);
     leapController.EnableGesture(Leap.Gesture.GestureType.TYPESWIPE, true);
     leapController.EnableGesture(Leap.Gesture.GestureType.TYPEKEYTAP, true);
     leapController.EnableGesture(Leap.Gesture.GestureType.TYPESCREENTAP, true);
 }
Esempio n. 29
0
 // Use this for initialization
 void Start()
 {
     hUtil          = new HandsUtil();
     leapcontroller = new Leap.Controller();
     frame          = leapcontroller.Frame();
     HUDMgr         = GameObject.Find("Managers").GetComponent <HUDManager>();
     dcg            = GameObject.Find("DCG").GetComponent <DCGBase>();
 }
Esempio n. 30
0
 public override void OnConnect(Controller controller)
 {
     SafeWriteLine("Connected");
     controller.EnableGesture(Gesture.GestureType.TYPECIRCLE);
     //controller.EnableGesture(Gesture.GestureType.TYPEKEYTAP);
     controller.EnableGesture(Gesture.GestureType.TYPESCREENTAP);
     controller.EnableGesture(Gesture.GestureType.TYPESWIPE);
 }
        public LeapInterface()
        {
            listener = new LeapListener();
            controller = new Controller();
            controller.SetPolicyFlags(Controller.PolicyFlag.POLICYBACKGROUNDFRAMES);

            Start();
        }
Esempio n. 32
0
 public override void OnConnect(Controller controller)
 {
     _LogAction("Connected");
     controller.EnableGesture(Gesture.GestureType.TYPECIRCLE);
     //controller.EnableGesture(Gesture.GestureType.TYPEKEYTAP);
     //controller.EnableGesture(Gesture.GestureType.TYPESCREENTAP);
     controller.EnableGesture(Gesture.GestureType.TYPESWIPE);
     _LogAction("Gesures Enabled");
 }
Esempio n. 33
0
 // Use this for initialization
 void Start()
 {
     HUD            = GameObject.Find("Managers").GetComponent <HUDManager>();
     controller     = GameObject.Find("LoPoly_Rigged_Hand_Right").GetComponent <handController>();
     hUtil          = new HandsUtil();
     leapcontroller = new Leap.Controller();
     frame          = leapcontroller.Frame();
     HUDMgr         = GameObject.Find("Managers").GetComponent <HUDManager>();
     dcg            = GameObject.Find("DCG").GetComponent <DCGBase>();
     base.Start();
 }
Esempio n. 34
0
 public static void DestroyController()
 {
     if (leap_controller_ != null)
     {
         if (leap_controller_.IsConnected)
         {
             leap_controller_.ClearPolicy(Leap.Controller.PolicyFlag.POLICY_OPTIMIZE_HMD);
         }
         leap_controller_.StopConnection();
         leap_controller_ = null;
     }
 }
Esempio n. 35
0
        static void Main(string[] args)
        {
            Controller controller = new Leap.Controller(); // initialize the leap controller

            while (!controller.IsConnected)
            {
            }                                                                                                     // wait for it to connect

            PhaseModulationProvider pmProvider = new PhaseModulationProvider(440, (440f / 2f), 0.5f, 0.5f, 0.2f); // initialize the pm oscillator

            MixingSampleProvider mixer = new MixingSampleProvider(new[] { pmProvider });

            mixer.ReadFully = true;

            SynthController synthController = new SynthController(pmProvider, 0.1f);                       // initialize the object that controls the synth with leap

            WaveOut audioOut = new WaveOut();                                                              // hear things

            audioOut.Init(mixer);                                                                          // give it the oscillator

            audioOut.Play();                                                                               // play it

            RenderWindow window = new RenderWindow(new VideoMode(200, 200), "Test Window, Please Ignore"); // make the sfml window

            window.Closed += (object sender, EventArgs e) =>                                               // so I can close it
            {
                RenderWindow w = sender as RenderWindow;
                controller.Dispose();
                w.Close();
            };

            window.KeyPressed += (object sender, KeyEventArgs e) =>
            {
                if (e.Code == Keyboard.Key.Escape)
                {
                    RenderWindow w = sender as RenderWindow;
                    w.Close();
                }
            };

            while (window.IsOpen) // main loop
            {
                synthController.HandleFrame(controller);
                window.DispatchEvents();
                window.Clear();
                window.Display();
            }
        }