I’m using the Motion API and I’m trying to figure out a control scheme for the game I’m currently developing.
What I’m trying to achive is for a orienation of the device to collelate directly to a position. Such that tilting the phone forward and to the left represents the top left position and back to the right would be the bottom right position.
Photos to make it clearer (the red dot would be the calculated position).

Forward and Left

Back and Right
Now for the tricky bit. I also have to make sure that the values take into account left landscape and right landscape device orientations (portrait is the default so no calculations would be needed for it).
Has anyone done anything like this?
Notes:
-
I’ve tried using the yaw, pitch, roll and Quaternion readings.
-
I just realised the behaviour I’m talking about would be alot like a level.
Sample:
// Get device facing vector
public static Vector3 GetState()
{
lock (lockable)
{
var down = Vector3.Forward;
var direction = Vector3.Transform(down, state);
switch (Orientation) {
case Orientation.LandscapeLeft:
return Vector3.TransformNormal(direction, Matrix.CreateRotationZ(-rightAngle));
case Orientation.LandscapeRight:
return Vector3.TransformNormal(direction, Matrix.CreateRotationZ(rightAngle));
}
return direction;
}
}
You would like to control object on screen using acceleration sensor.
This is method that calculates position of object
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.
For this to work we don’t need X axes of sensor at all…
This is just quick implementation. You would find center for sensor since this
Viewport.Width / 2fisn’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.This code is tested on Windows Phone Device! (and works)