From bba691bd7818f5853a2b8b4166fd7e4fe6355ff8 Mon Sep 17 00:00:00 2001 From: Remco Stoutjesdijk Date: Fri, 3 Mar 2023 00:19:17 +0100 Subject: [PATCH 01/15] typo --- apps/renderer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/renderer.c b/apps/renderer.c index fa3a3d21ee..2485c5a057 100644 --- a/apps/renderer.c +++ b/apps/renderer.c @@ -909,7 +909,7 @@ int main( if ( !args.quietModeEnabled ) { - fprintf( stdout, "\n------ Running the rondoror ------\n\n" ); + fprintf( stdout, "\n------ Running the renderer ------\n\n" ); fprintf( stdout, "Frames processed: " ); } else -- GitLab From e96871af3e0032fb1b8f8f66966c65174fe65852 Mon Sep 17 00:00:00 2001 From: Remco Stoutjesdijk Date: Fri, 3 Mar 2023 01:16:54 +0100 Subject: [PATCH 02/15] remove Quat2Euler from header definition file --- lib_rend/ivas_orient_trk.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib_rend/ivas_orient_trk.c b/lib_rend/ivas_orient_trk.c index 70a14b1797..e9718b937c 100644 --- a/lib_rend/ivas_orient_trk.c +++ b/lib_rend/ivas_orient_trk.c @@ -462,6 +462,14 @@ ivas_error ivas_orient_trk_Process( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } + /* check for Euler angle signaling */ + //if ( pOTR->refRot.w == -3.0f ) + //{ + // // convert to quaternion + // // port https://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles + + //} + result = IVAS_ERR_OK; switch ( pOTR->trackingType ) -- GitLab From 8e0894b5e6a6643f95f7f3cf7cf18486142319b7 Mon Sep 17 00:00:00 2001 From: Remco Stoutjesdijk Date: Fri, 3 Mar 2023 01:49:50 +0100 Subject: [PATCH 03/15] function prototype for Euler2Quat --- lib_rend/ivas_orient_trk.c | 22 +++++++++++++++------- lib_rend/ivas_prot_rend.h | 11 +++++++++++ lib_rend/ivas_rotation.c | 24 ++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 7 deletions(-) diff --git a/lib_rend/ivas_orient_trk.c b/lib_rend/ivas_orient_trk.c index e9718b937c..5ef7ded17d 100644 --- a/lib_rend/ivas_orient_trk.c +++ b/lib_rend/ivas_orient_trk.c @@ -30,6 +30,7 @@ *******************************************************************************************************/ +#include "common_api_types.h" #include #include "options.h" #include "ivas_prot.h" @@ -456,19 +457,26 @@ ivas_error ivas_orient_trk_Process( float alpha = pOTR->alpha; float ang; ivas_error result; + IVAS_QUATERNION quat; if ( pOTR == NULL || pTrkRot == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } + quat.w = 0.0f; + quat.x = 0.0f; + quat.y = 0.0f; + quat.z = 0.0f; /* check for Euler angle signaling */ - //if ( pOTR->refRot.w == -3.0f ) - //{ - // // convert to quaternion - // // port https://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles - - //} + if ( pOTR->refRot.w == -3.0f ) + { + Euler2Quat(pOTR->refRot.x, pOTR->refRot.y, pOTR->refRot.z, &quat); + } + else + { + quat = pOTR->refRot; + } result = IVAS_ERR_OK; @@ -486,7 +494,7 @@ ivas_error ivas_orient_trk_Process( pOTR->alpha = sinf( 2.0f * EVS_PI * pOTR->centerAdaptationRate / updateRate ); /* Compute relative orientation = (absolute orientation) - (reference orientation) */ - QuaternionInverse( pOTR->refRot, pTrkRot ); + QuaternionInverse( quat, pTrkRot ); QuaternionProduct( *pTrkRot, *pAbsRot, pTrkRot ); break; diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index 4712ccbf67..ccf929a359 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -796,12 +796,23 @@ void ivas_headTrack_close( ); #endif +#ifndef FIX_I109_ORIENTATION_TRACKING void Quat2Euler( const IVAS_QUATERNION quat, /* i : quaternion describing the rotation */ float *yaw, /* o : yaw */ float *pitch, /* o : pitch */ float *roll /* o : roll */ ); +#endif + +#ifdef FIX_I109_ORIENTATION_TRACKING +void Euler2Quat( + const float yaw, /* i : yaw */ + const float pitch, /* i : pitch */ + const float roll, /* i : roll */ + IVAS_QUATERNION *quat /* o : quaternion describing the rotation */ +); +#endif void QuatToRotMat( const IVAS_QUATERNION quat, /* i : quaternion describing the rotation */ diff --git a/lib_rend/ivas_rotation.c b/lib_rend/ivas_rotation.c index 90354497a0..15b4f66421 100644 --- a/lib_rend/ivas_rotation.c +++ b/lib_rend/ivas_rotation.c @@ -213,6 +213,30 @@ void Quat2Euler( } #endif +#ifdef FIX_I109_ORIENTATION_TRACKING +/*------------------------------------------------------------------------- + * Euler2Quat() + * + * Quaternion handling: calculate corresponding Euler angles + *------------------------------------------------------------------------*/ + +void Euler2Quat( + const float yaw, /* i : yaw */ + const float pitch, /* i : pitch */ + const float roll, /* i : roll */ + IVAS_QUATERNION *quat /* o : quaternion describing the rotation */ +) +{ + // @TODO implementation here + quat->w = -3.0f; + quat->x = yaw; + quat->y = pitch; + quat->z = roll; + + return; +} +#endif + /*------------------------------------------------------------------------- * rotateAziEle() -- GitLab From 17e2c2ad708b505fe2329df8e6c54472c9f45597 Mon Sep 17 00:00:00 2001 From: Remco Stoutjesdijk Date: Fri, 3 Mar 2023 01:59:34 +0100 Subject: [PATCH 04/15] implementation of Euler2Quat --- lib_rend/ivas_rotation.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib_rend/ivas_rotation.c b/lib_rend/ivas_rotation.c index 15b4f66421..8ff48c1104 100644 --- a/lib_rend/ivas_rotation.c +++ b/lib_rend/ivas_rotation.c @@ -227,11 +227,17 @@ void Euler2Quat( IVAS_QUATERNION *quat /* o : quaternion describing the rotation */ ) { - // @TODO implementation here - quat->w = -3.0f; - quat->x = yaw; - quat->y = pitch; - quat->z = roll; + float cr = cos( roll * 0.5f ); + float sr = sin( roll * 0.5f ); + float cp = cos( pitch * 0.5f ); + float sp = sin( pitch * 0.5f ); + float cy = cos( yaw * 0.5f ); + float sy = sin( yaw * 0.5f ); + + quat->w = cr * cp * cy + sr * sp * sy; + quat->x = sr * cp * cy - cr * sp * sy; + quat->y = cr * sp * cy + sr * cp * sy; + quat->z = cr * cp * sy - sr * sp * cy; return; } -- GitLab From 642e358a7aa7599f1ca9be8585543465b87591d0 Mon Sep 17 00:00:00 2001 From: Remco Stoutjesdijk Date: Fri, 3 Mar 2023 02:06:19 +0100 Subject: [PATCH 05/15] cosmetics --- lib_rend/ivas_prot_rend.h | 8 ++++---- lib_rend/ivas_rotation.c | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index ccf929a359..000d1c905b 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -807,10 +807,10 @@ void Quat2Euler( #ifdef FIX_I109_ORIENTATION_TRACKING void Euler2Quat( - const float yaw, /* i : yaw */ - const float pitch, /* i : pitch */ - const float roll, /* i : roll */ - IVAS_QUATERNION *quat /* o : quaternion describing the rotation */ + const float yaw, /* i : yaw */ + const float pitch, /* i : pitch */ + const float roll, /* i : roll */ + IVAS_QUATERNION *quat /* o : quaternion describing the rotation */ ); #endif diff --git a/lib_rend/ivas_rotation.c b/lib_rend/ivas_rotation.c index 8ff48c1104..ddcb059bfc 100644 --- a/lib_rend/ivas_rotation.c +++ b/lib_rend/ivas_rotation.c @@ -217,14 +217,14 @@ void Quat2Euler( /*------------------------------------------------------------------------- * Euler2Quat() * - * Quaternion handling: calculate corresponding Euler angles + * Calculate corresponding Quaternion from Euler angles *------------------------------------------------------------------------*/ void Euler2Quat( - const float yaw, /* i : yaw */ - const float pitch, /* i : pitch */ - const float roll, /* i : roll */ - IVAS_QUATERNION *quat /* o : quaternion describing the rotation */ + const float yaw, /* i : yaw */ + const float pitch, /* i : pitch */ + const float roll, /* i : roll */ + IVAS_QUATERNION *quat /* o : quaternion describing the rotation */ ) { float cr = cos( roll * 0.5f ); -- GitLab From 0d67d76c7e7f9c2cb3ef6744a358f9619671a2c3 Mon Sep 17 00:00:00 2001 From: Remco Stoutjesdijk Date: Tue, 7 Mar 2023 18:26:15 +0100 Subject: [PATCH 06/15] re-enable and fix quat2euler --- lib_rend/ivas_orient_trk.c | 52 ++++++++++++++++++++++++++++---------- lib_rend/ivas_prot_rend.h | 2 -- lib_rend/ivas_rotation.c | 24 ++++++++++-------- 3 files changed, 53 insertions(+), 25 deletions(-) diff --git a/lib_rend/ivas_orient_trk.c b/lib_rend/ivas_orient_trk.c index 5ef7ded17d..b0865c9322 100644 --- a/lib_rend/ivas_orient_trk.c +++ b/lib_rend/ivas_orient_trk.c @@ -457,25 +457,40 @@ ivas_error ivas_orient_trk_Process( float alpha = pOTR->alpha; float ang; ivas_error result; - IVAS_QUATERNION quat; + IVAS_QUATERNION refQuat, trkQuat; + IVAS_QUATERNION trkEuler; if ( pOTR == NULL || pTrkRot == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } - quat.w = 0.0f; - quat.x = 0.0f; - quat.y = 0.0f; - quat.z = 0.0f; + refQuat.w = 0.0f; + refQuat.x = 0.0f; + refQuat.y = 0.0f; + refQuat.z = 0.0f; /* check for Euler angle signaling */ if ( pOTR->refRot.w == -3.0f ) { - Euler2Quat(pOTR->refRot.x, pOTR->refRot.y, pOTR->refRot.z, &quat); + Euler2Quat(pOTR->refRot.x, pOTR->refRot.y, pOTR->refRot.z, &refQuat); } else { - quat = pOTR->refRot; + refQuat = pOTR->refRot; + } + + trkQuat.w = 0.0f; + trkQuat.x = 0.0f; + trkQuat.y = 0.0f; + trkQuat.z = 0.0f; + /* check for Euler angle signaling */ + if ( pTrkRot->w == -3.0f ) + { + Euler2Quat(pTrkRot->x, pTrkRot->y, pTrkRot->z, &trkQuat); + } + else + { + trkQuat = *pTrkRot; } result = IVAS_ERR_OK; @@ -483,7 +498,7 @@ ivas_error ivas_orient_trk_Process( switch ( pOTR->trackingType ) { case OTR_TRACKING_NONE: - *pTrkRot = *pAbsRot; + trkQuat = *pAbsRot; break; case OTR_TRACKING_REF_ORIENT: @@ -494,8 +509,8 @@ ivas_error ivas_orient_trk_Process( pOTR->alpha = sinf( 2.0f * EVS_PI * pOTR->centerAdaptationRate / updateRate ); /* Compute relative orientation = (absolute orientation) - (reference orientation) */ - QuaternionInverse( quat, pTrkRot ); - QuaternionProduct( *pTrkRot, *pAbsRot, pTrkRot ); + QuaternionInverse( refQuat, &trkQuat ); + QuaternionProduct( trkQuat, *pAbsRot, &trkQuat ); break; case OTR_TRACKING_AVG_ORIENT: @@ -503,8 +518,8 @@ ivas_error ivas_orient_trk_Process( QuaternionSlerp( pOTR->absAvgRot, *pAbsRot, alpha, &pOTR->absAvgRot ); /* Compute relative orientation = (absolute orientation) - (average absolute orientation) */ - QuaternionInverse( pOTR->absAvgRot, pTrkRot ); - QuaternionProduct( *pTrkRot, *pAbsRot, pTrkRot ); + QuaternionInverse( pOTR->absAvgRot, &trkQuat ); + QuaternionProduct( trkQuat, *pAbsRot, &trkQuat ); /* Adapt LPF constant based on orientation excursion relative to current mean: - low cutoff (slow adaptation) for small excursions (around center) @@ -542,7 +557,18 @@ ivas_error ivas_orient_trk_Process( if ( result == IVAS_ERR_OK ) { - pOTR->trkRot = *pTrkRot; + pOTR->trkRot = trkQuat; + + if ( pTrkRot->w == -3.0f ) + { + Quat2Euler(trkQuat, &trkEuler.x, &trkEuler.y, &trkEuler.z); + trkEuler.w = -3.0f; + *pTrkRot = trkEuler; + } + else + { + *pTrkRot = trkQuat; + } } return result; diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index 000d1c905b..d22977452b 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -796,14 +796,12 @@ void ivas_headTrack_close( ); #endif -#ifndef FIX_I109_ORIENTATION_TRACKING void Quat2Euler( const IVAS_QUATERNION quat, /* i : quaternion describing the rotation */ float *yaw, /* o : yaw */ float *pitch, /* o : pitch */ float *roll /* o : roll */ ); -#endif #ifdef FIX_I109_ORIENTATION_TRACKING void Euler2Quat( diff --git a/lib_rend/ivas_rotation.c b/lib_rend/ivas_rotation.c index ddcb059bfc..d98138126b 100644 --- a/lib_rend/ivas_rotation.c +++ b/lib_rend/ivas_rotation.c @@ -176,7 +176,6 @@ void QuatToRotMat( return; } -#ifndef FIX_I109_ORIENTATION_TRACKING /*------------------------------------------------------------------------- * Quat2Euler() * @@ -204,14 +203,19 @@ void Quat2Euler( * pitch: rotate scene in the median plane, increase elevation with positive values * roll: rotate scene from the right ear to the top */ - *yaw = quat.z; +#ifdef FIX_I109_ORIENTATION_TRACKING + *yaw = quat.x; + *pitch = quat.y; + *roll = quat.z; +#else + *yaw = quat.z; *pitch = quat.y; - *roll = quat.x; + *roll = quat.x; +#endif } return; } -#endif #ifdef FIX_I109_ORIENTATION_TRACKING /*------------------------------------------------------------------------- @@ -227,12 +231,12 @@ void Euler2Quat( IVAS_QUATERNION *quat /* o : quaternion describing the rotation */ ) { - float cr = cos( roll * 0.5f ); - float sr = sin( roll * 0.5f ); - float cp = cos( pitch * 0.5f ); - float sp = sin( pitch * 0.5f ); - float cy = cos( yaw * 0.5f ); - float sy = sin( yaw * 0.5f ); + float cr = cosf( roll * 0.5f ); + float sr = sinf( roll * 0.5f ); + float cp = cosf( pitch * 0.5f ); + float sp = sinf( pitch * 0.5f ); + float cy = cosf( yaw * 0.5f ); + float sy = sinf( yaw * 0.5f ); quat->w = cr * cp * cy + sr * sp * sy; quat->x = sr * cp * cy - cr * sp * sy; -- GitLab From 0ea486611c209693e0050f56c9dd5fe084760938 Mon Sep 17 00:00:00 2001 From: Remco Stoutjesdijk Date: Tue, 7 Mar 2023 22:39:09 +0100 Subject: [PATCH 07/15] Euler processing correct in degrees - all internal processign in ivas_orient_trk_Process() now done in Quat - output in Eulers in quasi-quaternion format when necessary - Euler angles assumed in degrees, conversion to and from radians added --- lib_rend/ivas_orient_trk.c | 40 ++++++++++++++++++++-------- lib_rend/ivas_prot_rend.h | 4 +++ lib_rend/ivas_rotation.c | 53 ++++++++++++++++++++++++++++---------- 3 files changed, 72 insertions(+), 25 deletions(-) diff --git a/lib_rend/ivas_orient_trk.c b/lib_rend/ivas_orient_trk.c index b0865c9322..2b8d332d93 100644 --- a/lib_rend/ivas_orient_trk.c +++ b/lib_rend/ivas_orient_trk.c @@ -457,7 +457,7 @@ ivas_error ivas_orient_trk_Process( float alpha = pOTR->alpha; float ang; ivas_error result; - IVAS_QUATERNION refQuat, trkQuat; + IVAS_QUATERNION refQuat, absQuat, trkQuat; IVAS_QUATERNION trkEuler; if ( pOTR == NULL || pTrkRot == NULL ) @@ -472,13 +472,27 @@ ivas_error ivas_orient_trk_Process( /* check for Euler angle signaling */ if ( pOTR->refRot.w == -3.0f ) { - Euler2Quat(pOTR->refRot.x, pOTR->refRot.y, pOTR->refRot.z, &refQuat); + Euler2Quat(deg2rad( pOTR->refRot.x ), deg2rad( pOTR->refRot.y ), deg2rad( pOTR->refRot.z ), &refQuat); } else { refQuat = pOTR->refRot; } + absQuat.w = 0.0f; + absQuat.x = 0.0f; + absQuat.y = 0.0f; + absQuat.z = 0.0f; + /* check for Euler angle signaling */ + if ( pAbsRot->w == -3.0f ) + { + Euler2Quat(deg2rad( pAbsRot->x ), deg2rad( pAbsRot->y ), deg2rad( pAbsRot->z ), &absQuat); + } + else + { + absQuat = *pAbsRot; + } + trkQuat.w = 0.0f; trkQuat.x = 0.0f; trkQuat.y = 0.0f; @@ -486,7 +500,7 @@ ivas_error ivas_orient_trk_Process( /* check for Euler angle signaling */ if ( pTrkRot->w == -3.0f ) { - Euler2Quat(pTrkRot->x, pTrkRot->y, pTrkRot->z, &trkQuat); + Euler2Quat(deg2rad( pTrkRot->x ), deg2rad( pTrkRot->y ), deg2rad( pTrkRot->z ), &trkQuat); } else { @@ -498,34 +512,34 @@ ivas_error ivas_orient_trk_Process( switch ( pOTR->trackingType ) { case OTR_TRACKING_NONE: - trkQuat = *pAbsRot; + trkQuat = absQuat; break; case OTR_TRACKING_REF_ORIENT: /* Reset average orientation */ - pOTR->absAvgRot = *pAbsRot; + pOTR->absAvgRot = absQuat; /* Reset adaptation filter - start adaptation at center rate */ pOTR->alpha = sinf( 2.0f * EVS_PI * pOTR->centerAdaptationRate / updateRate ); /* Compute relative orientation = (absolute orientation) - (reference orientation) */ QuaternionInverse( refQuat, &trkQuat ); - QuaternionProduct( trkQuat, *pAbsRot, &trkQuat ); + QuaternionProduct( trkQuat, absQuat, &trkQuat ); break; case OTR_TRACKING_AVG_ORIENT: /* Compute average (low-pass filtered) absolute orientation */ - QuaternionSlerp( pOTR->absAvgRot, *pAbsRot, alpha, &pOTR->absAvgRot ); + QuaternionSlerp( pOTR->absAvgRot, absQuat, alpha, &pOTR->absAvgRot ); /* Compute relative orientation = (absolute orientation) - (average absolute orientation) */ QuaternionInverse( pOTR->absAvgRot, &trkQuat ); - QuaternionProduct( trkQuat, *pAbsRot, &trkQuat ); + QuaternionProduct( trkQuat, absQuat, &trkQuat ); /* Adapt LPF constant based on orientation excursion relative to current mean: - low cutoff (slow adaptation) for small excursions (around center) - high cutoff (fast adaptation) for large excursions (off-center) */ - ang = QuaternionAngle( *pAbsRot, *pTrkRot ); + ang = QuaternionAngle( absQuat, *pTrkRot ); normalizedOrientation = ang * ang; relativeOrientationRate = sqrtf( normalizedOrientation ) / pOTR->adaptationAngle; @@ -558,10 +572,14 @@ ivas_error ivas_orient_trk_Process( if ( result == IVAS_ERR_OK ) { pOTR->trkRot = trkQuat; + pOTR->refRot = refQuat; - if ( pTrkRot->w == -3.0f ) + if ( ( pTrkRot->w == -3.0f) || ( pAbsRot->w == -3.0f ) ) { - Quat2Euler(trkQuat, &trkEuler.x, &trkEuler.y, &trkEuler.z); + Quat2Euler( trkQuat, &trkEuler.z, &trkEuler.y, &trkEuler.x ); + trkEuler.x = rad2deg( trkEuler.x ); + trkEuler.y = rad2deg( trkEuler.y ); + trkEuler.z = rad2deg( trkEuler.z ); trkEuler.w = -3.0f; *pTrkRot = trkEuler; } diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index d22977452b..73c3025b0c 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -810,6 +810,10 @@ void Euler2Quat( const float roll, /* i : roll */ IVAS_QUATERNION *quat /* o : quaternion describing the rotation */ ); + +float deg2rad( float degrees ); + +float rad2deg( float radians ); #endif void QuatToRotMat( diff --git a/lib_rend/ivas_rotation.c b/lib_rend/ivas_rotation.c index d98138126b..d6f1f5fe09 100644 --- a/lib_rend/ivas_rotation.c +++ b/lib_rend/ivas_rotation.c @@ -127,7 +127,11 @@ void QuatToRotMat( * Euler angles instead of quaternions. In this case, all the w values must * be set to -3.0 in the trajectory file to signal switching to Euler angles. * The x,y, and z components of the quaternion are then interpreted as +#ifdef FIX_I109_ORIENTATION_TRACKING * yaw-pitch-roll. +#else // see below: "Euler angles in R_X(roll)*R_Y(pitch)*R_Z(yaw) convention" + * roll-pitch-yaw. +#endif */ if ( quat.w != -3.0 ) { @@ -179,21 +183,27 @@ void QuatToRotMat( /*------------------------------------------------------------------------- * Quat2Euler() * - * Quaternion handling: calculate corresponding Euler angles + * Quaternion handling: calculate corresponding Euler angles in radians *------------------------------------------------------------------------*/ void Quat2Euler( const IVAS_QUATERNION quat, /* i : quaternion describing the rotation */ - float *yaw, /* o : yaw */ - float *pitch, /* o : pitch */ - float *roll /* o : roll */ + float *yaw, /* o : yaw (z) */ + float *pitch, /* o : pitch (y) */ + float *roll /* o : roll (x) */ ) { if ( quat.w != -3.0 ) { +#ifdef FIX_I109_ORIENTATION_TRACKING + *roll = atan2f( 2 * ( quat.w * quat.x + quat.y * quat.z ), 1 - 2 * ( quat.x * quat.x + quat.y * quat.y ) ); + *pitch = asinf( 2 * ( quat.w * quat.y - quat.z * quat.x ) ); + *yaw = atan2f( 2 * ( quat.w * quat.z + quat.x * quat.y ), 1 - 2 * ( quat.y * quat.y + quat.z * quat.z ) ); +#else // bug: x and z swapped *yaw = atan2f( 2 * ( quat.w * quat.x + quat.y * quat.z ), 1 - 2 * ( quat.x * quat.x + quat.y * quat.y ) ); *pitch = asinf( 2 * ( quat.w * quat.y - quat.z * quat.x ) ); *roll = atan2f( 2 * ( quat.w * quat.z + quat.x * quat.y ), 1 - 2 * ( quat.y * quat.y + quat.z * quat.z ) ); +#endif } else { @@ -203,15 +213,9 @@ void Quat2Euler( * pitch: rotate scene in the median plane, increase elevation with positive values * roll: rotate scene from the right ear to the top */ -#ifdef FIX_I109_ORIENTATION_TRACKING - *yaw = quat.x; - *pitch = quat.y; - *roll = quat.z; -#else *yaw = quat.z; *pitch = quat.y; *roll = quat.x; -#endif } return; @@ -221,13 +225,13 @@ void Quat2Euler( /*------------------------------------------------------------------------- * Euler2Quat() * - * Calculate corresponding Quaternion from Euler angles + * Calculate corresponding Quaternion from Euler angles in radians *------------------------------------------------------------------------*/ void Euler2Quat( - const float yaw, /* i : yaw */ - const float pitch, /* i : pitch */ - const float roll, /* i : roll */ + const float roll, /* i : roll (x) */ + const float pitch, /* i : pitch (y) */ + const float yaw, /* i : yaw (z) */ IVAS_QUATERNION *quat /* o : quaternion describing the rotation */ ) { @@ -245,6 +249,27 @@ void Euler2Quat( return; } + +/*------------------------------------------------------------------------- + * rad2deg() + * + * Return angle in radians from degrees + *------------------------------------------------------------------------*/ +float deg2rad( float degrees ) +{ + return PI2 * degrees / 360.0f; +} + +/*------------------------------------------------------------------------- + * deg2rad() + * + * Return angle in degrees from radians + *------------------------------------------------------------------------*/ +float rad2deg( float radians ) +{ + return 360.0f * radians / PI2; +} + #endif -- GitLab From 1771b40dc6d5b981813b568d05a8d41f8d54976e Mon Sep 17 00:00:00 2001 From: hsd Date: Wed, 8 Mar 2023 07:49:22 +0100 Subject: [PATCH 08/15] [fix] adapt OTR_TRACKING_REF_VEC* mode to use ne w refQuat, absQuat, trkQuat variables (otherwise the results get overwritten in the result == IVAS_ERR_OK block) --- lib_rend/ivas_orient_trk.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/lib_rend/ivas_orient_trk.c b/lib_rend/ivas_orient_trk.c index ebf5ed4a4c..a7e47f422a 100644 --- a/lib_rend/ivas_orient_trk.c +++ b/lib_rend/ivas_orient_trk.c @@ -657,9 +657,6 @@ ivas_error ivas_orient_trk_Process( ivas_error result; IVAS_QUATERNION refQuat, absQuat, trkQuat; IVAS_QUATERNION trkEuler; -#ifdef OTR_REFERENCE_VECTOR_TRACKING - IVAS_QUATERNION refRot_absRot_product; -#endif /* OTR_REFERENCE_VECTOR_TRACKING */ if ( pOTR == NULL || pTrkRot == NULL ) { @@ -769,12 +766,7 @@ ivas_error ivas_orient_trk_Process( case OTR_TRACKING_REF_VEC_LEV: { /* This processing step of the OTR_TRACKING_REF_VEC/OTR_TRACKING_REF_VEC_LEVEL is identical */ - QuaternionProduct( pOTR->refRot, *pAbsRot, &refRot_absRot_product ); - - pTrkRot->w = refRot_absRot_product.w; - pTrkRot->x = refRot_absRot_product.x; - pTrkRot->y = refRot_absRot_product.y; - pTrkRot->z = refRot_absRot_product.z; + QuaternionProduct( refQuat, absQuat, &trkQuat ); break; } #endif /* OTR_REFERENCE_VECTOR_TRACKING */ -- GitLab From 3ee1c2154730f065be0e550c668afaee6c911d62 Mon Sep 17 00:00:00 2001 From: Remco Stoutjesdijk Date: Wed, 8 Mar 2023 11:23:29 +0100 Subject: [PATCH 09/15] harmonize euler2quat declaration and function --- lib_rend/ivas_prot_rend.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index 561af30aff..49dadd271d 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -806,18 +806,18 @@ void ivas_headTrack_close( #endif void Quat2Euler( - const IVAS_QUATERNION quat, /* i : quaternion describing the rotation */ - float *yaw, /* o : yaw */ - float *pitch, /* o : pitch */ - float *roll /* o : roll */ + const IVAS_QUATERNION quat, /* i : quaternion describing the rotation */ + float *yaw, /* o : yaw (z) */ + float *pitch, /* o : pitch (y) */ + float *roll /* o : roll (x) */ ); #ifdef FIX_I109_ORIENTATION_TRACKING void Euler2Quat( - const float yaw, /* i : yaw */ - const float pitch, /* i : pitch */ - const float roll, /* i : roll */ - IVAS_QUATERNION *quat /* o : quaternion describing the rotation */ + const float roll, /* i : roll (x) */ + const float pitch, /* i : pitch (y) */ + const float yaw, /* i : yaw (z) */ + IVAS_QUATERNION *quat /* o : quaternion describing the rotation */ ); float deg2rad( float degrees ); -- GitLab From 1f352872529d8323aa75d2039eb258bd296b5d19 Mon Sep 17 00:00:00 2001 From: Remco Stoutjesdijk Date: Wed, 8 Mar 2023 11:56:32 +0100 Subject: [PATCH 10/15] simplify decision logic --- lib_rend/ivas_orient_trk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_rend/ivas_orient_trk.c b/lib_rend/ivas_orient_trk.c index a7e47f422a..a6d0dd61a5 100644 --- a/lib_rend/ivas_orient_trk.c +++ b/lib_rend/ivas_orient_trk.c @@ -780,7 +780,7 @@ ivas_error ivas_orient_trk_Process( pOTR->trkRot = trkQuat; pOTR->refRot = refQuat; - if ( ( pTrkRot->w == -3.0f) || ( pAbsRot->w == -3.0f ) ) + if ( pAbsRot->w == -3.0f ) { Quat2Euler( trkQuat, &trkEuler.z, &trkEuler.y, &trkEuler.x ); trkEuler.x = rad2deg( trkEuler.x ); -- GitLab From 7830d38b3f8934de43bd8ee251dc3e10cba7e673 Mon Sep 17 00:00:00 2001 From: Remco Stoutjesdijk Date: Wed, 8 Mar 2023 12:07:48 +0100 Subject: [PATCH 11/15] convert reference rotation in ivas_orient_trk_init --- lib_rend/ivas_orient_trk.c | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/lib_rend/ivas_orient_trk.c b/lib_rend/ivas_orient_trk.c index a6d0dd61a5..5a72d317ff 100644 --- a/lib_rend/ivas_orient_trk.c +++ b/lib_rend/ivas_orient_trk.c @@ -509,7 +509,17 @@ ivas_error ivas_orient_trk_SetReferenceRotation( { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } - pOTR->refRot = refRot; + + /* check for Euler angle signaling */ + if ( refRot.w == -3.0f ) + { + Euler2Quat(deg2rad( refRot.x ), deg2rad( refRot.y ), deg2rad( refRot.z ), &pOTR->refRot ); + } + else + { + pOTR->refRot = refRot; + } + return IVAS_ERR_OK; } @@ -655,7 +665,7 @@ ivas_error ivas_orient_trk_Process( float alpha = pOTR->alpha; float ang; ivas_error result; - IVAS_QUATERNION refQuat, absQuat, trkQuat; + IVAS_QUATERNION absQuat, trkQuat; IVAS_QUATERNION trkEuler; if ( pOTR == NULL || pTrkRot == NULL ) @@ -663,20 +673,6 @@ ivas_error ivas_orient_trk_Process( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } - refQuat.w = 0.0f; - refQuat.x = 0.0f; - refQuat.y = 0.0f; - refQuat.z = 0.0f; - /* check for Euler angle signaling */ - if ( pOTR->refRot.w == -3.0f ) - { - Euler2Quat(deg2rad( pOTR->refRot.x ), deg2rad( pOTR->refRot.y ), deg2rad( pOTR->refRot.z ), &refQuat); - } - else - { - refQuat = pOTR->refRot; - } - absQuat.w = 0.0f; absQuat.x = 0.0f; absQuat.y = 0.0f; @@ -721,7 +717,7 @@ ivas_error ivas_orient_trk_Process( pOTR->alpha = sinf( 2.0f * EVS_PI * pOTR->centerAdaptationRate / updateRate ); /* Compute relative orientation = (absolute orientation) - (reference orientation) */ - QuaternionInverse( refQuat, &trkQuat ); + QuaternionInverse( pOTR->refRot, &trkQuat ); QuaternionProduct( trkQuat, absQuat, &trkQuat ); break; @@ -737,7 +733,7 @@ ivas_error ivas_orient_trk_Process( - low cutoff (slow adaptation) for small excursions (around center) - high cutoff (fast adaptation) for large excursions (off-center) */ - ang = QuaternionAngle( absQuat, *pTrkRot ); + ang = QuaternionAngle( absQuat, trkQuat ); normalizedOrientation = ang * ang; relativeOrientationRate = sqrtf( normalizedOrientation ) / pOTR->adaptationAngle; @@ -766,7 +762,7 @@ ivas_error ivas_orient_trk_Process( case OTR_TRACKING_REF_VEC_LEV: { /* This processing step of the OTR_TRACKING_REF_VEC/OTR_TRACKING_REF_VEC_LEVEL is identical */ - QuaternionProduct( refQuat, absQuat, &trkQuat ); + QuaternionProduct( pOTR->refRot, absQuat, &trkQuat ); break; } #endif /* OTR_REFERENCE_VECTOR_TRACKING */ @@ -778,7 +774,6 @@ ivas_error ivas_orient_trk_Process( if ( result == IVAS_ERR_OK ) { pOTR->trkRot = trkQuat; - pOTR->refRot = refQuat; if ( pAbsRot->w == -3.0f ) { -- GitLab From 6fee008f4a9f540e108e6ee509a896e96de38da6 Mon Sep 17 00:00:00 2001 From: Remco Stoutjesdijk Date: Wed, 8 Mar 2023 12:07:48 +0100 Subject: [PATCH 12/15] convert reference rotation in ivas_orient_trk_SetReferenceRotation --- lib_rend/ivas_orient_trk.c | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/lib_rend/ivas_orient_trk.c b/lib_rend/ivas_orient_trk.c index a6d0dd61a5..5a72d317ff 100644 --- a/lib_rend/ivas_orient_trk.c +++ b/lib_rend/ivas_orient_trk.c @@ -509,7 +509,17 @@ ivas_error ivas_orient_trk_SetReferenceRotation( { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } - pOTR->refRot = refRot; + + /* check for Euler angle signaling */ + if ( refRot.w == -3.0f ) + { + Euler2Quat(deg2rad( refRot.x ), deg2rad( refRot.y ), deg2rad( refRot.z ), &pOTR->refRot ); + } + else + { + pOTR->refRot = refRot; + } + return IVAS_ERR_OK; } @@ -655,7 +665,7 @@ ivas_error ivas_orient_trk_Process( float alpha = pOTR->alpha; float ang; ivas_error result; - IVAS_QUATERNION refQuat, absQuat, trkQuat; + IVAS_QUATERNION absQuat, trkQuat; IVAS_QUATERNION trkEuler; if ( pOTR == NULL || pTrkRot == NULL ) @@ -663,20 +673,6 @@ ivas_error ivas_orient_trk_Process( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } - refQuat.w = 0.0f; - refQuat.x = 0.0f; - refQuat.y = 0.0f; - refQuat.z = 0.0f; - /* check for Euler angle signaling */ - if ( pOTR->refRot.w == -3.0f ) - { - Euler2Quat(deg2rad( pOTR->refRot.x ), deg2rad( pOTR->refRot.y ), deg2rad( pOTR->refRot.z ), &refQuat); - } - else - { - refQuat = pOTR->refRot; - } - absQuat.w = 0.0f; absQuat.x = 0.0f; absQuat.y = 0.0f; @@ -721,7 +717,7 @@ ivas_error ivas_orient_trk_Process( pOTR->alpha = sinf( 2.0f * EVS_PI * pOTR->centerAdaptationRate / updateRate ); /* Compute relative orientation = (absolute orientation) - (reference orientation) */ - QuaternionInverse( refQuat, &trkQuat ); + QuaternionInverse( pOTR->refRot, &trkQuat ); QuaternionProduct( trkQuat, absQuat, &trkQuat ); break; @@ -737,7 +733,7 @@ ivas_error ivas_orient_trk_Process( - low cutoff (slow adaptation) for small excursions (around center) - high cutoff (fast adaptation) for large excursions (off-center) */ - ang = QuaternionAngle( absQuat, *pTrkRot ); + ang = QuaternionAngle( absQuat, trkQuat ); normalizedOrientation = ang * ang; relativeOrientationRate = sqrtf( normalizedOrientation ) / pOTR->adaptationAngle; @@ -766,7 +762,7 @@ ivas_error ivas_orient_trk_Process( case OTR_TRACKING_REF_VEC_LEV: { /* This processing step of the OTR_TRACKING_REF_VEC/OTR_TRACKING_REF_VEC_LEVEL is identical */ - QuaternionProduct( refQuat, absQuat, &trkQuat ); + QuaternionProduct( pOTR->refRot, absQuat, &trkQuat ); break; } #endif /* OTR_REFERENCE_VECTOR_TRACKING */ @@ -778,7 +774,6 @@ ivas_error ivas_orient_trk_Process( if ( result == IVAS_ERR_OK ) { pOTR->trkRot = trkQuat; - pOTR->refRot = refQuat; if ( pAbsRot->w == -3.0f ) { -- GitLab From 1c005b6909c234870c7a3e4a4c66665d8bc6b91c Mon Sep 17 00:00:00 2001 From: Remco Stoutjesdijk Date: Wed, 8 Mar 2023 12:51:57 +0100 Subject: [PATCH 13/15] see if CI will let us get away without quat inits --- lib_rend/ivas_orient_trk.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/lib_rend/ivas_orient_trk.c b/lib_rend/ivas_orient_trk.c index 5a72d317ff..5eaff413d9 100644 --- a/lib_rend/ivas_orient_trk.c +++ b/lib_rend/ivas_orient_trk.c @@ -673,10 +673,6 @@ ivas_error ivas_orient_trk_Process( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } - absQuat.w = 0.0f; - absQuat.x = 0.0f; - absQuat.y = 0.0f; - absQuat.z = 0.0f; /* check for Euler angle signaling */ if ( pAbsRot->w == -3.0f ) { @@ -687,10 +683,6 @@ ivas_error ivas_orient_trk_Process( absQuat = *pAbsRot; } - trkQuat.w = 0.0f; - trkQuat.x = 0.0f; - trkQuat.y = 0.0f; - trkQuat.z = 0.0f; /* check for Euler angle signaling */ if ( pTrkRot->w == -3.0f ) { -- GitLab From 2c6fdebfc4fa870a08e30305845fdacb2aacd73a Mon Sep 17 00:00:00 2001 From: Remco Stoutjesdijk Date: Wed, 8 Mar 2023 14:13:06 +0100 Subject: [PATCH 14/15] remove unnecessary conversion of pTrkRot --- lib_rend/ivas_orient_trk.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/lib_rend/ivas_orient_trk.c b/lib_rend/ivas_orient_trk.c index 5eaff413d9..d63decba09 100644 --- a/lib_rend/ivas_orient_trk.c +++ b/lib_rend/ivas_orient_trk.c @@ -683,16 +683,6 @@ ivas_error ivas_orient_trk_Process( absQuat = *pAbsRot; } - /* check for Euler angle signaling */ - if ( pTrkRot->w == -3.0f ) - { - Euler2Quat(deg2rad( pTrkRot->x ), deg2rad( pTrkRot->y ), deg2rad( pTrkRot->z ), &trkQuat); - } - else - { - trkQuat = *pTrkRot; - } - result = IVAS_ERR_OK; switch ( pOTR->trackingType ) -- GitLab From 6d9fcc64ec3e1960c01021a582560740336b2642 Mon Sep 17 00:00:00 2001 From: Remco Stoutjesdijk Date: Wed, 8 Mar 2023 14:23:54 +0100 Subject: [PATCH 15/15] using constants in deg2rad / rad2deg --- lib_rend/ivas_rotation.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib_rend/ivas_rotation.c b/lib_rend/ivas_rotation.c index d6f1f5fe09..409626de0b 100644 --- a/lib_rend/ivas_rotation.c +++ b/lib_rend/ivas_rotation.c @@ -30,6 +30,7 @@ *******************************************************************************************************/ +#include "ivas_cnst.h" #include #include #include "options.h" @@ -257,7 +258,7 @@ void Euler2Quat( *------------------------------------------------------------------------*/ float deg2rad( float degrees ) { - return PI2 * degrees / 360.0f; + return PI_OVER_180 * degrees; } /*------------------------------------------------------------------------- @@ -267,7 +268,7 @@ float deg2rad( float degrees ) *------------------------------------------------------------------------*/ float rad2deg( float radians ) { - return 360.0f * radians / PI2; + return _180_OVER_PI * radians; } #endif -- GitLab