/MonoGame.Framework/PSSuite/Input/Accelerometer.cs

https://bitbucket.org/refuzion/monogame · C# · 78 lines · 31 code · 7 blank · 40 comment · 0 complexity · a6898806ecfba51ebaf95559eb7fc32b MD5 · raw file

  1. // #region License
  2. // /*
  3. // Microsoft Public License (Ms-PL)
  4. // MonoGame - Copyright © 2009 The MonoGame Team
  5. //
  6. // All rights reserved.
  7. //
  8. // This license governs use of the accompanying software. If you use the software, you accept this license. If you do not
  9. // accept the license, do not use the software.
  10. //
  11. // 1. Definitions
  12. // The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under
  13. // U.S. copyright law.
  14. //
  15. // A "contribution" is the original software, or any additions or changes to the software.
  16. // A "contributor" is any person that distributes its contribution under this license.
  17. // "Licensed patents" are a contributor's patent claims that read directly on its contribution.
  18. //
  19. // 2. Grant of Rights
  20. // (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
  21. // each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
  22. // (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
  23. // each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.
  24. //
  25. // 3. Conditions and Limitations
  26. // (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
  27. // (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software,
  28. // your patent license from such contributor to the software ends automatically.
  29. // (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
  30. // notices that are present in the software.
  31. // (D) If you distribute any portion of the software in source code form, you may do so only under this license by including
  32. // a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object
  33. // code form, you may only do so under a license that complies with this license.
  34. // (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees
  35. // or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent
  36. // permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular
  37. // purpose and non-infringement.
  38. // */
  39. // #endregion License
  40. //
  41. using System;
  42. using Sce.PlayStation.Core.Environment;
  43. using Sce.PlayStation.Core.Input;
  44. namespace Microsoft.Xna.Framework.Input
  45. {
  46. public static class Accelerometer
  47. {
  48. private static AccelerometerState _state;
  49. private static AccelerometerCapabilities _capabilities = new AccelerometerCapabilities();
  50. private static Vector3 _accelerometerVector = new Vector3(0, 0, 0);
  51. public static void SetupAccelerometer()
  52. {
  53. _state = new AccelerometerState { IsConnected = true };
  54. }
  55. public static AccelerometerCapabilities GetCapabilities()
  56. {
  57. return _capabilities;
  58. }
  59. public static AccelerometerState GetState()
  60. {
  61. Update();
  62. return _state;
  63. }
  64. internal static void Update()
  65. {
  66. var motionData = Motion.GetData(0);
  67. _accelerometerVector = new Vector3(motionData.Acceleration.X, motionData.Acceleration.Y, motionData.Acceleration.Z);
  68. _state.Acceleration = _accelerometerVector;
  69. }
  70. }
  71. }