Skip to content
Snippets Groups Projects
Commit 9e63c45a authored by RZ-WIN\vr-admin's avatar RZ-WIN\vr-admin
Browse files

imrpove gaze tracking and logging

parent f992c2ca
No related branches found
No related tags found
1 merge request!2GazeTracking Logging
This commit is part of merge request !2. Comments created here will be created in the context of that merge request.
...@@ -34,10 +34,11 @@ void USFGazeTracker::Init(EGazeTrackerMode Mode) ...@@ -34,10 +34,11 @@ void USFGazeTracker::Init(EGazeTrackerMode Mode)
} }
} }
FGazeRay USFGazeTracker::GetGazeDirection() FGazeRay USFGazeTracker::GetLocalGazeDirection()
{ {
if(!IsTrackingEyes()) if(!IsTrackingEyes())
{ {
// if no eye tracker is used we always "look ahead"
FGazeRay GazeRay; FGazeRay GazeRay;
GazeRay.Origin = FVector::ZeroVector; GazeRay.Origin = FVector::ZeroVector;
GazeRay.Direction = FVector::ForwardVector;; GazeRay.Direction = FVector::ForwardVector;;
...@@ -54,14 +55,9 @@ FGazeRay USFGazeTracker::GetGazeDirection() ...@@ -54,14 +55,9 @@ FGazeRay USFGazeTracker::GetGazeDirection()
return GazeRay; return GazeRay;
} }
FString USFGazeTracker::GetCurrentGazeTarget() FGazeRay USFGazeTracker::GetWorldGazeDirection()
{ {
FString GazedAtTarget = ""; FGazeRay LocalGazeRay = GetLocalGazeDirection();
const float Distance = 1000.0f;
FGazeRay GazeRay = GetGazeDirection();
// if no eye tracker is used we always "look ahead"
// GazeDirection = FVector(1,0,0);
UWorld* World = USFGameInstance::Get()->GetWorld(); UWorld* World = USFGameInstance::Get()->GetWorld();
...@@ -70,13 +66,41 @@ FString USFGazeTracker::GetCurrentGazeTarget() ...@@ -70,13 +66,41 @@ FString USFGazeTracker::GetCurrentGazeTarget()
PlayerCameraManager; PlayerCameraManager;
const FVector CameraLocation = CamManager->GetCameraLocation(); const FVector CameraLocation = CamManager->GetCameraLocation();
const FRotator CameraRotation = CamManager->GetCameraRotation(); const FRotator CameraRotation = CamManager->GetCameraRotation();
const FVector RayCastOrigin = CameraLocation + CameraRotation.RotateVector(GazeRay.Origin);
const FVector RayCastEnd = (CameraRotation.RotateVector(GazeRay.Direction) * Distance) + RayCastOrigin; FGazeRay GazeRay;
GazeRay.Origin = CameraLocation + CameraRotation.RotateVector(LocalGazeRay.Origin);
GazeRay.Direction = CameraRotation.RotateVector(LocalGazeRay.Direction);
return GazeRay;
}
FString USFGazeTracker::GetCurrentGazeTarget()
{
FString GazedAtTarget = "";
const float Distance = 1000.0f;
FGazeRay GazeRay = GetWorldGazeDirection();
const FVector RayCastOrigin = GazeRay.Origin;
const FVector RayCastEnd = (GazeRay.Direction * Distance) + RayCastOrigin;
//FSFUtils::Log("Cast Ray from "+RayCastOrigin.ToString()+" to "+RayCastEnd.ToString()); //FSFUtils::Log("Cast Ray from "+RayCastOrigin.ToString()+" to "+RayCastEnd.ToString());
FHitResult HitResult; FHitResult HitResult;
World->LineTraceSingleByChannel(HitResult, RayCastOrigin, RayCastEnd, EYE_TRACKING_TRACE_CHANNEL); UWorld* World = USFGameInstance::Get()->GetWorld();
FCollisionQueryParams QueryParams;
QueryParams.AddIgnoredActor(World->GetFirstPlayerController()->AcknowledgedPawn);
QueryParams.AddIgnoredActor(USFGameInstance::Get()->GetHUD()->GetHUDHelper());
World->LineTraceSingleByChannel(HitResult, RayCastOrigin, RayCastEnd, EYE_TRACKING_TRACE_CHANNEL, QueryParams);
if (bDebugRenderRayTraces)
{
//this line trace is more comfortable for debug drawing, however has problems with channel tracing, so we use LineTraceSingleByChannel() above
FHitResult TmpHitRes;
UKismetSystemLibrary::LineTraceSingle(World, RayCastOrigin, RayCastEnd, ETraceTypeQuery::TraceTypeQuery4, false, {}, EDrawDebugTrace::ForDuration, TmpHitRes, true);
}
if (HitResult.bBlockingHit) if (HitResult.bBlockingHit)
...@@ -104,17 +128,20 @@ FString USFGazeTracker::GetCurrentGazeTarget() ...@@ -104,17 +128,20 @@ FString USFGazeTracker::GetCurrentGazeTarget()
void USFGazeTracker::LaunchCalibration() void USFGazeTracker::LaunchCalibration()
{ {
#ifdef WITH_SRANIPAL #ifdef WITH_SRANIPAL
//TODO: not tested yet!
ViveSR::anipal::Eye::LaunchEyeCalibration(nullptr); ViveSR::anipal::Eye::LaunchEyeCalibration(nullptr);
#endif #endif
} }
bool USFGazeTracker::IsTrackingEyes() bool USFGazeTracker::IsTrackingEyes()
{ {
//TODO: maybe use if (!bEyeTrackingStarted)
//#ifdef WITH_SRANIPAL return false;
//ViveSR::anipal::AnipalStatus Status; //TODO: this does not seem to work properly!!!! check gaze logs
//int Error = ViveSR::anipal::GetStatus(ViveSR::anipal::Eye::ANIPAL_TYPE_EYE_V2, &Status); #ifdef WITH_SRANIPAL
//#endif ViveSR::anipal::AnipalStatus Status;
return bEyeTrackingStarted; int Error = ViveSR::anipal::GetStatus(ViveSR::anipal::Eye::ANIPAL_TYPE_EYE_V2, &Status);
return Status == ViveSR::anipal::AnipalStatus::WORKING;
#endif
return true;
} }
...@@ -245,3 +245,7 @@ void ASFMasterHUD::OnShowConditionsButtonPressed() ...@@ -245,3 +245,7 @@ void ASFMasterHUD::OnShowConditionsButtonPressed()
} }
} }
} }
const ASFHMDSpectatorHUDHelp* ASFMasterHUD::GetHUDHelper() {
return HMDHUDHelper;
}
...@@ -105,8 +105,8 @@ void USFLogObject::WriteGazeTrackingLogHeaderRow() { ...@@ -105,8 +105,8 @@ void USFLogObject::WriteGazeTrackingLogHeaderRow() {
"\t" + FString("Condition") + "\t" + FString("Condition") +
"\t" + FString("UsingEyetracking") + "\t" + FString("UsingEyetracking") +
"\t" + FString("GazeTarget") + "\t" + FString("GazeTarget") +
"\t" + FString("HeadRotation-Origin") + "\t" + FString("Gaze-Origin-X-Y-Z") +
"\t" + FString("HeadRotation-Direction"); "\t" + FString("Gaze-Direction-X-Y-Z");
UniLog.Log(GazeTrackingLogHeader, "GazeTrackingLog"); UniLog.Log(GazeTrackingLogHeader, "GazeTrackingLog");
} }
...@@ -127,8 +127,12 @@ void USFLogObject::WriteGazeTrackingLogToFile() { ...@@ -127,8 +127,12 @@ void USFLogObject::WriteGazeTrackingLogToFile() {
"\t" + CurrentCondition + "\t" + CurrentCondition +
"\t" + isTrackingEyes + "\t" + isTrackingEyes +
"\t" + GazeTarget + "\t" + GazeTarget +
"\t" + GazeTracker->GetGazeDirection().Origin.ToCompactString() + "\t" + FString::Printf(TEXT("%.3f"), GazeTracker->GetWorldGazeDirection().Origin.X) +
"\t" + GazeTracker->GetGazeDirection().Direction.ToCompactString(); "\t" + FString::Printf(TEXT("%.3f"), GazeTracker->GetWorldGazeDirection().Origin.Y) +
"\t" + FString::Printf(TEXT("%.3f"), GazeTracker->GetWorldGazeDirection().Origin.Z) +
"\t" + FString::Printf(TEXT("%.3f"), GazeTracker->GetWorldGazeDirection().Direction.X) +
"\t" + FString::Printf(TEXT("%.3f"), GazeTracker->GetWorldGazeDirection().Direction.Y) +
"\t" + FString::Printf(TEXT("%.3f"), GazeTracker->GetWorldGazeDirection().Direction.Z);
if (UniLog.GetLogStream("GazeTrackingLog")) if (UniLog.GetLogStream("GazeTrackingLog"))
{ {
UniLog.Log(out, "GazeTrackingLog"); UniLog.Log(out, "GazeTrackingLog");
......
...@@ -30,20 +30,27 @@ class STUDYFRAMEWORKPLUGIN_API USFGazeTracker : public UObject ...@@ -30,20 +30,27 @@ class STUDYFRAMEWORKPLUGIN_API USFGazeTracker : public UObject
public: public:
void Init(EGazeTrackerMode Mode); void Init(EGazeTrackerMode Mode);
//returns pair of Origin and Direction, relative to the head! //returns pair of Origin and Direction, in world coordinates
UFUNCTION(BlueprintCallable) UFUNCTION(BlueprintCallable)
FGazeRay GetGazeDirection(); FGazeRay GetWorldGazeDirection();
//returns the name of the gaze target or empty string if none found or not tracking //returns the name of the gaze target or empty string if none found or not tracking
UFUNCTION(BlueprintCallable) UFUNCTION(BlueprintCallable)
FString GetCurrentGazeTarget(); FString GetCurrentGazeTarget();
//returns pair of Origin and Direction, relative to the head!
UFUNCTION(BlueprintCallable)
FGazeRay GetLocalGazeDirection();
UFUNCTION(BlueprintCallable) UFUNCTION(BlueprintCallable)
void LaunchCalibration(); void LaunchCalibration();
UFUNCTION(BlueprintCallable) UFUNCTION(BlueprintCallable)
bool IsTrackingEyes(); bool IsTrackingEyes();
UPROPERTY(BlueprintReadWrite)
bool bDebugRenderRayTraces = false;
private: private:
bool bEyeTrackingStarted = false; bool bEyeTrackingStarted = false;
......
...@@ -61,6 +61,8 @@ public: ...@@ -61,6 +61,8 @@ public:
UFUNCTION() UFUNCTION()
void OnShowConditionsButtonPressed(); void OnShowConditionsButtonPressed();
const ASFHMDSpectatorHUDHelp* GetHUDHelper();
protected: protected:
UPROPERTY(VisibleAnywhere) UPROPERTY(VisibleAnywhere)
USFHUDWidget* HUDWidget; USFHUDWidget* HUDWidget;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment