summaryrefslogtreecommitdiff
path: root/platform/iphone
diff options
context:
space:
mode:
Diffstat (limited to 'platform/iphone')
-rw-r--r--platform/iphone/app_delegate.h3
-rw-r--r--platform/iphone/app_delegate.mm35
-rw-r--r--platform/iphone/os_iphone.cpp7
3 files changed, 34 insertions, 11 deletions
diff --git a/platform/iphone/app_delegate.h b/platform/iphone/app_delegate.h
index 3441dac6f3..6883692b15 100644
--- a/platform/iphone/app_delegate.h
+++ b/platform/iphone/app_delegate.h
@@ -34,12 +34,9 @@
// Include coremotion for accelerometer, gyroscope and magnetometer access, available since IOS 4.0 but some functionality won't work for anything before IOS 5.0
#import <CoreMotion/CoreMotion.h>
-//@interface AppDelegate : NSObject <UIApplicationDelegate, UIAccelerometerDelegate, GLViewDelegate> {
@interface AppDelegate : NSObject <UIApplicationDelegate, GLViewDelegate> {
//@property (strong, nonatomic) UIWindow *window;
ViewController* view_controller;
-// UIAccelerationValue accel[3];
-// UIAccelerationValue last_accel[3];
};
@property (strong, nonatomic) UIWindow *window;
diff --git a/platform/iphone/app_delegate.mm b/platform/iphone/app_delegate.mm
index 31e5e15e8d..4d05c4b19c 100644
--- a/platform/iphone/app_delegate.mm
+++ b/platform/iphone/app_delegate.mm
@@ -196,7 +196,6 @@ static int frame_count = 0;
}; break; // no fallthrough
default: {
-
if (OSIPhone::get_singleton()) {
// OSIPhone::get_singleton()->update_accelerometer(accel[0], accel[1], accel[2]);
if (motionInitialised) {
@@ -207,14 +206,42 @@ static int frame_count = 0;
// Apple splits our accelerometer date into a gravity and user movement component. We add them back together
CMAcceleration gravity = motionManager.deviceMotion.gravity;
CMAcceleration acceleration = motionManager.deviceMotion.userAcceleration;
- OSIPhone::get_singleton()->update_accelerometer(acceleration.x + gravity.x, acceleration.y + gravity.y, acceleration.z + gravity.z);
+ ///@TODO We don't seem to be getting data here, is my device broken or is this code incorrect?
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);
+
+ // Adjust for screen orientation.
+ // [[UIDevice currentDevice] orientation] changes even if we've fixed our orientation which is not
+ // a good thing when you're trying to get your user to move the screen in all directions and want consistent output
+
+ ///@TODO Using [[UIApplication sharedApplication] statusBarOrientation] is a bit of a hack. Godot obviously knows the orientation so maybe we
+ // can use that instead?
+
+ switch ([[UIApplication sharedApplication] statusBarOrientation]) {
+ case UIDeviceOrientationLandscapeLeft: {
+ OSIPhone::get_singleton()->update_accelerometer(-(acceleration.y + gravity.y), acceleration.x + gravity.x, acceleration.z + gravity.z);
+ OSIPhone::get_singleton()->update_magnetometer(-magnetic.y, magnetic.x, magnetic.z);
+ OSIPhone::get_singleton()->update_gyroscope(-rotation.y, rotation.x, rotation.z);
+ }; break;
+ case UIDeviceOrientationLandscapeRight: {
+ OSIPhone::get_singleton()->update_accelerometer(acceleration.y + gravity.y, acceleration.x + gravity.x, acceleration.z + gravity.z);
+ OSIPhone::get_singleton()->update_magnetometer(magnetic.y, magnetic.x, magnetic.z);
+ OSIPhone::get_singleton()->update_gyroscope(rotation.y, rotation.x, rotation.z);
+ }; break;
+ case UIDeviceOrientationPortraitUpsideDown: {
+ OSIPhone::get_singleton()->update_accelerometer(-(acceleration.x + gravity.x), acceleration.y + gravity.y, acceleration.z + gravity.z);
+ OSIPhone::get_singleton()->update_magnetometer(-magnetic.x, magnetic.y, magnetic.z);
+ OSIPhone::get_singleton()->update_gyroscope(-rotation.x, rotation.y, rotation.z);
+ }; break;
+ default: { // assume portrait
+ OSIPhone::get_singleton()->update_accelerometer(acceleration.x + gravity.x, acceleration.y + gravity.y, acceleration.z + gravity.z);
+ OSIPhone::get_singleton()->update_magnetometer(magnetic.x, magnetic.y, magnetic.z);
+ OSIPhone::get_singleton()->update_gyroscope(rotation.x, rotation.y, rotation.z);
+ }; break;
+ };
}
bool quit_request = OSIPhone::get_singleton()->iterate();
diff --git a/platform/iphone/os_iphone.cpp b/platform/iphone/os_iphone.cpp
index 7e35bf787b..0ef6cd7c32 100644
--- a/platform/iphone/os_iphone.cpp
+++ b/platform/iphone/os_iphone.cpp
@@ -325,8 +325,8 @@ static const float ACCEL_RANGE = 1;
void OSIPhone::update_accelerometer(float p_x, float p_y, float p_z) {
- ///@TODO I've made the Z negative like the original accelerometer code, this probably needs more work
- input->set_accelerometer(Vector3(p_x / (float)ACCEL_RANGE, p_y / (float)ACCEL_RANGE, -p_z / (float)ACCEL_RANGE));
+ // Found out the Z should not be negated! Pass as is!
+ input->set_accelerometer(Vector3(p_x / (float)ACCEL_RANGE, p_y / (float)ACCEL_RANGE, p_z / (float)ACCEL_RANGE));
/*
if (p_x != last_accel.x) {
@@ -366,8 +366,7 @@ void OSIPhone::update_accelerometer(float p_x, float p_y, float p_z) {
};
void OSIPhone::update_magnetometer(float p_x, float p_y, float p_z) {
- ///@TODO I've made the Z negative like the original accelerometer code, this probably needs more work
- input->set_magnetometer(Vector3(p_x, p_y, -p_z));
+ input->set_magnetometer(Vector3(p_x, p_y, p_z));
};
void OSIPhone::update_gyroscope(float p_x, float p_y, float p_z) {