视频1 视频21 视频41 视频61 视频文章1 视频文章21 视频文章41 视频文章61 推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37 推荐39 推荐41 推荐43 推荐45 推荐47 推荐49 关键词1 关键词101 关键词201 关键词301 关键词401 关键词501 关键词601 关键词701 关键词801 关键词901 关键词1001 关键词1101 关键词1201 关键词1301 关键词1401 关键词1501 关键词1601 关键词1701 关键词1801 关键词1901 视频扩展1 视频扩展6 视频扩展11 视频扩展16 文章1 文章201 文章401 文章601 文章801 文章1001 资讯1 资讯501 资讯1001 资讯1501 标签1 标签501 标签1001 关键词1 关键词501 关键词1001 关键词1501 专题2001
android重力感应详解
2025-10-03 05:30:05 责编:小OO
文档
星期天在家没有事情,一边翻译sdk中onSensorChanged 的解释,一遍摸索G1下onSensorChanged 第二个参数values的含义:

总结如下,发完赶紧吃饭! 

1public abstract void onAccuracyChanged (int sensor, int accuracy)

复制代码

Called when the accuracy of a sensor has changed. See SensorManager for details.

Parameters:

sensor  The ID of the sensor being monitored

accuracy  The new accuracy of this sensor.  

当sensor的"精确度"发生改变的时候,该方法会被回调,详细信息请参看 SensorManager 类

参数:

sensor  被监视的sensor的ID

accuracy 关于此sensor的新精确度描述

2public abstract void onSensorChanged (int sensor, float[] values)

复制代码

Called when sensor values have changed. The length and contents of the values array vary depending on

which sensor is being monitored. See SensorManager for details on possible sensor types.

当sensor的值发生改变的时候被回调,values数组的元素个数和其中的内容取决于哪个sensor正在被监视,sensor的可

用类型请参看SensorManager类

Definition of the coordinate system used below.

The X axis refers to the screen's horizontal axis (the small edge in portrait mode, the long edge in

landscape mode) and points to the right.

The Y axis refers to the screen's vertical axis and points towards the top of the screen (the origin is

in the lower-left corner).

The Z axis points toward the sky when the device is lying on its back on a table.

X轴:和屏幕平行并且指向右边的轴(在portrait中使用"小边角在landscape模式中使用"长边角")

Y轴:和屏幕垂直并且指向屏幕上方的轴(坐标原点在左下角)

Z轴:当设备(手机)背面着地放在桌子上的时候,指向天空的方向就是Z轴

IMPORTANT NOTE: The axis are swapped when the device's screen orientation changes. To access the

unswapped values, use indices 3, 4 and 5 in values[].

一定要大家注意的:坐标系是跟随手机屏幕的方向改变而改变的,values数组中下标为3、4、5的3个元素,使用的是恒

定的坐标系,(和尚注:你可以通过这三个元素得到一个不变的坐标,游戏开发中可能会用到)

(和尚注:此方法的第一个参数sensor可能是

SensorManager.SENSOR_ORIENTATION

SensorManager.SENSOR_ORIENTATION

中的一个)

解释如下:

SENSOR_ORIENTATION, SENSOR_ORIENTATION_RAW:

All values are angles in degrees.

values[0]: Azimuth, rotation around the Z axis (0<=azimuth<360). 0 = North, 90 = East, 180 = South, 270 =

West

values[1]: Pitch, rotation around X axis (-180<=pitch<=180), with positive values when the z-axis moves

toward the y-axis.

values[2]: Roll, rotation around Y axis (-90<=roll<=90), with positive values when the z-axis moves

toward the x-axis.

所有的值都是以角度为单位的

values[0]:经度,以Z轴为中心旋转(0-360之间),北方=0,东方=90,南方=180,西方=270

(和尚注:这个方向指的是google标志所对的方向,为了测试这个值,手都酸了(*^__^*) )

values[1]: 着地点(终于选了一个合适的词),以X为轴转动(-180到180),Z轴向Y轴方向运动的相对偏移量

(和尚注:当手机垂直放在面前的时候为-90,当你面对着手机屏幕看天花板的时候为180/-180,当手机屏幕朝上放在水平

的桌子上的时候为0,当手机的USB口朝向天花板垂直放置的时候为90)

values[2]: 转动,以Y为中心转动(-90到90),Z轴向X轴方向运动的相对偏移量

(和尚注:这个运动其实就是我们所说的"垂直屏幕和水平屏幕的切换")

Note that this definition of yaw, pitch and roll is different from the traditional definition used in

aviation where the X axis is along the long side of the plane (tail to nose).

需要注意的是在传统意义上的航空定位中,X轴指的是飞机的机身,而这里的yaw、pitch、roll和它是不一样的,这里的

X轴指的是飞机的水平翼

(和尚注:SDK中的这个解释对于西方人可能有帮助,对于我们可能会更加迷茫,我相信我上边已经说的够清楚了。)

SENSOR_ACCELEROMETER:

All values are in SI units (m/s^2) and measure contact forces.

这个模式下,所有的值都是用国际标准单位,并且能反映出相关力度

values[0]: force applied by the device on the x-axis

values[1]: force applied by the device on the y-axis

values[2]: force applied by the device on the z-axis

values[0]:在X轴方向的力度

values[1]:在Y轴方向的力度

values[2]:在Z轴方向的力度

Examples:

When the device is pushed on its left side toward the right, the x acceleration value is negative (the

device applies a reaction force to the push toward the left)

When the device lies flat on a table, the acceleration value is -STANDARD_GRAVITY, which correspond to

the force the device applies on the table in reaction to gravity.

which correspond to the force the device applies on the table in reaction to gravity.

例如:

当手机按照螺丝钉拧紧的方向"转动"时,X速度就是负的(反之X就是正的)(和尚注:不是按照原文翻译的,意思一样)

当手机放在水平的桌面上的时候,"加速度"值为-STANDARD_GRAVITY(和尚注:SDK中STANDARD_GRAVITY为:Standard

 gravity (g) on Earth,次数为负的STANDARD_GRAVITY)

(和尚注:通过反复测试,借助DDMS的截图,得出如下结论,一句话:

SENSOR_ACCELEROMETER模式下,手机的重力被3个轴所分担,values[0]、values[1]、values[2]分别记录3个坐标轴上承

受的重力大小

更易懂的解释:

正常模式下:

  

如果手机的重力都由htc标志的长侧边承担,那么values[0]为-9.8

如果手机的重力都由htc标志对面的长侧边承担,那么values[0]为9.8

如果手机的重力都由USB口的一面承担,那么values[1]为-9.8

如果手机的重力都由USB口对面的窄面承担,那么values[1]为9.8

如果手机的重力都由的背部(Google标志的一面)承担values[2]为-9.8

如果手机的重力都由的手机屏幕承担values[2]为9.8

9.8为g的值

)

Note: the magnetic field's Z axis is inverted.下载本文

显示全文
专题