diff options
Diffstat (limited to 'platform/android/godot_android.cpp')
-rw-r--r-- | platform/android/godot_android.cpp | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/platform/android/godot_android.cpp b/platform/android/godot_android.cpp index 9f909d7041..2371274d9d 100644 --- a/platform/android/godot_android.cpp +++ b/platform/android/godot_android.cpp @@ -314,6 +314,7 @@ struct engine { ASensorManager* sensorManager; const ASensor* accelerometerSensor; const ASensor* magnetometerSensor; + const ASensor* gyroscopeSensor; ASensorEventQueue* sensorEventQueue; bool display_active; @@ -746,6 +747,15 @@ static void engine_handle_cmd(struct android_app* app, int32_t cmd) { engine->magnetometerSensor, (1000L/60)*1000); } + // And the gyroscope. + if (engine->gyroscopeSensor != NULL) { + ASensorEventQueue_enableSensor(engine->sensorEventQueue, + engine->gyroscopeSensor); + // We'd like to get 60 events per second (in us). + ASensorEventQueue_setEventRate(engine->sensorEventQueue, + engine->gyroscopeSensor, (1000L/60)*1000); + + } engine->animating = 1; break; case APP_CMD_LOST_FOCUS: @@ -759,6 +769,10 @@ static void engine_handle_cmd(struct android_app* app, int32_t cmd) { ASensorEventQueue_disableSensor(engine->sensorEventQueue, engine->magnetometerSensor); } + if (engine->gyroscopeSensor != NULL) { + ASensorEventQueue_disableSensor(engine->sensorEventQueue, + engine->gyroscopeSensor); + } // Also stop animating. engine->animating = 0; engine_draw_frame(engine); @@ -788,6 +802,8 @@ void android_main(struct android_app* state) { ASENSOR_TYPE_ACCELEROMETER); engine.magnetometerSensor = ASensorManager_getDefaultSensor(engine.sensorManager, ASENSOR_TYPE_MAGNETIC_FIELD); + engine.gyroscopeSensor = ASensorManager_getDefaultSensor(engine.sensorManager, + ASENSOR_TYPE_GYROSCOPE); engine.sensorEventQueue = ASensorManager_createEventQueue(engine.sensorManager, state->looper, LOOPER_ID_USER, NULL, NULL); @@ -828,7 +844,7 @@ void android_main(struct android_app* state) { // If a sensor has data, process it now. // LOGI("events\n"); if (ident == LOOPER_ID_USER) { - if (engine.accelerometerSensor != NULL || engine.magnetometerSensor != NULL) { + if (engine.accelerometerSensor != NULL || engine.magnetometerSensor != NULL || engine.gyroscopeSensor != NULL) { ASensorEvent event; while (ASensorEventQueue_getEvents(engine.sensorEventQueue, &event, 1) > 0) { @@ -843,6 +859,10 @@ void android_main(struct android_app* state) { engine.os->process_magnetometer(Vector3(event.magnetic.x, event.magnetic.y, event.magnetic.z)); } + if (event.vector != NULL) { + engine.os->process_gyroscope(Vector3(event.vector.x, event.vector.y, + event.vector.z)); + } } } |