Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/rocket-launch.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ then a timer decrements until launch time is achieved.
- **LaunchController**: Attached to the rocket object. Controls the overall launch process.
- Launch time: The starting launch time in seconds. May be increased by adaptive difficulty features below.
- **Head Movement Variables**: Determine the amount of head movement required to decrement the timer.
- Head Pose Buffer Capacity (n) and speed time (s): head speed is measured as the average change in pitch or yaw over the time period speed time. The buffer will need to be sufficiently large to support the time based on game frame rate.
- Head speed time (s): head speed is measured as the average change in pitch or yaw over the time period speed time.
- Minimum head speed (pitch or yaw) required to reduce the launch timer. The yaw speed is set higher than pitch, because it is possible (for me at least) to shake my head quicker than I can nod.
- Minimum n items: the minimum number of head pose readings used to calculate a head speed

- **Steady Gaze Variables**: Determine how steady the gave must be to decrement the timer.
- Timer Duration: How long (in seconds) the player must maintain a steady gaze to increment the count down code display.
- Gaze Pose Buffer Capacity (n) and gaze time (s), gaze steadiness is measured as the standard deviation of gaze over gaze time seconds. The buffer will need to be sufficiently large to support the time based on game frame rate.
- Gaze time (s), gaze steadiness is measured as the standard deviation of gaze over gaze time seconds.
- Gaze Tolerance - the allowable gaze standard deviation to be steady. Smaller number will require steadier gaze. This may be reduced by the adaptive difficulty settings below.
- Minimum n items: the minimum number of gaze points used to calculate steadiness.
- Target Object - if this is set you are required to look at that object, if not gaze can be anywhere on screen but must be steady. The size of the target object will be matched to the gaze tolerance.
Expand Down
4 changes: 2 additions & 2 deletions docs/star-collector.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ top of the screen.
- Number of games in a row that must meet the upgrade % to increase the time limit
- The length of the time window used to evaluate player performance
- The % of stars that must be collected to increase speed or time limit
- The maximum number of head yaw readings to keep in the buffer at one time (these are used for the head speed save data)
- The minimum number of head yaw readings needed to calculate a head speed
- The number of seconds to calculate head yaw speed over
- The number of seconds between head yaw speed samples for the save data
- Whether to write sampled speeds to a text file (star-collector-speeds.txt)

- **StarGenerator**: values related to generation of the wave of stars
- Min, max and base star speed
Expand Down
3 changes: 2 additions & 1 deletion docs/zero-gravity.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The zero gravity mini-game asks the player to copy various poses, and awards poi
- The number of unity units moved per mm of head movement
- The limit of head movement before scoring stops
- The colour when the head is in / out of range
- The minimum number of seconds between increases to nTimesOutOfRange (this is the number of 'falls' for the save data). This minimum interval helps to prevent teetering on the edge of the in-range zone being counted many times.

- **PoseAvatar**: values related to display of poses
- Sprites for each pose
Expand All @@ -39,4 +40,4 @@ Data is saved to `ZeroGravityScores.csv`, with one row per pose. This means ther
- `poseTimeLimitSeconds`: the time limit in seconds for each pose
- `poseDurationSeconds`: the number of seconds the player tried this pose (rounded to the nearest second). If they completed the pose, this will be equal to poseTimeLimitSeconds; if they exited early, it will be less.
- `balanceStabilityScore`: the balance stability score for this pose (this is equal to the displayed score increase shown while playing the game). Currently, 5 points are awarded per second the player stays in bounds. If the player exited before scoring for this pose started, this value will be left blank.
- `falls`: the number of falls while holding this pose. A 'fall' is counted each time the player's head moves out of bounds - for example, if they move too far left or right (in the game, this causes the sway line to change colour from white to black), or the tracker can no longer detect the player (for example, if they step backwards too far). If the player exited before scoring for this pose started, this value will be left blank.
- `falls`: the number of falls while holding this pose. A 'fall' is counted each time the player's head moves out of bounds (with a minimum time interval between falls of `nTimesOutOfRangeCooldown` - this is adjustable on `SwayLine` as mentioned above). The player is out of bounds if, for example, they move too far left or right (in the game, this causes the sway line to change colour from white to black), or the tracker can no longer detect the player (for example, if they step backwards too far). If the player exited before scoring for this pose started, this value will be left blank.
4 changes: 4 additions & 0 deletions projects/AstroBalance/Assets/Scenes/RocketLaunch.unity
Original file line number Diff line number Diff line change
Expand Up @@ -21582,6 +21582,10 @@ PrefabInstance:
propertyPath: headPoseBufferCapacity
value: 100
objectReference: {fileID: 0}
- target: {fileID: 8902890511493098178, guid: 00c1b36d25d21214eb8e6df02c079dea, type: 3}
propertyPath: samplingIntervalSeconds
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 8902890511493098178, guid: 00c1b36d25d21214eb8e6df02c079dea, type: 3}
propertyPath: countDownSprites.Array.size
value: 10
Expand Down
2 changes: 1 addition & 1 deletion projects/AstroBalance/Assets/Scenes/StarCollector.unity
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,9 @@ MonoBehaviour:
difficultyWindowSeconds: 10
speedUpgradePercent: 60
timeLimitUpgradePercent: 60
maxNItemsInBuffer: 100
minNItemsForSpeed: 5
samplingIntervalSeconds: 0.5
writeSampledSpeeds: 0
--- !u!4 &847101234
Transform:
m_ObjectHideFlags: 0
Expand Down
4 changes: 4 additions & 0 deletions projects/AstroBalance/Assets/Scenes/ZeroGravity.unity
Original file line number Diff line number Diff line change
Expand Up @@ -2094,6 +2094,10 @@ PrefabInstance:
propertyPath: poseHoldTimer
value:
objectReference: {fileID: 1701992181}
- target: {fileID: 8594660642365272174, guid: 0cb2dfec0947b7748a27c676454475c0, type: 3}
propertyPath: nTimesOutOfRangeCooldown
value: 0.5
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
Expand Down
35 changes: 17 additions & 18 deletions projects/AstroBalance/Assets/Scripts/RocketLaunch/LaunchControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ public class LaunchControl : MonoBehaviour
private float launchTime = 30;

[Header("Head Movement Variables")]
[SerializeField, Tooltip("The capacity of the head pose buffer to use.")]
private int headPoseBufferCapacity = 100;

[SerializeField, Tooltip("The time in seconds to measure head speed over.")]
private float speedTime = 2.0f;

Expand All @@ -43,9 +40,6 @@ public class LaunchControl : MonoBehaviour
[SerializeField, Tooltip("Time between new random numbers in seconds.")]
private float timerDuration = 1.0F;

[SerializeField, Tooltip("The capacity of the gaze buffer to use.")]
private int gazeBufferCapacity = 100;

[SerializeField, Tooltip("The time in seconds that the gaze should be steady for.")]
private float gazeTime = 3.0f;

Expand Down Expand Up @@ -177,13 +171,17 @@ void Awake()

InitialiseTarget();

headPoseBuffer = new HeadPoseBuffer(headPoseBufferCapacity, minNItemsForSpeed);
// Make sure buffers have a large enough capacity to cover sampling for save data + the speed/gaze steady time for gameplay
float maxSecondsOfPoseInfo = Mathf.Max(new float[] { samplingIntervalSeconds, speedTime });
float maxSecondsOfGazeInfo = Mathf.Max(new float[] { samplingIntervalSeconds, gazeTime });
headPoseBuffer = new HeadPoseBuffer(maxSecondsOfPoseInfo, minNItemsForSpeed);
gazeBuffer = new GazeBuffer(maxSecondsOfGazeInfo, minNItemsForGaze);

instructionsText.text = usePitch
? "Nod your head and repeat the code to launch the rocket!"
: "Shake your head and repeat the code to launch the rocket!";
timeToLaunch = launchTime;
timeToNextSample = samplingIntervalSeconds;
gazeBuffer = new GazeBuffer(gazeBufferCapacity, minNItemsForGaze);
}

// Start is called once before the first execution of Update after the MonoBehaviour is created
Expand Down Expand Up @@ -416,7 +414,7 @@ private Vector2 GetTargetCentre()
private GazeItem AddToBuffers()
{
HeadPose headPose = new HeadPose();
GazeItem gazeItem = new GazeItem();
GazePoint gazePoint = new GazePoint();
if (useMouseForTracker)
{
var mousePos = Input.mousePosition;
Expand All @@ -429,21 +427,22 @@ private GazeItem AddToBuffers()
headPose.TimeStampMicroSeconds = (long)(Time.timeSinceLevelLoad * 1000000);

Vector3 mousePoseWorld = Camera.main.ScreenToWorldPoint(mousePos);
gazeItem.gazePoint.X = mousePoseWorld.x;
gazeItem.gazePoint.Y = mousePoseWorld.y;
gazeItem.gazePoint.TimeStampMicroSeconds = (long)(Time.timeSinceLevelLoad * 1000000);
gazePoint.X = mousePoseWorld.x;
gazePoint.Y = mousePoseWorld.y;
gazePoint.TimeStampMicroSeconds = (long)(Time.timeSinceLevelLoad * 1000000);
}
else
{
headPose = tracker.getHeadPose();
gazePoint = tracker.getGazePoint();

gazeItem.gazePoint = tracker.getGazePoint();
Vector2 worldGaze = tracker.ConvertGazePointToWorldCoordinates(gazeItem.gazePoint);
gazeItem.gazePoint.X = worldGaze.x;
gazeItem.gazePoint.Y = worldGaze.y;
Vector2 worldGaze = tracker.ConvertGazePointToWorldCoordinates(gazePoint);
gazePoint.X = worldGaze.x;
gazePoint.Y = worldGaze.y;
}

headPoseBuffer.addIfNew(new HeadPoseItem(headPose));
GazeItem gazeItem = new(gazePoint);
gazeBuffer.addIfNew(gazeItem);

return gazeItem;
Expand All @@ -468,9 +467,9 @@ private void writeDebugInformation(float headSpeed, GazeItem gazeItem, bool gaze
+ targetCentre.y
+ "\n"
+ "Looking here -> "
+ gazeItem.gazePoint.X
+ gazeItem.getX()
+ ", "
+ gazeItem.gazePoint.Y
+ gazeItem.getY()
+ "\n"
+ steadyText;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using TMPro;
using Tobii.GameIntegration.Net;
Expand Down Expand Up @@ -50,21 +51,21 @@ public class StarCollectorManager : MonoBehaviour
]
private int timeLimitUpgradePercent = 60;

[
SerializeField,
Tooltip("Maximum number of head yaw readings to keep in the buffer at one time")
]
private int maxNItemsInBuffer = 100;

[
SerializeField,
Tooltip("The minimum number of head yaw readings needed to calculate a head speed")
]
private int minNItemsForSpeed = 5;

[SerializeField, Tooltip("The number of seconds to calculate head yaw speed over")]
[SerializeField, Tooltip("The interval between head yaw speed samples for the save data")]
private float samplingIntervalSeconds = 0.5f;

[
SerializeField,
Tooltip("Whether to write sampled speeds to a file called star-collector-speeds.txt")
]
private bool writeSampledSpeeds = false;

private TextMeshProUGUI winText;
private Tracker tracker;
private int timeLimit;
Expand Down Expand Up @@ -94,7 +95,7 @@ void Start()
score = 0;
scoreText.text = score.ToString();

headPoseBuffer = new HeadPoseBuffer(maxNItemsInBuffer, minNItemsForSpeed);
headPoseBuffer = new HeadPoseBuffer(samplingIntervalSeconds, minNItemsForSpeed);
timer.StartCountdown(timeLimit);

speedWindowStart = Time.time;
Expand Down Expand Up @@ -348,6 +349,16 @@ private void SaveGameData(bool gameComplete)
gameData.gameNumber = saveData.GetNextGameNumber();
saveData.Save(gameData);

if (writeSampledSpeeds)
{
string filePath = Path.Combine(
Application.persistentDataPath,
"star-collector-speeds.txt"
);
IEnumerable<string> lines = headYawSpeeds.Select(v => v.ToString());
File.WriteAllLines(filePath, lines);
}

// Update save data for this session
if (gameComplete)
{
Expand Down
47 changes: 46 additions & 1 deletion projects/AstroBalance/Assets/Scripts/TrackerBuffers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using Tobii.GameIntegration.Net;
using UnityEngine;

/// <summary>
/// Head pose rotation and position axes
Expand Down Expand Up @@ -29,6 +30,14 @@ class HeadPoseBuffer : TobiiBuffer<HeadPoseItem>
public HeadPoseBuffer(int capacity, int minDataRequired)
: base(capacity, minDataRequired) { }

/// <summary>
/// Initializes a new instance of the HeadPoseBuffer class.
/// </summary>
/// <param name="secondsOfData">The number of seconds of tracker data this buffer must store.</param>
/// <param name="minDataRequired">The minimum number of data points required to calculate a speed.</param>
public HeadPoseBuffer(float secondsOfData, int minDataRequired)
: base(secondsOfData, minDataRequired) { }

/// <summary>
/// Calculates the average speed of the buffer over a given time period.
/// Speed is calculated as the average change in angle (for roll / pitch / yaw) or position (X, Y, Z)
Expand Down Expand Up @@ -89,6 +98,14 @@ class GazeBuffer : TobiiBuffer<GazeItem>
public GazeBuffer(int capacity, int minDataRequired)
: base(capacity, minDataRequired) { }

/// <summary>
/// Initializes a new instance of the GazeBuffer class.
/// </summary>
/// <param name="secondsOfData">The number of seconds of tracker data this buffer must store.</param>
/// <param name="minDataRequired">The minimum number of data points required to calculate steadiness.</param>
public GazeBuffer(float secondsOfData, int minDataRequired)
: base(secondsOfData, minDataRequired) { }

/// <summary>
/// returns true if the data more recent than the time have a summed
/// square distance from the target point less than the tolerance.
Expand Down Expand Up @@ -178,7 +195,12 @@ interface ITimeStampMicroSeconds
/// </summary>
class GazeItem : ITimeStampMicroSeconds
{
public GazePoint gazePoint;
protected GazePoint gazePoint;

public GazeItem(GazePoint gazePoint)
{
this.gazePoint = gazePoint;
}

public long TimeStampMicroSeconds() => gazePoint.TimeStampMicroSeconds;

Expand Down Expand Up @@ -229,6 +251,17 @@ class TobiiBuffer<T>
protected int minDataRequired;
protected T[] buffer;

/// <summary>
/// Initializes a new instance of the <see cref="TobiiBuffer{T}"/> class.
/// </summary>
/// <param name="secondsOfData">
/// The number of seconds of tracker data this buffer must store. The max capacity will be estimated
/// based on the measured tobii refresh rate.
/// </param>
/// <param name="minDataRequired">The minimum number of data points required for calculations to be meaningful.</param>
public TobiiBuffer(float secondsOfData, int minDataRequired)
: this(EstimateCapacity(secondsOfData), minDataRequired) { }

/// <summary>
/// Initializes a new instance of the <see cref="TobiiBuffer{T}"/> class.
/// </summary>
Expand All @@ -249,6 +282,18 @@ public TobiiBuffer(int capacity, int minDataRequired)
this.minDataRequired = minDataRequired;
}

/// <summary>
/// Estimate required capacity of the buffer based on the number of seconds
/// of tracker data it must store.
/// </summary>
private static int EstimateCapacity(float secondsOfData)
{
// New tracker readings are taken ~every 0.03 seconds (measured directly from tracker during gameplay)
// We set the capacity to 1.5x the required amount based on this, to ensure we definitely
// have enough space.
return (int)Mathf.Ceil(1.5f * (secondsOfData / 0.03f));
}

/// <summary>
/// Adds a new item to the buffer if it has a different timestamp to the last added item.
/// returns true if the point was added, false otherwise.
Expand Down
Loading