android重力感应详解

上传人:壹****1 文档编号:458058469 上传时间:2023-05-21 格式:DOC 页数:6 大小:187KB
返回 下载 相关 举报
android重力感应详解_第1页
第1页 / 共6页
android重力感应详解_第2页
第2页 / 共6页
android重力感应详解_第3页
第3页 / 共6页
android重力感应详解_第4页
第4页 / 共6页
android重力感应详解_第5页
第5页 / 共6页
点击查看更多>>
资源描述

《android重力感应详解》由会员分享,可在线阅读,更多相关《android重力感应详解(6页珍藏版)》请在金锄头文库上搜索。

1、星期天在家没有事情,一边翻译 sdk 中 onSensorChanged的解释,一遍摸索 G1 下onSensorChanged第二个参数 values的含义:总结如下,发完赶紧吃饭!public 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 monitoredaccura

2、cy The new accuracy of this sensor.当 sensor的 精确度 发生改变的时候,该方法会被回调,详细信息请参看 SensorManager 类参数:sensor被监视的 sensor的 IDaccuracy 关于此 sensor的新精确度描述public abstract void onSensorChanged (int sensor, float values复制代码Called when sensor values have changed. The length and contents of the values array vary dependi

3、ng onwhich 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 screens horizontal axis (the small edge in por

4、trait mode, the long edge inlandscape mode and points to the right.The Y axis refers to the screens vertical axis and points towards the top of the screen (the origin isin the lower-left corner.The Z axis points toward the sky when the device is lying on its back on a table.X 轴:和屏幕平行并且指向右边的轴(在式中使用 长

5、边角 )portrait中使用 小边角 ,在landscape模Y 轴:和屏幕垂直并且指向屏幕上方的轴(坐标原点在左下角)Z 轴:当设备 (手机背面着地放在桌子上的时候,指向天空的方向就是Z 轴IMPORTANT NOTE: The axis are swapped when the devices screen orientation changes. To access theunswapped values, use indices 3, 4 and 5 in values.一定要大家注意的:坐标系是跟随手机屏幕的方向改变而改变的, values数组中下标为 3、 4、 5 的 3 个元

6、素,使用的是恒定的坐标系, (和尚注:你可以通过这三个元素得到一个不变的坐标,游戏开发中可能会用到(和尚注:此方法的第一个参数sensor可能是SensorManager.SENSOR_ORIENTATIONSensorManager.SENSOR_ORIENTATION中的一个解释如下:SENSOR_ORIENTATION, SENSOR_ORIENTATION_RAW:All values are angles in degrees.values0: Azimuth, rotation around the Z axis (0=azimuth360. 0 = North, 90 = Eas

7、t, 180 = South, 270 =Westvalues1: Pitch, rotation around X axis (-180=pitch=180, with positive values when the z-axis movestoward the y-axis.values2: Roll, rotation around Y axis (-90=roll=90, with positive values when the z-axis movestoward the x-axis.所有的值都是以角度为单位的values0:经度,以 Z 轴为中心旋转 (0-360 之间,北方

8、 =0,东方 =90,南方 =180,西方 =270(和尚注:这个方向指的是google标志所对的方向,为了测试这个值,手都酸了(*_*values1: 着地点 (终于选了一个合适的词,以 X 为轴转动 (-180 到 180, Z 轴向 Y 轴方向运动的相对偏移量(和尚注:当手机垂直放在面前的时候为 -90,当你面对着手机屏幕看天花板的时候为 180/-180,当手机屏幕朝上放在水平的桌子上的时候为0,当手机的 USB 口朝向天花板垂直放置的时候为90values2: 转动,以 Y 为中心转动 (-90 到 90,Z 轴向 X 轴方向运动的相对偏移量(和尚注:这个运动其实就是我们所说的 垂直

9、屏幕和水平屏幕的切换Note that this definition of yaw, pitch and roll is different from the traditional definition used inaviation where the X axis is along the long side of the plane (tail to nose.需要注意的是在传统意义上的航空定位中, X 轴指的是飞机的机身,而这里的yaw、pitch、roll 和它是不一样的,这里的X 轴指的是飞机的水平翼(和尚注: SDK 中的这个解释对于西方人可能有帮助,对于我们可能会更加迷茫,

10、我相信我上边已经说的够清楚了。SENSOR_ACCELEROMETER:All values are in SI units (m/s2 and measure contact forces.这个模式下,所有的值都是用国际标准单位,并且能反映出相关力度values0: force applied by the device on the x-axisvalues1: force applied by the device on the y-axisvalues2: force applied by the device on the z-axisvalues0:在 X 轴方向的力度values

11、1:在 Y 轴方向的力度values2:在 Z 轴方向的力度Examples:When the device is pushed on its left side toward the right, the x acceleration value is negative (thedevice applies a reaction force to the push toward the leftWhen the device lies flat on a table, the acceleration value is -STANDARD_GRAVITY, which correspond

12、tothe 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 就是正的 (和尚注 :不是按照原文翻译的,意思一样当手机放在水平的桌面上的时候,注 :SDK 中 STANDARD_GRAVITY 加速度 值为 -STANDARD_GRAVITY(为:Standard和尚gravity

13、 (g on Earth,次数为负的 STANDARD_GRAVITY(和尚注 :通过反复测试,借助DDMS 的截图,得出如下结论,一句话:SENSOR_ACCELEROMETER 模式下 ,手机的重力被 3 个轴所分担, values0、values1、 values2分别记录 3 个坐标轴上承受的重力大小更易懂的解释 :正常模式下:如果手机的重力都由htc 标志的长侧边承担,那么values0为 -9.8如果手机的重力都由htc 标志对面的长侧边承担,那么values0为9.8如果手机的重力都由USB 口的一面承担,那么values1为-9.8如果手机的重力都由USB 口对面的窄面承担,那么values1为9.8如果手机的重力都由的背部(Google标志的一面承担 values2为 -9.8如果手机的重力都由的手机屏幕承担values2为 9.89.8 为 g 的值Note: the mag

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > 活动策划

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号