SLProject 4.0.000
SLDeviceRotation Class Reference

Encapsulation of a mobile device rotation set by the device's IMU sensor. More...

#include <SLDeviceRotation.h>

Public Member Functions

 SLDeviceRotation ()
 
void init ()
 
void onRotationQUAT (SLfloat quatX, SLfloat quatY, SLfloat quatZ, SLfloat quatW)
 
void isUsed (SLbool isUsed)
 Setter that turns on the device rotation sensor. More...
 
void hasStarted (SLbool started)
 
void zeroYawAtStart (SLbool zeroYaw)
 
void numAveraged (SLint numAvg)
 Returns the device rotation averaged over multple frames. More...
 
void offsetMode (SLRotOffsetMode rom)
 
void updateRPY (SLbool doUpdate)
 
SLbool isUsed () const
 
SLMat3f rotation () const
 
SLMat3f rotationAveraged ()
 
SLQuat4f quaternion () const
 
SLfloat pitchRAD () const
 
SLfloat pitchDEG () const
 
SLfloat yawRAD () const
 
SLfloat yawDEG () const
 
SLfloat rollRAD () const
 
SLfloat rollDEG () const
 
SLbool zeroYawAtStart () const
 
SLfloat startYawRAD () const
 
SLint numAveraged ()
 
SLRotOffsetMode offsetMode ()
 
SLstring offsetModeStr () const
 Returns the rotation offset mode as string. More...
 
SLbool updateRPY () const
 

Private Attributes

SLbool _isUsed
 Flag if device rotation is used. More...
 
SLbool _isFirstSensorValue
 Flag for the first sensor values. More...
 
SLfloat _pitchRAD
 Device pitch angle in radians. More...
 
SLfloat _yawRAD
 Device yaw angle in radians. More...
 
SLfloat _rollRAD
 Device roll angle in radians. More...
 
SLMat3f _rotation
 Mobile device rotation as matrix. More...
 
Averaged< SLMat3f_rotationAvg
 Component wise averaged rotation matrix. More...
 
SLQuat4f _quaternion
 
SLbool _zeroYawAtStart
 Quaternion rotation that is set by IMU. More...
 
SLfloat _startYawRAD
 Initial yaw angle after _zeroYawAfterSec in radians. More...
 
SLRotOffsetMode _offsetMode
 Rotation offset mode. More...
 
SLbool _updateRPY
 Calculate roll pitch yaw in onRotationQUAT. More...
 

Detailed Description

Encapsulation of a mobile device rotation set by the device's IMU sensor.

This class is only used if SLProject runs on a mobile device. Check out the app-Demo-SLProject/android and app_demo_slproject/ios how the sensor data is generated and passed to this object hold by AppDemo. It stores the devices rotation that it gets from its IMU (inertial measurement unit) sensor. This is a fused orientation that is calculated from the magnetometer, the accelerometer and the gyroscope. The device rotation can be used in the active camera to apply it to the scene camera (s. SLCamera::setView).

Constructor & Destructor Documentation

◆ SLDeviceRotation()

SLDeviceRotation::SLDeviceRotation ( )

Member Function Documentation

◆ hasStarted()

void SLDeviceRotation::hasStarted ( SLbool  started)
inline

◆ init()

void SLDeviceRotation::init ( )

◆ isUsed() [1/2]

SLbool SLDeviceRotation::isUsed ( ) const
inline

◆ isUsed() [2/2]

void SLDeviceRotation::isUsed ( SLbool  isUsed)

Setter that turns on the device rotation sensor.

◆ numAveraged() [1/2]

SLint SLDeviceRotation::numAveraged ( )
inline

◆ numAveraged() [2/2]

void SLDeviceRotation::numAveraged ( SLint  numAvg)

Returns the device rotation averaged over multple frames.

◆ offsetMode() [1/2]

SLRotOffsetMode SLDeviceRotation::offsetMode ( )
inline

◆ offsetMode() [2/2]

void SLDeviceRotation::offsetMode ( SLRotOffsetMode  rom)
inline

◆ offsetModeStr()

SLstring SLDeviceRotation::offsetModeStr ( ) const

Returns the rotation offset mode as string.

◆ onRotationQUAT()

void SLDeviceRotation::onRotationQUAT ( SLfloat  quatX,
SLfloat  quatY,
SLfloat  quatZ,
SLfloat  quatW 
)

onRotationQUAT: Event handler for rotation change of a mobile device from a rotation quaternion. This function will only be called in an Android or iOS project. See e.g. onSensorChanged in GLES3Activity.java in the Android project. This handler is only called if the flag SLScene::_usesRotation is true. If so the mobile device turns on it's IMU sensor system. The device rotation is so far only used in SLCamera::setView if the cameras animation is on CA_deciveRotYUp. If _zeroYawAfterStart is true the start yaw value is subtracted. This means that the magnetic north will be ignored. The angles should be:
Roll from -halfpi (ccw) to zero (horizontal) to +halfpi (clockwise)
Pitch from -halfpi (down) to zero (horizontal) to +halfpi (up)
Yaw from -pi (south) to zero (north) to +pi (south)

◆ pitchDEG()

SLfloat SLDeviceRotation::pitchDEG ( ) const
inline

◆ pitchRAD()

SLfloat SLDeviceRotation::pitchRAD ( ) const
inline

◆ quaternion()

SLQuat4f SLDeviceRotation::quaternion ( ) const
inline

◆ rollDEG()

SLfloat SLDeviceRotation::rollDEG ( ) const
inline

◆ rollRAD()

SLfloat SLDeviceRotation::rollRAD ( ) const
inline

◆ rotation()

SLMat3f SLDeviceRotation::rotation ( ) const
inline

◆ rotationAveraged()

SLMat3f SLDeviceRotation::rotationAveraged ( )
inline

◆ startYawRAD()

SLfloat SLDeviceRotation::startYawRAD ( ) const
inline

◆ updateRPY() [1/2]

SLbool SLDeviceRotation::updateRPY ( ) const
inline

◆ updateRPY() [2/2]

void SLDeviceRotation::updateRPY ( SLbool  doUpdate)
inline

◆ yawDEG()

SLfloat SLDeviceRotation::yawDEG ( ) const
inline

◆ yawRAD()

SLfloat SLDeviceRotation::yawRAD ( ) const
inline

◆ zeroYawAtStart() [1/2]

SLbool SLDeviceRotation::zeroYawAtStart ( ) const
inline

◆ zeroYawAtStart() [2/2]

void SLDeviceRotation::zeroYawAtStart ( SLbool  zeroYaw)
inline

Member Data Documentation

◆ _isFirstSensorValue

SLbool SLDeviceRotation::_isFirstSensorValue
private

Flag for the first sensor values.

◆ _isUsed

SLbool SLDeviceRotation::_isUsed
private

Flag if device rotation is used.

◆ _offsetMode

SLRotOffsetMode SLDeviceRotation::_offsetMode
private

Rotation offset mode.

◆ _pitchRAD

SLfloat SLDeviceRotation::_pitchRAD
private

Device pitch angle in radians.

◆ _quaternion

SLQuat4f SLDeviceRotation::_quaternion
private

◆ _rollRAD

SLfloat SLDeviceRotation::_rollRAD
private

Device roll angle in radians.

◆ _rotation

SLMat3f SLDeviceRotation::_rotation
private

Mobile device rotation as matrix.

◆ _rotationAvg

Averaged<SLMat3f> SLDeviceRotation::_rotationAvg
private

Component wise averaged rotation matrix.

◆ _startYawRAD

SLfloat SLDeviceRotation::_startYawRAD
private

Initial yaw angle after _zeroYawAfterSec in radians.

◆ _updateRPY

SLbool SLDeviceRotation::_updateRPY
private

Calculate roll pitch yaw in onRotationQUAT.

◆ _yawRAD

SLfloat SLDeviceRotation::_yawRAD
private

Device yaw angle in radians.

◆ _zeroYawAtStart

SLbool SLDeviceRotation::_zeroYawAtStart
private

Quaternion rotation that is set by IMU.

Flag if yaw angle should be zeroed at sensor start


The documentation for this class was generated from the following files: