Fix rotation counter stats during rotation drag

This commit is contained in:
Kung-vr
2019-01-24 00:58:15 +09:00
parent ec0d35bf0d
commit 499a0e3ede
5 changed files with 97 additions and 127 deletions
+2 -2
View File
@@ -489,9 +489,9 @@ MyStackViewPage {
function updateStatistics() { function updateStatistics() {
var rotations = StatisticsTabController.hmdRotations var rotations = StatisticsTabController.hmdRotations
if (rotations > 0) { if (rotations > 0) {
summaryHmdRotationsText.text = rotations.toFixed(1) + " CCW" summaryHmdRotationsText.text = rotations.toFixed(2) + " CCW"
} else { } else {
summaryHmdRotationsText.text = -rotations.toFixed(1) + " CW" summaryHmdRotationsText.text = -rotations.toFixed(2) + " CW"
} }
summaryDroppedFramesText.text = StatisticsTabController.droppedFrames summaryDroppedFramesText.text = StatisticsTabController.droppedFrames
summaryReprojectedFramesText.text = StatisticsTabController.reprojectedFrames summaryReprojectedFramesText.text = StatisticsTabController.reprojectedFrames
+2 -2
View File
@@ -198,9 +198,9 @@ MyStackViewPage {
statsHmdMovedText.text = StatisticsTabController.hmdDistanceMoved.toFixed(1) + " m" statsHmdMovedText.text = StatisticsTabController.hmdDistanceMoved.toFixed(1) + " m"
var rotations = StatisticsTabController.hmdRotations var rotations = StatisticsTabController.hmdRotations
if (rotations > 0) { if (rotations > 0) {
statsHmdRotationText.text = rotations.toFixed(1) + " CCW" statsHmdRotationText.text = rotations.toFixed(2) + " CCW"
} else { } else {
statsHmdRotationText.text = -rotations.toFixed(1) + " CW" statsHmdRotationText.text = -rotations.toFixed(2) + " CW"
} }
statsLeftControllerSpeedText.text = " " + StatisticsTabController.leftControllerMaxSpeed.toFixed(1) + " m/s" statsLeftControllerSpeedText.text = " " + StatisticsTabController.leftControllerMaxSpeed.toFixed(1) + " m/s"
statsRightControllerSpeedText.text = " " + StatisticsTabController.rightControllerMaxSpeed.toFixed(1) + " m/s" statsRightControllerSpeedText.text = " " + StatisticsTabController.rightControllerMaxSpeed.toFixed(1) + " m/s"
+80 -3
View File
@@ -510,6 +510,16 @@ void MoveCenterTabController::reset()
emit rotationChanged( m_rotation ); emit rotationChanged( m_rotation );
} }
double MoveCenterTabController::getHmdYawTotal()
{
return m_hmdYawTotal;
}
void MoveCenterTabController::resetHmdYawTotal()
{
m_hmdYawTotal = 0.0;
}
bool isMoveShortCutPressed( vr::ETrackedControllerRole hand ) bool isMoveShortCutPressed( vr::ETrackedControllerRole hand )
{ {
auto handId auto handId
@@ -618,6 +628,67 @@ void MoveCenterTabController::eventLoopTick(
} }
auto oldMoveHand = m_activeMoveController; auto oldMoveHand = m_activeMoveController;
auto newMoveHand = getMoveShortcutHand(); auto newMoveHand = getMoveShortcutHand();
double angle = m_rotation * M_PI / 18000.0;
// hmd rotation tracking stuff:
// 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)
vr::HmdMatrix34_t hmdMatrix = devicePoses[0].mDeviceToAbsoluteTracking;
// Set up (un)rotation matrix
vr::HmdMatrix34_t hmdMatrixRotMat;
vr::HmdMatrix34_t hmdMatrixAbsolute;
utils::initRotationMatrix(
hmdMatrixRotMat, 1, static_cast<float>( angle ) );
// Get hmdMatrixAbsolute in un-rotated coordinates.
utils::matMul33( hmdMatrixAbsolute, hmdMatrixRotMat, hmdMatrix );
// Convert pose matrix to quaternion
hmdQuaternion = utils::getQuaternion( hmdMatrixAbsolute );
// Get rotation change of hmd
// Checking if set to -1000.0 placeholder for invalid hmd pose.
if ( lastHmdQuaternion.w < -900.0 )
{
lastHmdQuaternion = hmdQuaternion;
}
else
{
// Construct a quaternion representing difference between old
// hmd pose and new hmd pose.
vr::HmdQuaternion_t hmdDiffQuaternion = utils::multiplyQuaternion(
hmdQuaternion,
utils::quaternionConjugate( lastHmdQuaternion ) );
// Calculate yaw from quaternion.
double hmdYawDiff = atan2(
2.0
* ( hmdDiffQuaternion.y * hmdDiffQuaternion.w
+ hmdDiffQuaternion.x * hmdDiffQuaternion.z ),
-1.0
+ 2.0
* ( hmdDiffQuaternion.w * hmdDiffQuaternion.w
+ hmdDiffQuaternion.x * hmdDiffQuaternion.x ) );
// Apply yaw difference to m_hmdYawTotal.
m_hmdYawTotal += hmdYawDiff;
lastHmdQuaternion = hmdQuaternion;
}
// end check if hmdpose is ok
}
else
{
// set lastHmdQuaternion.w to placeholder -1000.0 for invalid
lastHmdQuaternion.w = -1000.0;
}
// end hmd rotating tracking stuff
if ( newMoveHand == vr::TrackedControllerRole_Invalid ) if ( newMoveHand == vr::TrackedControllerRole_Invalid )
{ {
emit offsetXChanged( m_offsetX ); emit offsetXChanged( m_offsetX );
@@ -663,7 +734,6 @@ void MoveCenterTabController::eventLoopTick(
pose->mDeviceToAbsoluteTracking.m[1][3], pose->mDeviceToAbsoluteTracking.m[1][3],
pose->mDeviceToAbsoluteTracking.m[2][3] }; pose->mDeviceToAbsoluteTracking.m[2][3] };
double angle = m_rotation * M_PI / 18000.0;
rotateCoordinates( relativeControllerPosition, -angle ); rotateCoordinates( relativeControllerPosition, -angle );
float absoluteControllerPosition[] = { float absoluteControllerPosition[] = {
static_cast<float>( relativeControllerPosition[0] ) + m_offsetX, static_cast<float>( relativeControllerPosition[0] ) + m_offsetX,
@@ -764,8 +834,15 @@ void MoveCenterTabController::eventLoopTick(
utils::quaternionConjugate( lastHandQuaternion ) ); utils::quaternionConjugate( lastHandQuaternion ) );
// Calculate yaw from quaternion. // Calculate yaw from quaternion.
double handYawDiff double handYawDiff = atan2(
= atan2( handDiffQuaternion.y, handDiffQuaternion.w ) * 2.0; 2.0
* ( handDiffQuaternion.y * handDiffQuaternion.w
+ handDiffQuaternion.x * handDiffQuaternion.z ),
-1.0
+ 2.0
* ( handDiffQuaternion.w * handDiffQuaternion.w
+ handDiffQuaternion.x
* handDiffQuaternion.x ) );
int newRotationAngleDeg = static_cast<int>( int newRotationAngleDeg = static_cast<int>(
round( handYawDiff * 18000.0 / M_PI ) + m_rotation ); round( handYawDiff * 18000.0 / M_PI ) + m_rotation );
@@ -70,6 +70,10 @@ private:
// Set lastHandQuaternion.w to -1000.0 when last hand is invalid. // Set lastHandQuaternion.w to -1000.0 when last hand is invalid.
vr::HmdQuaternion_t lastHandQuaternion = { -1000.0, 0.0, 0.0, 0.0 }; vr::HmdQuaternion_t lastHandQuaternion = { -1000.0, 0.0, 0.0, 0.0 };
vr::HmdQuaternion_t handQuaternion; vr::HmdQuaternion_t handQuaternion;
// Set lastHmdQuaternion.w to -1000.0 when last hmd pose is invalid.
vr::HmdQuaternion_t lastHmdQuaternion = { -1000.0, 0.0, 0.0, 0.0 };
vr::HmdQuaternion_t hmdQuaternion;
double m_hmdYawTotal = 0.0;
unsigned settingsUpdateCounter = 0; unsigned settingsUpdateCounter = 0;
@@ -95,6 +99,8 @@ public:
bool lockXToggle() const; bool lockXToggle() const;
bool lockYToggle() const; bool lockYToggle() const;
bool lockZToggle() const; bool lockZToggle() const;
double getHmdYawTotal();
void resetHmdYawTotal();
public slots: public slots:
int trackingUniverse() const; int trackingUniverse() const;
+7 -120
View File
@@ -77,126 +77,12 @@ void StatisticsTabController::eventLoopTick(
m_rightControllerMaxSpeed = rightSpeed; m_rightControllerMaxSpeed = rightSpeed;
} }
// Hmd Rotation // // HMD Rotation //
/* double playspaceHmdYawTotal
| Intrinsic y-x'-z" rotation matrix: = parent->m_moveCenterTabController.getHmdYawTotal();
| cr*cy+sp*sr*sy | cr*sp*sy-cy*sr | cp*sy | m_hmdRotation = static_cast<float>( playspaceHmdYawTotal / ( 2.0 * M_PI ) );
| cp*sr | cp*cr |-sp |
| cy*sp*sr-cr*sy | cr*cy*sp+sr*sy | cp*cy |
yaw = atan2(cp*sy, cp*cy) [pi, -pi], CCW if ( lastPosTimer <= 0 )
pitch = -asin(-sp) [pi/2, -pi/2]
roll = atan2(cp*sr, cp*cr) [pi, -pi], CW
*/
double yawRaw = 0.0;
double yaw = 0.0;
bool rotationChanged = false;
if ( devicePoses[0].bPoseIsValid
&& devicePoses[0].eTrackingResult == vr::TrackingResult_Running_OK )
{
yawRaw = std::atan2( m[0][2], m[2][2] );
if ( yawRaw < 0.0f )
{
yawRaw += 2 * M_PI; // map to [0, 2*pi], CCW
}
yaw = yawRaw - rotationOffset;
if ( yaw < 0.0 )
{
yaw = 2 * M_PI + yaw;
}
if ( rotationResetFlag )
{
rotationDir = 0;
rotationCounter = 0;
rotationOffset = yawRaw;
rotationResetFlag = false;
lastYaw = -1.0f;
rotationChanged = true;
}
else if ( lastYaw < 0.0f && yaw > 0.0 )
{
lastYaw = yaw;
rotationChanged = true;
if ( yaw <= M_PI )
{
rotationDir = 1;
}
else
{
rotationDir = -1;
}
}
else if ( std::abs( lastYaw - yaw ) >= 0.01 && yaw > 0.0 )
{
auto diff = yaw - lastYaw;
int mode = 0;
if ( std::abs( diff ) > M_PI )
{
if ( diff < -M_PI )
{ // CCW overflow
mode = 1;
}
else if ( diff > M_PI )
{ // CW overflow
mode = -1;
}
}
else
{
if ( lastYaw < 0.0 && yaw > 0.0 )
{
mode = 1;
}
else if ( lastYaw > 0.0 && yaw < 0.0 )
{
mode = -1;
}
}
if ( mode > 0 )
{
if ( rotationCounter == 0 && rotationDir <= 0 )
{
rotationDir = 1;
}
else
{
rotationCounter++;
}
}
else if ( mode < 0 )
{
if ( rotationCounter == 0 && rotationDir >= 0 )
{
rotationDir = -1;
}
else
{
rotationCounter--;
}
}
lastYaw = yaw;
rotationChanged = true;
}
}
else
{
lastYaw = -1;
}
if ( rotationChanged )
{
m_hmdRotation = ( float ) rotationCounter;
if ( rotationDir > 0 )
{
m_hmdRotation += yaw / ( 2 * M_PI );
}
else if ( rotationDir < 0 )
{
m_hmdRotation += -1.0f + yaw / ( 2 * M_PI );
}
}
if ( lastPosTimer == 0 )
{ {
lastPosTimer = 10; lastPosTimer = 10;
} }
@@ -273,7 +159,8 @@ void StatisticsTabController::statsDistanceResetClicked()
void StatisticsTabController::statsRotationResetClicked() void StatisticsTabController::statsRotationResetClicked()
{ {
rotationResetFlag = true; // rotationResetFlag = true;
parent->m_moveCenterTabController.resetHmdYawTotal();
} }
void StatisticsTabController::statsLeftControllerSpeedResetClicked() void StatisticsTabController::statsLeftControllerSpeedResetClicked()