Skip to content

Commit

Permalink
Remixed: Apply EnsureSameHemisphere() fix for Oculus Medium.
Browse files Browse the repository at this point in the history
Copied from Revive.
  • Loading branch information
CrossVR committed Apr 12, 2018
1 parent a13761e commit e0e3b6a
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions Remixed/REM_CAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,22 +361,31 @@ OVR_PUBLIC_FUNCTION(ovrTrackingState) ovr_GetTrackingState(ovrSession session, d
state.HeadPose.ThePose.Orientation = REM::Quatf(leftEye);
state.HeadPose.ThePose.Position = leftEye.GetTranslation();

static const REM::Quatf OrientationOffset(OVR::Axis_X, -MATH_FLOAT_PIOVER4);
static const REM::Quatf orientationOffset(OVR::Axis_X, -MATH_FLOAT_PIOVER4);
static ovrPosef lastPose[2] = { OVR::Posef::Identity(), OVR::Posef::Identity() };
auto sources = session->Interaction.GetDetectedSourcesAtTimestamp(timestamp);
for (SpatialInteractionSourceState source : sources)
{
ovrHandType hand = (source.Source().Handedness() == SpatialInteractionSourceHandedness::Right) ? ovrHand_Right : ovrHand_Left;
SpatialInteractionSourceLocation location = source.Properties().TryGetLocation(session->Tracking->CoordinateSystem());
if (location)
{
// Make sure the orientation stays in the same hemisphere as the previous orientation, this prevents
// linear interpolations from suddenly flipping the long way around in Oculus Medium.
OVR::Quatf orientation = REM::Quatf(location.Orientation()) * orientationOffset;
orientation.EnsureSameHemisphere(lastPose[hand].Orientation);

// TODO: Calculate the angular and linear acceleration.
state.HandPoses[hand].ThePose.Orientation = REM::Quatf(location.Orientation()) * OrientationOffset;
state.HandPoses[hand].ThePose.Orientation = orientation;
state.HandPoses[hand].ThePose.Position = REM::Vector3f(location.Position());
state.HandPoses[hand].AngularVelocity = REM::Vector3f(location.AngularVelocity());
state.HandPoses[hand].LinearVelocity = REM::Vector3f(location.Velocity());
//state.HandPoses[hand].AngularAcceleration = REM::Vector3f(location.AbsoluteAngularAcceleration());
//state.HandPoses[hand].LinearAcceleration = REM::Vector3f(location.AbsoluteLinearAcceleration());
state.HandStatusFlags[hand] = ovrStatus_OrientationTracked | ovrStatus_PositionTracked;


lastPose[hand] = state.HandPoses[hand].ThePose;
}
}

Expand Down

0 comments on commit e0e3b6a

Please sign in to comment.