Commit 195d4014 authored by Maximilian Tomio's avatar Maximilian Tomio
Browse files

Finish Distractor Test

parent 6ac14557
......@@ -24,12 +24,6 @@ public class ClickableSphere : MonoBehaviour
}
}
// Update is called once per frame
void Update()
{
}
public void SetActive(bool isActive)
{
if (isActive)
......
......@@ -41,12 +41,12 @@ public class Clicker : MonoBehaviour
float errorRate = (float)MissClicks / (float)TotalClicks;
ClickDataSet dataHit = new ClickDataSet(
LastClickTime,
Camera.main.WorldToScreenPoint(hit.point),
LastClickTime,
Camera.main.WorldToScreenPoint(hit.point),
Camera.main.WorldToScreenPoint(hit.transform.position),
errorRate,
SphereHandler.DistancePixel,
SphereHandler.AmplitudePixel);
SphereHandler.GetCurrentDensity(),
SphereHandler.GetCurrentSphereNumbers());
Logger.AddDataSet(dataHit);
SphereHandler.NextActive();
......@@ -64,9 +64,9 @@ public class Clicker : MonoBehaviour
Input.mousePosition,
Camera.main.WorldToScreenPoint(active.transform.position),
errorRate,
SphereHandler.DistancePixel,
SphereHandler.AmplitudePixel);
SphereHandler.GetCurrentDensity(),
SphereHandler.GetCurrentSphereNumbers());
Logger.AddDataSet(dataMiss);
}
......
......@@ -45,12 +45,12 @@ public class Logger : MonoBehaviour
}
StringBuilder builder = new StringBuilder();
builder.AppendLine("User,A,W,ID,MT,EP,TP,Acc,Err");
builder.AppendLine("User,SphereNum,Density,MT,EP,TP,Acc,Err");
foreach (var set in Data)
{
var endPoint = $"({set.EndPoint.x}/{set.EndPoint.y})";
var targetPoint = $"({set.TargetPoint.x}/{set.TargetPoint.y})";
builder.AppendLine($"{UserID},{set.Amplitude},{set.Width},{set.DifficultyIndex},{set.MoveTime},{endPoint},{targetPoint},{set.Accuracy},{set.ErrorRate}");
builder.AppendLine($"{UserID},{set.SphereNumber},{set.Density},{set.MoveTime},{endPoint},{targetPoint},{set.Accuracy},{set.ErrorRate}");
}
File.WriteAllText(path, builder.ToString());
......@@ -69,19 +69,17 @@ public struct ClickDataSet
public readonly Vector2 TargetPoint;
public readonly float Accuracy;
public readonly float ErrorRate;
public readonly float Width;
public readonly float Amplitude;
public readonly float DifficultyIndex;
public readonly float Density;
public readonly int SphereNumber;
public ClickDataSet(float time, Vector2 ep, Vector2 tp, float errorRate, float width, float amplitude)
public ClickDataSet(float time, Vector2 ep, Vector2 tp, float errorRate, float density, int sphereNumber)
{
MoveTime = time;
EndPoint = ep;
TargetPoint = tp;
Accuracy = Vector2.Distance(ep, tp);
ErrorRate = errorRate;
Width = width;
Amplitude = amplitude;
DifficultyIndex = Mathf.Log((amplitude / width) + 1.0f, 2.0f);
Density = density;
SphereNumber = sphereNumber;
}
}
\ No newline at end of file
......@@ -904,7 +904,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 963194225}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 1, z: -10}
m_LocalPosition: {x: 0, y: 0, z: -10}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
......@@ -1291,14 +1291,10 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 0bdf07fa2de0c3947a4bf612bbc7edbc, type: 3}
m_Name:
m_EditorClassIdentifier:
SphereNumber: 13
DistanceWidths:
- {x: 3, y: 1}
- {x: 2, y: 0.75}
- {x: 1, y: 0.5}
- {x: 3.5, y: 1}
- {x: 3.5, y: 1.5}
- {x: 4, y: 0.5}
Min: {x: -7, y: -2, z: -4}
Max: {x: 7, y: 2, z: 4}
DensityNumbers:
- {x: 6, y: 40}
MaxSphereSwitches: 30
SphereTemplate: {fileID: 316699081740425071, guid: e765bcf0e7e93b348892df145571802b, type: 3}
--- !u!4 &1656067821
......
......@@ -7,13 +7,12 @@ public class SphereHandler : MonoBehaviour
private List<ClickableSphere> Spheres = new List<ClickableSphere>();
public ClickableSphere CurrentActive { get; private set; }
[SerializeField]
private int SphereNumber = 13;
public Vector3 Min = new Vector3(-10, -10, -10);
public Vector3 Max = new Vector3(10, 10, 10);
public int DifficultyIndex { get; private set; } = 0;
public int Index { get; private set; } = 0;
[SerializeField]
private List<Vector2> DistanceWidths = new List<Vector2>();
public List<Vector2> DensityNumbers = new List<Vector2>();
public float DistancePixel { get; private set; }
public float AmplitudePixel { get; private set; }
......@@ -31,25 +30,17 @@ public class SphereHandler : MonoBehaviour
public void SpawnSpheres()
{
var DistWidth = DistanceWidths[DifficultyIndex];
var DensityNums = DensityNumbers[Index];
for (var i = 0; i < SphereNumber; i++)
for (var i = 0; i < DensityNums.y; i++)
{
var angle = i * Mathf.PI * 2 / SphereNumber;
var pos = new Vector3(Mathf.Cos(angle), Mathf.Sin(angle), 0) * DistWidth.x;
var sphere = Instantiate(SphereTemplate);
sphere.transform.localScale *= DistWidth.y;
var pos = UnityEngine.Random.insideUnitSphere * DensityNums.x;
var sphere = Instantiate(SphereTemplate, pos, Quaternion.identity);
var clickComp = sphere.GetComponent<ClickableSphere>();
Spheres.Add(clickComp);
sphere.transform.position = pos;
sphere.name += i;
}
var firstActive = Spheres[UnityEngine.Random.Range(0, SphereNumber - 1)];
firstActive.SetActive(true);
CurrentActive = firstActive;
CalcPixelDistances();
}
public void NextActive()
......@@ -62,9 +53,24 @@ public class SphereHandler : MonoBehaviour
return;
}
var len = Spheres.Count;
ActivateRandomSphere();
}
public void ActivateRandomSphere()
{
var idx = Spheres.IndexOf(CurrentActive);
var newIdx = (idx + Mathf.CeilToInt(len * 0.5f)) % len;
int newIdx = idx;
int maxTries = 100;
int i = 0;
while ((newIdx == idx || !SphereValid(Spheres[newIdx])) && i < maxTries)
{
newIdx = UnityEngine.Random.Range(0, Spheres.Count - 1);
i++;
}
if (i >= maxTries)
Debug.Log("Didnt find a sphere");
ClickableSphere newActive = Spheres[newIdx];
if (CurrentActive != null)
......@@ -76,10 +82,46 @@ public class SphereHandler : MonoBehaviour
CurrentActive.SetActive(true);
}
private bool SphereValid(ClickableSphere sphere)
{
bool foundOcclusion = false;
bool foundHit = false;
for (int i = 0; i < 100; i++)
{
var randomPoint = sphere.transform.position + (UnityEngine.Random.onUnitSphere * 0.5f);
var screenPoint = Camera.main.WorldToScreenPoint(randomPoint);
var ray = Camera.main.ScreenPointToRay(screenPoint);
if (Physics.Raycast(ray, out RaycastHit hit, 1000.0f))
{
if (hit.transform.gameObject == sphere.gameObject)
{
foundHit = true;
Debug.Log("Hit the sphere again");
}
else if (hit.transform.name == "Wall")
{
Debug.Log("Hit the wall");
}
else
{
Debug.Log("Hit another sphere");
foundOcclusion = true;
}
}
if (foundHit && foundOcclusion)
{
Debug.Log("Found a partially occluded sphere");
return true;
}
}
return foundHit && foundOcclusion;
}
public void NextDifficulty()
{
DifficultyIndex++;
if (DifficultyIndex >= DistanceWidths.Count)
Index++;
if (Index >= DensityNumbers.Count)
{
TestFinished?.Invoke(this, new EventArgs());
return;
......@@ -92,26 +134,18 @@ public class SphereHandler : MonoBehaviour
Spheres.Clear();
SpawnSpheres();
ActivateRandomSphere();
CurrentSphereSwitches = 0;
}
// Update is called once per frame
void Update()
public int GetCurrentSphereNumbers()
{
return (int)DensityNumbers[Index].y;
}
private void CalcPixelDistances()
public float GetCurrentDensity()
{
var DistWidth = DistanceWidths[DifficultyIndex];
var spherePos = CurrentActive.transform.position;
var spherePosRad = new Vector3(spherePos.x + DistWidth.y, spherePos.y, spherePos.z);
var pixelPosSphere = Camera.main.WorldToScreenPoint(spherePos);
var pixelPosRad = Camera.main.WorldToScreenPoint(spherePosRad);
AmplitudePixel = Vector3.Distance(pixelPosSphere, pixelPosRad);
var ringCenter = new Vector3();
var pixelRingCenter = Camera.main.WorldToScreenPoint(ringCenter);
DistancePixel = Vector3.Distance(pixelRingCenter, pixelPosSphere);
return DensityNumbers[Index].x;
}
}
......@@ -38,7 +38,7 @@ public class TestHandler : MonoBehaviour
SphereHandler.DifficultyFinished += (sender, args) =>
{
Logger.SaveData(SphereHandler.DifficultyIndex);
Logger.SaveData(SphereHandler.Index);
Logger.ClearData();
SphereHandler.NextDifficulty();
};
......@@ -48,11 +48,6 @@ public class TestHandler : MonoBehaviour
};
SphereHandler.SpawnSpheres();
}
// Update is called once per frame
void Update()
{
SphereHandler.ActivateRandomSphere();
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment