Esempio n. 1
0
        static void JoystickUpdate(int deviceID, double dt)
        {
            JoystickState jss = JoystickInput.GetAsJoystickState(deviceID);

            curButtons.Clear();

            for (int i = 0; i < (int)config.NUM_KEY; i++)
            {
                if (!Key[i] && jss.buttonMap[i])                  //今押された
                {
                    curButtons.Add((byte)i);
                    onKeyDown[i] = true;
                    onKeyUp[i]   = false;
                    continue;                    //今押されたって事は、今離されたかどうかなんて聞くまでも無いだろって事で。
                }
                else
                {
                    onKeyDown[i] = false;
                }
                if (Key[i] && !jss.buttonMap[i])                  //今離された
                {
                    onKeyUp[i] = true;
                    keyTime[i] = 0.0;
                }
                else
                {
                    onKeyUp[i] = false;
                }
            }
            for (int i = 0; i < (int)config.NUM_KEY; i++)
            {
                if (jss.buttonMap[i])                  //古い状態を捨てて新しい状態に切り替える
                {
                    Key[i]      = true;
                    keyTime[i] += dt;
                }
                else
                {
                    Key[i] = false;
                }
            }
            // デバイスIDのアナログの十字の状態、未入力で-1、上が0で時計回りに増加)
            //int degree = jsStates[deviceID].GetPointOfView()[0];
            //if ( degree == -1 ) V.set( 0.0f , 0.0f );
            //else	V.set((float)Math.Cos((double)xmath.ToRadians(degree/100)),(float)Math.Sin((double)xmath.ToRadians(degree/100)));
            float axisx = jss.PositionX;            //jsStates[deviceID].X;
            float axisy = jss.PositionY;            //jsStates[deviceID].Y;

            if (jss.PositionX == 0 && jss.PositionY == 0)
            {
                if (jss.DPad.Right == xnainput.ButtonState.Pressed)
                {
                    axisx = 1.0f;
                }
                else if (jss.DPad.Left == xnainput.ButtonState.Pressed)
                {
                    axisx = -1.0f;
                }
                if (jss.DPad.Down == xnainput.ButtonState.Pressed)
                {
                    axisy = -1.0f;
                }
                else if (jss.DPad.Up == xnainput.ButtonState.Pressed)
                {
                    axisy = 1.0f;
                }
            }
            Vector2 oldV = V;

            V.X = ((Math.Abs(axisx) < PRESSED_THRESHOLD) ? 0.0f : axisx);
            V.Y = ((Math.Abs(axisy) < PRESSED_THRESHOLD) ? 0.0f : axisy);
            //普通にセットしちゃってから
            if (V.Length() != 0)
            {
                V.Normalize();
            }
            //加工。TODO:アナログにちゃんと対応するならここを変えないと。

            Direction oldDirection = stickDirection;

            if (V.Y <= -0.7071)                //0.7071==√2
            {
                stickDirection = Direction.UP; //上
            }
            else if (V.Y >= 0.7071)
            {
                stickDirection = Direction.DOWN;                //下
            }
            else if (V.X <= -0.7071)
            {
                stickDirection = Direction.LEFT;                //左
            }
            else if (V.X >= 0.7071)
            {
                stickDirection = Direction.RIGHT;                //右
            }
            else
            {
                stickDirection = Direction.NEWTRAL;               //ニュートラル
            }
            if (oldDirection == stickDirection)
            {
                stickTime += dt;
                onStickDirectionChanged = false;
            }
            else
            {
                stickTime = 0.0;
                onStickDirectionChanged = true;
            }
        }
Esempio n. 2
0
        internal float GetValue(ref JoystickState state)
        {
            float value = state.GetPosition(Axis);

            return(IsNegate ? -value : value);
        }