Exemple #1
0
 protected override int Read(ref JoystickState state)
 {
     return(state.GetAccelerationSliders()[base.Index]);
 }
 protected override int Read(ref JoystickState state)
 {
   return state.GetAccelerationSliders()[base.Index];
 }
    /// <summary>
    /// Update state of joystick
    /// </summary>
    public void Update()
    {
        //Get the state of the joystick
        JoystickState state = joystick.GetCurrentState();

        //Save prev values for autodetection of axis
        Array.Copy(axis, axisPrev, axis.Length);

        //Update axes values
        axis[0]  = state.AccelerationX;        //Ax
        axis[1]  = state.AccelerationY;        //Ay
        axis[2]  = state.AccelerationZ;        //Az
        axis[3]  = state.AngularAccelerationX; //aAx
        axis[4]  = state.AngularAccelerationY; //aAy
        axis[5]  = state.AngularAccelerationZ; //aAz
        axis[6]  = state.AngularVelocityX;     //aVx
        axis[7]  = state.AngularVelocityY;     //aVy
        axis[8]  = state.AngularVelocityZ;     //aVz
        axis[9]  = state.ForceX;               //Fx
        axis[10] = state.ForceY;               //Fy
        axis[11] = state.ForceZ;               //Fz
        axis[12] = state.RotationX;            //Rx
        axis[13] = state.RotationY;            //Ry
        axis[14] = state.RotationZ;            //Rz
        axis[15] = state.TorqueX;              //Tx
        axis[16] = state.TorqueY;              //Ty
        axis[17] = state.TorqueZ;              //Tz
        axis[18] = state.VelocityX;            //Vx
        axis[19] = state.VelocityY;            //Vy
        axis[20] = state.VelocityZ;            //Vz
        axis[21] = state.X;                    //x
        axis[22] = state.Y;                    //y
        axis[23] = state.Z;                    //z

        int asl = state.GetAccelerationSliders().Length;
        int fsl = state.GetForceSliders().Length;
        int vsl = state.GetVelocitySliders().Length;
        int sl  = state.GetSliders().Length;

        Array.Copy(state.GetAccelerationSliders(), 0, axis, 24, asl);
        Array.Copy(state.GetForceSliders(), 0, axis, 24 + asl, fsl);
        Array.Copy(state.GetVelocitySliders(), 0, axis, 24 + asl + fsl, vsl);
        Array.Copy(state.GetForceSliders(), 0, axis, 24 + asl + fsl + vsl, sl);

        //Save previous
        Array.Copy(button, buttonPrev, button.Length);



        //Update button values

        //first, convert powController into boolean array to represent them as buttons
        int[] pov  = state.GetPointOfViewControllers();
        int   povl = pov.Length;

        bool[] povButton = new bool[povl * 4];
        for (int i = 0; i < povl; i += 4)
        {
            int povValue = pov[i / 4];
            if (povValue == -1)
            {
                povButton[i + 0] = false;
                povButton[i + 1] = false;
                povButton[i + 2] = false;
                povButton[i + 3] = false;
                continue;
            }

            //north
            if (povValue >= 31500 || povValue <= 4500)
            {
                povButton[i + 0] = true;
            }

            //east
            if (povValue >= 4500 && povValue <= 13500)
            {
                povButton[i + 1] = true;
            }

            //south
            if (povValue >= 13500 && povValue <= 22500)
            {
                povButton[i + 2] = true;
            }

            //west
            if (povValue >= 22500 && povValue <= 31500)
            {
                povButton[i + 3] = true;
            }
        }

        int bl = state.GetButtons().Length;

        Array.Copy(state.GetButtons(), 0, button, 0, bl);
        Array.Copy(povButton, 0, button, bl, povButton.Length);



        //TEMP for debugging of joystick input

        /*
         * if (povPrev == null)
         * {
         *      aslidersPrev = state.GetAccelerationSliders();
         *      fslidersPrev = state.GetForceSliders();
         *      povPrev = state.GetPointOfViewControllers();
         *      slidersPrev = state.GetSliders();
         *      vslidersPrev = state.GetVelocitySliders();
         * }
         *
         * int[] asliders = state.GetAccelerationSliders();
         * int[] fsliders = state.GetForceSliders();
         * int[] povC = state.GetPointOfViewControllers();
         * int[] sliders = state.GetSliders();
         * int[] vsliders = state.GetVelocitySliders();
         *
         * for(int i = 0; i < asliders.Length; i++)
         * {
         *      if (asliders[i] != aslidersPrev[i])
         *              Console.WriteLine(asliders[i]);
         * }
         * aslidersPrev = asliders;
         *
         * for (int i = 0; i < fsliders.Length; i++)
         * {
         *      if (fsliders[i] != fslidersPrev[i])
         *              Console.WriteLine(fsliders[i]);
         * }
         * fslidersPrev = fsliders;
         *
         * for (int i = 0; i < pov.Length; i++)
         * {
         *      if (povC[i] != povPrev[i])
         *              Console.WriteLine(povC[i]);
         * }
         * povPrev = povC;
         *
         * for (int i = 0; i < sliders.Length; i++)
         * {
         *      if (sliders[i] != slidersPrev[i])
         *              Console.WriteLine(sliders[i]);
         * }
         * slidersPrev = sliders;
         *
         * for (int i = 0; i < vsliders.Length; i++)
         * {
         *      if (vsliders[i] != vslidersPrev[i])
         *              Console.WriteLine(vsliders[i]);
         * }
         * vslidersPrev = vsliders;
         */
    }