MVP using pos/quat

This commit is contained in:
Hartmut Seichter 2025-07-02 13:01:47 +02:00
parent 2a701c0ac7
commit 63230b7754
3 changed files with 16 additions and 18 deletions

View file

@ -1,12 +1,9 @@
[gd_scene load_steps=6 format=3 uid="uid://bj5ykdjle10tt"]
[gd_scene load_steps=5 format=3 uid="uid://bj5ykdjle10tt"]
[ext_resource type="Script" uid="uid://dmq3i7qmo1qe0" path="res://VRPN.gd" id="2_24d08"]
[ext_resource type="Script" uid="uid://dpj1wrvfsiq4v" path="res://VRPN_Receiver.gd" id="2_170dk"]
[ext_resource type="PackedScene" uid="uid://b426fy7d6jw2d" path="res://axis.blend" id="3_170dk"]
[sub_resource type="BoxMesh" id="BoxMesh_24d08"]
size = Vector3(0.1, 0.1, 0.1)
[sub_resource type="PlaneMesh" id="PlaneMesh_24d08"]
size = Vector2(6, 2)
@ -24,21 +21,21 @@ shadow_enabled = true
[node name="VRPN" type="Node3D" parent="Root" node_paths=PackedStringArray("tracker_receivers")]
script = ExtResource("2_24d08")
tracker_receivers = [NodePath("RB1"), NodePath("RB2"), NodePath("../SpinTracker/Offset0/Tracker0"), NodePath("../SpinTracker/Tracker1"), NodePath("../SpinTracker/Offset2/Tracker2")]
vrpn_server = "212.201.64.122"
[node name="RB1" type="Node3D" parent="Root/VRPN"]
script = ExtResource("2_170dk")
tracker_name = "RB1"
[node name="Box" type="MeshInstance3D" parent="Root/VRPN/RB1"]
mesh = SubResource("BoxMesh_24d08")
[node name="axis" parent="Root/VRPN/RB1" instance=ExtResource("3_170dk")]
transform = Transform3D(0.1, 0, 0, 0, 0.1, 0, 0, 0, 0.1, 0, 0, 0)
[node name="RB2" type="Node3D" parent="Root/VRPN"]
script = ExtResource("2_170dk")
tracker_name = "RB2"
[node name="Box2" type="MeshInstance3D" parent="Root/VRPN/RB2"]
mesh = SubResource("BoxMesh_24d08")
skeleton = NodePath("../../RB1")
[node name="axis" parent="Root/VRPN/RB2" instance=ExtResource("3_170dk")]
transform = Transform3D(0.1, 0, 0, 0, 0.1, 0, 0, 0, 0.1, 0, 0, 0)
[node name="Floor" type="MeshInstance3D" parent="Root"]
mesh = SubResource("PlaneMesh_24d08")
@ -49,6 +46,7 @@ mesh = SubResource("PlaneMesh_24d08")
[node name="SpinTracker" type="Node3D" parent="Root"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.764802, 0)
visible = false
[node name="Tracker1" type="Node3D" parent="Root/SpinTracker"]
script = ExtResource("2_170dk")

View file

@ -177,6 +177,8 @@ static func marshall_body(data : PackedByteArray,message_type : int, sender_id:
var quat_y = body.get_double()
var quat_z = body.get_double()
#var quat = Quaternion(quat_x,quat_y,quat_z,quat_w).normalized()
# bug? Documentation of Godot Quaternion c'tor is x,y,x,w
# but implementation follow classic w,x,y,z order
var quat = Quaternion(quat_w,quat_x,quat_y,quat_z).normalized()
for r in session.tracker_receivers:
@ -186,8 +188,6 @@ static func marshall_body(data : PackedByteArray,message_type : int, sender_id:
"position" : pos,
"rotation" : quat
})
#print("Sender:{0} Sensor:{1} Pos:{2} Quat:{3}".format([session.sensors[sender_id],sensor_id,pos,quat]))
_:
pass
#print("unhandled message type {0}".format([message_type]))

View file

@ -4,14 +4,14 @@ class_name VRPN_Receiver
@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
func _on_pos_quat(tracker_data : Dictionary):
if tracker_data['tracker'] == tracker_name and tracker_data['sensor'] == tracker_sensor:
#self.global_position = tracker_data['position']
var rotation := tracker_data['rotation'] as Quaternion
var rot_basis = Basis(rotation)
self.global_basis = rot_basis
#self.global_basis = Basis(rot_basis.z,-rot_basis.y,rot_basis.x)
if tracker_use_position:
self.global_position = tracker_data['position']
if tracker_use_rotation:
var rotation := tracker_data['rotation'] as Quaternion
self.global_basis = Basis(rotation)