Skip to content

Commit

Permalink
Merge pull request #44 from patrickdown/add_trigger_clicked
Browse files Browse the repository at this point in the history
Add support for trigger_click button input
  • Loading branch information
patrickdown authored Nov 14, 2023
2 parents 6c1efde + abb8ad8 commit d0c1df2
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 1 deletion.
8 changes: 7 additions & 1 deletion example/Controls.tscn
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
[gd_scene load_steps=3 format=3 uid="uid://dnx42xctfl3mx"]
[gd_scene load_steps=4 format=3 uid="uid://dnx42xctfl3mx"]

[sub_resource type="CapsuleMesh" id="4"]

[sub_resource type="BoxMesh" id="BoxMesh_dc5d6"]

[sub_resource type="SphereMesh" id="3"]

[node name="Controls" type="Node3D"]
Expand All @@ -11,6 +13,10 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0748157, -0.00207818, 0.009
transform = Transform3D(0.01, 0, 0, 0, 0.01, 0, 0, 0, 0.01, -0.000888377, -0.0415742, -0.0168045)
mesh = SubResource("4")

[node name="TriggerClick" type="MeshInstance3D" parent="."]
transform = Transform3D(0.01, 0, 0, 0, 0.01, 0, 0, 0, 0.01, -0.000888377, -0.00848173, -0.0840266)
mesh = SubResource("BoxMesh_dc5d6")

[node name="Three" type="MeshInstance3D" parent="."]
transform = Transform3D(0.01, 0, 0, 0, 0.01, 0, 0, 0, 0.01, 0, 0, 0)
mesh = SubResource("3")
Expand Down
1 change: 1 addition & 0 deletions example/addons/tiltfive/T5Interface.gd
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func _enter_tree():
if tilt_five_xr_interface:
tilt_five_xr_interface.application_id = T5ProjectSettings.application_id
tilt_five_xr_interface.application_version = T5ProjectSettings.application_version
tilt_five_xr_interface.trigger_click_threshold = T5ProjectSettings.trigger_click_threshhold

XRServer.add_interface(tilt_five_xr_interface)
tilt_five_xr_interface.glasses_event.connect(_on_glasses_event)
Expand Down
5 changes: 5 additions & 0 deletions example/addons/tiltfive/T5ProjectSettings.gd
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ static func setup_properties():
_define_project_setting("xr/tilt_five/application_id", TYPE_STRING, PROPERTY_HINT_NONE, "", "my.game.com")
_define_project_setting("xr/tilt_five/application_version", TYPE_STRING, PROPERTY_HINT_NONE, "", "0.1.0")
_define_project_setting("xr/tilt_five/default_display_name", TYPE_STRING, PROPERTY_HINT_NONE, "", "Game: Player One")
_define_project_setting("xr/tilt_five/trigger_click_threshhold", TYPE_FLOAT, PROPERTY_HINT_RANGE, "0,1,0.01", 0.3)
_initialized = true

static var application_id : String:
Expand All @@ -47,3 +48,7 @@ static var default_display_name : String:
setup_properties()
return ProjectSettings.get_setting_with_override("xr/tilt_five/default_display_name")

static var trigger_click_threshhold : float:
get:
setup_properties()
return ProjectSettings.get_setting_with_override("xr/tilt_five/trigger_click_threshhold")
6 changes: 6 additions & 0 deletions example/pointer_control.gd
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const WAND_BUTTON_1 := "button_1"
const WAND_BUTTON_2 := "button_2"
const WAND_BUTTON_STICK := "button_3"
const WAND_BUTTON_T5 := "button_t5"
const WAND_BUTTON_TRIGGER := "trigger_click"
# Axis
const WAND_ANALOG_STICK := "stick"
const WAND_ANALOG_TRIGGER := "trigger"
Expand All @@ -34,6 +35,7 @@ func _ready():
$Controls/Three.material_override = unselected_mat
$Controls/T5.material_override = unselected_mat
$Controls/Trigger.material_override = unselected_mat
$Controls/TriggerClick.material_override = unselected_mat


# Called every frame. 'delta' is the elapsed time since the previous frame.
Expand Down Expand Up @@ -62,6 +64,8 @@ func _on_button_pressed(button):
$Controls/Three.material_override = selected_mat
WAND_BUTTON_T5:
$Controls/T5.material_override = selected_mat
WAND_BUTTON_TRIGGER:
$Controls/TriggerClick.material_override = selected_mat


func _on_button_released(button):
Expand All @@ -82,3 +86,5 @@ func _on_button_released(button):
$Controls/Three.material_override = unselected_mat
WAND_BUTTON_T5:
$Controls/T5.material_override = unselected_mat
WAND_BUTTON_TRIGGER:
$Controls/TriggerClick.material_override = unselected_mat
7 changes: 7 additions & 0 deletions extension/src/GodotT5Glasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,13 @@ void GodotT5Glasses::update_wand(size_t wand_idx) {
Vector2 stick;
get_wand_stick(wand_idx, stick.x, stick.y);
tracker->set_input("stick", Variant(stick));

if(trigger_value > _trigger_click_threshold + g_trigger_hysteresis_range) {
tracker->set_input("trigger_click", Variant(true));
}
else if(trigger_value < (_trigger_click_threshold - g_trigger_hysteresis_range)) {
tracker->set_input("trigger_click", Variant(false));
}
}
if(is_wand_state_set(wand_idx, WandState::BUTTONS_VALID)) {
WandButtons buttons;
Expand Down
9 changes: 9 additions & 0 deletions extension/src/GodotT5Glasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ using T5Integration::Glasses;
namespace GodotT5Integration {

constexpr int g_swap_chain_length = 3;
constexpr float g_trigger_hysteresis_range = 0.002; // Sort of arbitrary assume 8 bit DAC +/-(1/256)/2

class GodotT5Service;

Expand Down Expand Up @@ -47,6 +48,8 @@ namespace GodotT5Integration {

StringName get_wand_tracker_name(size_t wand_idx);

void set_trigger_click_threshold(float threshold);

protected:
virtual void on_glasses_reserved() override;
virtual void on_glasses_released() override;
Expand All @@ -61,6 +64,8 @@ namespace GodotT5Integration {

Ref<XRPositionalTracker> _head;
std::vector<Ref<XRPositionalTracker>> _wand_trackers;

float _trigger_click_threshold;
};

inline bool GodotT5Glasses::is_reserved() {
Expand All @@ -73,6 +78,10 @@ namespace GodotT5Integration {
return _wand_trackers[wand_idx]->get_tracker_name();
}

inline void GodotT5Glasses::set_trigger_click_threshold(float threshold) {
_trigger_click_threshold = threshold;
}

}


Expand Down
20 changes: 20 additions & 0 deletions extension/src/TiltFiveXRInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ void TiltFiveXRInterface::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_application_version"), &TiltFiveXRInterface::get_application_version);
ADD_PROPERTY(PropertyInfo(Variant::STRING, "application_version"), "set_application_version", "get_application_version");

ClassDB::bind_method(D_METHOD("set_trigger_click_threshold", "threshold"), &TiltFiveXRInterface::set_trigger_click_threshold);
ClassDB::bind_method(D_METHOD("get_trigger_click_threshold"), &TiltFiveXRInterface::get_trigger_click_threshold);
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "trigger_click_threshold"), "set_trigger_click_threshold", "get_trigger_click_threshold");

// Signals.
ADD_SIGNAL(MethodInfo("service_event", PropertyInfo(Variant::INT, "event")));
ADD_SIGNAL(MethodInfo("glasses_event", PropertyInfo(Variant::STRING, "glasses_id"), PropertyInfo(Variant::INT, "event")));
Expand Down Expand Up @@ -72,6 +76,20 @@ void TiltFiveXRInterface::set_application_version(const String &p_string) {
application_version = p_string;
}

float TiltFiveXRInterface::get_trigger_click_threshold() {
return _trigger_click_threshold;
}

void TiltFiveXRInterface::set_trigger_click_threshold(float threshold) {
_trigger_click_threshold = threshold;

for(auto& entry : _glasses_index) {
if(!entry.glasses.expired()) {
entry.glasses.lock()->set_trigger_click_threshold(_trigger_click_threshold);
}
}
}

TiltFiveXRInterface::GlassesIndexEntry* TiltFiveXRInterface::lookup_glasses_entry(StringName glasses_id) {
for(auto& entry : _glasses_index) {
if(glasses_id == entry.id) {
Expand Down Expand Up @@ -436,6 +454,8 @@ void TiltFiveXRInterface::_process() {
}
_glasses_index.resize(glasses_idx + 1);
auto glasses = t5_service->get_glasses(glasses_idx);
glasses->set_trigger_click_threshold(_trigger_click_threshold);

_glasses_index[glasses_idx].glasses = glasses;
_glasses_index[glasses_idx].id = glasses->get_id().c_str();
_glasses_index[glasses_idx].idx = glasses_idx;
Expand Down
4 changes: 4 additions & 0 deletions extension/src/TiltFiveXRInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ class TiltFiveXRInterface : public XRInterfaceExtension {
String get_application_version() const;
void set_application_version(const String &p_string);

float get_trigger_click_threshold();
void set_trigger_click_threshold(float threshold);

// Functions.

void reserve_glasses(const StringName glasses_id, const String display_name);
Expand Down Expand Up @@ -150,6 +153,7 @@ class TiltFiveXRInterface : public XRInterfaceExtension {

String application_id;
String application_version;
float _trigger_click_threshold = 0.5;

std::vector<GlassesIndexEntry> _glasses_index;
std::vector<GlassesEvent> _glasses_events;
Expand Down

0 comments on commit d0c1df2

Please sign in to comment.