From 4157eef8940f6d5f3c965428d63fc694e28325ae Mon Sep 17 00:00:00 2001 From: Deve Date: Fri, 2 Mar 2018 21:38:15 +0100 Subject: [PATCH] Get device orientation only if accelerometer is used --- .../source/Irrlicht/CIrrDeviceAndroid.cpp | 43 +++++++------------ .../source/Irrlicht/CIrrDeviceAndroid.h | 12 ++++-- 2 files changed, 24 insertions(+), 31 deletions(-) diff --git a/lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.cpp b/lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.cpp index 4e0c8d6d3..1c319fc88 100644 --- a/lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.cpp +++ b/lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.cpp @@ -51,7 +51,7 @@ CIrrDeviceAndroid::CIrrDeviceAndroid(const SIrrlichtCreationParameters& param) IsMousePressed(false), GamepadAxisX(0), GamepadAxisY(0), - DefaultOrientation(0) + DefaultOrientation(ORIENTATION_UNKNOWN) { #ifdef _DEBUG setDebugName("CIrrDeviceAndroid"); @@ -64,8 +64,6 @@ CIrrDeviceAndroid::CIrrDeviceAndroid(const SIrrlichtCreationParameters& param) Android->onAppCmd = handleAndroidCommand; Android->onInputEvent = handleInput; - DefaultOrientation = getDefaultRotation(); - printConfig(); createKeyMap(); @@ -159,22 +157,6 @@ void CIrrDeviceAndroid::printConfig() os::Printer::log(" touch:", core::stringc(touch).c_str(), ELL_DEBUG); os::Printer::log(" ui_mode_type:", core::stringc(ui_mode_type).c_str(), ELL_DEBUG); os::Printer::log(" ui_mode_night:", core::stringc(ui_mode_night).c_str(), ELL_DEBUG); - - int rotation = getRotation(); - int deg[4] = {0, 90, 180, 270}; - - os::Printer::log("Rotation: ", core::stringc(deg[rotation]).c_str(), ELL_DEBUG); - - int default_rotation = getDefaultRotation(); - - if (default_rotation == 1) - { - os::Printer::log("Default rotation: landscape", ELL_DEBUG); - } - else - { - os::Printer::log("Default rotation: portrait", ELL_DEBUG); - } } void CIrrDeviceAndroid::createVideoModeList() @@ -254,16 +236,16 @@ bool CIrrDeviceAndroid::run() SEvent accEvent; accEvent.EventType = EET_ACCELEROMETER_EVENT; - if (DefaultOrientation == 0) - { - accEvent.AccelerometerEvent.X = event.acceleration.x; - accEvent.AccelerometerEvent.Y = event.acceleration.y; - } - else + if (DefaultOrientation == ORIENTATION_LANDSCAPE) { accEvent.AccelerometerEvent.X = event.acceleration.y; accEvent.AccelerometerEvent.Y = -event.acceleration.x; } + else + { + accEvent.AccelerometerEvent.X = event.acceleration.x; + accEvent.AccelerometerEvent.Y = event.acceleration.y; + } accEvent.AccelerometerEvent.Z = event.acceleration.z; if (accEvent.AccelerometerEvent.X < 0) @@ -1197,7 +1179,7 @@ int CIrrDeviceAndroid::getRotation() return rotation; } -int CIrrDeviceAndroid::getDefaultRotation() +DeviceOrientation CIrrDeviceAndroid::getDefaultOrientation() { int rotation = getRotation(); @@ -1208,11 +1190,11 @@ int CIrrDeviceAndroid::getDefaultRotation() ((rotation == 1 || rotation == 3) && orientation == ACONFIGURATION_ORIENTATION_PORT)) { - return 1; + return ORIENTATION_LANDSCAPE; } else { - return 0; + return ORIENTATION_PORTRAIT; } } @@ -1220,6 +1202,11 @@ bool CIrrDeviceAndroid::activateAccelerometer(float updateInterval) { if (!isAccelerometerAvailable()) return false; + + if (DefaultOrientation == ORIENTATION_UNKNOWN) + { + DefaultOrientation = getDefaultOrientation(); + } ASensorEventQueue_enableSensor(SensorEventQueue, Accelerometer); ASensorEventQueue_setEventRate(SensorEventQueue, Accelerometer, diff --git a/lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.h b/lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.h index 97ce5da71..33ce575b9 100644 --- a/lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.h +++ b/lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.h @@ -23,7 +23,13 @@ namespace irr { - + enum DeviceOrientation + { + ORIENTATION_UNKNOWN, + ORIENTATION_PORTRAIT, + ORIENTATION_LANDSCAPE + }; + class CIrrDeviceAndroid : public CIrrDeviceStub, video::IImagePresenter { public: @@ -123,7 +129,7 @@ namespace irr bool IsMousePressed; float GamepadAxisX; float GamepadAxisY; - int DefaultOrientation; + DeviceOrientation DefaultOrientation; video::SExposedVideoData ExposedVideoData; @@ -135,7 +141,7 @@ namespace irr void createVideoModeList(); void getKeyChar(SEvent& event); int getRotation(); - int getDefaultRotation(); + DeviceOrientation getDefaultOrientation(); video::SExposedVideoData& getExposedVideoData(); static void handleAndroidCommand(android_app* app, int32_t cmd);