From aeb63daed2c62235552be972da4af5b90c885d71 Mon Sep 17 00:00:00 2001
From: "valentin.dasbach" <valentin.dasbach@rwth-aachen.de>
Date: Fri, 8 Mar 2024 15:24:37 +0100
Subject: [PATCH] Corrections for gaze tracking with vive pro eye

---
 .../Private/GazeTracking/SFGazeTracker.cpp    | 27 ++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/Source/StudyFrameworkPlugin/Private/GazeTracking/SFGazeTracker.cpp b/Source/StudyFrameworkPlugin/Private/GazeTracking/SFGazeTracker.cpp
index d74b75a..dcdae81 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();
-- 
GitLab