Example #1
0
        /// <summary>
        /// Transform a point from one rectangle onto another using this class's warp matrix.
        /// </summary>
        /// <param name="srcX">Source point, X coordinate.</param>
        /// <param name="srcY">Source point, Y coordinate.</param>
        /// <param name="dstX">Destination point, X coordinate.</param>
        /// <param name="dstY">Destination point, Y coordinate.</param>
        public void warp(float srcX, float srcY, ref float dstX, ref float dstY)
        {
            // If our matrix is out of date, recompute it.
            if (dirty)
            {
                computeWarp();
            }

            // Compute the coordinate transform.
            Warper.warp(warpMat, srcX, srcY, ref dstX, ref dstY);
        }
Example #2
0
        /// <summary>
        /// This is called when the state of the wiimote changes and a new state report is available.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void handleWiimoteChanged(object sender, WiimoteChangedEventArgs e)
        {
            // Obtain mutual excluseion.
            pDeviceMutex.WaitOne();

            // If we not running then leave.
            if (!bRunning)
            {
                pDeviceMutex.ReleaseMutex();
                return;
            }

            // Store the state.
            WiimoteState pState = e.WiimoteState;

            // Contain active sensor data.
            List <SpatioTemporalInput> lInputs = new List <SpatioTemporalInput>();

            // For each IR sensor with data.
            IRSensor[] tSensors = pState.IRState.IRSensors;
            for (int iSensor = 0; iSensor < tSensors.Length; ++iSensor)
            {
                // If the sensor has data - queue an input for it.
                if (tSensors[iSensor].Found)
                {
                    // Extract the data from the sensor.
                    int   x        = tSensors[iSensor].RawPosition.X;
                    int   y        = tSensors[iSensor].RawPosition.Y;
                    float fWarpedX = x;
                    float fWarpedY = y;

                    // If we have transformation enabled
                    if (TransformResults)
                    {
                        // Transform the coordinates with the warper.
                        pWarper.warp(x, y, ref fWarpedX, ref fWarpedY);
                    }

                    // Make it into an input.
                    lInputs.Add(new SpatioTemporalInput((double)fWarpedX, (double)fWarpedY));
                }
            }

            // Prepare the frame to recieve new inputs.
            if (this.lFrame != null)
            {
                this.lFrame = null;
            }
            this.lFrame = new Queue <WiiContact>(1);

            // Now run these inputs through the classifier to see if they are related to any previous ones.
            // Thanks Nintendo... fix ye'r buffer ordering!
            this.InputClassifier.processFrame(lInputs);

            // Build that frame off to the input dispatcher.
            FrameEventArgs pFrame = new FrameEventArgs((ulong)Stopwatch.GetTimestamp(), this.lFrame);

            this.lFrame = null;

            // Ship it out!
            this.OnNewFrame(this, pFrame);

            /*
             * // Has the 'A' button changed?
             * if (!bLastTriggerState && pState.ButtonState.B)
             * {
             *  // Click the button programmatically.
             *  Dispatcher.BeginInvoke(new Action(delegate()
             *  {
             *      Button_Calibrate.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
             *  }), null);
             * }
             * bLastTriggerState = pState.ButtonState.B;
             */

            // Update the battery state on the GUI.
            //Dispatcher.BeginInvoke(new Action(delegate()
            //{
            //    // float f = (((100.0f * 48.0f * (float)(ws.Battery / 48.0f))) / 192.0f);
            //    Bar_Battery.Value = (pState.Battery > 0xc8 ? 0xc8 : (int)pState.Battery);
            //}), null);
            this.BatteryState = (pState.Battery > 0xc8 ? 0xc8 : (int)pState.Battery);

            // Release mutual exclusion.
            pDeviceMutex.ReleaseMutex();
        }