剛剛開始實現基於增強現實的項目,獲得了GPS位置,航向和兩個缺失的變量來操縱虛擬攝像機是Pitch/Roll。是否有現成的公式可以從iPhone 3GS的加速度計X/Y/Z獲得Pitch/Roll值?
我想知道是否有現成的公式我可以合併到項目中。能省下我很多時間。提前致謝。
剛剛開始實現基於增強現實的項目,獲得了GPS位置,航向和兩個缺失的變量來操縱虛擬攝像機是Pitch/Roll。是否有現成的公式可以從iPhone 3GS的加速度計X/Y/Z獲得Pitch/Roll值?
我想知道是否有現成的公式我可以合併到項目中。能省下我很多時間。提前致謝。
我鑽進了問題,因爲,所以有關解決方案的一個真的詳細後可以在這裏讀到:
Get pitch and roll angles from the iPhone's accelerometer vector在gotoandplay.freeblog.hu
我認爲this post關於iphone加速計將回答你的大部分問題,包括示例代碼。
您可以通過它計算弧度CMMotionManager
訪問設備旋轉基於原始數據(加速度計,陀螺儀等)。請確保您啓用了傳感器的更新:
if (motionMng.deviceMotionAvailable && !motionMng.deviceMotionActive) {
motionMng.deviceMotionUpdateInterval = 1.0/50.0;
[motionMng startDeviceMotionUpdates];
}
之後訪問旋轉 - pitch
(X),roll
(y)和yaw
(Z) - 通過查詢attitude
對象:
CMDeviceMotion *motion = [motionMng deviceMotion];
if (motion != NULL) {
float pitch = motion.attitude.pitch;
float roll = motion.attitude.roll;
float yaw = motion.attitude.yaw;
NSLog(@"ROTATION: x:%f y:%f z:%f", pitch, roll, yaw);
}
喔,所以索性pitch = acceleration.x,roll = acceleration.y。而acceleration.z組件告訴我該設備是否顛倒過來。這將幫助我創建「360度免費相機」。謝謝傑勒。 – Geri 2010-06-08 09:33:27