class_name VRPN_Tracker
extends Node3D

@export var vrpn_client : VRPN_Client = null
@export var tracker_name : String = "Tracker0"
@export var tracker_sensor : int = 0
@export var tracker_use_position : bool = true
@export var tracker_use_rotation : bool = true
@export var register_on_ready : bool = true

func _ready() -> void:
	if vrpn_client and register_on_ready:
		vrpn_client.tracker.append(self)

func _on_vrpn(vrpn_data : Dictionary):
	match vrpn_data['type'] as VRPN_Client.TrackingDataType:
		VRPN_Client.TrackingDataType.POS_QUAT:
			if vrpn_data['tracker'] == tracker_name and vrpn_data['sensor'] == tracker_sensor:
				if tracker_use_position:
					self.global_position = vrpn_data['position']
				if tracker_use_rotation:
					var rotation := vrpn_data['rotation'] as Quaternion
					self.global_basis =  Basis(rotation)
		VRPN_Client.TrackingDataType.ACCELERATION:
			pass
		VRPN_Client.TrackingDataType.VELOCITY:
			pass
		_:
			push_warning("unknown tracker datatype")

func _on_vrpn_connected(s):
	pass # Replace with function body.
