Fix rotation counter stats during rotation drag
This commit is contained in:
@@ -510,6 +510,16 @@ void MoveCenterTabController::reset()
|
||||
emit rotationChanged( m_rotation );
|
||||
}
|
||||
|
||||
double MoveCenterTabController::getHmdYawTotal()
|
||||
{
|
||||
return m_hmdYawTotal;
|
||||
}
|
||||
|
||||
void MoveCenterTabController::resetHmdYawTotal()
|
||||
{
|
||||
m_hmdYawTotal = 0.0;
|
||||
}
|
||||
|
||||
bool isMoveShortCutPressed( vr::ETrackedControllerRole hand )
|
||||
{
|
||||
auto handId
|
||||
@@ -618,6 +628,67 @@ void MoveCenterTabController::eventLoopTick(
|
||||
}
|
||||
auto oldMoveHand = m_activeMoveController;
|
||||
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 )
|
||||
{
|
||||
emit offsetXChanged( m_offsetX );
|
||||
@@ -663,7 +734,6 @@ void MoveCenterTabController::eventLoopTick(
|
||||
pose->mDeviceToAbsoluteTracking.m[1][3],
|
||||
pose->mDeviceToAbsoluteTracking.m[2][3] };
|
||||
|
||||
double angle = m_rotation * M_PI / 18000.0;
|
||||
rotateCoordinates( relativeControllerPosition, -angle );
|
||||
float absoluteControllerPosition[] = {
|
||||
static_cast<float>( relativeControllerPosition[0] ) + m_offsetX,
|
||||
@@ -764,8 +834,15 @@ void MoveCenterTabController::eventLoopTick(
|
||||
utils::quaternionConjugate( lastHandQuaternion ) );
|
||||
|
||||
// Calculate yaw from quaternion.
|
||||
double handYawDiff
|
||||
= atan2( handDiffQuaternion.y, handDiffQuaternion.w ) * 2.0;
|
||||
double handYawDiff = atan2(
|
||||
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>(
|
||||
round( handYawDiff * 18000.0 / M_PI ) + m_rotation );
|
||||
|
||||
@@ -70,6 +70,10 @@ private:
|
||||
// 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 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;
|
||||
|
||||
@@ -95,6 +99,8 @@ public:
|
||||
bool lockXToggle() const;
|
||||
bool lockYToggle() const;
|
||||
bool lockZToggle() const;
|
||||
double getHmdYawTotal();
|
||||
void resetHmdYawTotal();
|
||||
|
||||
public slots:
|
||||
int trackingUniverse() const;
|
||||
|
||||
@@ -77,126 +77,12 @@ void StatisticsTabController::eventLoopTick(
|
||||
m_rightControllerMaxSpeed = rightSpeed;
|
||||
}
|
||||
|
||||
// Hmd Rotation //
|
||||
/*
|
||||
| Intrinsic y-x'-z" rotation matrix:
|
||||
| cr*cy+sp*sr*sy | cr*sp*sy-cy*sr | cp*sy |
|
||||
| cp*sr | cp*cr |-sp |
|
||||
| cy*sp*sr-cr*sy | cr*cy*sp+sr*sy | cp*cy |
|
||||
// HMD Rotation //
|
||||
double playspaceHmdYawTotal
|
||||
= parent->m_moveCenterTabController.getHmdYawTotal();
|
||||
m_hmdRotation = static_cast<float>( playspaceHmdYawTotal / ( 2.0 * M_PI ) );
|
||||
|
||||
yaw = atan2(cp*sy, cp*cy) [pi, -pi], CCW
|
||||
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 )
|
||||
if ( lastPosTimer <= 0 )
|
||||
{
|
||||
lastPosTimer = 10;
|
||||
}
|
||||
@@ -273,7 +159,8 @@ void StatisticsTabController::statsDistanceResetClicked()
|
||||
|
||||
void StatisticsTabController::statsRotationResetClicked()
|
||||
{
|
||||
rotationResetFlag = true;
|
||||
// rotationResetFlag = true;
|
||||
parent->m_moveCenterTabController.resetHmdYawTotal();
|
||||
}
|
||||
|
||||
void StatisticsTabController::statsLeftControllerSpeedResetClicked()
|
||||
|
||||
Reference in New Issue
Block a user