mirror of
https://github.com/CrispyPin/ovr-utils.git
synced 2024-11-10 02:40:25 +01:00
switch to quaternions for offset rotation
This commit is contained in:
parent
1cca61aac2
commit
53ace41594
3 changed files with 23 additions and 22 deletions
|
@ -19,10 +19,6 @@ transform = Transform( -4.37114e-08, -0.707107, -0.707107, 0, -0.707107, 0.70710
|
|||
overlay_scene = ExtResource( 3 )
|
||||
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 )]
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.25 )
|
||||
overlay_scene = ExtResource( 5 )
|
||||
|
@ -31,5 +27,8 @@ overlay_scene = ExtResource( 5 )
|
|||
|
||||
[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"]
|
||||
|
|
|
@ -60,26 +60,27 @@ func begin_move():
|
|||
_mover_hand_offsets.rot = get_parent().rotation
|
||||
|
||||
# offset from active controller to overlay
|
||||
|
||||
var global_rot = _overlay_area.global_transform.basis.get_euler()
|
||||
get_parent().offsets[_mover_hand_name].rot = global_rot - _active_controller.rotation
|
||||
var global_rot = _overlay_area.global_transform.basis.get_rotation_quat()
|
||||
# var global_rot = _overlay_area.get_parent().transform.basis.get_rotation_quat() * _overlay_area.transform.basis.get_rotation_quat()
|
||||
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().current_target = _mover_hand_name
|
||||
get_parent().update_tracker_id()
|
||||
get_parent().update_offset()
|
||||
# get_parent().update_tracker_id()
|
||||
# get_parent().update_offset()
|
||||
|
||||
|
||||
func finish_move():
|
||||
is_moving = false
|
||||
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
|
||||
get_parent().update_current_target()
|
||||
get_parent().update_tracker_id()
|
||||
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()
|
||||
_update_target()
|
||||
|
||||
|
@ -133,16 +134,16 @@ func _on_OverlayArea_entered(body: Node) -> void:
|
|||
if body.get_node("../../..") != self or is_moving:
|
||||
return
|
||||
_touch_state = true
|
||||
_active_controller = body.get_parent()
|
||||
if not is_moving:
|
||||
_active_controller = body.get_parent()
|
||||
emit_signal("touch_on")
|
||||
|
||||
|
||||
func _on_OverlayArea_exited(body: Node) -> void:
|
||||
if body.get_node("../../..") != self:
|
||||
if body.get_node("../../..") != self or is_moving:
|
||||
return
|
||||
# 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
|
||||
emit_signal("touch_off")
|
||||
|
||||
|
|
|
@ -12,10 +12,10 @@ export var overlay_scene =\
|
|||
export var width_meters = 0.4 setget set_width_in_meters
|
||||
|
||||
export var offsets:Dictionary = {
|
||||
"head": {"pos": Vector3(), "rot": Vector3()},
|
||||
"left": {"pos": Vector3(), "rot": Vector3()},
|
||||
"right": {"pos": Vector3(), "rot": Vector3()},
|
||||
"world": {"pos": Vector3(), "rot": Vector3()}
|
||||
"head": {"pos": Vector3(), "rot": Quat()},
|
||||
"left": {"pos": Vector3(), "rot": Quat()},
|
||||
"right": {"pos": Vector3(), "rot": Quat()},
|
||||
"world": {"pos": Vector3(), "rot": Quat()}
|
||||
}
|
||||
# also contains temp offset that is created when dragged
|
||||
|
||||
|
@ -30,7 +30,7 @@ onready var container = $OverlayViewport/Container
|
|||
func _ready() -> void:
|
||||
# TEMP
|
||||
offsets.left.pos = translation
|
||||
offsets.left.rot = rotation
|
||||
offsets.left.rot = transform.basis.get_rotation_quat()
|
||||
###
|
||||
|
||||
ARVRServer.connect("tracker_added", self, "_tracker_changed")
|
||||
|
@ -63,7 +63,7 @@ func update_tracker_id() -> void:
|
|||
|
||||
func update_offset() -> void:
|
||||
translation = offsets[current_target].pos
|
||||
rotation = offsets[current_target].rot
|
||||
transform.basis = Basis(offsets[current_target].rot)
|
||||
|
||||
match current_target:
|
||||
"head":
|
||||
|
@ -97,6 +97,7 @@ func set_target(new: String):
|
|||
|
||||
func _set_current_target(new: String): # overrides target
|
||||
current_target = new
|
||||
update_tracker_id()
|
||||
update_offset()
|
||||
emit_signal("target_changed")
|
||||
|
||||
|
|
Loading…
Reference in a new issue