Esempio n. 1
0
        public override void Initialize()
        {
            base.Initialize();

            var windowHandle = Game.Window.NativeWindow;

            switch (windowHandle.Context)
            {
            case AppContextType.WindowsRuntime:
                InitializeFromFrameworkElement((FrameworkElement)windowHandle.NativeHandle);
                break;

            default:
                throw new ArgumentException(string.Format("WindowContext [{0}] not supported", Game.Context.ContextType));
            }

            // Scan all registered inputs
            Scan();

            // get sensor default instances
            windowsAccelerometer = WindowsAccelerometer.GetDefault();
            windowsCompass       = WindowsCompass.GetDefault();
            windowsGyroscope     = WindowsGyroscope.GetDefault();
            windowsOrientation   = WindowsOrientation.GetDefault();

            // determine which sensors are available
            Accelerometer.IsSupported    = windowsAccelerometer != null;
            Compass.IsSupported          = windowsCompass != null;
            Gyroscope.IsSupported        = windowsGyroscope != null;
            Orientation.IsSupported      = windowsOrientation != null;
            Gravity.IsSupported          = Orientation.IsSupported && Accelerometer.IsSupported;
            UserAcceleration.IsSupported = Gravity.IsSupported;
        }
        private static Quaternion GetOrientation(WindowsOrientation orientation)
        {
            var reading = orientation.GetCurrentReading();

            if (reading == null)
            {
                return(Quaternion.Identity);
            }

            var q = reading.Quaternion;

            return(new Quaternion(q.X, q.Z, -q.Y, q.W));
        }
Esempio n. 3
0
        public override void Initialize()
        {
            base.Initialize();

            var windowHandle = Game.Window.NativeWindow;

            switch (windowHandle.Context)
            {
            case AppContextType.UWP:
                InitializeFromFrameworkElement((FrameworkElement)windowHandle.NativeWindow);
                break;

            default:
                throw new ArgumentException(string.Format("WindowContext [{0}] not supported", Game.Context.ContextType));
            }

            // Scan all registered inputs
            Scan();

            // get sensor default instances
            windowsAccelerometer = WindowsAccelerometer.GetDefault();
            windowsCompass       = WindowsCompass.GetDefault();
            windowsGyroscope     = WindowsGyroscope.GetDefault();
            windowsOrientation   = WindowsOrientation.GetDefault();

            // determine which sensors are available
            Accelerometer.IsSupported    = windowsAccelerometer != null;
            Compass.IsSupported          = windowsCompass != null;
            Gyroscope.IsSupported        = windowsGyroscope != null;
            Orientation.IsSupported      = windowsOrientation != null;
            Gravity.IsSupported          = Orientation.IsSupported && Accelerometer.IsSupported;
            UserAcceleration.IsSupported = Gravity.IsSupported;

            if (mouseCapabilities.MousePresent > 0)
            {
                MouseDevice.GetForCurrentView().MouseMoved += (_, y) => HandleRelativeOnMouseMoved(y);
            }
        }
Esempio 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();
        }
Esempio 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();
        }
        private static Quaternion GetOrientation(WindowsOrientation orientation)
        {
            var reading = orientation.GetCurrentReading();
            if (reading == null)
                return Quaternion.Identity;

            var q = reading.Quaternion;
            return new Quaternion(q.X, q.Z, -q.Y, q.W);
        }
        public override void Initialize()
        {
            base.Initialize();

            var windowHandle = Game.Window.NativeWindow;
            switch (windowHandle.Context)
            {
                case AppContextType.UWP:
                    InitializeFromFrameworkElement((FrameworkElement)windowHandle.NativeWindow);
                    break;
                default:
                    throw new ArgumentException(string.Format("WindowContext [{0}] not supported", Game.Context.ContextType));
            }

            // Scan all registered inputs
            Scan();
            
            // get sensor default instances
            windowsAccelerometer = WindowsAccelerometer.GetDefault();
            windowsCompass = WindowsCompass.GetDefault();
            windowsGyroscope = WindowsGyroscope.GetDefault();
            windowsOrientation = WindowsOrientation.GetDefault();

            // determine which sensors are available
            Accelerometer.IsSupported = windowsAccelerometer != null;
            Compass.IsSupported = windowsCompass != null;
            Gyroscope.IsSupported = windowsGyroscope != null;
            Orientation.IsSupported = windowsOrientation != null;
            Gravity.IsSupported = Orientation.IsSupported && Accelerometer.IsSupported;
            UserAcceleration.IsSupported = Gravity.IsSupported;

            if (mouseCapabilities.MousePresent > 0)
                MouseDevice.GetForCurrentView().MouseMoved += (_,y) => HandleRelativeOnMouseMoved(y);
        }
        public override void Initialize()
        {
            base.Initialize();

            var windowHandle = Game.Window.NativeWindow;
            switch (windowHandle.Context)
            {
                case AppContextType.WindowsRuntime:
                    InitializeFromFrameworkElement((FrameworkElement)windowHandle.NativeHandle);
                    break;
                default:
                    throw new ArgumentException(string.Format("WindowContext [{0}] not supported", Game.Context.ContextType));
            }

            // Scan all registered inputs
            Scan();
            
            // get sensor default instances
            windowsAccelerometer = WindowsAccelerometer.GetDefault();
            windowsCompass = WindowsCompass.GetDefault();
            windowsGyroscope = WindowsGyroscope.GetDefault();
            windowsOrientation = WindowsOrientation.GetDefault();

            // determine which sensors are available
            Accelerometer.IsSupported = windowsAccelerometer != null;
            Compass.IsSupported = windowsCompass != null;
            Gyroscope.IsSupported = windowsGyroscope != null;
            Orientation.IsSupported = windowsOrientation != null;
            Gravity.IsSupported = Orientation.IsSupported && Accelerometer.IsSupported;
            UserAcceleration.IsSupported = Gravity.IsSupported;
        }