Beispiel #1
0
void FOSVRHMD::UpdateHeadPose(FQuat& lastHmdOrientation, FVector& lastHmdPosition, FQuat& hmdOrientation, FVector& hmdPosition)
{
    OSVR_Pose3 pose;
    OSVR_ReturnCode returnCode;
    FScopeLock lock(mOSVREntryPoint->GetClientContextMutex());
    auto clientContext = mOSVREntryPoint->GetClientContext();

    returnCode = osvrClientUpdate(clientContext);
    check(returnCode == OSVR_RETURN_SUCCESS);

    returnCode = osvrClientGetViewerPose(DisplayConfig, 0, &pose);
    if (returnCode == OSVR_RETURN_SUCCESS)
    {
        LastHmdOrientation = CurHmdOrientation;
        LastHmdPosition = CurHmdPosition;
        CurHmdPosition = BaseOrientation.Inverse().RotateVector(OSVR2FVector(pose.translation, WorldToMetersScale) - BasePosition);
        CurHmdOrientation = BaseOrientation.Inverse() * OSVR2FQuat(pose.rotation);
        lastHmdOrientation = LastHmdOrientation;
        lastHmdPosition = LastHmdPosition;
        hmdOrientation = CurHmdOrientation;
        hmdPosition = CurHmdPosition;
    }
    else
    {
        lastHmdOrientation = hmdOrientation = FQuat::Identity;
        lastHmdPosition = hmdPosition = FVector(0.0f, 0.0f, 0.0f);
    }
}
Beispiel #2
0
static void OSVRPositionCallback(void* Userdata, const OSVR_TimeValue* Timestamp, const OSVR_PositionReport* Report)
{
	auto This = reinterpret_cast< OSVRInterface* >(Userdata);
	if (This && Report)
	{
		This->PoseState.SetTranslation(OSVR2FVector(Report->xyz));

		This->Callback(This, OSVRInterface::POSITION_STATE_AVAILABLE);
	}
}
Beispiel #3
0
bool OSVRInterface::GetPosition(FVector& Value, bool Latest) const
{
	if (Latest)
	{
#if OSVR_ENABLED
		OSVR_TimeValue Time;
		OSVR_PositionState Position;
		OSVR_ReturnCode ReturnCode = osvrGetPositionState(OSVRClientInterface, &Time, &Position);

		Value = OSVR2FVector(Position);

		return ReturnCode == OSVR_RETURN_SUCCESS;
#endif // OSVR_ENABLED
	}
	else
	{
		Value = PoseState.GetLocation();
	}

	return HasPositionState();
}
Beispiel #4
0
bool OSVRInterface::GetPose(FTransform& Value, bool Latest) const
{
	if (Latest)
	{
#if OSVR_ENABLED
		OSVR_TimeValue Time;
		OSVR_PoseState Pose;
		OSVR_ReturnCode ReturnCode = osvrGetPoseState(OSVRClientInterface, &Time, &Pose);

		Value.SetTranslation(OSVR2FVector(Pose.translation));
		Value.SetRotation(OSVR2FQuat(Pose.rotation));

		return ReturnCode == OSVR_RETURN_SUCCESS;
#endif // OSVR_ENABLED
	}
	else
	{
		Value = PoseState;
	}

	return HasPoseState();
}
Beispiel #5
0
/**
* Returns the calibration-space orientation of the requested controller's hand.
*
* @param ControllerIndex	The Unreal controller (player) index of the contoller set
* @param DeviceHand		Which hand, within the controller set for the player, to get the orientation and position for
* @param OutOrientation	(out) If tracked, the orientation (in calibrated-space) of the controller in the specified hand
* @param OutPosition		(out) If tracked, the position (in calibrated-space) of the controller in the specified hand
* @return					True if the device requested is valid and tracked, false otherwise
*/
bool FOSVRInputDevice::GetControllerOrientationAndPosition(const int32 ControllerIndex, const EControllerHand DeviceHand, FRotator& OutOrientation, FVector& OutPosition) const
{
    bool bRet = false;
    if (ControllerIndex == 0)
    {
        FScopeLock lock(contextMutex);
        if (osvrClientCheckStatus(context) == OSVR_RETURN_SUCCESS
            && osvrClientUpdate(context) == OSVR_RETURN_SUCCESS)
        {
            auto iface = DeviceHand == EControllerHand::Left ? leftHand : rightHand;
            OSVR_PoseState state;
            OSVR_TimeValue tvalue;
            if (osvrGetPoseState(iface, &tvalue, &state) == OSVR_RETURN_SUCCESS)
            {
                // @todo: how do we get the world to meters scale without the HMD?
                float worldToMetersScale = mOSVRHMD.IsValid() ? mOSVRHMD->GetWorldToMetersScale() : 100.0f;
                OutPosition = OSVR2FVector(state.translation, worldToMetersScale);
                OutOrientation = OSVR2FQuat(state.rotation).Rotator();
                bRet = true;
            }
        }
    }
    return bRet;
}