switch to quaternions for offset rotation

This commit is contained in:
Crispy 2021-05-22 14:58:55 +02:00
parent 1cca61aac2
commit 53ace41594
3 changed files with 23 additions and 22 deletions

View file

@ -19,10 +19,6 @@ transform = Transform( -4.37114e-08, -0.707107, -0.707107, 0, -0.707107, 0.70710
overlay_scene = ExtResource( 3 ) overlay_scene = ExtResource( 3 )
width_meters = 0.1 width_meters = 0.1
[node name="OverlayInstance Battery" parent="." instance=ExtResource( 1 )]
transform = Transform( -4.37114e-08, -0.707107, -0.707107, 0, -0.707107, 0.707107, -1, 3.09086e-08, 3.09086e-08, -0.12, 0, 0.1 )
overlay_scene = ExtResource( 7 )
[node name="OverlayInstance UI demo" parent="." instance=ExtResource( 1 )] [node name="OverlayInstance UI demo" parent="." instance=ExtResource( 1 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.25 ) transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.25 )
overlay_scene = ExtResource( 5 ) overlay_scene = ExtResource( 5 )
@ -31,5 +27,8 @@ overlay_scene = ExtResource( 5 )
[node name="XYZ Widget" parent="." instance=ExtResource( 4 )] [node name="XYZ Widget" parent="." instance=ExtResource( 4 )]
[editable path="OverlayInstance UI demo"] [node name="OverlayInstance Battery" parent="." instance=ExtResource( 1 )]
transform = Transform( -4.37114e-08, -0.707107, -0.707107, 0, -0.707107, 0.707107, -1, 3.09086e-08, 3.09086e-08, -0.12, 0, 0.1 )
overlay_scene = ExtResource( 7 )
[editable path="OverlayInstance UI demo/OverlayInteraction"] [editable path="OverlayInstance UI demo/OverlayInteraction"]

View file

@ -60,26 +60,27 @@ func begin_move():
_mover_hand_offsets.rot = get_parent().rotation _mover_hand_offsets.rot = get_parent().rotation
# offset from active controller to overlay # offset from active controller to overlay
var global_rot = _overlay_area.global_transform.basis.get_rotation_quat()
var global_rot = _overlay_area.global_transform.basis.get_euler() # var global_rot = _overlay_area.get_parent().transform.basis.get_rotation_quat() * _overlay_area.transform.basis.get_rotation_quat()
get_parent().offsets[_mover_hand_name].rot = global_rot - _active_controller.rotation var hand_rot = _active_controller.transform.basis.get_rotation_quat()
get_parent().offsets[_mover_hand_name].rot = global_rot * (hand_rot.inverse())
get_parent().offsets[_mover_hand_name].pos = _active_controller.transform.xform_inv(_overlay_area.global_transform.origin) get_parent().offsets[_mover_hand_name].pos = _active_controller.transform.xform_inv(_overlay_area.global_transform.origin)
get_parent().current_target = _mover_hand_name get_parent().current_target = _mover_hand_name
get_parent().update_tracker_id() # get_parent().update_tracker_id()
get_parent().update_offset() # get_parent().update_offset()
func finish_move(): func finish_move():
is_moving = false is_moving = false
var new_pos = tracker_nodes[_pre_move_target].transform.xform_inv(_overlay_area.global_transform.origin) var new_pos = tracker_nodes[_pre_move_target].transform.xform_inv(_overlay_area.global_transform.origin)
# this is only local rotations??
var new_rot = _overlay_area.get_parent().rotation + _overlay_area.rotation - tracker_nodes[_pre_move_target].rotation var new_rot = _overlay_area.get_parent().rotation + _overlay_area.rotation - tracker_nodes[_pre_move_target].rotation
get_parent().update_current_target() get_parent().update_current_target()
get_parent().update_tracker_id() get_parent().update_tracker_id()
get_parent().offsets[get_parent().current_target].pos = new_pos get_parent().offsets[get_parent().current_target].pos = new_pos
get_parent().offsets[get_parent().current_target].rot = new_rot # get_parent().offsets[get_parent().current_target].rot = new_rot
get_parent().update_offset() get_parent().update_offset()
_update_target() _update_target()
@ -133,15 +134,15 @@ func _on_OverlayArea_entered(body: Node) -> void:
if body.get_node("../../..") != self or is_moving: if body.get_node("../../..") != self or is_moving:
return return
_touch_state = true _touch_state = true
if not is_moving:
_active_controller = body.get_parent() _active_controller = body.get_parent()
emit_signal("touch_on") emit_signal("touch_on")
func _on_OverlayArea_exited(body: Node) -> void: func _on_OverlayArea_exited(body: Node) -> void:
if body.get_node("../../..") != self: if body.get_node("../../..") != self or is_moving:
return return
# TEMP # TEMP
if not is_moving:
_active_controller = null # TODO revert to other controller if both were touching (edge case) _active_controller = null # TODO revert to other controller if both were touching (edge case)
_touch_state = false _touch_state = false
emit_signal("touch_off") emit_signal("touch_off")

View file

@ -12,10 +12,10 @@ export var overlay_scene =\
export var width_meters = 0.4 setget set_width_in_meters export var width_meters = 0.4 setget set_width_in_meters
export var offsets:Dictionary = { export var offsets:Dictionary = {
"head": {"pos": Vector3(), "rot": Vector3()}, "head": {"pos": Vector3(), "rot": Quat()},
"left": {"pos": Vector3(), "rot": Vector3()}, "left": {"pos": Vector3(), "rot": Quat()},
"right": {"pos": Vector3(), "rot": Vector3()}, "right": {"pos": Vector3(), "rot": Quat()},
"world": {"pos": Vector3(), "rot": Vector3()} "world": {"pos": Vector3(), "rot": Quat()}
} }
# also contains temp offset that is created when dragged # also contains temp offset that is created when dragged
@ -30,7 +30,7 @@ onready var container = $OverlayViewport/Container
func _ready() -> void: func _ready() -> void:
# TEMP # TEMP
offsets.left.pos = translation offsets.left.pos = translation
offsets.left.rot = rotation offsets.left.rot = transform.basis.get_rotation_quat()
### ###
ARVRServer.connect("tracker_added", self, "_tracker_changed") ARVRServer.connect("tracker_added", self, "_tracker_changed")
@ -63,7 +63,7 @@ func update_tracker_id() -> void:
func update_offset() -> void: func update_offset() -> void:
translation = offsets[current_target].pos translation = offsets[current_target].pos
rotation = offsets[current_target].rot transform.basis = Basis(offsets[current_target].rot)
match current_target: match current_target:
"head": "head":
@ -97,6 +97,7 @@ func set_target(new: String):
func _set_current_target(new: String): # overrides target func _set_current_target(new: String): # overrides target
current_target = new current_target = new
update_tracker_id()
update_offset() update_offset()
emit_signal("target_changed") emit_signal("target_changed")