summaryrefslogtreecommitdiff
path: root/platform/iphone/app_delegate.mm
diff options
context:
space:
mode:
Diffstat (limited to 'platform/iphone/app_delegate.mm')
-rw-r--r--platform/iphone/app_delegate.mm47
1 files changed, 46 insertions, 1 deletions
diff --git a/platform/iphone/app_delegate.mm b/platform/iphone/app_delegate.mm
index feb87e742f..f65599a35a 100644
--- a/platform/iphone/app_delegate.mm
+++ b/platform/iphone/app_delegate.mm
@@ -84,6 +84,9 @@ extern char** gargv;
extern int iphone_main(int, int, int, char**);
extern void iphone_finish();
+CMMotionManager *motionManager;
+bool motionInitialised;
+
static ViewController* mainViewController = nil;
+ (ViewController*) getViewController
{
@@ -195,7 +198,22 @@ static int frame_count = 0;
default: {
if (OSIPhone::get_singleton()) {
- OSIPhone::get_singleton()->update_accelerometer(accel[0], accel[1], accel[2]);
+// OSIPhone::get_singleton()->update_accelerometer(accel[0], accel[1], accel[2]);
+ if (motionInitialised) {
+ // Just using polling approach for now, we can set this up so it sends data to us in intervals, might be better.
+ // See Apple reference pages for more details:
+ // https://developer.apple.com/reference/coremotion/cmmotionmanager?language=objc
+ CMAcceleration acceleration = motionManager.deviceMotion.userAcceleration;
+ OSIPhone::get_singleton()->update_accelerometer(acceleration.x, acceleration.y, acceleration.z);
+
+ CMMagneticField magnetic = motionManager.deviceMotion.magneticField.field;
+ OSIPhone::get_singleton()->update_magnetometer(magnetic.x, magnetic.y, magnetic.z);
+
+ ///@TODO we can access rotationRate as a CMRotationRate variable (processed date) or CMGyroData (raw data), have to see what works best
+ CMRotationRate rotation = motionManager.deviceMotion.rotationRate;
+ OSIPhone::get_singleton()->update_gyroscope(rotation.x, rotation.y, rotation.z);
+ }
+
bool quit_request = OSIPhone::get_singleton()->iterate();
};
@@ -253,11 +271,24 @@ static int frame_count = 0;
[window makeKeyAndVisible];
//Configure and start accelerometer
+/*
+ Old accelerometer approach deprecated since IOS 7.0
+
last_accel[0] = 0;
last_accel[1] = 0;
last_accel[2] = 0;
[[UIAccelerometer sharedAccelerometer] setUpdateInterval:(1.0 / kAccelerometerFrequency)];
[[UIAccelerometer sharedAccelerometer] setDelegate:self];
+*/
+
+ if (!motionInitialised) {
+ motionManager = [[CMMotionManager alloc] init];
+ if (motionManager.deviceMotionAvailable) {
+ motionManager.deviceMotionUpdateInterval = 1.0/70.0;
+ [motionManager startDeviceMotionUpdates];
+ motionInitialised = YES;
+ };
+ };
//OSIPhone::screen_width = rect.size.width - rect.origin.x;
//OSIPhone::screen_height = rect.size.height - rect.origin.y;
@@ -297,12 +328,23 @@ static int frame_count = 0;
- (void)applicationWillTerminate:(UIApplication*)application {
printf("********************* will terminate\n");
+
+ if (motionInitialised) {
+ ///@TODO is this the right place to clean this up?
+ [motionManager stopDeviceMotionUpdates];
+ // no free ?
+ motionManager = nil;
+ motionInitialised = NO;
+ };
+
iphone_finish();
};
- (void)applicationDidEnterBackground:(UIApplication *)application
{
printf("********************* did enter background\n");
+ ///@TODO maybe add pause motionManager? and where would we unpause it?
+
if (OS::get_singleton()->get_main_loop())
OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_WM_FOCUS_OUT);
[view_controller.view stopAnimation];
@@ -340,12 +382,15 @@ static int frame_count = 0;
};
}
+/*
+ Depricated since IOS 7.0
- (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration {
//Use a basic low-pass filter to only keep the gravity in the accelerometer values
accel[0] = acceleration.x; // * kFilteringFactor + accel[0] * (1.0 - kFilteringFactor);
accel[1] = acceleration.y; // * kFilteringFactor + accel[1] * (1.0 - kFilteringFactor);
accel[2] = acceleration.z; // * kFilteringFactor + accel[2] * (1.0 - kFilteringFactor);
}
+*/
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
#ifdef MODULE_FACEBOOKSCORER_IOS_ENABLED