godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.03k stars 21.11k forks source link

Parity between iOS and Android 9dof sensors #8101

Closed BastiaanOlij closed 5 years ago

BastiaanOlij commented 7 years ago

I'm hoping someone who has got both an Android phone and Apple phone can diagnose this further then I can at this moment.

Now that we have accelerometer, gyroscope and magnetometer data working on both iOS and Android in both Godot 2.1 and 3.0 it looks like the coordinate systems do not line up and the devices have a different idea of what "down" is.

If there is someone who has both devices it would be good if they could put the devices side by side and compare the output of these sensors in different orientations of the device. This project outputs raw data to screen (amongst others) and could be used to test this: https://github.com/BastiaanOlij/testCoreMotion

If I get my hands on a suitable android phone I will certainly do this myself. Note that PR #8100 contains a small fix to make the magnetometer give output for iOS.

BastiaanOlij commented 7 years ago

Ok, just some more info on this as I'm getting feedback from others who are giving me some values they are getting on their Android phones. Looking at the source code it so far looks to support the following figures.

On Android we are taking the output of the sensors as they are an making them available in Godot unmodified.

When I implemented CoreMotion support on iOS I found out that Apple will change the coordinate system depending on your device orientation and the code compensates this so you always get predictable output instead of having your coordinate system turn upside down as you move your device around.

I took care to align the output in iOS to the coordinate system in Godot, so if the acceleration vector points down, it is also down within your world.

I am not sure what Android does at this point in time. It makes sense to have Android output axis aligned with Godots coordinate system but seeing this implementation has been around for awhile and is used by several people, it would be a breaking change. And that is assuming I'm drawing the right conclusions.

I am trying to get a hold of an Android phone with all 3 sensors to do more in depth testing. If anyone reading this is in Sydney and has one and is willing to help out, let me know :)

@akien-mga , I'll probably bring this up next time I'm on IRC but how do we generally handle scenarios like this?

BastiaanOlij commented 7 years ago

Ok, I have gotten Godot to work on an old HTC desire. Unfortunately it only has an accelerometer. I'm pretty convinced that android simply has the X and Z axis inverted. I've adjusted for that in my test project that I originally wrote for Core Motion: https://github.com/BastiaanOlij/testCoreMotion

If someone can test that on a phone that also has a gyro and magnetometer we can know for sure.

Then we need to make a choice, leave it as is, or invert the axis and possibly break peoples code...

HummusSamurai commented 7 years ago

3.0 is a compatibility breaking release, so what's another compatibility break for the sake of progress?

BastiaanOlij commented 7 years ago

@HummusSamurai that probably is the best version to do this in, leave things as is in 2.1, then do it properly in 3. Once the Android build is stable enough I can make the change.

Probably a good a time as any to also have a discussion if there are any other improvements that are worth while at this time.

ghost commented 7 years ago

Good call. What does "any other improvements" encompass?

BastiaanOlij commented 7 years ago

@fluffrabbit anything that may have come up that people have encountered. The current implementation is very straight forward.

I am theorising here but one of the things that I am really interested in is what happens if you have multiple sensors. For instance, my old Desire 610 only has an accelerometer, for these types of phones Xiaomi now has a headset with build in accelerometer, gyro and magnetometer that your phone can use, I'm tempted to get one in due time if it turns out to be any good. I have no idea how that would work in practice or how that would combine with the sensor logic in the operating system.

BastiaanOlij commented 7 years ago

(mind you, the desire 610 isn't a good option for VR but there are a bunch of cheap phones out there with a good screen and decent GPU but otherwise bear bones, a headset with build in sensor may be a nice combo)

ghost commented 7 years ago

Very very interesting. I have not heard of such a thing and it sounds kind of odd considering the sensors are usually built into the phones themselves or controllers, so I'm assuming it acts as a Bluetooth or USB OTG controller.

The device I am interested in but currently can't afford the cash or time to order is a headset from some other Chinese company which is an all-in-one that runs Android. The interesting thing there is that it must implement a split-screen version of Android, which I'm not even sure Google has done. Android 7 has a VR launcher for VR apps, but overall the OS is strictly a single screen, and given the company's track record I wouldn't be surprised if a fully VR launcher and viewer for all apps is in the works. But anyhow the device has accelerometer and magneto but no gyro, which is also the case for most phones. It's not that I don't see the value in a gyro, it's just that I have never tried a VR setup which uses a gyro to improve orientation tracking.

BastiaanOlij commented 7 years ago

You would be surprised, many phones don't come with all 3 sensors, it makes the phones a bunch cheaper and as most applications don't need the sensors, why spend the money? Only the accelerometer is handy.

ghost commented 7 years ago

There seem to be 3 tiers of devices:

The first two categories can be purchased at Walgreens for $25. The last category jumps up in price $100.

BastiaanOlij commented 7 years ago

Exactly, but I'm getting to the point that the without a gyro, VR just doesn't work well. AR you can get away with it being imprecise, but VR.. nah

ghost commented 7 years ago

You should test Sky Hammer. I have gotten it to where it should work on iOS now. I make extensive use of smoothing, which makes it feel better than AR apps. No gyro used there.

EDIT: I won't be offended if you shit all over it. That's what the collaborative process of improvement is for.

ghost commented 7 years ago

Anyhow regarding VR improvements, not sure if this technically falls into what you're doing but controllers are a part of VR and #4944 applies on Android (not just the OUYA controller).

BastiaanOlij commented 5 years ago

As far as I'm aware this was resolved ages ago.