Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Working on Oculus remote support #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions demo/Main.tscn
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
[gd_scene load_steps=12 format=2]
[gd_scene load_steps=13 format=2]

[ext_resource path="res://Main.gd" type="Script" id=1]
[ext_resource path="res://Milkyway.png" type="Texture" id=2]
[ext_resource path="res://Table.tscn" type="PackedScene" id=3]
[ext_resource path="res://addons/godot-oculus/scenes/oculus_first_person.tscn" type="PackedScene" id=4]
[ext_resource path="res://addons/vr-common/functions/Function_Teleport.tscn" type="PackedScene" id=5]
[ext_resource path="res://addons/vr-common/functions/Function_Direct_movement.tscn" type="PackedScene" id=6]
[ext_resource path="res://Oculus_remote.gd" type="Script" id=7]

[sub_resource type="PanoramaSky" id=1]

Expand Down Expand Up @@ -103,6 +104,7 @@ flags_use_point_size = false
flags_world_triplanar = false
flags_fixed_size = false
flags_albedo_tex_force_srgb = false
flags_do_not_receive_shadows = false
vertex_color_use_as_albedo = false
vertex_color_is_srgb = false
params_diffuse_mode = 1
Expand Down Expand Up @@ -147,6 +149,8 @@ _sections_unfolded = [ "Albedo" ]
[sub_resource type="PlaneMesh" id=4]

material = SubResource( 3 )
custom_aabb = AABB( 0, 0, 0, 0, 0, 0 )
flip_faces = false
size = Vector2( 10, 10 )
subdivide_width = 10
subdivide_depth = 10
Expand All @@ -156,15 +160,12 @@ subdivide_depth = 10
plane = Plane( 0, 1, 0, 0 )

[node name="Main" type="Spatial" index="0"]

script = ExtResource( 1 )

[node name="WorldEnvironment" type="WorldEnvironment" parent="." index="0"]

environment = SubResource( 2 )

[node name="DirectionalLight" type="DirectionalLight" parent="." index="1"]

transform = Transform( 0.623013, -0.733525, 0.271654, 0.321394, 0.55667, 0.766044, -0.713134, -0.389948, 0.582563, 0, 100, 0 )
layers = 1
light_color = Color( 1, 1, 1, 1 )
Expand Down Expand Up @@ -192,7 +193,6 @@ directional_shadow_max_distance = 200.0
_sections_unfolded = [ "Transform" ]

[node name="Ground" type="StaticBody" parent="." index="2"]

input_ray_pickable = true
input_capture_on_drag = false
collision_layer = 1
Expand All @@ -203,7 +203,6 @@ constant_linear_velocity = Vector3( 0, 0, 0 )
constant_angular_velocity = Vector3( 0, 0, 0 )

[node name="Ground" type="MeshInstance" parent="Ground" index="0"]

transform = Transform( 100, 0, 0, 0, 100, 0, 0, 0, 100, 0, 0, 0 )
layers = 1
material_override = null
Expand All @@ -220,14 +219,12 @@ material/0 = null
_sections_unfolded = [ "Transform" ]

[node name="CollisionShape" type="CollisionShape" parent="Ground" index="1"]

shape = SubResource( 5 )
disabled = false

[node name="Table" parent="." index="3" instance=ExtResource( 3 )]

[node name="Test" type="MeshInstance" parent="." index="4"]

transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.63647, -1.15364 )
layers = 1
material_override = null
Expand All @@ -244,13 +241,17 @@ skeleton = NodePath("..")
[node name="FirstPerson" parent="." index="5" instance=ExtResource( 4 )]

[node name="Function_Teleport" parent="FirstPerson/Left_Hand" index="1" instance=ExtResource( 5 )]

origin = NodePath("../..")

[node name="Function_Direct_movement" parent="FirstPerson/Right_Hand" index="1" instance=ExtResource( 6 )]

origin = NodePath("../..")
camera = NodePath("../../ARVRCamera")

[node name="Oculus_remote" type="ARVRController" parent="FirstPerson" index="4"]
controller_id = 3
rumble = 0.0
script = ExtResource( 7 )

[connection signal="button_pressed" from="FirstPerson/Oculus_remote" to="FirstPerson/Oculus_remote" method="_on_Oculus_remote_button_pressed"]

[editable path="FirstPerson"]
5 changes: 5 additions & 0 deletions demo/Oculus_remote.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
extends ARVRController

func _on_Oculus_remote_button_pressed(button):
# just testing for now
print("Button " + str(button) + " pressed on the oculus remote")
35 changes: 33 additions & 2 deletions src/ARVRInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,36 @@ void oculus_update_touch_controller(arvr_data_struct *p_arvr_data, int p_which)
arvr_api->godot_arvr_set_controller_transform(p_arvr_data->trackers[p_which], &transform, true, true);
}

void oculus_update_remote_controller(arvr_data_struct *p_arvr_data) {
if (p_arvr_data->trackers[TRACKER_OCULUS_REMOTE] == 0) {
// It doesn't actualy track orientation or position, bit of a shame it doesn't do orientation actually...
// Really should register this as only a joystick
p_arvr_data->trackers[TRACKER_OCULUS_REMOTE] = arvr_api->godot_arvr_add_controller("Oculus Remote", 0, false, false);
}

// VolUp/Down is caught by Oculus and may not be given to us...
// 4 = JOY_L -> ovrButton_VolDown (volume down)
arvr_api->godot_arvr_set_controller_button(p_arvr_data->trackers[TRACKER_OCULUS_REMOTE], 4, p_arvr_data->inputState.Buttons & ovrButton_VolDown);
// 5 = JOY_R -> ovrButton_VolUp (volume up)
arvr_api->godot_arvr_set_controller_button(p_arvr_data->trackers[TRACKER_OCULUS_REMOTE], 5, p_arvr_data->inputState.Buttons & ovrButton_VolUp);

// Yes, SeLect and Back overlap with A and B on the touch controllers AND with A and B on the xbox controller, we do not get separate states for these!
// 10 = JOY_SELECT -> ovrButton_A (select)
arvr_api->godot_arvr_set_controller_button(p_arvr_data->trackers[TRACKER_OCULUS_REMOTE], 10, p_arvr_data->inputState.Buttons & ovrButton_A);
// 11 = JOY_START -> ovrButton_B (back, not a good match but we don't have a back)
arvr_api->godot_arvr_set_controller_button(p_arvr_data->trackers[TRACKER_OCULUS_REMOTE], 11, p_arvr_data->inputState.Buttons & ovrButton_B);

// And same for d-pad so these will become pressed even when pressed on the xbox controller... ugh
// 12 = JOY_DPAD_UP -> ovrButton_Up
arvr_api->godot_arvr_set_controller_button(p_arvr_data->trackers[TRACKER_OCULUS_REMOTE], 12, p_arvr_data->inputState.Buttons & ovrButton_Up);
// 13 = JOY_DPAD_DOWN -> ovrButton_Down
arvr_api->godot_arvr_set_controller_button(p_arvr_data->trackers[TRACKER_OCULUS_REMOTE], 13, p_arvr_data->inputState.Buttons & ovrButton_Down);
// 14 = JOY_DPAD_LEFT -> ovrButton_Left
arvr_api->godot_arvr_set_controller_button(p_arvr_data->trackers[TRACKER_OCULUS_REMOTE], 14, p_arvr_data->inputState.Buttons & ovrButton_Left);
// 15 = JOY_DPAD_RIGHT -> ovrButton_Right
arvr_api->godot_arvr_set_controller_button(p_arvr_data->trackers[TRACKER_OCULUS_REMOTE], 15, p_arvr_data->inputState.Buttons & ovrButton_Right);
}

void godot_arvr_process(void *p_data) {
arvr_data_struct *arvr_data = (arvr_data_struct *)p_data;

Expand Down Expand Up @@ -611,9 +641,10 @@ void godot_arvr_process(void *p_data) {
}

if (which_controllers_do_we_have & ovrControllerType_Remote) {
// should add support for our remote...
oculus_update_remote_controller(arvr_data);
} else {
// if we previously had our remote, clean up
arvr_api->godot_arvr_remove_controller(arvr_data->trackers[TRACKER_OCULUS_REMOTE]);
arvr_data->trackers[TRACKER_OCULUS_REMOTE] = 0;
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/ARVRInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ extern const godot_arvr_interface_gdnative interface_struct;
enum trackers {
TRACKER_LEFT_TOUCH,
TRACKER_RIGHT_TOUCH,
TRACKER_OCULUS_REMOTE,
MAX_TRACKERS
};

Expand Down