コード例 #1
0
ファイル: ClientForm.xaml.cs プロジェクト: m0ti0nblur/wiituio
        /// <summary>
        /// Try to create the WiiProvider (this involves connecting to the Wiimote).
        /// </summary>
        private bool createProviders()
        {
            try
            {
                // Connect a Wiimote, hook events then start.
                this.pWiiProvider                  = new WiiProvider();
                this.pWiiProvider.OnNewFrame      += new EventHandler <FrameEventArgs>(pWiiProvider_OnNewFrame);
                this.pWiiProvider.OnBatteryUpdate += new Action <int>(pWiiProvider_OnBatteryUpdate);
                this.pWiiProvider.start();
                return(true);
            }
            catch (Exception pError)
            {
                // Tear down.
                try
                {
                    this.disconnectProviders();
                }
                catch { }

                // Report the error.
                showMessage(pError.Message, MessageType.Error);
                //MessageBox.Show(pError.Message, "WiiTUIO", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
        }
コード例 #2
0
ファイル: ClientForm.xaml.cs プロジェクト: m0ti0nblur/wiituio
 /// <summary>
 /// Tear down the provider connections.
 /// </summary>
 private void disconnectProviders()
 {
     // Disconnect the Wiimote.
     if (this.pWiiProvider != null)
     {
         this.pWiiProvider.stop();
     }
     this.pWiiProvider = null;
 }
コード例 #3
0
        /// <summary>
        /// This is called internally when calibration is finished.
        /// </summary>
        private void finishedCalibration()
        {
            // Die if we have no provider.
            if (this.pWiiProvider == null)
            {
                throw new Exception("Cannot finish calibration without an input provider!");
            }

            // Re-enable the transformation step in the provider.
            pWiiProvider.TransformResults = true;

            // Feed that data into the provider.
            Vector vScreenSize = new Vector(this.ActualWidth, this.ActualHeight);

            this.pWiiProvider.setCalibrationData(pSourceRectangle, pDestinationRectangle, vScreenSize);

            // Detach the event handler.
            this.pWiiProvider.OnNewFrame -= pEventHandler;

            // Dereference the provider.
            this.pWiiProvider = null;

            // Hide the calibration point.
            Dispatcher.BeginInvoke((Action) delegate()
            {
                // Hide the calibration point.
                this.CalibrationPoint.Visibility = Visibility.Hidden;

                // Ensure the form is at the back, the correct size and visible.
                Canvas.SetTop(this, 0.0);
                Canvas.SetLeft(this, 0.0);
                Canvas.SetZIndex(this, -999);
                this.Width  = 0; // (double)this.Parent.GetValue(Canvas.ActualWidthProperty);
                this.Height = 0; // (double)this.Parent.GetValue(Canvas.ActualHeightProperty);

                // Raise the event.
                if (OnCalibrationFinished != null)
                {
                    OnCalibrationFinished(pSourceRectangle, pDestinationRectangle, vScreenSize);
                }
            });
        }
コード例 #4
0
        /// <summary>
        /// Method to begin calibration.
        /// </summary>
        /// <param name="pWiiProvider">A reference to the input provider we want to calibrate.</param>
        public void beginCalibration(WiiProvider pWiiProvider)
        {
            // Store a reference to the WiiInput provider.
            this.pWiiProvider = pWiiProvider;

            // Die if we have no provider.
            if (this.pWiiProvider == null)
            {
                throw new Exception("Cannot begin calibrate without an input provider!");
            }

            // Wipe the rectangles.
            this.pSourceRectangle      = new WiiProvider.CalibrationRectangle();
            this.pDestinationRectangle = new WiiProvider.CalibrationRectangle();

            // Disable the transformation step in the provider.
            pWiiProvider.TransformResults = false;

            // Give us an event for the input.
            pEventHandler            = new EventHandler <FrameEventArgs>(pWiiProvider_OnNewFrame);
            pWiiProvider.OnNewFrame += pEventHandler;

            // Set our calibration phase to 1.
            this.iCalibrationPhase = 1;

            // Show the calibration point.
            this.CalibrationPoint.Visibility = Visibility.Visible;

            // Ensure the form is at the top, the correct size and visible.
            Canvas.SetTop(this, 0.0);
            Canvas.SetLeft(this, 0.0);
            Canvas.SetZIndex(this, 999);
            this.Width  = (double)this.Parent.GetValue(Canvas.ActualWidthProperty);
            this.Height = (double)this.Parent.GetValue(Canvas.ActualHeightProperty);

            // Step into the calibration.
            this.movePoint(0.1, 0.1);
            this.stepCalibration();
        }