Skip to content
Snippets Groups Projects
Commit b81f1312 authored by 6brosius's avatar 6brosius
Browse files

final Changes, Commentary version TBA

parent 33b5d3ab
No related branches found
No related tags found
No related merge requests found
......@@ -10,132 +10,121 @@ public class ActionHandler : MonoBehaviour
public static ActionHandler instance;
public SteamVR_Action_Boolean GrabbingBall; //reference to the SteamVR2.0 Action Binding on Trigger Button
public SteamVR_Action_Boolean NextRound;
public SteamVR_Action_Boolean NextRound; //reference to the SteamVR2.0 Action Reference - TargetActivation
public SteamVR_Input_Sources handType; // reference to Hand
public SteamVR_Behaviour_Pose trackedObject;
public VelocityEstimator velocityEst;
public SteamVR_Behaviour_Pose trackedObject; // reference to Behaviour in SteamVR2.0
public VelocityEstimator velocityEst; //reference to VelocityEstimator Script
public GameObject Ball; // Reference to Ball Game Obj
public GameObject BallSnapPos;
public Vector3 initBallPos;
public Vector3 lockedGazePoint;
public float Boost;
public GameObject BallSnapPos; //Reference to Ball Snapping position on Controller
public Vector3 initBallPos; //reference where the ball should spawn
public Vector3 lockedGazePoint; //reference to the detected Fixation of user with the Eyetracker
private Boolean ballInHand;
public bool touchpressed;
private Vector3 _currentGrabbedLocation;
private GameObject collidingObject;
public string SysTimeTriggerpress;
public string SysTimeTriggerRelease;
public string SysTimeTargetAct;
public bool isTriggerpressed;
public bool targetActButtonPress;
private Boolean ballInHand; //Ref. wether the Ball is in the Users Hand
public bool touchpressed; //Marker when the Touchpad was triggered - Marker when the Target was Activated
private Vector3 _currentGrabbedLocation;
private GameObject collidingObject; //reference to the Controller/Ball Obj for Collision detection to pick up the Ball
public Vector3 _velocityMotorThrow;
public string SysTimeTriggerpress; //Timestamp when trigger was pressed
public string SysTimeTriggerRelease; //Timestamp when trigger was released
public string SysTimeTargetAct; //Time when Target was activated
public bool isTriggerpressed; //Bool wether trigger is currently pressed
public bool targetActButtonPress; //Bool wheter touch pad for target act. is pressed
public int ballsThrown;
public Vector3 _velocityMotorThrow; //Vector to hold the Velocity measured with the controllers movement (Velocity for motor Throw)
public int ballsThrown; //Counter how many balls have been thrown
private System.Random rndm;
private void Awake()
private void Awake() //Awake Method called before start
{
if (instance != null && instance != this)
if (instance != null && instance != this) //Check if instance of this script already is loaded
{
Destroy(this.gameObject);
Destroy(this.gameObject); //if so, destroy this Obj.
}
else
{
instance = this;
}
instance = this; //else the instance is this Obj.
} //This Part helps referencing this script with the call instance.XXXXX
}
// Start is called before the first frame update
void Start()
{
GrabbingBall.AddOnStateDownListener(TriggerDown, handType);
GrabbingBall.AddOnStateDownListener(TriggerDown, handType); //Add the listeners to the Buttons of the Controller
GrabbingBall.AddOnStateUpListener(TriggerUp, handType);
NextRound.AddOnStateDownListener(TouchPress, handType);
trackedObject = this.gameObject.GetComponent<SteamVR_Behaviour_Pose>();
velocityEst = this.gameObject.GetComponent<VelocityEstimator>();
_currentGrabbedLocation = new Vector3();
trackedObject = this.gameObject.GetComponent<SteamVR_Behaviour_Pose>(); //saving controller reference from SteamVR in trackedObj
velocityEst = this.gameObject.GetComponent<VelocityEstimator>(); //saving reference to velocity estimator
_currentGrabbedLocation = new Vector3(); //creating new vector for current grabed Location
ballInHand = false;
ballInHand = false; //instancing the initial Bool Values
touchpressed = false;
isTriggerpressed = false;
targetActButtonPress = false;
ballsThrown = 0;
touchpressed = false; //instancing the initial Bool Values
isTriggerpressed = false; //instancing the initial Bool Values
targetActButtonPress = false; //instancing the initial Bool Values
ballsThrown = 0; //instancing the initial throw counter
}
// Update is called once per frame
void Update()
{
Debug.DrawRay(transform.position, velocityEst.GetVelocityEstimate().normalized * 100f, Color.red);
Debug.DrawRay(transform.position, trackedObject.GetVelocity().normalized * 100f, Color.green);
}
public void TriggerUp(SteamVR_Action_Boolean fromAction, SteamVR_Input_Sources fromSource)
public void TriggerUp(SteamVR_Action_Boolean fromAction, SteamVR_Input_Sources fromSource) //when Trigger gets released this method gets called
{
isTriggerpressed = false;
// Debug.Log("Trigger is up");
if (collidingObject != null && ballInHand == true)
isTriggerpressed = false; //set status Bool
if (collidingObject != null && ballInHand == true) //when ball is in Hand, do
{
// EyeTracking_GazeDetect.instance.calcTargetGazePoint();
// EyeTracking_GazeDetect.instance.gazeAverager();
Vector3 velocity = velocityEst.GetVelocityEstimate();
_velocityMotorThrow = velocity;
initBallPos = Ball.transform.position;
if (GameManager.instance.SpawnDebugPoints)
Vector3 velocity = velocityEst.GetVelocityEstimate(); //get the estimated and smoothed velocity of the Controller
_velocityMotorThrow = velocity; //save it in BPublic Var
initBallPos = Ball.transform.position; //save pos where Ball got released
if (GameManager.instance.SpawnDebugPoints) //when debug Points spawn is activated
{
GazeAssist.instance.spawnGazeTargetBall();
GazeAssist.instance.spawnTobiiPoint();
GazeAssist.instance.spawnGazeTargetBall(); //spwan visual representation of weighted Ball target
GazeAssist.instance.spawnTobiiPoint(); //spawn visual representation of Eyetracking fixation
}
ballsThrown += 1;
ballsThrown += 1; //incr. throws
Vector3 velocityAngu = velocityEst.GetAngularVelocityEstimate();
//ReleaseGameObj(velocity);
// ReleaseGameObj(GazeAssistCalc(target));
Vector3 velocityAngu = velocityEst.GetAngularVelocityEstimate(); //save smoothed angular velocity of throw behaviour
lockedGazePoint = GazeAssist.instance._focusedGazeHitPoint;
ReleaseGameObj(ConditionHandler());
SysTimeTriggerRelease = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString();
ballInHand = false;
// Debug.Log("Collider IN Active");
lockedGazePoint = GazeAssist.instance._focusedGazeHitPoint; //get fixated Target Point
ReleaseGameObj(ConditionHandler()); //Release BallMethod called with value of condition
SysTimeTriggerRelease = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString(); //Timestamp TriggerRelease
ballInHand = false; //bool setting
}
}
public void TriggerDown(SteamVR_Action_Boolean fromAction, SteamVR_Input_Sources fromSource)
public void TriggerDown(SteamVR_Action_Boolean fromAction, SteamVR_Input_Sources fromSource) //gets called when trigger gets pressed down
{
isTriggerpressed = true;
//Debug.Log("Trigger is down");
if (collidingObject != null)
isTriggerpressed = true; //update bools
if (collidingObject != null) //if controller collides with ball
{
HoldGameObj(collidingObject);
SysTimeTriggerpress = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString();
// Debug.Log("ColliderActive");
HoldGameObj(collidingObject); //call Hold Ball Method
SysTimeTriggerpress = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString(); //Timestamp saved when trigger got pressed
}
}
public void TouchPress(SteamVR_Action_Boolean fromAction, SteamVR_Input_Sources fromSource)
public void TouchPress(SteamVR_Action_Boolean fromAction, SteamVR_Input_Sources fromSource) //when touchpad gets clicked, this method gets called
{
if (Ballmanager.instance.ready4nextRound)
if (Ballmanager.instance.ready4nextRound) //when system is ready for next round do...
{
// Debug.Log("Entered Trigger if");
targetActButtonPress = true;
MaterialManager.instance.ChangeColorMaterial(GameManager.instance.ActiveTargetNr);
//SysTimeTargetAct = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString();
MaterialManager.instance.ChangeColorMaterial(GameManager.instance.ActiveTargetNr); //set status bools, activate the coloured version of Material
Ballmanager.instance.ready4nextRound = false;
}
}
......@@ -151,7 +140,7 @@ public class ActionHandler : MonoBehaviour
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.GetComponent<Throwable>() || other.tag == "Ball")
if (other.gameObject.GetComponent<Throwable>() || other.tag == "Ball") //find stable collision with only the Ball object, with Tag Ball
{
SetCollidingObject(other);
}
......@@ -174,38 +163,36 @@ public class ActionHandler : MonoBehaviour
collidingObject = null;
}
public void HoldGameObj(GameObject throwableObj)
public void HoldGameObj(GameObject throwableObj) //Method that handles holding the Ball at the Controller
{
if (throwableObj != null)
{
throwableObj.transform.parent = this.gameObject.transform;
collidingObject.GetComponent<Rigidbody>().isKinematic = true;
collidingObject.transform.position = BallSnapPos.transform.position;
// _currentGrabbedLocation = collidingObject.transform.position;
ballInHand = true;
throwableObj.transform.parent = this.gameObject.transform; //create Parent child relationship between ball & controller
collidingObject.GetComponent<Rigidbody>().isKinematic = true; //kinematic of Ball gets activatd
collidingObject.transform.position = BallSnapPos.transform.position; //set Position of ball to snapping Pos.
ballInHand = true; //Status bool
}
}
public void ReleaseGameObj(Vector3 ReleaseVelocity)
public void ReleaseGameObj(Vector3 ReleaseVelocity) //Method that handles releasing the Ball
{
collidingObject.transform.parent = null;
Rigidbody rigidbody = collidingObject.GetComponent<Rigidbody>();
rigidbody.isKinematic = false;
rigidbody.velocity = ReleaseVelocity;
collidingObject.transform.parent = null; //destroy parent relationship
Rigidbody rigidbody = collidingObject.GetComponent<Rigidbody>(); //get rigidbody of ball to apply velocities
rigidbody.isKinematic = false; //disable kinematic
rigidbody.velocity = ReleaseVelocity; //Apply calculated release velocity, that will fly the ball in the desired Target point.
collidingObject = null;
ballInHand = false;
}
public Vector3 GazeAssistCalc(Vector3 Target)
public Vector3 GazeAssistCalc(Vector3 Target) //Method that handels calculation triggering for Release Velocity
{
var initBallVelo = collidingObject.GetComponent<Rigidbody>().velocity;
//GazeAssist.instance.calcThrowAngle(GazeAssist.instance._focusedGazeHitPoint);
Vector3 Velocity = GazeAssist.instance.CalcVelII(Target);
Debug.Log("MAX VELO" + Velocity);
return Velocity;
var initBallVelo = collidingObject.GetComponent<Rigidbody>().velocity; //get initial velocity of Ball
Vector3 Velocity = GazeAssist.instance.CalcVelII(Target); //Call Method, that simulates Trajectory into target Point
return Velocity; //Return needed Velocity for Throw into desired Target Point
}
public Vector3 ConditionHandler()
public Vector3 ConditionHandler() //This Method handles setting the right Ball Weighting between Gaze Point and Motor
// Point depending on the Set Condition in the Game Manager and the Nr. of throws
{
switch (GameManager.instance.condition)
{
......
......@@ -14,29 +14,13 @@ public class BallSpawner : MonoBehaviour
// spawn();
}
public Rigidbody spawn()
public Rigidbody spawn() //Method that handles the firs Appearance of the Ball
{
Rigidbody ballInstance;
ballInstance = Instantiate(ballPrefab);
ballInstance.transform.position = transform.position;
ballInstance.transform.position = transform.position; //Set Position of Ball and return Instance of the Ball
return ballInstance;
}
public void spawnXBalls(int x)
{
// Debug.Log("Coroutine started");
StartCoroutine(spawnX(x));
}
private IEnumerator spawnX(int x)
{
for (int i = 0; i < x; i++)
{
spawn();
yield return new WaitForSeconds(0.5f);
}
yield return null;
}
}
......
......@@ -7,7 +7,8 @@ public class Ballmanager : MonoBehaviour
{
public static Ballmanager instance;
private int ballToRemove;
public GameObject BallSpawnPos;
public GameObject BallSpawnPos; //Creating the needed Public Fields Spawn Pos. of Ball, Reference to collider of Ball,
//Ground Collider Ref, Explosion Animation....
public Collider BallCollider;
public Collider GroundCollider;
public ParticleSystem Explosion;
......@@ -23,52 +24,41 @@ public class Ballmanager : MonoBehaviour
{
Destroy(this.gameObject);
}
else
else //initialize fields, make this script the only instance or destroy if another instance already exists
{
instance = this;
}
ready4nextRound = false;
Ballhit = false;
rndm = new System.Random();
rndm = new System.Random(); //save random Number for random Target Activation
}
private void OnTriggerEnter(Collider Ball)
private void OnTriggerEnter(Collider Ball) //This Method handles wether the Ball hit the Target or Ground Plate
{
if (Ball.tag == "Ball")
{
Ballhit = true;
BallCollider = Ball;
GameManager.instance.BallhitTarget();
GameManager.instance.BallhitTarget(); //Trigger Explosion Animation
Explode(Ball.transform.position);
GetComponent<BoxCollider>().enabled = false;
Ball.attachedRigidbody.isKinematic = true;
Debug.Log("Ball Entered Collider");
}
}
private void DestroyBall(Collider Ball)
{
Destroy(Ball.gameObject);
}
public IEnumerator ResetBall(Collider Ball)
public IEnumerator ResetBall(Collider Ball) //Method that Resets Ball Position to Spawn
{
if (Ball.tag == "Ball")
{
Debug.Log("ResetBall meth. Aufgerufen");
Ball.attachedRigidbody.velocity = Vector3.zero;
Ball.attachedRigidbody.velocity = Vector3.zero; //set Movement of Ball to zero
Ball.attachedRigidbody.angularVelocity = Vector3.zero;
yield return new WaitForSeconds(0.5f);
var x= rndm.Next(0, 3);
while (GameManager.instance.oldTarg == x)
while (GameManager.instance.oldTarg == x) //Async Call for another random Target Nr for next round after Reset
{
x = rndm.Next(0, 3);
}
......@@ -76,27 +66,20 @@ public class Ballmanager : MonoBehaviour
GameManager.instance.SetThrowCounter(1);
EyeTracking_GazeDetect.instance.clearAveragers();
Ballhit = false;
Ball.transform.position = BallSpawnPos.transform.position;
Ball.transform.position = BallSpawnPos.transform.position; //Set Position of Ball to Spawn
Ball.attachedRigidbody.isKinematic = false;
GetComponent<BoxCollider>().enabled = true;
GroundCollider.enabled = true;
MaterialManager.instance.DeactivateTarg();
MaterialManager.instance.DeactivateTarg(); //deactevate activated Target
ready4nextRound = true;
// yield return new WaitForSeconds(4);
// MaterialManager.instance.ChangeColorMaterial(GameManager.instance.ActiveTargetNr);
}
}
public void ForceBallReset(GameObject Ball)
{
Ball.transform.position = BallSpawnPos.transform.position;
}
void Explode(Vector3 Position)
{
var exp = Explosion;
exp.transform.position = Position;
exp.transform.position = Position; //Play Animation at Position
exp.Play();
}
}
\ No newline at end of file
......@@ -15,10 +15,9 @@ using System.Threading.Tasks;
public class EyeTrackingCSV_Recorder: MonoBehaviour
{
public static EyeTrackingCSV_Recorder instance;
//string FilePath;
//List as Buffer for Eyetracking Information
public List<string> EyeTrackingDataBuffer = new List<string>();
//Create Vector Variables for Origin, Direction Screen Position
Vector3 rayOrigin = new Vector3();
Vector3 rayDirection = new Vector3();
Vector3 screenPosition = new Vector3();
......@@ -26,16 +25,19 @@ public class EyeTrackingCSV_Recorder: MonoBehaviour
public Camera cam;
public GameObject Ball;
public bool LogEye2Console;
public bool LogEye2Console; //Bool wether Eyetracking info should be logged to Console
public int interval = 200;
private int counter = 0;
//private string dateTimeFileName = DateTime.Now.ToString("dd/mm/yy_hh.mmtt");
//references to Dateand Time File Name as well as File Path for the recorded Data
private string dateTimeFileName;
private string FilePath;
private void Awake()
{
if (instance != null && instance != this)
......@@ -50,39 +52,46 @@ public class EyeTrackingCSV_Recorder: MonoBehaviour
private void Start()
{
//Create File Name and Path where the logged Data should be Saved
dateTimeFileName = DateTime.Now.ToString("MM/dd/yyyy hh-mm tt");
dateTimeFileName = dateTimeFileName.Replace("/", "-");
FilePath = Application.dataPath;
FilePath = FilePath + "/Data";
//Show user in console, where Data will be saved
Debug.Log("The EyeTracking Data will be Saved @:" + FilePath);
}
//Write the collected Data ansynchronously to the File.
async void WriteCSV(List<string> Buffer, string FileName)
{
string fn= Path.Combine(FilePath, FileName+".csv");
//Open Stream Writer to fill csv. with Data.
using (FileStream fs = new FileStream(fn, FileMode.Append, FileAccess.Write, FileShare.ReadWrite))
using (StreamWriter sw = new StreamWriter(fs))
{
if (counter == 0)
{
//Header at top of CSV
await sw.WriteLineAsync("UnixTimeStamp;Time since GameStart;Origin V3(x,y,z);Direction V3(x,y,z);GazeRay isValid;isLeftEyeBlinking;isRightEyeBlinking;ScreenPositionfromWorldspace(pixelWidth, pixelHeight, WorldUnitsfromCamera);TriggerState;BallPosition(x,y,z);BallLockedonTarget;GazeHitPoint;Gaze to Target Distance; Ball to Target Distance");
await sw.WriteLineAsync("SubjectID: " + RecordingController.Instance.SubjectID.ToString() + ";" + "ExperimentName: " + RecordingController.Instance.ExperimentName.ToString());
counter += 1;
}
foreach (var item in Buffer)
{
//Write Data to file
await sw.WriteLineAsync(item);
}
//Empty the Stream Writer after everything got written
sw.Flush();
}
}
public string CaptureEyeTrackingData()
public string CaptureEyeTrackingData() //Method that collects all the information that sould be Logged from all the Scripts
{
var gazeRay = TobiiXR.EyeTrackingData.GazeRay;
rayOrigin = TobiiXR.EyeTrackingData.GazeRay.Origin;
......@@ -106,6 +115,7 @@ public class EyeTrackingCSV_Recorder: MonoBehaviour
string BallPos = V3toString(Ball.transform.position);
string BallState = Ballmanager.instance.Ballhit.ToString();
//Build String with all Variables that have been collected
string FrameDataBuffer = $"{SystemTime};{GameTime};{rayOriginStr};{rayDirectionStr};{gazeValidity};{leftEyeBlinking};" +
$"{rightEyeBlinking};{worldtoScreenCoord(rayOrigin, rayDirection, Convergence, cam)};{triggerstate};" +
$"{BallPos};{BallState};{GazeRayhitPoint};{GazeTargetDist};{BallTargetDist}";
......@@ -119,7 +129,7 @@ public class EyeTrackingCSV_Recorder: MonoBehaviour
}
public string worldtoScreenCoord(Vector3 Origin, Vector3 Direction, float convergence, Camera cam)
public string worldtoScreenCoord(Vector3 Origin, Vector3 Direction, float convergence, Camera cam) //Method to translate Gaze to screen coordinates
{
if (TobiiXR.EyeTrackingData.ConvergenceDistanceIsValid && TobiiXR.EyeTrackingData.GazeRay.IsValid)
......@@ -136,13 +146,13 @@ public class EyeTrackingCSV_Recorder: MonoBehaviour
}
}
public string V3toString(Vector3 vec)
public string V3toString(Vector3 vec) //Method to transform Vector Info to String
{
string formattedVec = (vec.x + ";" + vec.y + ";" + vec.z);
return formattedVec;
}
void tempSaveEyeTrackingData()
void tempSaveEyeTrackingData() //Temporarily save Data to the TempList so nothing gets lost when system Lags or Stops
{
List<string> TempList = new List<string>();
......@@ -152,33 +162,30 @@ public class EyeTrackingCSV_Recorder: MonoBehaviour
}
EyeTrackingDataBuffer.Clear();
Task.Factory.StartNew(() => WriteCSV(TempList, $"{dateTimeFileName.Replace(" ", "_")} EyeTrackingData_All"));
//WriteCSV(TempList, $"{dateTimeFileName.Replace( " ", "_" )} EyeTrackingData_All");
Task.Factory.StartNew(() => WriteCSV(TempList, $"{dateTimeFileName.Replace(" ", "_")} EyeTrackingData_All")); //Call new asynchronous Task of collecting Data
}
private void Update()
{
EyeTrackingDataBuffer.Add(CaptureEyeTrackingData());
EyeTrackingDataBuffer.Add(CaptureEyeTrackingData()); //add Data to the Buffer in every calculated Frame
if (Time.frameCount % interval == 0)
{
tempSaveEyeTrackingData();
tempSaveEyeTrackingData(); //save the Data temporarily every interval that was Set
}
}
public string CaptureStudyInfo(string Systime, string gameTime, string StartEndNewRound, int taregtID)
public string CaptureStudyInfo(string Systime, string gameTime, string StartEndNewRound, int taregtID) //save Information of Study
{
string target = resolveTargetID(taregtID);
string StudyInfo = $"{Systime};{gameTime};{StartEndNewRound};{target}";
return StudyInfo;
}
public string resolveTargetID(int targetNr)
public string resolveTargetID(int targetNr) //resolve target id to readable location
{
switch (targetNr)
{
......@@ -200,12 +207,12 @@ public class EyeTrackingCSV_Recorder: MonoBehaviour
}
}
public void SaveTrackingData()
public void SaveTrackingData() //save the tracking Data from thr Buffer.
{
WriteCSV(EyeTrackingDataBuffer, $"{dateTimeFileName.Replace( " ", "_" )} EyeTrackingData_All");
}
void OnApplicationQuit()
void OnApplicationQuit() //before Quitting Application, save the Data
{
//tempSaveEyeTrackingData
SaveTrackingData();
......
......@@ -12,12 +12,12 @@ public class EyeTracking_GazeDetect : MonoBehaviour
public Vector3 GazeOrigin;
public Vector3 GazeDirection;
public GameObject TargetCenterPointleft;
public GameObject TargetCenterPointmiddle;
public GameObject TargetCenterPointmiddle; //References to The center Points of the BullsEyes
public GameObject TargetCenterPointright;
public GameObject Ball;
public GameObject Ball; //Ref to Ball
public List<Vector3> GazetargetFixations;
public List<float> GazeDists;
public List<Vector3> GazetargetFixations; //List of fixated Points in scene
public List<float> GazeDists; //List of Distances to Bulls Eye
private Vector3 summedGazeVec;
private float sGD;
public Vector3 avgV3;
......@@ -40,20 +40,17 @@ public class EyeTracking_GazeDetect : MonoBehaviour
// Update is called once per frame
void Update()
{
var gazeRay = TobiiXR.EyeTrackingData.GazeRay;
var gazeRay = TobiiXR.EyeTrackingData.GazeRay; //get Eyetracker Ray for Every Frame
if (gazeRay.IsValid)
if (gazeRay.IsValid) //when gaze is Valid do..
{
// Eye Origin is in World Space
GazeOrigin = TobiiXR.EyeTrackingData.GazeRay.Origin;
// Eye Direction is a normalized direction vector in World Space
GazeDirection = TobiiXR.EyeTrackingData.GazeRay.Direction;
Debug.DrawRay(transform.position, GazeDirection.normalized * 100, Color.magenta, 1f);
if (ActionHandler.instance.isTriggerpressed && ActionHandler.instance.targetActButtonPress)
if (ActionHandler.instance.isTriggerpressed && ActionHandler.instance.targetActButtonPress) //save Focus Points only when Ball is in Hand and Target is Active
{
GazetargetFixations.Add(GazeRayHitPoint(GazeOrigin, GazeDirection));
GazeDists.Add(GazeToTargetDist(GameManager.instance.ActiveTargetNr));
......@@ -61,13 +58,13 @@ public class EyeTracking_GazeDetect : MonoBehaviour
}
}
public Vector3 GazeRayHitPoint(Vector3 Origin, Vector3 Dircetion)
public Vector3 GazeRayHitPoint(Vector3 Origin, Vector3 Dircetion) //Raycast Pixel Exact hit Point of Eyetracking Gaze
{
Physics.Raycast(Origin, Dircetion, out RaycastHit hit, Mathf.Infinity, 1 << LayerMask.NameToLayer("GazeDetection"));
return hit.point;
}
public Vector3 resolveTargetIDtoV3(int targetNr)
public Vector3 resolveTargetIDtoV3(int targetNr) //Translate Target ID to Vector to Center Point
{
if (targetNr == 0)
{
......@@ -97,7 +94,7 @@ public class EyeTracking_GazeDetect : MonoBehaviour
public float GazeToTargetDist(int TargetID)
{
float dist = Vector3.Distance(GazeRayHitPoint(GazeOrigin, GazeDirection), resolveTargetIDtoV3(TargetID));
float dist = Vector3.Distance(GazeRayHitPoint(GazeOrigin, GazeDirection), resolveTargetIDtoV3(TargetID)); //Calculate Distance between Gaze and Target
return dist;
}
......@@ -105,7 +102,7 @@ public class EyeTracking_GazeDetect : MonoBehaviour
{
if(Ballmanager.instance.Ballhit)
{
float dist = Vector3.Distance(Ball.transform.position, resolveTargetIDtoV3(TargetID));
float dist = Vector3.Distance(Ball.transform.position, resolveTargetIDtoV3(TargetID)); //Calculate Distance of Ball to Target center
return dist;
}
else
......@@ -114,7 +111,7 @@ public class EyeTracking_GazeDetect : MonoBehaviour
}
}
public Vector3 calcTargetGazePoint()
public Vector3 calcTargetGazePoint() //smooth gaze fixation Point
{
GazetargetFixations.Reverse();
int count = GazetargetFixations.Count;
......@@ -134,7 +131,7 @@ public class EyeTracking_GazeDetect : MonoBehaviour
}
public void gazeAverager()
public void gazeAverager() //smooth gaze Distance also
{
GazeDists.Reverse();
int count = GazeDists.Count;
......@@ -148,7 +145,7 @@ public class EyeTracking_GazeDetect : MonoBehaviour
finalaverageGazeDist = sGD / count;
}
public void clearAveragers()
public void clearAveragers() //clear the averager Variables
{
GazetargetFixations.Clear();
GazeDists.Clear();
......@@ -158,14 +155,13 @@ public class EyeTracking_GazeDetect : MonoBehaviour
summedGazeVec = Vector3.zero;
}
//TODO:
public float Motor2TargetDist(Vector3 MotorHP, Vector3 TargetP)
public float Motor2TargetDist(Vector3 MotorHP, Vector3 TargetP) //Calc distance of Motor Hit Point to Target
{
var M2TD = Vector3.Distance(MotorHP, TargetP);
return M2TD;
}
public float Motor2GazeDist(Vector3 MotorHP, Vector3 GazeHP)
public float Motor2GazeDist(Vector3 MotorHP, Vector3 GazeHP) //Calc Distance of Gaze to Motor hit point
{
var M2GD = Vector3.Distance(MotorHP, GazeHP);
return M2GD;
......
......@@ -7,19 +7,13 @@ using UnityEngine;
public class GameManager : MonoBehaviour
{
public int ThrowsInTrial;
public enum Condition { Motor, Gaze, Motor2Gaze, Gaze2Motor, BullsEye2Motor, Motor2BullsEye };
public enum Condition { Motor, Gaze, Motor2Gaze, Gaze2Motor, BullsEye2Motor, Motor2BullsEye }; //Options to select Condition that shall be Played in Unity
public Condition condition;
public enum Hand { LeftHand, RightHand };
public enum Hand { LeftHand, RightHand }; //select Hand that user is using
public Hand hand;
public bool SpawnDebugPoints;
public int SubjectID;
public bool SpawnDebugPoints; //Debug Points shall be displayed or not?
public int SubjectID; //Field to enter SUbj ID
public String ExpName;
private int Points;
public int ThrowCounter;
private bool first;
......@@ -86,29 +80,27 @@ public class GameManager : MonoBehaviour
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown("s"))
if (Input.GetKeyDown("s")) //Press Key S to start game / spawn Ball
{
StartGame();
}
if (Input.GetKeyDown("e"))
if (Input.GetKeyDown("e")) //Press E to force Game to quit
{
EndGame();
}
if (Input.GetKeyDown("r"))
if (Input.GetKeyDown("r")) //Press R to reset the Ball
{
Ballmanager.instance.ForceBallReset(Ball);
}
if (ThrowCounter > (ThrowsInTrial-1) && ActGame == true)
if (ThrowCounter > (ThrowsInTrial-1) && ActGame == true) //Automatically end Game after desired number of throws have been reached
{
//Debug.Log("Irgendwie Hier gelandet..");
EndGame();
}
......@@ -116,7 +108,7 @@ public class GameManager : MonoBehaviour
private void StartGame()
private void StartGame() //Set values and initiates everything needed to start the game
{
ActGame = true;
StudyEndText.SetActive(false);
......@@ -129,7 +121,7 @@ public class GameManager : MonoBehaviour
}
private void EndGame()
private void EndGame() //Set values and everything to force end the Game also save the Data
{
ActGame = false;
StudyEndText.SetActive(true);
......@@ -143,7 +135,7 @@ public class GameManager : MonoBehaviour
//ThrowCounter = 0;
}
private void NewRound()
private void NewRound() //Method that handles everything needed to
{
oldTarg = ActiveTargetNr;
ActionHandler.instance.lockedGazePoint = Vector3.zero;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment