From 12fd124f6d2196f2940c04ef30d294ce07532031 Mon Sep 17 00:00:00 2001 From: graf Date: Thu, 11 Jul 2019 02:27:24 +0200 Subject: [PATCH] * movement in 1st person view is only accepted if vr_mode is disabled * added a draft for a symbol of the player position in 3rd person view * but currently does not work --- Perspectives/PC/FirstPersonPC.tscn | 13 +++- Perspectives/PC/Minimap/MinimapIcon.gd | 2 +- Perspectives/PC/PlayerController.gd | 73 +++++++++++++-------- Perspectives/PC/ThirdPersonPC.tscn | 3 +- Perspectives/WireframeSupportingViewport.gd | 2 +- 5 files changed, 60 insertions(+), 33 deletions(-) diff --git a/Perspectives/PC/FirstPersonPC.tscn b/Perspectives/PC/FirstPersonPC.tscn index 9ecb55d19..a25728990 100644 --- a/Perspectives/PC/FirstPersonPC.tscn +++ b/Perspectives/PC/FirstPersonPC.tscn @@ -1,10 +1,11 @@ -[gd_scene load_steps=7 format=2] +[gd_scene load_steps=8 format=2] [ext_resource path="res://Perspectives/PC/PlayerController.gd" type="Script" id=1] [ext_resource path="res://Perspectives/PC/SettingsCamera.gd" type="Script" id=2] [ext_resource path="res://Perspectives/PC/MousePoint.tscn" type="PackedScene" id=3] [ext_resource path="res://Perspectives/PC/Minimap/MinimapIcon.tscn" type="PackedScene" id=4] [ext_resource path="res://Resources/Images/UI/MapIcons/MapCursor.png" type="Texture" id=5] +[ext_resource path="res://Resources/Images/UI/MapIcons/red_dot.png" type="Texture" id=6] [sub_resource type="CapsuleShape" id=1] @@ -35,7 +36,15 @@ transform = Transform( 1.00002, 0, 0, 0, 1, 0, 0, 0, 1.00002, 0, 0, 0 ) icon = ExtResource( 5 ) rotate = true +[node name="PlayerMarker" type="Sprite3D" parent="Head"] +layers = 4 +opacity = 0.7 +pixel_size = 1.0 +axis = 1 +texture = ExtResource( 6 ) + [node name="CollisionShape" type="CollisionShape" parent="."] -transform = Transform( 1, 0, 1.77636e-15, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 1.65595, 0 ) +transform = Transform( 1, 0, 1.77636e-015, 0, -4.37114e-008, -1, 0, 1, -4.37114e-008, 0, 1.65595, 0 ) shape = SubResource( 1 ) disabled = true + diff --git a/Perspectives/PC/Minimap/MinimapIcon.gd b/Perspectives/PC/Minimap/MinimapIcon.gd index 26070e345..55caef321 100644 --- a/Perspectives/PC/Minimap/MinimapIcon.gd +++ b/Perspectives/PC/Minimap/MinimapIcon.gd @@ -32,4 +32,4 @@ func update_icon(var texture): icon_sprite.texture = texture - icon_sprite.modulate = color_modulate \ No newline at end of file + icon_sprite.modulate = color_modulate diff --git a/Perspectives/PC/PlayerController.gd b/Perspectives/PC/PlayerController.gd index a53369602..5b908f6b0 100644 --- a/Perspectives/PC/PlayerController.gd +++ b/Perspectives/PC/PlayerController.gd @@ -13,6 +13,7 @@ var camera_angle = 0 var velocity = Vector3() var dragging : bool = false var rotating : bool = false +var _vr_mode : bool = false var walking = Settings.get_setting("player", "start-walking-enabled") @@ -24,6 +25,11 @@ onready var head = get_node("Head") onready var camera = head.get_node("Camera") +func _ready(): + GlobalSignal.connect("vr_enable", self, "_set_vr_mode", [true]) + GlobalSignal.connect("vr_disable", self, "_set_vr_mode", [false]) + + # To prevent floating point errors, the player.translation does not reflect the player's # actual position in the whole world. This function returns the true world position of # the player (in webmercator meters) as integers. @@ -37,42 +43,48 @@ func get_look_direction(): func _physics_process(delta): - fly(delta) - PlayerInfo.update_player_look_direction(get_look_direction()) + + # only change position if vr_mode is disabled + if not _vr_mode: + fly(delta) + PlayerInfo.update_player_look_direction(get_look_direction()) func _input(event): - # checks if the mouse is over the associated viewport - # FIXME: if the viewport is covered by another viewport the event is still propagated down - # TODO: input could be generalized in AbstractPlayer? - if get_viewport().get_visible_rect().has_point(get_viewport().get_mouse_position()): + # only accept input if vr mode is disabled + if not _vr_mode: - if event is InputEventMouseButton: - if event.button_index == BUTTON_LEFT: - if event.pressed: - dragging = true - else: - dragging = false - elif event.button_index == BUTTON_RIGHT: - if event.pressed: - rotating = true - else: - rotating = false - - # Rotate the camera if the event is mouse motion and the mouse is currently captured or right mouse button is pressed - if event is InputEventMouseMotion and (Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED or rotating): - head.rotate_y(deg2rad(-event.relative.x * mouse_sensitivity)) + # checks if the mouse is over the associated viewport + # FIXME: if the viewport is covered by another viewport the event is still propagated down + # TODO: input could be generalized in AbstractPlayer? + if get_viewport().get_visible_rect().has_point(get_viewport().get_mouse_position()): - var change = -event.relative.y * mouse_sensitivity + if event is InputEventMouseButton: + if event.button_index == BUTTON_LEFT: + if event.pressed: + dragging = true + else: + dragging = false + elif event.button_index == BUTTON_RIGHT: + if event.pressed: + rotating = true + else: + rotating = false - if change + camera_angle < 90 and change + camera_angle > -90: - camera.rotate_x(deg2rad(change)) - camera_angle += change + # Rotate the camera if the event is mouse motion and the mouse is currently captured or right mouse button is pressed + if event is InputEventMouseMotion and (Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED or rotating): + head.rotate_y(deg2rad(-event.relative.x * mouse_sensitivity)) - elif event.is_action_pressed("pc_toggle_walk"): - walking = not walking - + var change = -event.relative.y * mouse_sensitivity + + if change + camera_angle < 90 and change + camera_angle > -90: + camera.rotate_x(deg2rad(change)) + camera_angle += change + + elif event.is_action_pressed("pc_toggle_walk"): + walking = not walking + func fly(delta): # reset the direction of the player @@ -120,3 +132,8 @@ func fly(delta): func switch_follow_mode(): PlayerInfo.update_player_pos(translation) PlayerInfo.is_follow_enabled = !PlayerInfo.is_follow_enabled + + +func _set_vr_mode(vr_mode): + logger.info("vr mode set to %s " % [vr_mode]) + _vr_mode = vr_mode diff --git a/Perspectives/PC/ThirdPersonPC.tscn b/Perspectives/PC/ThirdPersonPC.tscn index 4b2a91b2c..6eee90d43 100644 --- a/Perspectives/PC/ThirdPersonPC.tscn +++ b/Perspectives/PC/ThirdPersonPC.tscn @@ -31,7 +31,8 @@ collision_mask = 16385 shape = SubResource( 1 ) [node name="MinimapIcon" parent="." instance=ExtResource( 4 )] -transform = Transform( 1, 0, 0, 0, 1, 5.36442e-07, 0, -5.36442e-07, 1, 0, 0, 0 ) +transform = Transform( 1, 0, 0, 0, 1, 5.36442e-007, 0, -5.36442e-007, 1, 0, 0, 0 ) icon = ExtResource( 5 ) color_modulate = Color( 0.25, 0.25, 0.25, 1 ) rotate = true + diff --git a/Perspectives/WireframeSupportingViewport.gd b/Perspectives/WireframeSupportingViewport.gd index 738b01684..b2e94b815 100644 --- a/Perspectives/WireframeSupportingViewport.gd +++ b/Perspectives/WireframeSupportingViewport.gd @@ -19,4 +19,4 @@ func _on_wireframe_toggle(toggled): if toggled: debug_draw = DEBUG_DRAW_WIREFRAME else: - debug_draw = DEBUG_DRAW_DISABLED \ No newline at end of file + debug_draw = DEBUG_DRAW_DISABLED