コード例 #1
0
ファイル: Program.cs プロジェクト: andyhebear/extramegablob
        static bool AxisMoved(JoyStickEvent arg, int axis)
        {
            //Provide a little dead zone
            Axis_NativePtr axiscls = arg.state.GetAxis(axis);

            if (axiscls.abs > 2500 || axiscls.abs < -2500)
            {
                Console.Write("\n" + arg.device.Vendor() + ". Axis # " + axis + " Value: " + axiscls.abs);
            }
            return(true);
        }
コード例 #2
0
        private static bool ProcessUnbufferedInput(FrameEvent evt)
        {
            m_Bus.ProcessMessages();
            mNinjaKeyboard.Capture();
            mNinjaMouse.Capture();

            m_time += (ulong)(evt.timeSinceLastFrame * 1000);
            ////IMotion currentMovement= m_Path.GetCurrentMotion(m_time);
            //var motion = currentMovement.GetCurrentPosition(m_time);
            ////motion.x += 50;
            //var rotation = new Angle(currentMovement.GetVelocity(m_time));
            //rotation.ReduceAngle();

            //Quaternion quat = new Quaternion(new Radian(rotation.Value ), new Vector3(0, -1, 0));

            //mNinjaNode.Position = new Vector3(motion.x,  0.0, motion.y);
            //mNinjaNode.Orientation = quat;
            ////Vector3 ninjaMove = Vector3.ZERO;

            if (mNinjaMouse.MouseState.ButtonDown(MOIS.MouseButtonID.MB_Left))
            {
                Axis_NativePtr x = mNinjaMouse.MouseState.X;
                var            y = mNinjaMouse.MouseState.Y;
            }

            if (mNinjaKeyboard.IsKeyDown(MOIS.KeyCode.KC_SPACE))
            {
                mLight.Visible = !mLight.Visible;
            }

            if (mLightToggleTimeout > 0)
            {
                mLightToggleTimeout -= evt.timeSinceLastFrame;
            }
            else
            {
                if (mNinjaKeyboard.IsKeyDown(MOIS.KeyCode.KC_SPACE))
                {
                    mLight.Visible      = !mLight.Visible;
                    mLightToggleTimeout = 0.5f;
                }
            }

            if (mNinjaKeyboard.IsKeyDown(MOIS.KeyCode.KC_ESCAPE))
            {
                return(false);
            }

            return(true);
        }
コード例 #3
0
        public static Vector2 GetJoystickVector(IList <JoyStick> joysticks, Boolean lowSens, int axisX, int axisY)
        {
            if (joysticks != null)
            {
                int i = 0;
                foreach (JoyStick j in joysticks)
                {
                    if (i != GetCurrentJoystickIndex())
                    {
                        i++;
                        continue;
                    }
                    i++;

                    int num = j.JoyStickState.AxisCount;
                    if (num >= 2)
                    {
                        int axisCount = j.JoyStickState.AxisCount;

                        if (axisY > axisCount - 1)
                        {
                            axisY = 0;
                            //  throw new Exception("JoystickVerticalAxisNo is greater than number of axes. Please change it in your KeyMap.ini");
                        }

                        if (axisX > axisCount - 1)
                        {
                            axisX = 1;
                            //throw new Exception("JoystickHorizontalAxisNo is greater than number of axes. Please change it in your KeyMap.ini");
                        }

                        Axis_NativePtr axisHPtr = j.JoyStickState.GetAxis(axisX);
                        Axis_NativePtr axisVPtr = j.JoyStickState.GetAxis(axisY);

                        /*
                         * for(int z=0; z< j.JoyStickState.VectorCount; z++) {
                         *      Console.Write("vector "+z+": "+j.JoyStickState.GetVector(z)+", ");
                         * }
                         * Console.WriteLine();*/



                        double v = (KeyMap.Instance.JoystickSensivity * axisVPtr.abs / JoyStick.MAX_AXIS);
                        double h = (KeyMap.Instance.JoystickSensivity * axisHPtr.abs / JoyStick.MAX_AXIS);

                        // Console.WriteLine(h + " " + v);
                        double dead = KeyMap.Instance.JoystickDeadZone;
                        dead = lowSens ? 3 * dead : dead;
                        if (Math.Abs(v) < dead)
                        {
                            v = 0;
                        }
                        else if (v > 1)
                        {
                            v = 1;
                        }
                        else if (v < -1)
                        {
                            v = -1;
                        }

                        if (Math.Abs(h) < dead)
                        {
                            h = 0;
                        }
                        else if (h > 1)
                        {
                            h = 1;
                        }
                        else if (h < -1)
                        {
                            h = -1;
                        }

                        //     Console.WriteLine("Joystick X=" + axisH.abs  +"/"+ JoyStick.MAX_AXIS + "; Y=" + axisV.abs  +"/"+ JoyStick.MAX_AXIS );


                        //	h = Math.Log(1+h);
                        //   v = Math.Log(1+v);

                        //    Console.WriteLine("Joystick X=" + h  +" Y=" + v  );

                        return(new Vector2((float)h, (float)-v));
                    }
                    else
                    {
                        // no joys and no POVs
                        return(Vector2.ZERO);
                    }
                }
            }
            else
            {
                return(Vector2.ZERO);
            }
            return(Vector2.ZERO);
        }