Example #1
0
        private async void Compass_ReadingChanged(Windows.Devices.Sensors.Compass sender, Windows.Devices.Sensors.CompassReadingChangedEventArgs args)
        {
            if (args?.Reading?.HeadingTrueNorth.HasValue ?? false)
            {
#if SILVERLIGHT
                System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    OnCompassChanged(new CompassChangedEventArgs(args.Reading.HeadingTrueNorth.Value));
                });
#else
                var dispatcher = Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher;
                if (dispatcher != null)
                {
                    await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        OnCompassChanged(new CompassChangedEventArgs(args.Reading.HeadingTrueNorth.Value));
                    });
                }
                else
                {
                    OnCompassChanged(new CompassChangedEventArgs(args.Reading.HeadingTrueNorth.Value));
                }
#endif
            }
        }
Example #2
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 float GetNorth(WindowsCompass compass)
        {
            var currentReading = compass.GetCurrentReading();

            if (currentReading == null)
            {
                return(0f);
            }

            return(MathUtil.DegreesToRadians((float)(currentReading.HeadingTrueNorth ?? currentReading.HeadingMagneticNorth)));
        }
Example #4
0
        /// <summary>
        /// Dispose
        /// </summary>
        /// <param name="disposing"></param>
        public override void Dispose(bool disposing)
        {
            if (!disposed)
            {
                if (disposing)
                {
                    Stop();
                    compass = null;
                }

                disposed = true;
            }

            base.Dispose(disposing);
        }
Example #5
0
        /// <summary>
        /// Start compass
        /// </summary>
        public override void Start()
        {
            if (!IsSupported)
            {
                return;
            }

            if (compass == null)
            {
                // Instantiate the compass.
                compass = Windows.Devices.Sensors.Compass.GetDefault();
                compass.ReportInterval = compass.MinimumReportInterval >= 20 ? 20 : compass.MinimumReportInterval;
            }


            compass.ReadingChanged += Compass_ReadingChanged;
        }
Example #6
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);
            }
        }
Example #7
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();
        }
Example #8
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 float GetNorth(WindowsCompass compass)
 {
     var currentReading = compass.GetCurrentReading();
     if (currentReading == null)
         return 0f;
     
     return MathUtil.DegreesToRadians((float)(currentReading.HeadingTrueNorth ?? currentReading.HeadingMagneticNorth));
 }
        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;
        }