标签:imp name new 手机 解决 根据 class init gravity
#import <CoreMotion/CoreMotion.h>
CMMotionManager *motionManager = [[CMMotionManager alloc]init];
CMAccelerometerData *newestAccel = motionManager.accelerometerData;
double accelerationX = newestAccel.acceleration.x;
double accelerationY = newestAccel.acceleration.y;
double accelerationZ = newestAccel.acceleration.z;
2. Gravity 获取手机的重力值在各个方向上的分量,根据这个就可以获得手机的空间位置,倾斜角度等
double gravityX = motionManager.deviceMotion.gravity.x;
double gravityY = motionManager.deviceMotion.gravity.y;
double gravityZ = motionManager.deviceMotion.gravity.z;
double zTheta = atan2(gravityZ,sqrtf(gravityX*gravityX+gravityY*gravityY))/M_PI*180.0;
double xyTheta = atan2(gravityX,gravityY)/M_PI*180.0;zTheta是手机与水平面的夹角, xyTheta是手机绕自身旋转的角度
//旋转角速度: CMRotationRate rotationRate = motionManager.deviceMotion.rotationRate; double rotationX = rotationRate.x; double rotationY = rotationRate.y; double rotationZ = rotationRate.z;
double roll = motionManager.deviceMotion.attitude.roll;
double pitch = motionManager.deviceMotion.attitude.pitch;
double yaw = motionManager.deviceMotion.attitude.yaw;
double w = motionManager.deviceMotion.attitude.quaternion.w;
double wx = motionManager.deviceMotion.attitude.quaternion.x;
double wy = motionManager.deviceMotion.attitude.quaternion.y;
double wz = motionManager.deviceMotion.attitude.quaternion.z;
标签:imp name new 手机 解决 根据 class init gravity
原文地址:http://www.cnblogs.com/yang-shuai/p/7404933.html