Split off hand-turn hand-drag and hmdrotation
Hand-turn hand-drag and hmdrotationstats counting are split off into separate functions from the event loop.
This commit is contained in:
@@ -61,6 +61,7 @@ constexpr int k_utilitiesSettingsUpdateCounter = 19;
|
|||||||
// k_nonVsyncTickRate determines number of ms we wait to force the next event
|
// k_nonVsyncTickRate determines number of ms we wait to force the next event
|
||||||
// loop tick when vsync is too late due to dropped frames.
|
// loop tick when vsync is too late due to dropped frames.
|
||||||
constexpr int k_nonVsyncTickRate = 20;
|
constexpr int k_nonVsyncTickRate = 20;
|
||||||
|
constexpr int k_hmdRotationCounterUpdateRate = 7;
|
||||||
|
|
||||||
class OverlayController : public QObject
|
class OverlayController : public QObject
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -859,32 +859,20 @@ void MoveCenterTabController::optionalOverrideRightHandRoomTurn(
|
|||||||
|
|
||||||
// END of turn bindings.
|
// END of turn bindings.
|
||||||
|
|
||||||
void MoveCenterTabController::eventLoopTick(
|
void MoveCenterTabController::updateHmdRotationCounter(
|
||||||
vr::ETrackingUniverseOrigin universe,
|
vr::TrackedDevicePose_t hmdPose,
|
||||||
vr::TrackedDevicePose_t* devicePoses )
|
double angle )
|
||||||
{
|
{
|
||||||
if ( settingsUpdateCounter >= k_moveCenterSettingsUpdateCounter )
|
// If hmd tracking is bad, set m_lastHmdQuaternion invalid
|
||||||
|
if ( !hmdPose.bPoseIsValid
|
||||||
|
|| hmdPose.eTrackingResult != vr::TrackingResult_Running_OK )
|
||||||
{
|
{
|
||||||
if ( parent->isDashboardVisible() )
|
m_lastHmdQuaternion.w = k_quaternionInvalidValue;
|
||||||
{
|
return;
|
||||||
setTrackingUniverse( int( universe ) );
|
|
||||||
}
|
|
||||||
settingsUpdateCounter = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
settingsUpdateCounter++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double angle = m_rotation * k_centidegreesToRadians;
|
|
||||||
|
|
||||||
// START of hmd rotation stats tracking:
|
|
||||||
// Check if hmd is tracking ok and do everything
|
|
||||||
if ( devicePoses[0].bPoseIsValid
|
|
||||||
&& devicePoses[0].eTrackingResult == vr::TrackingResult_Running_OK )
|
|
||||||
{
|
|
||||||
// Get hmd pose matrix (in rotated coordinates)
|
// Get hmd pose matrix (in rotated coordinates)
|
||||||
vr::HmdMatrix34_t hmdMatrix = devicePoses[0].mDeviceToAbsoluteTracking;
|
vr::HmdMatrix34_t hmdMatrix = hmdPose.mDeviceToAbsoluteTracking;
|
||||||
|
|
||||||
// Set up (un)rotation matrix
|
// Set up (un)rotation matrix
|
||||||
vr::HmdMatrix34_t hmdMatrixRotMat;
|
vr::HmdMatrix34_t hmdMatrixRotMat;
|
||||||
@@ -904,15 +892,12 @@ void MoveCenterTabController::eventLoopTick(
|
|||||||
if ( m_lastHmdQuaternion.w < k_quaternionUnderIsInvalidValueThreshold )
|
if ( m_lastHmdQuaternion.w < k_quaternionUnderIsInvalidValueThreshold )
|
||||||
{
|
{
|
||||||
m_lastHmdQuaternion = m_hmdQuaternion;
|
m_lastHmdQuaternion = m_hmdQuaternion;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// 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 = utils::quaternionMultiply(
|
||||||
m_hmdQuaternion,
|
m_hmdQuaternion, utils::quaternionConjugate( m_lastHmdQuaternion ) );
|
||||||
utils::quaternionConjugate( m_lastHmdQuaternion ) );
|
|
||||||
|
|
||||||
// Calculate yaw from quaternion.
|
// Calculate yaw from quaternion.
|
||||||
double hmdYawDiff = utils::quaternionGetYaw( hmdDiffQuaternion );
|
double hmdYawDiff = utils::quaternionGetYaw( hmdDiffQuaternion );
|
||||||
@@ -922,19 +907,13 @@ void MoveCenterTabController::eventLoopTick(
|
|||||||
m_lastHmdQuaternion = m_hmdQuaternion;
|
m_lastHmdQuaternion = m_hmdQuaternion;
|
||||||
}
|
}
|
||||||
|
|
||||||
// end check if hmdpose is ok
|
void MoveCenterTabController::updateHandDrag(
|
||||||
}
|
vr::TrackedDevicePose_t* devicePoses,
|
||||||
else
|
double angle )
|
||||||
{
|
{
|
||||||
m_lastHmdQuaternion.w = k_quaternionInvalidValue;
|
|
||||||
} // END of hmd rotation stats tracking
|
|
||||||
|
|
||||||
auto moveHandId = vr::VRSystem()->GetTrackedDeviceIndexForControllerRole(
|
auto moveHandId = vr::VRSystem()->GetTrackedDeviceIndexForControllerRole(
|
||||||
m_activeDragHand );
|
m_activeDragHand );
|
||||||
auto rotateHandId = vr::VRSystem()->GetTrackedDeviceIndexForControllerRole(
|
|
||||||
m_activeTurnHand );
|
|
||||||
|
|
||||||
// START of hand move
|
|
||||||
if ( m_activeDragHand == vr::TrackedControllerRole_Invalid
|
if ( m_activeDragHand == vr::TrackedControllerRole_Invalid
|
||||||
|| moveHandId == vr::k_unTrackedDeviceIndexInvalid
|
|| moveHandId == vr::k_unTrackedDeviceIndexInvalid
|
||||||
|| moveHandId >= vr::k_unMaxTrackedDeviceCount )
|
|| moveHandId >= vr::k_unMaxTrackedDeviceCount )
|
||||||
@@ -946,17 +925,17 @@ void MoveCenterTabController::eventLoopTick(
|
|||||||
emit offsetZChanged( m_offsetZ );
|
emit offsetZChanged( m_offsetZ );
|
||||||
}
|
}
|
||||||
m_lastMoveHand = m_activeDragHand;
|
m_lastMoveHand = m_activeDragHand;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
vr::TrackedDevicePose_t* movePose = devicePoses + moveHandId;
|
vr::TrackedDevicePose_t* movePose = devicePoses + moveHandId;
|
||||||
if ( !movePose->bPoseIsValid || !movePose->bDeviceIsConnected
|
if ( !movePose->bPoseIsValid || !movePose->bDeviceIsConnected
|
||||||
|| movePose->eTrackingResult != vr::TrackingResult_Running_OK )
|
|| movePose->eTrackingResult != vr::TrackingResult_Running_OK )
|
||||||
{
|
{
|
||||||
m_lastMoveHand = m_activeDragHand;
|
m_lastMoveHand = m_activeDragHand;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
double relativeControllerPosition[]
|
double relativeControllerPosition[]
|
||||||
= { movePose->mDeviceToAbsoluteTracking.m[0][3],
|
= { movePose->mDeviceToAbsoluteTracking.m[0][3],
|
||||||
movePose->mDeviceToAbsoluteTracking.m[1][3],
|
movePose->mDeviceToAbsoluteTracking.m[1][3],
|
||||||
@@ -1015,8 +994,7 @@ void MoveCenterTabController::eventLoopTick(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if diffFloat is anything before comitting.
|
// Check if diffFloat is anything before comitting.
|
||||||
if ( diffFloat[0] != 0 || diffFloat[1] != 0
|
if ( diffFloat[0] != 0 || diffFloat[1] != 0 || diffFloat[2] != 0 )
|
||||||
|| diffFloat[2] != 0 )
|
|
||||||
{
|
{
|
||||||
parent->AddOffsetToUniverseCenter(
|
parent->AddOffsetToUniverseCenter(
|
||||||
vr::TrackingUniverseOrigin( m_trackingUniverse ),
|
vr::TrackingUniverseOrigin( m_trackingUniverse ),
|
||||||
@@ -1029,9 +1007,13 @@ void MoveCenterTabController::eventLoopTick(
|
|||||||
m_lastControllerPosition[2] = absoluteControllerPosition[2];
|
m_lastControllerPosition[2] = absoluteControllerPosition[2];
|
||||||
m_lastMoveHand = m_activeDragHand;
|
m_lastMoveHand = m_activeDragHand;
|
||||||
}
|
}
|
||||||
} // END of hand move
|
|
||||||
|
|
||||||
// START of hand rotation
|
void MoveCenterTabController::updateHandTurn(
|
||||||
|
vr::TrackedDevicePose_t* devicePoses,
|
||||||
|
double angle )
|
||||||
|
{
|
||||||
|
auto rotateHandId = vr::VRSystem()->GetTrackedDeviceIndexForControllerRole(
|
||||||
|
m_activeTurnHand );
|
||||||
|
|
||||||
if ( m_activeTurnHand == vr::TrackedControllerRole_Invalid
|
if ( m_activeTurnHand == vr::TrackedControllerRole_Invalid
|
||||||
|| rotateHandId == vr::k_unTrackedDeviceIndexInvalid
|
|| rotateHandId == vr::k_unTrackedDeviceIndexInvalid
|
||||||
@@ -1042,21 +1024,18 @@ void MoveCenterTabController::eventLoopTick(
|
|||||||
m_lastHandQuaternion.w = k_quaternionInvalidValue;
|
m_lastHandQuaternion.w = k_quaternionInvalidValue;
|
||||||
}
|
}
|
||||||
m_lastRotateHand = m_activeTurnHand;
|
m_lastRotateHand = m_activeTurnHand;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
vr::TrackedDevicePose_t* rotatePose = devicePoses + rotateHandId;
|
vr::TrackedDevicePose_t* rotatePose = devicePoses + rotateHandId;
|
||||||
if ( !rotatePose->bPoseIsValid || !rotatePose->bDeviceIsConnected
|
if ( !rotatePose->bPoseIsValid || !rotatePose->bDeviceIsConnected
|
||||||
|| rotatePose->eTrackingResult != vr::TrackingResult_Running_OK )
|
|| rotatePose->eTrackingResult != vr::TrackingResult_Running_OK )
|
||||||
{
|
{
|
||||||
m_lastRotateHand = m_activeTurnHand;
|
m_lastRotateHand = m_activeTurnHand;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
// Get hand's rotation.
|
// Get hand's rotation.
|
||||||
// handMatrix is in rotated coordinates.
|
// handMatrix is in rotated coordinates.
|
||||||
vr::HmdMatrix34_t handMatrix
|
vr::HmdMatrix34_t handMatrix = rotatePose->mDeviceToAbsoluteTracking;
|
||||||
= rotatePose->mDeviceToAbsoluteTracking;
|
|
||||||
|
|
||||||
// We need un-rotated coordinates for valid comparison between
|
// We need un-rotated coordinates for valid comparison between
|
||||||
// handQuaternion and lastHandQuaternion. Set up (un)rotation
|
// handQuaternion and lastHandQuaternion. Set up (un)rotation
|
||||||
@@ -1070,16 +1049,14 @@ void MoveCenterTabController::eventLoopTick(
|
|||||||
utils::matMul33( handMatrixAbsolute, handMatrixRotMat, handMatrix );
|
utils::matMul33( handMatrixAbsolute, handMatrixRotMat, handMatrix );
|
||||||
|
|
||||||
// Convert pose matrix to quaternion
|
// Convert pose matrix to quaternion
|
||||||
m_handQuaternion
|
m_handQuaternion = utils::quaternionFromHmdMatrix34( handMatrixAbsolute );
|
||||||
= utils::quaternionFromHmdMatrix34( handMatrixAbsolute );
|
|
||||||
|
|
||||||
if ( m_lastRotateHand == m_activeTurnHand )
|
if ( m_lastRotateHand == m_activeTurnHand )
|
||||||
{
|
{
|
||||||
// Get rotation change of hand.
|
// Get rotation change of hand.
|
||||||
// Checking for invalid quaternion using < because == isn't
|
// Checking for invalid quaternion using < because == isn't
|
||||||
// guaranteed for doubles comparison.
|
// guaranteed for doubles comparison.
|
||||||
if ( m_lastHandQuaternion.w
|
if ( m_lastHandQuaternion.w < k_quaternionUnderIsInvalidValueThreshold )
|
||||||
< k_quaternionUnderIsInvalidValueThreshold )
|
|
||||||
{
|
{
|
||||||
m_lastHandQuaternion = m_handQuaternion;
|
m_lastHandQuaternion = m_handQuaternion;
|
||||||
}
|
}
|
||||||
@@ -1088,19 +1065,15 @@ void MoveCenterTabController::eventLoopTick(
|
|||||||
{
|
{
|
||||||
// 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
|
vr::HmdQuaternion_t handDiffQuaternion = utils::quaternionMultiply(
|
||||||
= utils::quaternionMultiply(
|
|
||||||
m_handQuaternion,
|
m_handQuaternion,
|
||||||
utils::quaternionConjugate(
|
utils::quaternionConjugate( m_lastHandQuaternion ) );
|
||||||
m_lastHandQuaternion ) );
|
|
||||||
|
|
||||||
// Calculate yaw from quaternion.
|
// Calculate yaw from quaternion.
|
||||||
double handYawDiff
|
double handYawDiff = utils::quaternionGetYaw( handDiffQuaternion );
|
||||||
= utils::quaternionGetYaw( handDiffQuaternion );
|
|
||||||
|
|
||||||
int newRotationAngleDeg = static_cast<int>(
|
int newRotationAngleDeg = static_cast<int>(
|
||||||
round( handYawDiff * k_radiansToCentidegrees )
|
round( handYawDiff * k_radiansToCentidegrees ) + m_rotation );
|
||||||
+ m_rotation );
|
|
||||||
|
|
||||||
// Keep angle within -18000 ~ 18000 centidegrees
|
// Keep angle within -18000 ~ 18000 centidegrees
|
||||||
if ( newRotationAngleDeg > 18000 )
|
if ( newRotationAngleDeg > 18000 )
|
||||||
@@ -1118,6 +1091,41 @@ void MoveCenterTabController::eventLoopTick(
|
|||||||
m_lastHandQuaternion = m_handQuaternion;
|
m_lastHandQuaternion = m_handQuaternion;
|
||||||
m_lastRotateHand = m_activeTurnHand;
|
m_lastRotateHand = m_activeTurnHand;
|
||||||
}
|
}
|
||||||
} // END of hand rotation
|
|
||||||
|
void MoveCenterTabController::eventLoopTick(
|
||||||
|
vr::ETrackingUniverseOrigin universe,
|
||||||
|
vr::TrackedDevicePose_t* devicePoses )
|
||||||
|
|
||||||
|
{
|
||||||
|
if ( settingsUpdateCounter >= k_moveCenterSettingsUpdateCounter )
|
||||||
|
{
|
||||||
|
if ( parent->isDashboardVisible() )
|
||||||
|
{
|
||||||
|
setTrackingUniverse( int( universe ) );
|
||||||
|
}
|
||||||
|
settingsUpdateCounter = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
settingsUpdateCounter++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get current space rotation in radians
|
||||||
|
double angle = m_rotation * k_centidegreesToRadians;
|
||||||
|
|
||||||
|
if ( m_hmdRotationStatsUpdateCounter >= k_hmdRotationCounterUpdateRate )
|
||||||
|
{
|
||||||
|
// device pose index 0 is always the hmd
|
||||||
|
updateHmdRotationCounter( devicePoses[0], angle );
|
||||||
|
m_hmdRotationStatsUpdateCounter = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_hmdRotationStatsUpdateCounter++;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateHandDrag( devicePoses, angle );
|
||||||
|
|
||||||
|
updateHandTurn( devicePoses, angle );
|
||||||
}
|
}
|
||||||
} // namespace advsettings
|
} // namespace advsettings
|
||||||
|
|||||||
@@ -96,6 +96,11 @@ private:
|
|||||||
bool m_overrideLeftHandTurnPressed = false;
|
bool m_overrideLeftHandTurnPressed = false;
|
||||||
bool m_overrideRightHandTurnPressed = false;
|
bool m_overrideRightHandTurnPressed = false;
|
||||||
unsigned settingsUpdateCounter = 0;
|
unsigned settingsUpdateCounter = 0;
|
||||||
|
int m_hmdRotationStatsUpdateCounter = 0;
|
||||||
|
void updateHmdRotationCounter( vr::TrackedDevicePose_t hmdPose,
|
||||||
|
double angle );
|
||||||
|
void updateHandDrag( vr::TrackedDevicePose_t* devicePoses, double angle );
|
||||||
|
void updateHandTurn( vr::TrackedDevicePose_t* devicePoses, double angle );
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void initStage1();
|
void initStage1();
|
||||||
|
|||||||
Reference in New Issue
Block a user