Skip to content

Commit

Permalink
Merge pull request #61 from patrickdown/change_xrrig_access_mthods
Browse files Browse the repository at this point in the history
Change T5XRRig to use getter functions
  • Loading branch information
patrickdown authored Nov 27, 2023
2 parents 2d1d04a + f3a49fd commit 934a9dc
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 32 deletions.
28 changes: 28 additions & 0 deletions example.csharp/addons/tiltfive/T5Def.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Godot;
using System;

public static class T5Def {

public enum GameboardType
{
Unknown = 1,
LE = 2,
XE = 3,
XE_Raised = 4
}

// Buttons
public static StringName WAND_BUTTON_A = "button_a";
public static StringName WAND_BUTTON_B = "button_b";
public static StringName WAND_BUTTON_X = "button_x";
public static StringName WAND_BUTTON_Y = "button_y";
public static StringName WAND_BUTTON_1 = "button_1";
public static StringName WAND_BUTTON_2 = "button_2";
public static StringName WAND_BUTTON_STICK = "button_3";
public static StringName WAND_BUTTON_T5 = "button_t5";
public static StringName WAND_BUTTON_TRIGGER = "trigger_click";
// Axis
public static StringName WAND_ANALOG_STICK = "stick";
public static StringName WAND_ANALOG_TRIGGER = "trigger";

}
12 changes: 2 additions & 10 deletions example.csharp/addons/tiltfive/T5Interface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,14 @@ enum GlassesEventType
E_GLASSES_STOPPED_ON_ERROR = 9
}

public enum GameboardType
{
Unknown = 1,
LE = 2,
XE = 3,
XE_Raised = 4
}

// State of a set of glasses.
class XRRigState {
public bool available = false;
public bool attemptingToReserve = false;
public bool reserved = false;

public T5XRRig rig;
public GameboardType gameboardType;
public T5Def.GameboardType gameboardType;

public bool CanAttemptToReserve { get { return available && !attemptingToReserve && !reserved; } }
}
Expand Down Expand Up @@ -196,7 +188,7 @@ void _OnGlassesEvent(String glassesID, int eventNum)
case GlassesEventType.E_GLASSES_TRACKING:
{
GD.Print(glassesID, " E_GLASSES_TRACKING");
var gbt = xrInterface.Call("get_gameboard_type", glassesID).As<GameboardType>();
var gbt = xrInterface.Call("get_gameboard_type", glassesID).As<T5Def.GameboardType>();
if(xrRigState.gameboardType != gbt)
{
xrRigState.gameboardType = gbt;
Expand Down
2 changes: 1 addition & 1 deletion example.csharp/addons/tiltfive/T5Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void ReleaseXRRig(T5XRRig xrRig)
xrRig.QueueFree();
}

public void SetGameboardType(T5XRRig rig, T5Interface.GameboardType gameboard_type)
public void SetGameboardType(T5XRRig rig, T5Def.GameboardType gameboard_type)
{
}
}
2 changes: 1 addition & 1 deletion example.csharp/addons/tiltfive/T5ManagerInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ public interface T5ManagerInterface
public void ReleaseXRRig(T5XRRig xrRig);

// Invoked by the T5Interface to set the gameboard type the Tilt Five glasses detected
public void SetGameboardType(T5XRRig rig, T5Interface.GameboardType gameboard_type);
public void SetGameboardType(T5XRRig rig, T5Def.GameboardType gameboard_type);
}

2 changes: 1 addition & 1 deletion example.csharp/addons/tiltfive/scenes/T5XRRig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public partial class T5XRRig : SubViewport
T5ControllerCS wand;

public string GlassesID { get; set; }
public T5Interface.GameboardType GameboardType { get; set; }
public T5Def.GameboardType GameboardType { get; set; }
public Aabb GameboardSize { get; set; }
public T5OriginCS Origin { get { return origin; } }
public T5CameraCS Camera{ get { return camera; } }
Expand Down
2 changes: 1 addition & 1 deletion example.csharp/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ config_version=5

config/name="T5Example.csharp"
run/main_scene="res://main.tscn"
config/features=PackedStringArray("4.2", "Forward Plus")
config/features=PackedStringArray("4.2", "C#", "Forward Plus")
config/icon="res://icon.png"

[autoload]
Expand Down
12 changes: 6 additions & 6 deletions example.gd/addons/tiltfive/T5Interface.gd
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ func _ready():
tilt_five_xr_interface.initialize()

func _start_display(glasses_id : StringName, xr_rig : T5XRRig):
tilt_five_xr_interface.start_display(glasses_id, xr_rig, xr_rig.origin)
xr_rig.camera.tracker = "/user/%s/head" % glasses_id
xr_rig.wand.tracker = "/user/%s/wand_1" % glasses_id
tilt_five_xr_interface.start_display(glasses_id, xr_rig, xr_rig.get_origin())
xr_rig.get_camera().tracker = "/user/%s/head" % glasses_id
xr_rig.get_wand().tracker = "/user/%s/wand_1" % glasses_id

func _process_glasses():
for glasses_id in id_to_state:
Expand Down Expand Up @@ -128,9 +128,9 @@ func _on_glasses_event(glasses_id, event_num):
TiltFiveXRInterface.E_GLASSES_TRACKING:
var gbt = tilt_five_xr_interface.get_gameboard_type(glasses_id)
var xr_rig = xr_rig_state.xr_rig
if xr_rig and xr_rig.gameboard_type != gbt:
xr_rig.gameboard_type = gbt
xr_rig.gameboard_size = tilt_five_xr_interface.get_gameboard_extents(gbt)
if xr_rig and xr_rig._gameboard_type != gbt:
xr_rig._gameboard_type = gbt
xr_rig._gameboard_size = tilt_five_xr_interface.get_gameboard_extents(gbt)
t5_manager.set_gameboard_type(xr_rig, gbt)
print_verbose(glasses_id, " E_TRACKING, Gameboard size = ", )

Expand Down
3 changes: 2 additions & 1 deletion example.gd/addons/tiltfive/T5Manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ func _ready():

func create_xr_rig(glasses_id : String) -> T5XRRig:
var xr_rig = glasses_scene.instantiate() as T5XRRig
xr_rig._glasses_id = glasses_id
glasses_node.add_child(xr_rig)
if start_location:
var origin := xr_rig.origin as T5Origin3D
var origin := xr_rig.get_origin()
origin.transform = start_location.transform
origin.gameboard_scale = start_location.content_scale
glasses_scene_was_added.emit(xr_rig)
Expand Down
35 changes: 24 additions & 11 deletions example.gd/addons/tiltfive/scenes/T5XRRig.gd
Original file line number Diff line number Diff line change
@@ -1,28 +1,41 @@
class_name T5XRRig extends SubViewport
## represents a scene with all the components needed for Tilt Five tracked glasses and wand

## An ID attached to a pair of Tilt Five glasses
var glasses_id : StringName
var _glasses_id : StringName
var _gameboard_type := T5Def.GameboardType.Unknown
var _gameboard_size := AABB()
var _origin : T5Origin3D
var _camera : T5Camera3D
var _wand : T5Controller3D

## Get the ID attached to a pair of Tilt Five glasses
func get_glasses_id() -> StringName:
return _glasses_id

## Type of gameboard that is set up
var gameboard_type := T5Def.GameboardType.Unknown
func get_gameboard_type() -> T5Def.GameboardType:
return _gameboard_type

## size of the gameboard in meters. Raised XE gameboards can have a height
var gameboard_size := AABB()
func get_gameboard_size() -> AABB:
return _gameboard_size

## the node that relates the center of the gameboard to world coordinates
var origin : T5Origin3D
func get_origin() -> T5Origin3D:
return _origin

## the tracked camera
var camera : T5Camera3D
func get_camera() -> T5Camera3D:
return _camera

## the tracked wand controller
var wand : T5Controller3D
func get_wand() -> T5Controller3D:
return _wand

func _enter_tree():
origin = $Origin
camera = $Origin/Camera
wand = $Origin/Wand_1
_origin = $Origin
_camera = $Origin/Camera
_wand = $Origin/Wand_1

func _process(_delta):
if wand: wand.visible = wand.get_has_tracking_data()
if _wand: _wand.visible = _wand.get_has_tracking_data()
8 changes: 8 additions & 0 deletions example.gd/project.godot
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
; Engine configuration file.
; It's best edited using the editor UI and not directly,
; since the parameters that go here are not all obvious.
;
; Format:
; [section] ; section goes between []
; param=value ; assign values to parameters

config_version=5

[application]
Expand Down

0 comments on commit 934a9dc

Please sign in to comment.