diff --git a/Source/StudyFrameworkPlugin/Private/GazeTracking/SFGazeTracker.cpp b/Source/StudyFrameworkPlugin/Private/GazeTracking/SFGazeTracker.cpp index d74b75ac9f97cd661cfd3095d07f2740064043b6..dcdae8166bc374bdb3a373b8c7bea8d024a765c7 100644 --- a/Source/StudyFrameworkPlugin/Private/GazeTracking/SFGazeTracker.cpp +++ b/Source/StudyFrameworkPlugin/Private/GazeTracking/SFGazeTracker.cpp @@ -5,6 +5,7 @@ #include "GazeTracking/SFGazeTarget.h" #include "GazeTracking/SFGazeTargetActor.h" #include "Help/SFUtils.h" +#include "Logging/SFLoggingUtils.h" #ifdef WITH_SRANIPAL #include "SRanipalEye_FunctionLibrary.h" @@ -168,10 +169,34 @@ FGazeRay USFGazeTracker::GetLocalGazeDirection() FGazeRay USFGazeTracker::GetWorldGazeDirection() { + if (GazeTrackingBackend == EGazeTrackingBackend::OpenXREyeTracker) { //this is already in world coordinates - return GetGazeRayFromEyeTrackerData(); + FGazeRay Gaze = GetGazeRayFromEyeTrackerData(); + + + // Corrections when using HTC Vive Pro Eye + UWorld* World = USFGameInstance::Get()->GetWorld(); + if (!World->GetFirstPlayerController()) { + return FGazeRay(); + } + const APlayerCameraManager* CamManager = World->GetFirstPlayerController()-> + PlayerCameraManager; + const FVector CameraLocation = CamManager->GetCameraLocation(); + FRotator CameraRotation = CamManager->GetCameraRotation(); + + Gaze.Origin = CameraLocation; + + FRotator AddRot = FRotator(0.0f, 180.0f, 0.0f); + Gaze.Direction = AddRot.RotateVector(Gaze.Direction); + Gaze.Direction = World->GetFirstPlayerController()->GetControlRotation().UnrotateVector(Gaze.Direction); + Gaze.Direction = CameraRotation.RotateVector(Gaze.Direction); + + + + return Gaze; } + //otherwise take local and transform it into world space FGazeRay LocalGazeRay = GetLocalGazeDirection();