| Summary: | [patch] automatically remap accelerometer coordinates according to screen orientation on Android | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Denis Bernard <denis> |
| Component: | joystick | Assignee: | Sam Lantinga <slouken> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | CC: | denis, philipp.wiesemann |
| Version: | HG 2.0 | ||
| Hardware: | All | ||
| OS: | Android (All) | ||
| Attachments: |
Coordinate remapping of the accelerometer data according to screen orientation
Coordinate remapping of the accelerometer data according to screen orientation Coordinate remapping of the accelerometer data according to screen orientation |
||
|
Description
Denis Bernard
2013-10-15 17:18:02 UTC
About the implementation in your patch:
I think cloning of the array object is not needed. You could just use three local float variables. onSensorChanged() is called very often and this would prevent some creation and garbage collection overhead for a tiny performance improvement.
Also I think swapping through a temporary variable is not needed. You could just assign the values from the input array (maybe modified) into three local "output" variables and use these as parameters for the JNI call.
e.g.:
// ...
float x, y, z;
// ...
case Surface.ROTATION_90:
x = -event.values[1];
y = event.values[0];
z = event.values[2];
break;
// ...
default:
x = event.values[0];
y = event.values[1];
z = event.values[2];
break;
}
SDLActivity.onNativeAccel(x / SensorManager.GRAVITY_EARTH,
y / SensorManager.GRAVITY_EARTH,
z / SensorManager.GRAVITY_EARTH);
Created attachment 1370 [details] Coordinate remapping of the accelerometer data according to screen orientation Good point, I was initially using SensorManager.remapCoordinateSystem() (but overkill for our need), hence the clone. Here's a new patch where I kept the new variables to a minimum. No need to get Z out as it won't change (it just needs to be adjusted once, see bug 2156) Created attachment 1371 [details]
Coordinate remapping of the accelerometer data according to screen orientation
Had forgotten to remove yet another variable. This time it should be as lean a possible.
Good patch, thanks! http://hg.libsdl.org/SDL/rev/e2188abb7c10 |