Maintain tracker correction until it times out

This commit is contained in:
Marek S. Łukasiewicz 2025-03-10 10:03:15 +01:00
parent c7f7f85992
commit 2c72168568
3 changed files with 21 additions and 11 deletions

View file

@ -57,7 +57,6 @@ scons platform=windows use_mingw=yes use_llvm=yes
## Roadmap ## 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 - Try to have some acceptable setup for Varjo even without the tracker
- Rework the fly area - Rework the fly area
- Make it bigger - Make it bigger

View file

@ -19,42 +19,47 @@ var _rotor_azimuth: float = 0
@onready var xr_origin: XROrigin3D = $AttitudeRoot/PilotEyes/PilotFloor/XROrigin3D @onready var xr_origin: XROrigin3D = $AttitudeRoot/PilotEyes/PilotFloor/XROrigin3D
@onready var tracker: XRController3D = $AttitudeRoot/PilotEyes/PilotFloor/XROrigin3D/ViveTracker @onready var tracker: XRController3D = $AttitudeRoot/PilotEyes/PilotFloor/XROrigin3D/ViveTracker
@onready var xr_camera: XRCamera3D = $AttitudeRoot/PilotEyes/PilotFloor/XROrigin3D/XRCamera3D @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_cg: int = skeleton.find_bone("BodyCG")
@onready var bone_cyclic: int = skeleton.find_bone("Cyclic") @onready var bone_cyclic: int = skeleton.find_bone("Cyclic")
@onready var bone_rotor: int = skeleton.find_bone("Rotor") @onready var bone_rotor: int = skeleton.find_bone("Rotor")
func _process(delta: float) -> void: func _process(delta: float) -> void:
var target := connector.get_aircraft() var target: Transform3D = connector.get_aircraft()
position = target.origin position = target.origin
# Add the rotation to the correct bone for rotation around CG # Add the rotation to the correct bone for rotation around CG
var rest := skeleton.get_bone_rest(bone_cg).basis.get_rotation_quaternion() var rest: Quaternion = skeleton.get_bone_rest(bone_cg).basis.get_rotation_quaternion()
var attitude := target.basis.get_rotation_quaternion() var attitude: Quaternion = target.basis.get_rotation_quaternion()
skeleton.set_bone_pose_rotation(bone_cg, attitude * rest) skeleton.set_bone_pose_rotation(bone_cg, attitude * rest)
# Rotate other children (not using BoneAttachment3D due to jitter) # Rotate other children (not using BoneAttachment3D due to jitter)
attitude_root.rotation = target.basis.get_euler() attitude_root.rotation = target.basis.get_euler()
# Rotate the cyclic stick bone # Rotate the cyclic stick bone
var cyclic := connector.get_cyclic() var cyclic: Vector2 = connector.get_cyclic()
var cyc_rest := skeleton.get_bone_rest(bone_cyclic).basis.get_rotation_quaternion() var cyc_rest: Quaternion= skeleton.get_bone_rest(bone_cyclic).basis.get_rotation_quaternion()
var cyc_angles_rad := cyclic * deg_to_rad(range_cyclic) 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)) 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) skeleton.set_bone_pose_rotation(bone_cyclic, cyc_att * cyc_rest)
# Spin the rotor only when receiving flight data # Spin the rotor only when receiving flight data
if connector.get_model_connected(): if connector.get_model_connected():
_rotor_azimuth += rotor_rpm * 2 * PI / 60 * delta _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)) var rotor_att := Quaternion.from_euler(Vector3(0, _rotor_azimuth, 0))
# Note that this is reverse order, to rotate in local bone axes # Note that this is reverse order, to rotate in local bone axes
skeleton.set_bone_pose_rotation(bone_rotor, rotor_rest * rotor_att) 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(): 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() xr_origin.transform = tracker_mount.transform * tracker.transform.affine_inverse()
else: 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 xr_origin.transform = Transform3D.IDENTITY
func _on_vr_setup_failed() -> void: func _on_vr_setup_failed() -> void:

View file

@ -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) transform = Transform3D(0.25, 0, 0, 0, 0.25, 0, 0, 0, 0.25, 0, 0, 0)
visible = false 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"] [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) 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" hostname = "192.168.1.2"
[connection signal="use_fallback" from="." to="AttitudeRoot/PilotEyes" method="_on_aircraft_use_fallback"] [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"] [editable path="Mi-2"]