Move quaternion functions to quaternion namespace
This commit is contained in:
@@ -31,7 +31,7 @@ HEADERS += src/overlaycontroller.h \
|
|||||||
src/tabcontrollers/KeyboardInput.h \
|
src/tabcontrollers/KeyboardInput.h \
|
||||||
src/utils/Matrix.h \
|
src/utils/Matrix.h \
|
||||||
src/utils/ChaperoneUtils.h \
|
src/utils/ChaperoneUtils.h \
|
||||||
src/utils/quaternion.h \
|
src/quaternion/quaternion.h \
|
||||||
src/tabcontrollers/audiomanager/AudioManagerDummy.h \
|
src/tabcontrollers/audiomanager/AudioManagerDummy.h \
|
||||||
src/tabcontrollers/keyboardinput/KeyboardInputDummy.h \
|
src/tabcontrollers/keyboardinput/KeyboardInputDummy.h \
|
||||||
src/overlaycontroller/openvr_init.h \
|
src/overlaycontroller/openvr_init.h \
|
||||||
|
|||||||
@@ -3,9 +3,9 @@
|
|||||||
#include <openvr.h>
|
#include <openvr.h>
|
||||||
//#include <cmath>
|
//#include <cmath>
|
||||||
|
|
||||||
namespace utils
|
namespace quaternion
|
||||||
{
|
{
|
||||||
inline vr::HmdQuaternion_t quaternionFromHmdMatrix34( vr::HmdMatrix34_t matrix )
|
inline vr::HmdQuaternion_t fromHmdMatrix34( vr::HmdMatrix34_t matrix )
|
||||||
{
|
{
|
||||||
vr::HmdQuaternion_t q;
|
vr::HmdQuaternion_t q;
|
||||||
|
|
||||||
@@ -34,8 +34,8 @@ inline vr::HmdQuaternion_t quaternionFromHmdMatrix34( vr::HmdMatrix34_t matrix )
|
|||||||
return q;
|
return q;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline vr::HmdQuaternion_t quaternionMultiply( const vr::HmdQuaternion_t& lhs,
|
inline vr::HmdQuaternion_t multiply( const vr::HmdQuaternion_t& lhs,
|
||||||
const vr::HmdQuaternion_t& rhs )
|
const vr::HmdQuaternion_t& rhs )
|
||||||
{
|
{
|
||||||
return { ( lhs.w * rhs.w ) - ( lhs.x * rhs.x ) - ( lhs.y * rhs.y )
|
return { ( lhs.w * rhs.w ) - ( lhs.x * rhs.x ) - ( lhs.y * rhs.y )
|
||||||
- ( lhs.z * rhs.z ),
|
- ( lhs.z * rhs.z ),
|
||||||
@@ -47,8 +47,7 @@ inline vr::HmdQuaternion_t quaternionMultiply( const vr::HmdQuaternion_t& lhs,
|
|||||||
- ( lhs.y * rhs.x ) };
|
- ( lhs.y * rhs.x ) };
|
||||||
}
|
}
|
||||||
|
|
||||||
inline vr::HmdQuaternion_t
|
inline vr::HmdQuaternion_t conjugate( const vr::HmdQuaternion_t& quat )
|
||||||
quaternionConjugate( const vr::HmdQuaternion_t& quat )
|
|
||||||
{
|
{
|
||||||
return {
|
return {
|
||||||
quat.w,
|
quat.w,
|
||||||
@@ -58,7 +57,7 @@ inline vr::HmdQuaternion_t
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
inline double quaternionGetYaw( const vr::HmdQuaternion_t& quat )
|
inline double getYaw( const vr::HmdQuaternion_t& quat )
|
||||||
{
|
{
|
||||||
double yawResult
|
double yawResult
|
||||||
= atan2( 2.0 * ( quat.y * quat.w + quat.x * quat.z ),
|
= atan2( 2.0 * ( quat.y * quat.w + quat.x * quat.z ),
|
||||||
@@ -66,4 +65,4 @@ inline double quaternionGetYaw( const vr::HmdQuaternion_t& quat )
|
|||||||
return yawResult;
|
return yawResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace utils
|
} // namespace quaternion
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
#include <QQuickWindow>
|
#include <QQuickWindow>
|
||||||
#include "../overlaycontroller.h"
|
#include "../overlaycontroller.h"
|
||||||
#include "../utils/Matrix.h"
|
#include "../utils/Matrix.h"
|
||||||
#include "../utils/quaternion.h"
|
#include "../quaternion/quaternion.h"
|
||||||
|
|
||||||
void rotateCoordinates( double coordinates[3], double angle )
|
void rotateCoordinates( double coordinates[3], double angle )
|
||||||
{
|
{
|
||||||
@@ -1259,7 +1259,7 @@ void MoveCenterTabController::updateHmdRotationCounter(
|
|||||||
utils::matMul33( hmdMatrixAbsolute, hmdMatrixRotMat, hmdMatrix );
|
utils::matMul33( hmdMatrixAbsolute, hmdMatrixRotMat, hmdMatrix );
|
||||||
|
|
||||||
// Convert pose matrix to quaternion
|
// Convert pose matrix to quaternion
|
||||||
m_hmdQuaternion = utils::quaternionFromHmdMatrix34( hmdMatrixAbsolute );
|
m_hmdQuaternion = quaternion::fromHmdMatrix34( hmdMatrixAbsolute );
|
||||||
|
|
||||||
// Get rotation change of hmd
|
// Get rotation change of hmd
|
||||||
// Checking for invalid quaternion using < because == isn't guaranteed
|
// Checking for invalid quaternion using < because == isn't guaranteed
|
||||||
@@ -1271,11 +1271,11 @@ void MoveCenterTabController::updateHmdRotationCounter(
|
|||||||
}
|
}
|
||||||
// Construct a quaternion representing difference between old
|
// Construct a quaternion representing difference between old
|
||||||
// hmd pose and new hmd pose.
|
// hmd pose and new hmd pose.
|
||||||
vr::HmdQuaternion_t hmdDiffQuaternion = utils::quaternionMultiply(
|
vr::HmdQuaternion_t hmdDiffQuaternion = quaternion::multiply(
|
||||||
m_hmdQuaternion, utils::quaternionConjugate( m_lastHmdQuaternion ) );
|
m_hmdQuaternion, quaternion::conjugate( m_lastHmdQuaternion ) );
|
||||||
|
|
||||||
// Calculate yaw from quaternion.
|
// Calculate yaw from quaternion.
|
||||||
double hmdYawDiff = utils::quaternionGetYaw( hmdDiffQuaternion );
|
double hmdYawDiff = quaternion::getYaw( hmdDiffQuaternion );
|
||||||
|
|
||||||
// Apply yaw difference to m_hmdYawTotal.
|
// Apply yaw difference to m_hmdYawTotal.
|
||||||
m_hmdYawTotal += hmdYawDiff;
|
m_hmdYawTotal += hmdYawDiff;
|
||||||
@@ -1428,7 +1428,7 @@ void MoveCenterTabController::updateHandTurn(
|
|||||||
utils::matMul33( handMatrixAbsolute, handMatrixRotMat, handMatrix );
|
utils::matMul33( handMatrixAbsolute, handMatrixRotMat, handMatrix );
|
||||||
|
|
||||||
// Convert pose matrix to quaternion
|
// Convert pose matrix to quaternion
|
||||||
m_handQuaternion = utils::quaternionFromHmdMatrix34( handMatrixAbsolute );
|
m_handQuaternion = quaternion::fromHmdMatrix34( handMatrixAbsolute );
|
||||||
|
|
||||||
if ( m_lastRotateHand == m_activeTurnHand )
|
if ( m_lastRotateHand == m_activeTurnHand )
|
||||||
{
|
{
|
||||||
@@ -1444,12 +1444,12 @@ void MoveCenterTabController::updateHandTurn(
|
|||||||
{
|
{
|
||||||
// Construct a quaternion representing difference
|
// Construct a quaternion representing difference
|
||||||
// between old hand and new hand.
|
// between old hand and new hand.
|
||||||
vr::HmdQuaternion_t handDiffQuaternion = utils::quaternionMultiply(
|
vr::HmdQuaternion_t handDiffQuaternion = quaternion::multiply(
|
||||||
m_handQuaternion,
|
m_handQuaternion,
|
||||||
utils::quaternionConjugate( m_lastHandQuaternion ) );
|
quaternion::conjugate( m_lastHandQuaternion ) );
|
||||||
|
|
||||||
// Calculate yaw from quaternion.
|
// Calculate yaw from quaternion.
|
||||||
double handYawDiff = utils::quaternionGetYaw( handDiffQuaternion );
|
double handYawDiff = quaternion::getYaw( handDiffQuaternion );
|
||||||
|
|
||||||
int newRotationAngleDeg = static_cast<int>(
|
int newRotationAngleDeg = static_cast<int>(
|
||||||
round( handYawDiff * k_radiansToCentidegrees ) + m_rotation );
|
round( handYawDiff * k_radiansToCentidegrees ) + m_rotation );
|
||||||
|
|||||||
Reference in New Issue
Block a user