From 7fab33e6982b5f165c3260b33c4e8b1b0868f1d0 Mon Sep 17 00:00:00 2001
From: Klara Tyroller <klara.tyroller@rwth-aachen.de>
Date: Sat, 22 Jan 2022 01:58:08 +0100
Subject: [PATCH] mimick delay in eye movement implemented

---
 .../Private/VHListenerBackchannels.cpp        | 52 +++++++++++++++++++
 .../Public/VHListenerBackchannels.h           |  3 ++
 2 files changed, 55 insertions(+)

diff --git a/Source/CharacterPlugin/Private/VHListenerBackchannels.cpp b/Source/CharacterPlugin/Private/VHListenerBackchannels.cpp
index c76af24f..8c9ed6d4 100644
--- a/Source/CharacterPlugin/Private/VHListenerBackchannels.cpp
+++ b/Source/CharacterPlugin/Private/VHListenerBackchannels.cpp
@@ -417,8 +417,58 @@ FRotator UVHListenerBackchannels::MyFindLookAtRotaion(FVector Start, FVector Tar
 
 void UVHListenerBackchannels::GazeController(FRotator HeadRotation)
 {
+    float TimePassed = GetWorld()->GetRealTimeSeconds();
     FVector point = GetPlayerLookAtTarget(10000);
 
+    if (chameleon)
+    {
+        if (in_VH_FieldofView(point, HeadRotation))
+        {
+            EyeMimickQueue.push(point);
+        }
+        else
+        {
+            EyeMimickQueue.push(FVector(0.0, 0.0, 0.0));
+        }
+        if (TimePassed > mimick_delay)
+        {
+            if (EyeMimickQueue.front() == FVector(0.0, 0.0, 0.0))
+            {
+                EyeMimickQueue.pop();
+                SetEyeLookAtTarget(Player_vr_pawn->Head->GetComponentLocation(), HeadRotation, true);
+                SetEyeLookAtTarget(Player_vr_pawn->Head->GetComponentLocation(), HeadRotation, false);
+            }
+            else
+            {
+                point = EyeMimickQueue.front();
+                EyeMimickQueue.pop();
+                SetEyeLookAtTarget(point, HeadRotation, true);
+                SetEyeLookAtTarget(point, HeadRotation, false);
+            }
+        }
+        else
+        {
+            SetEyeLookAtTarget(Player_vr_pawn->Head->GetComponentLocation(), HeadRotation, true);
+            SetEyeLookAtTarget(Player_vr_pawn->Head->GetComponentLocation(), HeadRotation, false);
+        }
+    }
+    else
+    {
+        if (in_VH_FieldofView(point, HeadRotation))
+        {
+            SetEyeLookAtTarget(GetPlayerLookAtTarget(10000), HeadRotation, true);
+            SetEyeLookAtTarget(GetPlayerLookAtTarget(10000), HeadRotation, false);
+        }
+        else
+        {
+            SetEyeLookAtTarget(Player_vr_pawn->Head->GetComponentLocation(), HeadRotation, true);
+            SetEyeLookAtTarget(Player_vr_pawn->Head->GetComponentLocation(), HeadRotation, false);
+        }
+    }
+
+
+/*
+
     if (in_VH_FieldofView(point,HeadRotation ))
     {
         SetEyeLookAtTarget(GetPlayerLookAtTarget(10000), HeadRotation, true);
@@ -429,6 +479,7 @@ void UVHListenerBackchannels::GazeController(FRotator HeadRotation)
         SetEyeLookAtTarget(Player_vr_pawn->Head->GetComponentLocation(), HeadRotation, true);
         SetEyeLookAtTarget(Player_vr_pawn->Head->GetComponentLocation(), HeadRotation, false);
     }
+    */
 }
 
 
@@ -436,6 +487,7 @@ bool UVHListenerBackchannels::in_VH_FieldofView(FVector Point, FRotator HeadRota
 {
     FRotator LookAtTargetRot = LookAtTarget(Point);
     FRotator difference = LookAtTargetRot - HeadRotation;
+    //if ((abs(difference.Yaw) > 107.0) || (abs(difference.Roll) > 70.0))
     if ((abs(difference.Yaw) > 107.0) || (abs(difference.Roll) > 70.0))
     {
         return false;
diff --git a/Source/CharacterPlugin/Public/VHListenerBackchannels.h b/Source/CharacterPlugin/Public/VHListenerBackchannels.h
index 7a51067e..ac39c7b5 100644
--- a/Source/CharacterPlugin/Public/VHListenerBackchannels.h
+++ b/Source/CharacterPlugin/Public/VHListenerBackchannels.h
@@ -60,8 +60,11 @@ private:
     float BlinkValue = 0.0;
     float mimick_delay = 4.0; //in s
     std::queue<FRotator>MimickQueue;
+    std::queue<FVector>EyeMimickQueue;
     std::array<FRotator, 50> a1 = { FRotator(0.0, 0.0, 0.0)};
     int counter = 0;
+    std::array<FVector, 50> a2 = { FVector(0.0, 0.0, 0.0) };
+    //int counter2 = 0;
 
         FRotator NodRotator = FRotator(0.0f, 0.0f, 0.0f);
 
-- 
GitLab