SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLDeviceRotation.h
Go to the documentation of this file.
1 /**
2  * \file SLDeviceRotation.h
3  * \brief Mobile device rotation class declaration
4  * \authors Marcus Hudritsch
5  * \date November 2017
6  * \authors Marcus Hudritsch
7  * \copyright http://opensource.org/licenses/GPL-3.0
8  * \remarks Please use clangformat to format the code. See more code style on
9  * https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
10 */
11 
12 #ifndef SLDEVICEROTATION_H
13 #define SLDEVICEROTATION_H
14 
15 #include <SL.h>
16 #include <SLMat3.h>
17 #include <SLQuat4.h>
18 #include <Averaged.h>
19 
20 //-----------------------------------------------------------------------------
21 //! Device rotation offset mode
23 {
24  ROM_none = 0,
27 };
28 //-----------------------------------------------------------------------------
29 //! Encapsulation of a mobile device rotation set by the device's IMU sensor
30 /*! This class is only used if SLProject runs on a mobile device. Check out the
31  app-demo/android and app_demo_slproject/ios how the sensor data is
32  generated and passed to this object hold by AppCommon.
33  It stores the devices rotation that it gets from its IMU (inertial measurement
34  unit) sensor. This is a fused orientation that is calculated from the
35  magnetometer, the accelerometer and the gyroscope. The device rotation can
36  be used in the active camera to apply it to the scene camera
37  (s. SLCamera::setView).
38 */
40 {
41 public:
43  void init();
44  void onRotationQUAT(SLfloat quatX,
45  SLfloat quatY,
46  SLfloat quatZ,
47  SLfloat quatW);
48  // Setters
49  void isUsed(SLbool isUsed);
50  void hasStarted(SLbool started) { _isFirstSensorValue = started; }
51  void zeroYawAtStart(SLbool zeroYaw) { _zeroYawAtStart = zeroYaw; }
52  void numAveraged(SLint numAvg);
53  void offsetMode(SLRotOffsetMode rom) { _offsetMode = rom; }
54  void updateRPY(SLbool doUpdate) { _updateRPY = doUpdate; }
55 
56  // Getters
57  SLbool isUsed() const { return _isUsed; }
58  SLMat3f rotation() const { return _rotation; }
59  SLMat3f rotationAveraged() { return _rotationAvg.average(); }
60  SLQuat4f quaternion() const { return _quaternion; }
61  SLfloat pitchRAD() const { return _pitchRAD; }
62  SLfloat pitchDEG() const { return _pitchRAD * Utils::RAD2DEG; }
63  SLfloat yawRAD() const { return _yawRAD; }
64  SLfloat yawDEG() const { return _yawRAD * Utils::RAD2DEG; }
65  SLfloat rollRAD() const { return _rollRAD; }
66  SLfloat rollDEG() const { return _rollRAD * Utils::RAD2DEG; }
68  SLfloat startYawRAD() const { return _startYawRAD; }
69  SLint numAveraged() { return (int)_rotationAvg.size(); }
71  SLstring offsetModeStr() const;
72  SLbool updateRPY() const { return _updateRPY; }
73 
74 private:
75  SLbool _isUsed; //!< Flag if device rotation is used
76  SLbool _isFirstSensorValue; //!< Flag for the first sensor values
77  SLfloat _pitchRAD; //!< Device pitch angle in radians
78  SLfloat _yawRAD; //!< Device yaw angle in radians
79  SLfloat _rollRAD; //!< Device roll angle in radians
80  SLMat3f _rotation; //!< Mobile device rotation as matrix
81  Averaged<SLMat3f> _rotationAvg; //!< Component wise averaged rotation matrix
82  SLQuat4f _quaternion; //! Quaternion rotation that is set by IMU
83  SLbool _zeroYawAtStart; //!< Flag if yaw angle should be zeroed at sensor start
84  SLfloat _startYawRAD; //!< Initial yaw angle after _zeroYawAfterSec in radians
85  SLRotOffsetMode _offsetMode; //!< Rotation offset mode
86  SLbool _updateRPY; //!< Calculate roll pitch yaw in onRotationQUAT
87 };
88 //-----------------------------------------------------------------------------
89 #endif
float SLfloat
Definition: SL.h:173
bool SLbool
Definition: SL.h:175
string SLstring
Definition: SL.h:158
int SLint
Definition: SL.h:170
SLRotOffsetMode
Device rotation offset mode.
@ ROM_oneFingerX
@ ROM_none
@ ROM_oneFingerXY
Encapsulation of a mobile device rotation set by the device's IMU sensor.
SLfloat yawDEG() const
SLMat3f _rotation
Mobile device rotation as matrix.
SLbool updateRPY() const
SLfloat _rollRAD
Device roll angle in radians.
SLbool _isFirstSensorValue
Flag for the first sensor values.
SLbool isUsed() const
void hasStarted(SLbool started)
SLQuat4f quaternion() const
SLbool zeroYawAtStart() const
SLfloat _startYawRAD
Initial yaw angle after _zeroYawAfterSec in radians.
SLfloat pitchRAD() const
void offsetMode(SLRotOffsetMode rom)
SLfloat _yawRAD
Device yaw angle in radians.
SLMat3f rotationAveraged()
SLfloat rollDEG() const
SLbool _updateRPY
Calculate roll pitch yaw in onRotationQUAT.
SLbool _zeroYawAtStart
Quaternion rotation that is set by IMU.
void zeroYawAtStart(SLbool zeroYaw)
SLMat3f rotation() const
SLfloat yawRAD() const
SLfloat _pitchRAD
Device pitch angle in radians.
SLfloat rollRAD() const
SLRotOffsetMode _offsetMode
Rotation offset mode.
Averaged< SLMat3f > _rotationAvg
Component wise averaged rotation matrix.
SLbool _isUsed
Flag if device rotation is used.
void updateRPY(SLbool doUpdate)
SLfloat pitchDEG() const
void onRotationQUAT(SLfloat quatX, SLfloat quatY, SLfloat quatZ, SLfloat quatW)
SLfloat startYawRAD() const
SLRotOffsetMode offsetMode()
SLstring offsetModeStr() const
Returns the rotation offset mode as string.
Averaged template class provides an average value from a fixed size array.
Definition: Averaged.h:32
static const float RAD2DEG
Definition: Utils.h:238