Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You would like to control object on screen using acceleration sensor.</p> <pre><code>protected override void Initialize() { ... Accelerometer acc = new Accelerometer(); acc.ReadingChanged += AccReadingChanged; acc.Start(); ... } </code></pre> <p>This is method that calculates position of object</p> <pre><code>void AccReadingChanged(object sender, AccelerometerReadingEventArgs e) { // Y axes is same in both cases this.circlePosition.Y = (float)e.Z * GraphicsDevice.Viewport.Height + GraphicsDevice.Viewport.Height / 2.0f; // X axes needs to be negative when oriented Landscape - Left if (Window.CurrentOrientation == DisplayOrientation.LandscapeLeft) this.circlePosition.X = -(float)e.Y * GraphicsDevice.Viewport.Width + GraphicsDevice.Viewport.Width / 2.0f; else this.circlePosition.X = (float)e.Y * GraphicsDevice.Viewport.Width + GraphicsDevice.Viewport.Width / 2.0f; } </code></pre> <p>I'm using Z axes of sensor as my Y in game and Y axes of sensor as my X in game. Calibration will be done by subtracting Z axes of sensor from center. In this way, our sensor axes directly correspond to position (percentage) on screen. </p> <p>For this to work we don't need X axes of sensor at all...</p> <p>This is just quick implementation. You would find center for sensor since this <code>Viewport.Width / 2f</code> isn't center, sum and average of 3 measurements, calibration on X sensor axes so that you could play/use application on flat or some degree position, etc.</p> <p><strong>This code is tested on Windows Phone Device!</strong> (and works)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload