示例#1
0
        protected void UpdateWiimotes()
        {
            int i = 1;

            foreach (Wiimote wm in mWC)
            {
                IRState irs       = wm.WiimoteState.IRState;
                float   xmidpoint = Math.Min(irs.Midpoint.X * sensitivity, 1);
                if (xmidpoint > 0)
                {
                    if (i == 1)
                    {
                        float position = ((xmidpoint * 20) - 10) * 1;
                        //player1.scoreText.DisplayText = position.ToString();
                        player1.sprite.Y = position;
                    }
                    else
                    {
                        float position = ((xmidpoint * 20) - 10) * -1;
                        //player2.scoreText.DisplayText = position.ToString();
                        player2.sprite.Y = position;
                    }
                }
                i++;
            }
        }
示例#2
0
        // headtracking 'light'
        // computes the angles to the observer around the camera up and right directions
        // also calculates the distance between two IR points - used for scaling
        // todo: take screen distance into account
        private void HeadTracking(IRState irState)
        {
            if (irState.IRSensors[0].Found)
            {
                var    p0    = irState.IRSensors[0].RawPosition;
                double mx    = p0.X;
                double my    = p0.Y;
                double scale = 1;

                if (irState.IRSensors[1].Found)
                {
                    var    p1 = irState.IRSensors[1].RawPosition;
                    double dx = p0.X - p1.X;
                    double dy = p0.Y - p1.Y;
                    double d  = Math.Sqrt(dx * dx + dy * dy);
                    mx    = (p0.X + p1.X) * 0.5;
                    my    = (p0.Y + p1.Y) * 0.5;
                    scale = d / 200.0;
                }
                double theta = 20.0 * (mx - 512) / 512;
                double phi   = 20.0 * (my - 384) / 384;
                Dispatcher.BeginInvoke(new Action(() => SetTransform(scale, theta, phi)));
            }
            //else
            //    Dispatcher.BeginInvoke(new Action(() => SetTransform(1, 0, 0)));
        }
示例#3
0
 private void UpdateImage(IRState irState)
 {
     System.Drawing.Point p = new System.Drawing.Point((int)(irState.IRSensors[0].RawPosition.X / 3), (int)(irState.IRSensors[0].RawPosition.Y / 3));
     App.Current.Dispatcher.Invoke((Action) delegate
     {
         System.Windows.Media.Color color     = (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(Globals.color);
         System.Windows.Shapes.Rectangle rect = new System.Windows.Shapes.Rectangle();
         rect.Stroke = new SolidColorBrush(color);
         rect.Fill   = new SolidColorBrush(color);
         rect.Width  = 3;
         rect.Height = 3;
         Canvas.SetLeft(rect, p.X);
         Canvas.SetBottom(rect, p.Y);
         this.canvas.Children.Add(rect);
     });
 }
示例#4
0
        public RGame(IRState initialState, int ScreenWidth = 1280, int ScreenHeight = 720, int VirtualWidth = 1280, int VirtualHeight = 720)
        {
            graphicsDeviceManager = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            RGlobal.Game = this;
            RGlobal.Resolution = new Resolution(this, VirtualWidth, VirtualHeight, ScreenWidth, ScreenHeight);
            RGlobal.MainCamera = new Camera2D(RGlobal.Resolution);
            RGlobal.Cameras = new List<Camera2D>();
            RGlobal.Cameras.Add(RGlobal.MainCamera);

            RGlobal.Music = new MusicManager();
            RGlobal.Sound = new SoundManager();

            RGlobal.Input = new InputHelper();

            currentState = initialState;
        }
示例#5
0
 public StateHandler(IRState rState)
 {
     _rState = rState;
 }
示例#6
0
        public CursorPos CalculateCursorPos(WiimoteChangedEventArgs args)
        {
            int x;
            int y;

            IRState irState = args.WiimoteState.IRState;

            PointF relativePosition = new PointF();

            bool foundMidpoint = false;

            /*for(int i=0;i<irState.IRSensors.Count() && !foundMidpoint;i++)//IRSensor sensor in irState.IRSensors)
             * {
             *  IRSensor sensor = irState.IRSensors[i];
             *  if (sensor.Found)
             *  {
             *      for (int j = i + 1; j < irState.IRSensors.Count() && !foundMidpoint; j++)
             *      {
             *          IRSensor sensor2 = irState.IRSensors[j];
             *          if (sensor2.Found)
             *          {*/
            if (irState.IRSensors[0].Found && irState.IRSensors[1].Found)
            {
                foundMidpoint = true;

                relativePosition.X = (irState.IRSensors[0].Position.X + irState.IRSensors[1].Position.X) / 2.0f;
                relativePosition.Y = (irState.IRSensors[0].Position.Y + irState.IRSensors[1].Position.Y) / 2.0f;

                if (Settings.Default.pointer_considerRotation)
                {
                    //accelSmoothing.addValue(new System.Windows.Vector(args.WiimoteState.AccelState.RawValues.X, args.WiimoteState.AccelState.RawValues.Z));

                    //System.Windows.Vector smoothedRotation = accelSmoothing.getSmoothedValue();

                    /*
                     * while (accXhistory.Count >= Settings.Default.pointer_rotationSmoothing)
                     * {
                     *  accXhistory.Dequeue();
                     * }
                     * while (accZhistory.Count >= Settings.Default.pointer_rotationSmoothing)
                     * {
                     *  accZhistory.Dequeue();
                     * }
                     *
                     * accXhistory.Enqueue(args.WiimoteState.AccelState.RawValues.X);
                     * accZhistory.Enqueue(args.WiimoteState.AccelState.RawValues.Z);
                     *
                     * smoothedX = 0;
                     * smoothedZ = 0;
                     *
                     * foreach (double accX in accXhistory)
                     * {
                     *  smoothedX += accX;
                     * }
                     * smoothedX /= accXhistory.Count;
                     *
                     * foreach (double accZ in accZhistory)
                     * {
                     *  smoothedZ += accZ;
                     * }
                     * smoothedZ /= accZhistory.Count;
                     */

                    smoothedX = smoothedX * 0.9 + args.WiimoteState.AccelState.RawValues.X * 0.1;
                    smoothedZ = smoothedZ * 0.9 + args.WiimoteState.AccelState.RawValues.Z * 0.1;

                    double absx = Math.Abs(smoothedX - 128), absz = Math.Abs(smoothedZ - 128);

                    if (orientation == 0 || orientation == 2)
                    {
                        absx -= 5;
                    }
                    if (orientation == 1 || orientation == 3)
                    {
                        absz -= 5;
                    }

                    if (absz >= absx)
                    {
                        if (absz > 5)
                        {
                            orientation = (smoothedZ > 128) ? 0 : 2;
                        }
                    }
                    else
                    {
                        if (absx > 5)
                        {
                            orientation = (smoothedX > 128) ? 3 : 1;
                        }
                    }

                    int l = leftPoint, r;
                    //if (leftPoint == -1)
                    //{
                    switch (orientation)
                    {
                    case 0: l = (irState.IRSensors[0].RawPosition.X < irState.IRSensors[1].RawPosition.X) ? 0 : 1; break;

                    case 1: l = (irState.IRSensors[0].RawPosition.Y > irState.IRSensors[1].RawPosition.Y) ? 0 : 1; break;

                    case 2: l = (irState.IRSensors[0].RawPosition.X > irState.IRSensors[1].RawPosition.X) ? 0 : 1; break;

                    case 3: l = (irState.IRSensors[0].RawPosition.Y < irState.IRSensors[1].RawPosition.Y) ? 0 : 1; break;
                    }
                    leftPoint = l;
                    //}
                    r = 1 - l;

                    double dx = irState.IRSensors[r].RawPosition.X - irState.IRSensors[l].RawPosition.X;
                    double dy = irState.IRSensors[r].RawPosition.Y - irState.IRSensors[l].RawPosition.Y;

                    double d = Math.Sqrt(dx * dx + dy * dy);

                    dx /= d;
                    dy /= d;

                    smoothedRotation = 0.5 * smoothedRotation + 0.5 * Math.Atan2(dy, dx);

                    /*
                     * while (rotationHistory.Count >= Settings.Default.pointer_rotationSmoothing)
                     * {
                     *  rotationHistory.Dequeue();
                     * }
                     *
                     * rotationHistory.Enqueue(rotation);
                     *
                     * double smoothedRotation = 0;
                     * foreach (double rot in rotationHistory)
                     * {
                     *  smoothedRotation += rot;
                     * }
                     * smoothedRotation /= rotationHistory.Count;
                     */

                    //smoothedRotation = smoothedRotation * 0.9 + rotation * 0.1;
                    //rotation = smoothedRotation;
                }
                //}
                //}
                //}
            }

            if (!foundMidpoint)
            {
                leftPoint = -1;
                CursorPos err = new CursorPos(-1, -1, 0);

                return(err);
            }

            int offsetY = 0;

            if (Properties.Settings.Default.pointer_sensorBarPos == "top")
            {
                offsetY = -SBPositionOffset;
            }
            else if (Properties.Settings.Default.pointer_sensorBarPos == "bottom")
            {
                offsetY = SBPositionOffset;
            }

            relativePosition.X = 1 - relativePosition.X;

            if (Settings.Default.pointer_considerRotation)
            {
                //accelSmoothing.addValue(new System.Windows.Vector(args.WiimoteState.AccelState.Values.X, args.WiimoteState.AccelState.Values.Z));

                //System.Windows.Vector smoothedRotation = accelSmoothing.getSmoothedValue();

                //rotation = -1 * (Math.Atan2(smoothedRotation.Y, smoothedRotation.X) - (Math.PI / 2.0));

                relativePosition.X = relativePosition.X - 0.5F;
                relativePosition.Y = relativePosition.Y - 0.5F;

                relativePosition = this.rotatePoint(relativePosition, smoothedRotation);

                relativePosition.X = relativePosition.X + 0.5F;
                relativePosition.Y = relativePosition.Y + 0.5F;

                //relativePosition.X = 1 - relativePosition.X;
                //relativePosition.Y = 1 - relativePosition.Y;
            }

            x = Convert.ToInt32((float)maxWidth * relativePosition.X + minXPos);
            y = Convert.ToInt32((float)maxHeight * relativePosition.Y + minYPos) + offsetY;

            if (x <= 0)
            {
                x = 0;
            }
            else if (x >= Util.ScreenWidth)
            {
                x = Util.ScreenWidth - 1;
            }
            if (y <= 0)
            {
                y = 0;
            }
            else if (y >= Util.ScreenHeight)
            {
                y = Util.ScreenHeight - 1;
            }

            CursorPos result = new CursorPos(x, y, smoothedRotation);

            return(result);
        }
示例#7
0
        //resolve IR pointer co-ords and screen co-ords
        //0,0 on screen
        //   0 on IRState.Y
        //|-------------------|
        //|                   |
        //|                   | //0 on IRState.X
        //|                   |
        //|-------------------|

        public float GetY()
        {
            IRState _wiimoteIRState = Wiimote.WiimoteState.IRState;

            return(_wiimoteIRState.Midpoint.Y);
        }
示例#8
0
        public float GetX()
        {
            IRState _wiimoteIRState = Wiimote.WiimoteState.IRState;

            return(1.0f - _wiimoteIRState.Midpoint.X);
        }
示例#9
0
 public void SwitchState(IRState newState)
 {
     currentState.UnloadContent();
     currentState = newState;
     currentState.Initialize();
     currentState.LoadContent(Content);
 }
        public CursorPos CalculateCursorPos(WiimoteState wiimoteState)
        {
            int x;
            int y;

            IRState irState = wiimoteState.IRState;

            PointF relativePosition = new PointF();

            bool foundMidpoint = false;

            for (int i = 0; i < irState.IRSensors.Count() && !foundMidpoint; i++)
            {
                if (irState.IRSensors[i].Found)
                {
                    for (int j = i + 1; j < irState.IRSensors.Count() && !foundMidpoint; j++)
                    {
                        if (irState.IRSensors[j].Found)
                        {
                            foundMidpoint = true;

                            relativePosition.X = (irState.IRSensors[i].Position.X + irState.IRSensors[j].Position.X) / 2.0f;
                            relativePosition.Y = (irState.IRSensors[i].Position.Y + irState.IRSensors[j].Position.Y) / 2.0f;

                            if (Settings.Default.pointer_considerRotation)
                            {
                                smoothedX = smoothedX * 0.9f + wiimoteState.AccelState.RawValues.X * 0.1f;
                                smoothedZ = smoothedZ * 0.9f + wiimoteState.AccelState.RawValues.Z * 0.1f;

                                int l = leftPoint, r;
                                if (leftPoint == -1)
                                {
                                    double absx = Math.Abs(smoothedX - 128), absz = Math.Abs(smoothedZ - 128);

                                    if (orientation == 0 || orientation == 2)
                                    {
                                        absx -= 5;
                                    }
                                    if (orientation == 1 || orientation == 3)
                                    {
                                        absz -= 5;
                                    }

                                    if (absz >= absx)
                                    {
                                        if (absz > 5)
                                        {
                                            orientation = (smoothedZ > 128) ? 0 : 2;
                                        }
                                    }
                                    else
                                    {
                                        if (absx > 5)
                                        {
                                            orientation = (smoothedX > 128) ? 3 : 1;
                                        }
                                    }

                                    switch (orientation)
                                    {
                                    case 0: l = (irState.IRSensors[i].RawPosition.X < irState.IRSensors[j].RawPosition.X) ? i : j; break;

                                    case 1: l = (irState.IRSensors[i].RawPosition.Y > irState.IRSensors[j].RawPosition.Y) ? i : j; break;

                                    case 2: l = (irState.IRSensors[i].RawPosition.X > irState.IRSensors[j].RawPosition.X) ? i : j; break;

                                    case 3: l = (irState.IRSensors[i].RawPosition.Y < irState.IRSensors[j].RawPosition.Y) ? i : j; break;
                                    }
                                }
                                leftPoint = l;
                                r         = l == i ? j : i;

                                double dx = irState.IRSensors[r].RawPosition.X - irState.IRSensors[l].RawPosition.X;
                                double dy = irState.IRSensors[r].RawPosition.Y - irState.IRSensors[l].RawPosition.Y;

                                double d = Math.Sqrt(dx * dx + dy * dy);

                                dx /= d;
                                dy /= d;

                                smoothedRotation = Math.Atan2(dy, dx);
                            }
                        }
                    }
                }
            }

            if (!foundMidpoint)
            {
                CursorPos err = lastPos;
                err.OutOfReach = true;
                leftPoint      = -1;

                return(err);
            }

            int offsetY = 0;

            if (Properties.Settings.Default.pointer_sensorBarPos == "top")
            {
                offsetY = -SBPositionOffset;
            }
            else if (Properties.Settings.Default.pointer_sensorBarPos == "bottom")
            {
                offsetY = SBPositionOffset;
            }

            relativePosition.X = 1 - relativePosition.X;

            if (Settings.Default.pointer_considerRotation)
            {
                relativePosition.X = relativePosition.X - 0.5F;
                relativePosition.Y = relativePosition.Y - 0.5F;

                relativePosition = this.rotatePoint(relativePosition, smoothedRotation);

                relativePosition.X = relativePosition.X + 0.5F;
                relativePosition.Y = relativePosition.Y + 0.5F;
            }

            System.Windows.Point filteredPoint = coordFilter.AddGetFilteredCoord(new System.Windows.Point(relativePosition.X, relativePosition.Y), 1.0, 1.0);

            relativePosition.X = (float)filteredPoint.X;
            relativePosition.Y = (float)filteredPoint.Y;

            Vector smoothedPoint = smoothingBuffer.AddAndGet(new Vector(relativePosition.X, relativePosition.Y));


            x = Convert.ToInt32((float)maxWidth * smoothedPoint.X + minXPos);
            y = Convert.ToInt32((float)maxHeight * smoothedPoint.Y + minYPos) + offsetY;

            if (x <= 0)
            {
                x = 0;
            }
            else if (x >= primaryScreen.Bounds.Width)
            {
                x = primaryScreen.Bounds.Width - 1;
            }
            if (y <= 0)
            {
                y = 0;
            }
            else if (y >= primaryScreen.Bounds.Height)
            {
                y = primaryScreen.Bounds.Height - 1;
            }

            CursorPos result = new CursorPos(x, y, smoothedPoint.X, smoothedPoint.Y, smoothedRotation);

            lastPos = result;
            return(result);
        }