Upload
sarah-ferguson
View
224
Download
0
Tags:
Embed Size (px)
Citation preview
UFCFX5-15-3Mobile Device Development
Mobile Device Components
The Accelerometer and Gyroscope
UFCFX5-15-3Mobile Device Development
Agenda
Mobile Device Attitude PropertiesAccelerometerGyroscopeUnity 3D AccelerometerUnity 3D Gyroscope
UFCFX5-15-3Mobile Device Development
Mobile Axis Orientation A mobile device will use an internal Attitude
Measurement and Orientation System The orientation data can then be used by apps to
respond accordingly to changes in the orientation of the device.
Orientation data is typically used in the contexts of 3D environments such as games and 2D scenarios.
The devices Gyroscope is typically involved in providing the orientation data of the mobile device
See the respective API’s for more information on the available methods.
UFCFX5-15-3Mobile Device Development
Orientation Properties The 3D orientation of a mobile device is described by
three properties:
Pitch Roll Yaw
UFCFX5-15-3Mobile Device Development
3D Coordinate Axis
Z axisY axis
X axis
3D Device Coordinate axes for X, Y, Z
UFCFX5-15-3Mobile Device Development
Pitch
Rotation about the X axis is called ‘Pitch’
X axis
UFCFX5-15-3Mobile Device Development
Roll
Rotation about the Y axis is called ‘Roll’
Y axis
UFCFX5-15-3Mobile Device Development
YAW
Rotation about the Z axis is called ‘YAW’
Z axis
UFCFX5-15-3Mobile Device Development
Retrieving Gyroscope Values
// global variables to store gyro data
public float pitchValue = 0.0f;
public float rollValue = 0.0f;
public float yawValue = 0.0f;
void Start () {
// enable the Gyroscope
Input.gyro.enabled = true;
}
UFCFX5-15-3Mobile Device Development
Assigning Gyroscope Values
// Unity stores the values of pitch, roll and yaw in
// x, y, and z respectively
Void Update () {
pitchValue = Input.gyro.rotationRateUnbiased.x;
rollValue = Input.gyro.rotationRateUnbiased.y;
yawValue = Input.gyro.rotationRateUnbiased.z;
}
//see the API for the various methods
UFCFX5-15-3Mobile Device Development
Application of Accelerometer Values
// simple application of accelerometer data
public class AccelerometerInput : MonoBehaviour { void Update () { transform.Translate(Input.acceleration.x, 0, -Input.acceleration.z); }}
// attach script to a game object to control linear movement in x and z
UFCFX5-15-3Mobile Device Development
Retrieving Accelerometer Values
// global variables to store accelerometer data
public float xValue = 0.0f;
public float yValue = 0.0f;
public float zValue = 0.0f;
UFCFX5-15-3Mobile Device Development
Retrieving Accelerometer Values
// store the accelerometer values associated with
// x , y, and z as a Vector3 object (force and magnitude)
Vector3 accelerator = Input.acceleration;
Void Update () {
// basic retrieval of Vector3 values in x, y, and z
xValue = accelerator.x;
yValue = accelerator.y;
zValue = accelerator.z;
}
// would usually required more computation
UFCFX5-15-3Mobile Device Development
Summary
Mobile devices feature a gyroscope and an accelerometer The gyroscope maintains information on the device’s rotational
orientation The x , y and z axis rotational orientation are referred to a pitch, roll
and yaw respectively The rotational values for each axis represent radians per second The accelerometer measures acceleration force applied to the device
on x, y and z axes and gravitational force g, both in m/s2
Depending on the scenario, apps may require one set of device data or both