Jypeli 10
The simple game programming library
AndroidAccelerometer.cs
Siirry tämän tiedoston dokumentaatioon.
1//using System;
2//using Microsoft.Xna.Framework;
3// TODO: .NET Core 3.0 does not support Android.
4// fix using Xamarin.Android, or wait for .NET 5.0 coming in november 2020?
5
6//using XnaAccelerometer = Microsoft.Devices.Sensors.Accelerometer;
7
8//namespace Jypeli.Android
9//{
10// public class AndroidAccelerometer : Accelerometer
11// {
12// private readonly XnaAccelerometer _accelerometer = null;
13
14// public AndroidAccelerometer()
15// : base()
16// {
17// _accelerometer = new XnaAccelerometer();
18// CurrentState = PrevState = new Vector3( 0, 1, 0 );
19// }
20
21// /// <summary>
22// /// Käynnistää kiihtyvyysanturin.
23// /// </summary>
24// public override void Start()
25// {
26// if ( _accelerometer == null || started )
27// return;
28
29// _accelerometer.Start();
30// base.Start();
31// }
32
33// /// <summary>
34// /// Pysäyttää kiihtyvyysanturin.
35// /// </summary>
36// public override void Stop()
37// {
38// if ( _accelerometer == null || !started )
39// return;
40
41// _accelerometer.Stop();
42// base.Stop();
43// }
44
45// internal override Vector Project2d( Vector3 spaceVector )
46// {
47// spaceVector = Transform3d( spaceVector );
48
49// switch ( Calibration )
50// {
51// case AccelerometerCalibration.ZeroAngle:
52// return new Vector( spaceVector.X, spaceVector.Y );
53// case AccelerometerCalibration.HalfRightAngle:
54// return new Vector( spaceVector.X, spaceVector.Y - spaceVector.Z );
55// case AccelerometerCalibration.RightAngle:
56// return new Vector( spaceVector.X, -spaceVector.Z );
57// default:
58// return new Vector( spaceVector.X, spaceVector.Y );
59// }
60// }
61
62// private void UpdateDisplayOrientation( Vector3 e )
63// {
64// if ( e.Z > 0.8 )
65// return;
66
67// double angle = Math.Atan2( -e.X, e.Y ) * 180.0 / Math.PI;
68// double delta = 5;
69
70// if ( angle > -45 + delta && angle < 45 - delta )
71// Game.Device.DisplayOrientation = DisplayOrientation.Portrait;
72// else if ( angle > 45 + delta && angle < 135 - delta )
73// Game.Device.DisplayOrientation = DisplayOrientation.LandscapeRight;
74// else if ( angle > -135 + delta && angle < -45 - delta )
75// Game.Device.DisplayOrientation = DisplayOrientation.LandscapeLeft;
76// else
77// Game.Device.DisplayOrientation = DisplayOrientation.PortraitInverse;
78// }
79
80// internal override Vector3 GetState()
81// {
82// if ( _accelerometer == null || !started )
83// return PrevState;
84
85// var e = _accelerometer.CurrentValue.Acceleration;
86// UpdateDisplayOrientation( e );
87
88// return new Vector3( e.X, e.Y, e.Z );
89// }
90
91// private Vector3 Transform3d( Vector3 e )
92// {
93// int xmul = DisplayOrientation.Xmul;
94// int ymul = DisplayOrientation.Ymul;
95// return new Vector3( xmul * e.Y - ymul * e.X, -xmul * e.X - ymul * e.Y, -e.Z );
96
97// /*switch ( DisplayOrientation )
98// {
99// case DisplayOrientation.Landscape:
100// case DisplayOrientation.LandscapeLeft:
101// return new Vector3( e.Y, -e.X, -e.Z );
102// case DisplayOrientation.LandscapeRight:
103// return new Vector3( -e.Y, e.X, -e.Z );
104// case DisplayOrientation.PortraitInverse:
105// return new Vector3( e.X, e.Y, -e.Z );
106// case DisplayOrientation.Portrait:
107// default:
108// return new Vector3( -e.X, -e.Y, -e.Z );
109// }*/
110// }
111// }
112//}