Skip to content

Instantly share code, notes, and snippets.

@chuganzy
Last active January 17, 2019 19:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chuganzy/8194504 to your computer and use it in GitHub Desktop.
Save chuganzy/8194504 to your computer and use it in GitHub Desktop.
openFrameworks for iOSでデバイスの姿勢を取得する http://blog.ganzy.jp/cpp/64
#import <CoreMotion/CoreMotion.h>
class testApp : public ofxiOSApp {
CMMotionManager *motionManager;
public:
void setup();
void update();
void draw();
void exit();
void touchDown(ofTouchEventArgs & touch);
void touchMoved(ofTouchEventArgs & touch);
void touchUp(ofTouchEventArgs & touch);
void touchDoubleTap(ofTouchEventArgs & touch);
void touchCancelled(ofTouchEventArgs & touch);
void lostFocus();
void gotFocus();
void gotMemoryWarning();
void deviceOrientationChanged(int newOrientation);
};
void testApp::setup() {
motionManager = [[CMMotionManager alloc] init];
[motionManager startDeviceMotionUpdates];
}
void testApp::update() {
cout << motionManager.deviceMotion.attitude.pitch * RAD_TO_DEG << endl; // X軸回転
cout << motionManager.deviceMotion.attitude.roll * RAD_TO_DEG << endl; // Y軸回転
cout << motionManager.deviceMotion.attitude.yaw * RAD_TO_DEG << endl; // Z軸回転
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment