示例#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);
    }
}
示例#2
0
static void OSVROrientationCallback(void* Userdata, const OSVR_TimeValue* Timestamp, const OSVR_OrientationReport* Report)
{
	auto This = reinterpret_cast< OSVRInterface* >(Userdata);
	if (This && Report)
	{
		This->PoseState.SetRotation(OSVR2FQuat(Report->rotation));

		This->Callback(This, OSVRInterface::ORIENTATION_STATE_AVAILABLE);
	}
}
示例#3
0
bool OSVRInterface::GetOrientation(FQuat& Value, bool Latest) const
{
	if (Latest)
	{
#if OSVR_ENABLED
		OSVR_TimeValue Time;
		OSVR_OrientationState Orientation;
		OSVR_ReturnCode ReturnCode = osvrGetOrientationState(OSVRClientInterface, &Time, &Orientation);

		Value = OSVR2FQuat(Orientation);

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

	return HasOrientationState();
}
示例#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();
}
示例#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;
}