Exemplo n.º 1
0
        public override void Initialize(InputManager inputManager)
        {
            var context        = inputManager.Game.Context as GameContextiOS;
            var uiControl      = context.Control;
            var gameController = context.Control.GameViewController;

            pointer = new PointeriOS(this, uiControl, gameController);
            RegisterDevice(pointer);

            // Create sensor managers
            motionManager   = new CMMotionManager();
            locationManager = new CLLocationManager();

            // Set desired sensor sampling intervals
            double updateInterval = 1 / InputManager.DesiredSensorUpdateRate;

            motionManager.AccelerometerUpdateInterval = updateInterval;
            motionManager.GyroUpdateInterval          = updateInterval;
            motionManager.DeviceMotionUpdateInterval  = updateInterval;

            // Determine supported sensors
            if (motionManager.AccelerometerAvailable)
            {
                accelerometerSensor = new AccelerometerSensor(this, "iOS");
                RegisterDevice(accelerometerSensor);
            }

            if (CLLocationManager.HeadingAvailable)
            {
                compassSensor = new CompassSensor(this, "iOS");
                RegisterDevice(compassSensor);
            }

            if (motionManager.GyroAvailable)
            {
                gyroscopeSensor = new GyroscopeSensor(this, "iOS");
                RegisterDevice(gyroscopeSensor);
            }

            if (motionManager.DeviceMotionAvailable)
            {
                gravitySensor          = new GravitySensor(this, "iOS");
                userAccelerationSensor = new UserAccelerationSensor(this, "iOS");
                orientationSensor      = new OrientationSensor(this, "iOS");
                RegisterDevice(gravitySensor);
                RegisterDevice(userAccelerationSensor);
                RegisterDevice(orientationSensor);
            }
        }
Exemplo n.º 2
0
        public override void Initialize(InputManager inputManager)
        {
            var context = inputManager.Game.Context as GameContextAndroid;

            uiControl = context.Control;

            // Create android pointer and keyboard
            keyboard = new KeyboardAndroid(this, uiControl);
            pointer  = new PointerAndroid(this, uiControl);
            RegisterDevice(keyboard);
            RegisterDevice(pointer);

            // Create android sensors
            if ((accelerometerListener = TryGetSensorListener(SensorType.Accelerometer)) != null)
            {
                accelerometerSensor = new AccelerometerSensor(this, "Android");
                RegisterDevice(accelerometerSensor);
            }

            if ((linearAccelerationListener = TryGetSensorListener(SensorType.LinearAcceleration)) != null)
            {
                userAccelerationSensor = new UserAccelerationSensor(this, "Android");
                RegisterDevice(userAccelerationSensor);
            }

            if ((gyroscopeListener = TryGetSensorListener(SensorType.Gyroscope)) != null)
            {
                gyroscopeSensor = new GyroscopeSensor(this, "Android");
                RegisterDevice(gyroscopeSensor);
            }

            if ((gravityListener = TryGetSensorListener(SensorType.Gravity)) != null)
            {
                gravitySensor = new GravitySensor(this, "Android");
                RegisterDevice(gravitySensor);
            }

            if ((orientationListener = TryGetSensorListener(SensorType.RotationVector)) != null)
            {
                orientationSensor = new OrientationSensor(this, "Android");
                compassSensor     = new CompassSensor(this, "Android");
                RegisterDevice(orientationSensor);
                RegisterDevice(compassSensor);
            }
        }
Exemplo n.º 3
0
        public override void Initialize(InputManager inputManager)
        {
            base.Initialize(inputManager);

            // Create android sensors
            if ((accelerometerListener = TryGetSensorListener(SensorType.Accelerometer)) != null)
            {
                accelerometerSensor = new AccelerometerSensor(this, "Android");
                RegisterDevice(accelerometerSensor);
            }

            if ((linearAccelerationListener = TryGetSensorListener(SensorType.LinearAcceleration)) != null)
            {
                userAccelerationSensor = new UserAccelerationSensor(this, "Android");
                RegisterDevice(userAccelerationSensor);
            }

            if ((gyroscopeListener = TryGetSensorListener(SensorType.Gyroscope)) != null)
            {
                gyroscopeSensor = new GyroscopeSensor(this, "Android");
                RegisterDevice(gyroscopeSensor);
            }

            if ((gravityListener = TryGetSensorListener(SensorType.Gravity)) != null)
            {
                gravitySensor = new GravitySensor(this, "Android");
                RegisterDevice(gravitySensor);
            }

            if ((orientationListener = TryGetSensorListener(SensorType.RotationVector)) != null)
            {
                orientationSensor = new OrientationSensor(this, "Android");
                compassSensor     = new CompassSensor(this, "Android");
                RegisterDevice(orientationSensor);
                RegisterDevice(compassSensor);
            }
        }
Exemplo n.º 4
0
        public override void Initialize(InputManager inputManager)
        {
            var mouseCapabilities = new MouseCapabilities();

            if (mouseCapabilities.MousePresent > 0)
            {
                pointer = new MouseUWP(this, coreWindow);
                RegisterDevice(pointer);
            }

            var keyboardCapabilities = new KeyboardCapabilities();

            if (keyboardCapabilities.KeyboardPresent > 0)
            {
                keyboard = new KeyboardUWP(this, coreWindow);
                RegisterDevice(keyboard);
            }

            // get sensor default instances
            windowsAccelerometer = WindowsAccelerometer.GetDefault();
            if (windowsAccelerometer != null)
            {
                accelerometer = new AccelerometerSensor(this, "UWP");
                RegisterDevice(accelerometer);
            }

            windowsCompass = WindowsCompass.GetDefault();
            if (windowsCompass != null)
            {
                compass = new CompassSensor(this, "UWP");
                RegisterDevice(compass);
            }

            windowsGyroscope = WindowsGyroscope.GetDefault();
            if (windowsGyroscope != null)
            {
                gyroscope = new GyroscopeSensor(this, "UWP");
                RegisterDevice(gyroscope);
            }

            windowsOrientation = WindowsOrientation.GetDefault();
            if (windowsOrientation != null)
            {
                orientation = new OrientationSensor(this, "UWP");
                RegisterDevice(orientation);
            }

            // Virtual sensors
            if (windowsOrientation != null && windowsAccelerometer != null)
            {
                gravity          = new GravitySensor(this, "UWP");
                userAcceleration = new UserAccelerationSensor(this, "UWP");
                RegisterDevice(gravity);
                RegisterDevice(userAcceleration);
            }

            Gamepad.GamepadAdded   += GamepadOnGamepadAdded;
            Gamepad.GamepadRemoved += GamepadOnGamepadRemoved;

            Scan();
        }
Exemplo n.º 5
0
        public override void Initialize(InputManager inputManager)
        {
            var nativeWindow = inputManager.Game.Window.NativeWindow;

            CoreWindow coreWindow;

            if (nativeWindow.Context == AppContextType.UWPCoreWindow)
            {
                coreWindow = (CoreWindow)nativeWindow.NativeWindow;
            }
            else if (nativeWindow.Context == AppContextType.UWPXaml)
            {
                coreWindow = Window.Current.CoreWindow;
            }
            else
            {
                throw new ArgumentException(string.Format("WindowContext [{0}] not supported", nativeWindow.Context));
            }

            var mouseCapabilities = new MouseCapabilities();

            if (mouseCapabilities.MousePresent > 0)
            {
                pointer = new MouseUWP(this, coreWindow);
                RegisterDevice(pointer);
            }

            var keyboardCapabilities = new KeyboardCapabilities();

            if (keyboardCapabilities.KeyboardPresent > 0)
            {
                keyboard = new KeyboardUWP(this, coreWindow);
                RegisterDevice(keyboard);
            }

            // get sensor default instances
            windowsAccelerometer = WindowsAccelerometer.GetDefault();
            if (windowsAccelerometer != null)
            {
                accelerometer = new AccelerometerSensor(this, "UWP");
                RegisterDevice(accelerometer);
            }

            windowsCompass = WindowsCompass.GetDefault();
            if (windowsCompass != null)
            {
                compass = new CompassSensor(this, "UWP");
                RegisterDevice(compass);
            }

            windowsGyroscope = WindowsGyroscope.GetDefault();
            if (windowsGyroscope != null)
            {
                gyroscope = new GyroscopeSensor(this, "UWP");
                RegisterDevice(gyroscope);
            }

            windowsOrientation = WindowsOrientation.GetDefault();
            if (windowsOrientation != null)
            {
                orientation = new OrientationSensor(this, "UWP");
                RegisterDevice(orientation);
            }

            // Virtual sensors
            if (windowsOrientation != null && windowsAccelerometer != null)
            {
                gravity          = new GravitySensor(this, "UWP");
                userAcceleration = new UserAccelerationSensor(this, "UWP");
                RegisterDevice(gravity);
                RegisterDevice(userAcceleration);
            }

            Gamepad.GamepadAdded   += GamepadOnGamepadAdded;
            Gamepad.GamepadRemoved += GamepadOnGamepadRemoved;

            Scan();
        }