Bläddra i källkod

Added gravity vector back into the accelerometer data and flipped Z on the gyro

BastiaanOlij 8 år sedan
förälder
incheckning
ee98e06952
2 ändrade filer med 5 tillägg och 3 borttagningar
  1. 4 1
      platform/iphone/app_delegate.mm
  2. 1 2
      platform/iphone/os_iphone.cpp

+ 4 - 1
platform/iphone/app_delegate.mm

@@ -203,8 +203,11 @@ static int frame_count = 0;
 				// Just using polling approach for now, we can set this up so it sends data to us in intervals, might be better.
 				// 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:
 				// See Apple reference pages for more details:
 				// https://developer.apple.com/reference/coremotion/cmmotionmanager?language=objc
 				// https://developer.apple.com/reference/coremotion/cmmotionmanager?language=objc
+
+				// 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;
 				CMAcceleration acceleration = motionManager.deviceMotion.userAcceleration;
-				OSIPhone::get_singleton()->update_accelerometer(acceleration.x, acceleration.y, acceleration.z);
+				OSIPhone::get_singleton()->update_accelerometer(acceleration.x + gravity.x, acceleration.y + gravity.y, acceleration.z + gravity.z);
 
 
 				CMMagneticField magnetic = motionManager.deviceMotion.magneticField.field;
 				CMMagneticField magnetic = motionManager.deviceMotion.magneticField.field;
 				OSIPhone::get_singleton()->update_magnetometer(magnetic.x, magnetic.y, magnetic.z);
 				OSIPhone::get_singleton()->update_magnetometer(magnetic.x, magnetic.y, magnetic.z);

+ 1 - 2
platform/iphone/os_iphone.cpp

@@ -371,8 +371,7 @@ void OSIPhone::update_magnetometer(float p_x, float p_y, float p_z) {
 };
 };
 
 
 void OSIPhone::update_gyroscope(float p_x, float p_y, float p_z) {
 void OSIPhone::update_gyroscope(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_gyroscope(Vector3(p_x, p_y, -p_z));
+	input->set_gyroscope(Vector3(p_x, p_y, p_z));
 };
 };
 
 
 void OSIPhone::delete_main_loop() {
 void OSIPhone::delete_main_loop() {