diff --git a/README.md b/README.md index 60ddaef..bbaa62e 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,6 @@ scons platform=windows use_mingw=yes use_llvm=yes ## Roadmap -- When having a short tracker interruption, maintain it in the same position until it times out to minimize the viewport jumps - Try to have some acceptable setup for Varjo even without the tracker - Rework the fly area - Make it bigger diff --git a/project/aircraft/aircraft.gd b/project/aircraft/aircraft.gd index fec7cca..9ecfbde 100644 --- a/project/aircraft/aircraft.gd +++ b/project/aircraft/aircraft.gd @@ -19,43 +19,48 @@ var _rotor_azimuth: float = 0 @onready var xr_origin: XROrigin3D = $AttitudeRoot/PilotEyes/PilotFloor/XROrigin3D @onready var tracker: XRController3D = $AttitudeRoot/PilotEyes/PilotFloor/XROrigin3D/ViveTracker @onready var xr_camera: XRCamera3D = $AttitudeRoot/PilotEyes/PilotFloor/XROrigin3D/XRCamera3D +@onready var recent_tracking: Timer = $AttitudeRoot/PilotEyes/PilotFloor/XROrigin3D/RecentTracking @onready var bone_cg: int = skeleton.find_bone("BodyCG") @onready var bone_cyclic: int = skeleton.find_bone("Cyclic") @onready var bone_rotor: int = skeleton.find_bone("Rotor") func _process(delta: float) -> void: - var target := connector.get_aircraft() + var target: Transform3D = connector.get_aircraft() position = target.origin # Add the rotation to the correct bone for rotation around CG - var rest := skeleton.get_bone_rest(bone_cg).basis.get_rotation_quaternion() - var attitude := target.basis.get_rotation_quaternion() + var rest: Quaternion = skeleton.get_bone_rest(bone_cg).basis.get_rotation_quaternion() + var attitude: Quaternion = target.basis.get_rotation_quaternion() skeleton.set_bone_pose_rotation(bone_cg, attitude * rest) # Rotate other children (not using BoneAttachment3D due to jitter) attitude_root.rotation = target.basis.get_euler() # Rotate the cyclic stick bone - var cyclic := connector.get_cyclic() - var cyc_rest := skeleton.get_bone_rest(bone_cyclic).basis.get_rotation_quaternion() - var cyc_angles_rad := cyclic * deg_to_rad(range_cyclic) + var cyclic: Vector2 = connector.get_cyclic() + var cyc_rest: Quaternion= skeleton.get_bone_rest(bone_cyclic).basis.get_rotation_quaternion() + var cyc_angles_rad: Vector2 = cyclic * deg_to_rad(range_cyclic) var cyc_att := Quaternion.from_euler(Vector3(cyc_angles_rad.y, cyc_angles_rad.x, 0)) skeleton.set_bone_pose_rotation(bone_cyclic, cyc_att * cyc_rest) # Spin the rotor only when receiving flight data if connector.get_model_connected(): _rotor_azimuth += rotor_rpm * 2 * PI / 60 * delta - var rotor_rest := skeleton.get_bone_rest(bone_rotor).basis.get_rotation_quaternion() + var rotor_rest: Quaternion = skeleton.get_bone_rest(bone_rotor).basis.get_rotation_quaternion() var rotor_att := Quaternion.from_euler(Vector3(0, _rotor_azimuth, 0)) # Note that this is reverse order, to rotate in local bone axes skeleton.set_bone_pose_rotation(bone_rotor, rotor_rest * rotor_att) + # Move the XR origin in such way that the tracker is in reference position if tracker.get_has_tracking_data(): - var tracker_mount = tracker_mount_platform if track_platform else tracker_mount_chair + var tracker_mount: Node3D = tracker_mount_platform if track_platform else tracker_mount_chair xr_origin.transform = tracker_mount.transform * tracker.transform.affine_inverse() - else: - xr_origin.transform = Transform3D.IDENTITY + recent_tracking.start() + +# Only reset the position when tracking is lost for some time +func _on_recent_tracking_timeout() -> void: + xr_origin.transform = Transform3D.IDENTITY func _on_vr_setup_failed() -> void: xr_camera.current = false diff --git a/project/aircraft/aircraft.tscn b/project/aircraft/aircraft.tscn index 9e9fd84..47891c9 100644 --- a/project/aircraft/aircraft.tscn +++ b/project/aircraft/aircraft.tscn @@ -55,6 +55,11 @@ tracker = &"/user/vive_tracker_htcx/role/camera" transform = Transform3D(0.25, 0, 0, 0, 0.25, 0, 0, 0, 0.25, 0, 0, 0) visible = false +[node name="RecentTracking" type="Timer" parent="AttitudeRoot/PilotEyes/PilotFloor/XROrigin3D"] +wait_time = 5.0 +one_shot = true +ignore_time_scale = true + [node name="FallbackCamera" type="Camera3D" parent="AttitudeRoot/PilotEyes"] transform = Transform3D(1, 0, 0, 0, 0.980955, 0.194234, 0, -0.194234, 0.980955, 0, 0, 0) @@ -65,5 +70,6 @@ transform = Transform3D(-0.5, -1.27582e-08, 7.43353e-08, 4.33325e-10, 0.4923, 0. hostname = "192.168.1.2" [connection signal="use_fallback" from="." to="AttitudeRoot/PilotEyes" method="_on_aircraft_use_fallback"] +[connection signal="timeout" from="AttitudeRoot/PilotEyes/PilotFloor/XROrigin3D/RecentTracking" to="." method="_on_recent_tracking_timeout"] [editable path="Mi-2"]