Add accelerometer and gyroscope to iOS

This commit is contained in:
Benau 2019-07-16 01:03:37 +08:00
parent 05486943b7
commit 48fedb48c7
4 changed files with 30 additions and 51 deletions

View File

@ -302,6 +302,18 @@ namespace irr
virtual void toggleOnScreenKeyboard(bool show, s32 type = 0) = 0;
virtual void registerGetMovedHeightFunction(HeightFunc) = 0;
virtual bool activateAccelerometer(float updateInterval) { return false; }
virtual bool deactivateAccelerometer() { return false; }
virtual bool isAccelerometerActive() { return false; }
virtual bool isAccelerometerAvailable() { return false; }
virtual bool activateGyroscope(float updateInterval) { return false; }
virtual bool deactivateGyroscope() { return false; }
virtual bool isGyroscopeActive() { return false; }
virtual bool isGyroscopeAvailable() { return false; }
virtual bool activateDeviceMotion(float updateInterval) { return false; }
virtual bool deactivateDeviceMotion() { return false; }
virtual bool isDeviceMotionActive() { return false; }
virtual bool isDeviceMotionAvailable() { return false; }
//! Check if a driver type is supported by the engine.
/** Even if true is returned the driver may not be available
for a configuration requested when creating the device. */

View File

@ -37,11 +37,7 @@ MultitouchDevice::MultitouchDevice()
m_name = "Multitouch";
m_player = NULL;
m_controller = NULL;
#ifdef ANDROID
m_android_device = dynamic_cast<CIrrDeviceAndroid*>(
irr_driver->getDevice());
assert(m_android_device != NULL);
#endif
m_irrlicht_device = irr_driver->getDevice();
reset();
updateConfigParams();
@ -185,12 +181,10 @@ void MultitouchDevice::reset()
*/
void MultitouchDevice::activateAccelerometer()
{
#ifdef ANDROID
if (!m_android_device->isAccelerometerActive())
if (!m_irrlicht_device->isAccelerometerActive())
{
m_android_device->activateAccelerometer(1.0f / 30);
m_irrlicht_device->activateAccelerometer(1.0f / 30);
}
#endif
}
// ----------------------------------------------------------------------------
@ -198,12 +192,10 @@ void MultitouchDevice::activateAccelerometer()
*/
void MultitouchDevice::deactivateAccelerometer()
{
#ifdef ANDROID
if (m_android_device->isAccelerometerActive())
if (m_irrlicht_device->isAccelerometerActive())
{
m_android_device->deactivateAccelerometer();
m_irrlicht_device->deactivateAccelerometer();
}
#endif
}
// ----------------------------------------------------------------------------
@ -212,11 +204,7 @@ void MultitouchDevice::deactivateAccelerometer()
*/
bool MultitouchDevice::isAccelerometerActive()
{
#ifdef ANDROID
return m_android_device->isAccelerometerActive();
#endif
return false;
return m_irrlicht_device->isAccelerometerActive();
}
// ----------------------------------------------------------------------------
@ -224,14 +212,12 @@ bool MultitouchDevice::isAccelerometerActive()
*/
void MultitouchDevice::activateGyroscope()
{
#ifdef ANDROID
if (!m_android_device->isGyroscopeActive())
if (!m_irrlicht_device->isGyroscopeActive())
{
// Assume 60 FPS, some phones can do 90 and 120 FPS but we won't handle
// them now
m_android_device->activateGyroscope(1.0f / 60);
m_irrlicht_device->activateGyroscope(1.0f / 60);
}
#endif
}
// ----------------------------------------------------------------------------
@ -239,12 +225,10 @@ void MultitouchDevice::activateGyroscope()
*/
void MultitouchDevice::deactivateGyroscope()
{
#ifdef ANDROID
if (m_android_device->isGyroscopeActive())
if (m_irrlicht_device->isGyroscopeActive())
{
m_android_device->deactivateGyroscope();
m_irrlicht_device->deactivateGyroscope();
}
#endif
}
// ----------------------------------------------------------------------------
@ -253,11 +237,7 @@ void MultitouchDevice::deactivateGyroscope()
*/
bool MultitouchDevice::isGyroscopeActive()
{
#ifdef ANDROID
return m_android_device->isGyroscopeActive();
#endif
return false;
return m_irrlicht_device->isGyroscopeActive();
}
// ----------------------------------------------------------------------------

View File

@ -26,10 +26,6 @@
#include "utils/types.hpp"
#include "IEventReceiver.h"
#ifdef ANDROID
#include "../../../lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.h"
#endif
#define NUMBER_OF_MULTI_TOUCHES 10
enum MultitouchButtonType
@ -96,10 +92,8 @@ private:
float m_orientation;
uint64_t m_gyro_time;
#ifdef ANDROID
/** Pointer to the Android irrlicht device */
CIrrDeviceAndroid* m_android_device;
#endif
/** Pointer to the irrlicht device */
IrrlichtDevice* m_irrlicht_device;
float getSteeringFactor(float value, float sensitivity);
void handleControls(MultitouchButton* button);

View File

@ -28,10 +28,6 @@
#include "states_screens/race_gui_multitouch.hpp"
#include "utils/translation.hpp"
#ifdef ANDROID
#include "../../../lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.h"
#endif
#include <IGUIEnvironment.h>
@ -61,13 +57,10 @@ void MultitouchSettingsDialog::beforeAddingWidgets()
bool accelerometer_available = false;
bool gyroscope_available = false;
#ifdef ANDROID
CIrrDeviceAndroid* android_device = dynamic_cast<CIrrDeviceAndroid*>(
irr_driver->getDevice());
assert(android_device != NULL);
accelerometer_available = android_device->isAccelerometerAvailable();
gyroscope_available = android_device->isGyroscopeAvailable() && accelerometer_available;
#endif
IrrlichtDevice* irrlicht_device = irr_driver->getDevice();
assert(irrlicht_device != NULL);
accelerometer_available = irrlicht_device->isAccelerometerAvailable();
gyroscope_available = irrlicht_device->isGyroscopeAvailable() && accelerometer_available;
if (!accelerometer_available)
{
@ -201,7 +194,7 @@ GUIEngine::EventPropagation MultitouchSettingsDialog::processEvent(
if (StateManager::get()->getGameState() != GUIEngine::INGAME_MENU)
{
#ifdef ANDROID
#ifdef MOBILE_STK
UserConfigParams::m_multitouch_draw_gui = true;
#else
UserConfigParams::m_multitouch_draw_gui.revertToDefaults();