Skip to content

Commit de3e48d

Browse files
committed
.
1 parent 3eb4b41 commit de3e48d

12 files changed

Lines changed: 62 additions & 24 deletions

Scenes/Backends/DebugBackend.tscn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Camera = NodePath("Camera3D")
99
ElementRoot = NodePath("ElementRoot")
1010

1111
[node name="Camera3D" type="Camera3D" parent="."]
12-
transform = Transform3D(1, 0, 0, 0, 0.9076164, 0.4198006, 0, -0.4198006, 0.9076164, 0, 1.8, 0)
12+
transform = Transform3D(0.99999994, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.8, 0)
1313
current = true
1414

1515
[node name="ElementRoot" type="Node" parent="."]

Scripts/Backends/DebugBackend.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public override void _Process(double delta)
3939
_currentRotation = _currentRotation with { Y = Mathf.Clamp(_currentRotation.Y, -Mathf.Pi / 2, Mathf.Pi / 2) };
4040

4141
Camera.Transform = new Transform3D(Basis.FromEuler(new Vector3(_currentRotation.Y, _currentRotation.X, 0)),
42-
Vector3.Up * 1.8f);
42+
(Vector3.Up * 1.8f) + Vector3.Left);
4343
}
4444

4545
public ElementBase CreateHeadElement()

Scripts/MainScene.cs

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public partial class MainScene : Node
2121

2222
private bool _sendPackets = true;
2323

24+
public Transform3D OriginOffset { get; private set; }
25+
2426
public override void _Ready()
2527
{
2628
base._Ready();
@@ -39,14 +41,24 @@ public override void _Ready()
3941
var xrInterface = XRServer.FindInterface("OpenXR");
4042
if (xrInterface != null && xrInterface.IsInitialized()) enableXr = true;
4143

42-
foreach (var item in argsLower)
44+
var os = OS.GetName();
45+
var device = OS.GetModelName().ToLower();
46+
if (os == "Android")
4347
{
44-
if (item == "--use-openvr") enableOpenVr = true;
45-
else if (item == "--use-debug") enableDebug = true;
46-
else if (item == "--use-openxr-overlay") enableXrOverlay = true;
47-
else if (item == "--test-routines") enableTestRoutines = true;
48+
enableXr = true;
49+
if (device.Contains("pico")) enableXrOverlay = true; //only monado and pico support overlays
4850
}
49-
51+
else
52+
{
53+
foreach (var item in argsLower)
54+
{
55+
if (item == "--use-openvr") enableOpenVr = true;
56+
else if (item == "--use-debug") enableDebug = true;
57+
else if (item == "--use-openxr-overlay") enableXrOverlay = true;
58+
else if (item == "--test-routines") enableTestRoutines = true;
59+
}
60+
}
61+
5062
if (!enableOpenVr && !enableXr && !enableDebug) throw new Exception("Invalid configuration, no backend provided");
5163
if (enableOpenVr && (enableXr || enableXrOverlay)) throw new Exception("Invalid configuration, OpenXR cannot be enabled at the same time as OpenVR");
5264
if (enableXrOverlay && !enableXr) throw new Exception("Invalid configuration, OpenXR must be enabled to use OpenXR Overlay");
@@ -70,10 +82,8 @@ public override void _Ready()
7082
//test.SendPacket(new RunFixedLenghtRoutinePacket("debug"));
7183
test.SendPacket(new RunVariableLenghtRoutinePacket("convergencetutorial", TimeSpan.FromSeconds(5)));
7284
await Task.Delay(5000);
73-
test.SendPacket(new RunFixedLenghtRoutinePacket("startsound"));
7485
test.SendPacket(new RunVariableLenghtRoutinePacket("convergence", TimeSpan.FromSeconds(20)));
7586
await Task.Delay(20000);
76-
test.SendPacket(new RunFixedLenghtRoutinePacket("endsound"));
7787
});
7888
}
7989
else
@@ -107,6 +117,17 @@ public override void _Ready()
107117
Backend.Initialize();
108118

109119
StartRoutine<TextRoutine>(RoutineHelpers.LabelRoutineArgs(Tr(ConnectingString), true, Transform3D.Identity.TranslatedLocal(Vector3.Forward)));
120+
121+
Task.Run(async () =>
122+
{
123+
await Task.Delay(50);
124+
var headTransform = Backend.HeadTransform();
125+
var position = headTransform.Origin with { Y = 0 };
126+
var projected = ((headTransform.Basis.GetRotationQuaternion() * Vector3.Forward) with { Y = 0 }).Normalized();
127+
var newQuaternion = new Quaternion(Vector3.Forward, projected);
128+
129+
OriginOffset = new Transform3D(new Basis(newQuaternion), position);
130+
});
110131
}
111132
private static readonly StringName ConnectingString = "Connecting";
112133
public void SendPacket<T>(T packet) where T : IPacket
@@ -168,12 +189,15 @@ public void StartRoutine(string name, float time = 0)
168189
case "trainer":
169190
StartRoutine<GraphRoutine>();
170191
break;
192+
/*
171193
case "startsound":
172194
PlaySound(StartSound);
173195
break;
174196
case "endsound":
175197
PlaySound(EndSound);
176198
break;
199+
*/
200+
//blame red
177201
case "close":
178202
GetTree().Quit();
179203
break;
@@ -187,7 +211,8 @@ void StartTextTimerRoutine(string text) =>
187211
StartRoutine<TextTimerRoutine>(RoutineHelpers.LabelTimerRoutineArgs(text,
188212
time, true, Transform3D.Identity.TranslatedLocal(Vector3.Forward)));
189213
}
190-
214+
public void PlayStartSound() => PlaySound(StartSound);
215+
public void PlayEndSound() => PlaySound(EndSound);
191216
private void PlaySound(AudioStream stream)
192217
{
193218
_audioPlayer.Stop();
@@ -210,7 +235,7 @@ public override void _Process(double delta)
210235
CurrentRoutine.Initialize(Backend, args);
211236

212237
var elem = Backend.CreateElementWithObject(ResourceLoader.Load<PackedScene>("res://Scenes/Routines/FloorIndicator.tscn").Instantiate<PanelContainer>());
213-
elem.ElementTransform = new Transform3D(new Basis(new Quaternion(Vector3.Forward, Vector3.Down)), Vector3.Up * 0.001f);
238+
elem.ElementTransform = OriginOffset * new Transform3D(new Basis(new Quaternion(Vector3.Forward, Vector3.Down)), Vector3.Up * 0.001f);
214239
elem.ElementWidth = 1.5f;
215240
}
216241
}

Scripts/RoutineBase.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,22 @@ namespace BabbleCalibration.Scripts;
55

66
public abstract class RoutineBase
77
{
8+
public virtual bool PlaySounds => false;
9+
protected Transform3D OriginOffset => MainScene.Instance.OriginOffset;
810
public IBackend Backend { get; private set; }
911

10-
public virtual void Initialize(IBackend backend, Dictionary args = null) => Backend = backend;
12+
public virtual void Initialize(IBackend backend, Dictionary args = null)
13+
{
14+
Backend = backend;
15+
if (PlaySounds) MainScene.Instance.PlayStartSound();
16+
}
17+
1118
public virtual void Update(float delta){}
12-
public virtual void End(){}
19+
20+
public virtual void End()
21+
{
22+
if (PlaySounds) MainScene.Instance.PlayEndSound();
23+
}
1324

1425
public static T LoadScene<T>(string path) where T : Node => ResourceLoader.Load<PackedScene>(path).Instantiate<T>();
1526
}

Scripts/Routines/ConvergenceRoutine.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace BabbleCalibration.Scripts.Routines;
99

1010
public class ConvergenceRoutine : RoutineBase
1111
{
12+
public override bool PlaySounds => true;
1213
private Transform3D _transform = Transform3D.Identity;
1314
private float _height;
1415
private float _currentTime;
@@ -42,7 +43,7 @@ private void UpdateTransform()
4243
{
4344
const float interval = 2;
4445
var lerp = InOut(Mathf.PingPong(_currentTime, interval) / interval, 0, 1, 1);
45-
_transform = Transform3D.Identity.TranslatedLocal((Vector3.Forward * 0.5f).Lerp(Vector3.Forward * 2, lerp) + (Vector3.Up * _height));
46+
_transform = OriginOffset * Transform3D.Identity.TranslatedLocal((Vector3.Forward * 0.5f).Lerp(Vector3.Forward * 2, lerp) + (Vector3.Up * _height));
4647
_element.ElementTransform = _transform;
4748
}
4849

Scripts/Routines/DebugRoutine.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace BabbleCalibration.Scripts.Routines;
55

66
public class DebugRoutine : RoutineBase
77
{
8+
public override bool PlaySounds => true;
89
public override void Initialize(IBackend backend, Dictionary args = null)
910
{
1011
base.Initialize(backend, args);
@@ -30,7 +31,7 @@ void CreateAxis(Vector3 direction, string text, Color color)
3031
var elem = backend.CreateElementWithObject(label);
3132

3233
var rotation = new Quaternion(Vector3.Forward, direction);
33-
elem.ElementTransform = new Transform3D(new Basis(rotation), direction + up);
34+
elem.ElementTransform = OriginOffset * new Transform3D(new Basis(rotation), direction + up);
3435
}
3536
}
3637
}

Scripts/Routines/DilationRoutine.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace BabbleCalibration.Scripts.Routines;
66

77
public class DilationRoutine : RoutineBase
88
{
9+
public override bool PlaySounds => true;
910
private GradientTexture1D _texture = new();
1011
private Gradient _gradient = new();
1112
private Stopwatch _stopwatch = new();

Scripts/Routines/ImageRoutine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public override void Initialize(IBackend backend, Dictionary args = null)
2929
var (element, interf) = this.Load<TextureRoutineInterface>("res://Scenes/Routines/ImageRoutine.tscn", head);
3030
interf.TextureRect.Texture = ResourceLoader.Load<Texture2D>(imagePath);
3131
interf.Label.Text = text;
32-
element.ElementTransform = transform;
32+
element.ElementTransform = (head ? Transform3D.Identity : OriginOffset) * transform;
3333
}
3434
}
3535
}

Scripts/Routines/ReticleRoutine.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace BabbleCalibration.Scripts.Routines;
88

99
public class ReticleRoutine : RoutineBase
1010
{
11+
public override bool PlaySounds => true;
1112
private Transform3D _transform = Transform3D.Identity;
1213
public override void Initialize(IBackend backend, Dictionary args = null)
1314
{
@@ -22,11 +23,9 @@ public override void Initialize(IBackend backend, Dictionary args = null)
2223
time = value.AsSingle();
2324

2425
var (element, interf) = this.Load<ProgressCircle>("res://Scenes/Routines/ProgressCircle.tscn");
25-
element.ElementTransform = transform;
26-
element.ElementWidth = 0.1f;
26+
_transform = element.ElementTransform = OriginOffset * transform;
27+
element.ElementWidth = 0.075f;
2728
interf.Start(time);
28-
29-
_transform = transform;
3029
}
3130
}
3231

Scripts/Routines/TextRoutine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public override void Initialize(IBackend backend, Dictionary args = null)
2626

2727
var (element, interf) = this.Load<LabelRoutineInterface>("res://Scenes/Routines/TextRoutine.tscn", head);
2828
interf.Label.Text = text;
29-
element.ElementTransform = transform;
29+
element.ElementTransform = (head ? Transform3D.Identity : OriginOffset) * transform;
3030
}
3131
}
3232
}

0 commit comments

Comments
 (0)