Tilt Five™ Unity API  1.4.1
TiltFive.Wand Class Reference

The Wand API and runtime. More...

Inheritance diagram for TiltFive.Wand:
TiltFive.Singleton< Wand >

Classes

class  WaitUntilWandConnected
 Suspends coroutine execution until the provided player's wand has connected. More...
 
class  WandCore
 Internal Wand core runtime. More...
 
struct  WandPair
 

Static Public Member Functions

static Vector3 GetPosition (ControllerIndex controllerIndex=ControllerIndex.Right, ControllerPosition controllerPosition=ControllerPosition.Grip, PlayerIndex playerIndex=PlayerIndex.One)
 Gets the position of the wand in world space. More...
 
static Quaternion GetRotation (ControllerIndex controllerIndex=ControllerIndex.Right, PlayerIndex playerIndex=PlayerIndex.One)
 Gets the rotation of the wand in world space. More...
 
static bool IsTracked (ControllerIndex controllerIndex=ControllerIndex.Right, PlayerIndex playerIndex=PlayerIndex.One)
 
static bool TryCheckConnected (out bool connected, PlayerIndex playerIndex, ControllerIndex controllerIndex=ControllerIndex.Right)
 Gets the connection status of the indicated wand. More...
 
static bool TrySendImpulse (float amplitude, float duration, PlayerIndex playerIndex=PlayerIndex.One, ControllerIndex controllerIndex=ControllerIndex.Right)
 Try to send a haptics impulse to the specified wand More...
 
static void Update (WandSettings wandSettings, ScaleSettings scaleSettings, GameBoardSettings gameBoardSettings, PlayerIndex playerIndex=PlayerIndex.One)
 
static void ScanForWands ()
 

Private Member Functions

WandCore ObtainWandCore (GlassesHandle glassesHandle, ControllerIndex controllerIndex)
 

Static Private Member Functions

static bool TryScanForWands ()
 
static bool TryGetWandAvailability (out bool connected, GlassesHandle glassesHandle, ControllerIndex controllerIndex)
 

Private Attributes

Dictionary< GlassesHandle, WandPairwandCores = new Dictionary<GlassesHandle, WandPair>()
 The collection of WandCores. GlassesHandles are mapped to pairs of right/left WandCores. More...
 
HashSet< GlassesHandle > incomingHandles = new HashSet<GlassesHandle>()
 
HashSet< GlassesHandle > lostHandles = new HashSet<GlassesHandle>()
 
HashSet< WandCorelostWands = new HashSet<WandCore>()
 

Static Private Attributes

static readonly Vector3 DEFAULT_WAND_POSITION_GAME_BOARD_SPACE = new Vector3(0f, 0.25f, -0.25f)
 The default position of the wand relative to the board. More...
 
static readonly Vector3 DEFAULT_WAND_HANDEDNESS_OFFSET_GAME_BOARD_SPACE = new Vector3(0.125f, 0f, 0f)
 A left/right offset to the default wand position, depending on handedness. More...
 
static readonly Quaternion DEFAULT_WAND_ROTATION_GAME_BOARD_SPACE = Quaternion.Euler(new Vector3(-33f, 0f, 0f))
 The default rotation of the wand relative to the board. More...
 
static DateTime lastScanAttempt = System.DateTime.MinValue
 
static readonly double wandScanInterval = 0.5d
 
static bool wandAvailabilityErroredOnce = false
 
static int currentFrame = -1
 

Additional Inherited Members

- Protected Member Functions inherited from TiltFive.Singleton< Wand >
 Singleton ()
 
- Properties inherited from TiltFive.Singleton< Wand >
static T Instance [get]
 

Detailed Description

The Wand API and runtime.

Definition at line 55 of file Wand.cs.

Member Function Documentation

◆ GetPosition()

static Vector3 TiltFive.Wand.GetPosition ( ControllerIndex  controllerIndex = ControllerIndex.Right,
ControllerPosition  controllerPosition = ControllerPosition.Grip,
PlayerIndex  playerIndex = PlayerIndex.One 
)
static

Gets the position of the wand in world space.

Parameters
controllerIndex
controllerPosition
glassesHandleThe specified glasses. If null is provided, this uses the default glasses.
Returns
If the indicated wand is not connected, this returns the zero vector.

Definition at line 158 of file Wand.cs.

162  {
163  if(!Player.TryGetGlassesHandle(playerIndex, out var glassesHandle)
164  || !Instance.wandCores.TryGetValue(glassesHandle, out var wandPair)
165  || !wandPair.TryGet(controllerIndex, out var wandCore))
166  {
167  return Vector3.zero;
168  }
169 
170  switch (controllerPosition)
171  {
172  case ControllerPosition.Fingertips:
173  return wandCore.fingertipsPose_UnityWorldSpace.position;
174  case ControllerPosition.Aim:
175  return wandCore.aimPose_UnityWorldSpace.position;
176  case ControllerPosition.Grip:
177  return wandCore.Pose_UnityWorldSpace.position;
178  default:
179  return Vector3.zero;
180  }
181  }
ControllerPosition
Points of interest along the wand controller, such as the handle position or wand tip.

References TiltFive.Singleton< Wand >.Instance.

◆ GetRotation()

static Quaternion TiltFive.Wand.GetRotation ( ControllerIndex  controllerIndex = ControllerIndex.Right,
PlayerIndex  playerIndex = PlayerIndex.One 
)
static

Gets the rotation of the wand in world space.

Parameters
controllerIndex
glassesHandleThe specified glasses. If null is provided, this uses the default glasses.
Returns
If the indicated wand is not connected, this returns the identity quaternion.

Definition at line 189 of file Wand.cs.

190  {
191  if (!Player.TryGetGlassesHandle(playerIndex, out var glassesHandle)
192  || !Instance.wandCores.TryGetValue(glassesHandle, out var wandPair)
193  || !wandPair.TryGet(controllerIndex, out var wandCore))
194  {
195  return Quaternion.identity;
196  }
197 
198  return wandCore.Pose_UnityWorldSpace.rotation;
199  }

References TiltFive.Singleton< Wand >.Instance.

◆ IsTracked()

static bool TiltFive.Wand.IsTracked ( ControllerIndex  controllerIndex = ControllerIndex.Right,
PlayerIndex  playerIndex = PlayerIndex.One 
)
static

Definition at line 201 of file Wand.cs.

202  {
203  if (!Player.TryGetGlassesHandle(playerIndex, out var glassesHandle)
204  || !Instance.wandCores.TryGetValue(glassesHandle, out var wandPair)
205  || !wandPair.TryGet(controllerIndex, out var wandCore))
206  {
207  return false;
208  }
209 
210  return wandCore.IsTracked;
211  }

References TiltFive.Singleton< Wand >.Instance.

◆ ObtainWandCore()

WandCore TiltFive.Wand.ObtainWandCore ( GlassesHandle  glassesHandle,
ControllerIndex  controllerIndex 
)
private

Definition at line 670 of file Wand.cs.

671  {
672  WandCore wandCore = null;
673  var glassesAlreadyMonitored = wandCores.TryGetValue(glassesHandle, out var wandPair);
674 
675  // Ask the native plugin whether this wand is currently connected.
676  if (TryGetWandAvailability(out var wandConnected, glassesHandle, controllerIndex) && wandConnected)
677  {
678  // If we're not already monitoring this wand, go ahead and create a corresponding WandCore.
679  if (!glassesAlreadyMonitored || !wandPair.TryGet(controllerIndex, out wandCore))
680  {
681 #if UNITY_2019_1_OR_NEWER && INPUTSYSTEM_AVAILABLE
682  wandCore = new WandDeviceCore(glassesHandle, controllerIndex);
683 #else
684  wandCore = new WandCore(glassesHandle, controllerIndex);
685 #endif
686  }
687  return wandCore;
688  }
689  // If this wand is disconnected and we were previously monitoring it, mark it as disconnected
690  else if(glassesAlreadyMonitored && wandPair.TryGet(controllerIndex, out var lostWandCore))
691  {
692  lostWands.Add(lostWandCore);
693  }
694 
695  return wandCore;
696  }
static bool TryGetWandAvailability(out bool connected, GlassesHandle glassesHandle, ControllerIndex controllerIndex)
Definition: Wand.cs:637
Dictionary< GlassesHandle, WandPair > wandCores
The collection of WandCores. GlassesHandles are mapped to pairs of right/left WandCores.
Definition: Wand.cs:62
HashSet< WandCore > lostWands
Definition: Wand.cs:91

References TiltFive.Wand.lostWands, TiltFive.Wand.TryGetWandAvailability(), and TiltFive.Wand.wandCores.

◆ ScanForWands()

static void TiltFive.Wand.ScanForWands ( )
static

Definition at line 311 of file Wand.cs.

312  {
313  Scan();
314  }

◆ TryCheckConnected()

static bool TiltFive.Wand.TryCheckConnected ( out bool  connected,
PlayerIndex  playerIndex,
ControllerIndex  controllerIndex = ControllerIndex.Right 
)
static

Gets the connection status of the indicated wand.

Parameters
connected
playerIndex
controllerIndex
Returns
Returns false if something went wrong while attempting to check wand connectivity.

Definition at line 220 of file Wand.cs.

221  {
222  if(!Player.TryGetGlassesHandle(playerIndex, out var glassesHandle)
223  || !Instance.wandCores.TryGetValue(glassesHandle, out var wandPair)
224  || !wandPair.TryGet(controllerIndex, out var wandCore))
225  {
226  connected = false;
227  return true;
228  }
229 
230  connected = wandCore.IsConnected;
231  return true;
232  }

References TiltFive.Singleton< Wand >.Instance.

Referenced by TiltFive.Input.GetWandAvailability().

◆ TryGetWandAvailability()

static bool TiltFive.Wand.TryGetWandAvailability ( out bool  connected,
GlassesHandle  glassesHandle,
ControllerIndex  controllerIndex 
)
staticprivate

Definition at line 637 of file Wand.cs.

638  {
640  {
641  try
642  {
643  T5_Bool wandAvailable = false;
644  int result = NativePlugin.GetWandAvailability(glassesHandle, ref wandAvailable, controllerIndex);
645 
646  if (result == NativePlugin.T5_RESULT_SUCCESS)
647  {
648  connected = wandAvailable;
649  return true;
650  }
651  }
652  catch (DllNotFoundException e)
653  {
654  Log.Info("Could not connect to Tilt Five plugin for wand: {0}", e.Message);
656  }
657  catch (Exception e)
658  {
659  Log.Error(
660  "Failed to connect to Tilt Five plugin for wand availability: {0}",
661  e.ToString());
663  }
664  }
665 
666  connected = false;
667  return false;
668  }
The Logger.
Definition: Log.cs:42
static void Info(string m, params object[] list)
INFO logging function call.
Definition: Log.cs:140
static void Error(string m, params object[] list)
ERROR logging function call.
Definition: Log.cs:127
static bool wandAvailabilityErroredOnce
Definition: Wand.cs:100

References TiltFive.Logging.Log.Error(), TiltFive.Logging.Log.Info(), and TiltFive.Wand.wandAvailabilityErroredOnce.

Referenced by TiltFive.Wand.ObtainWandCore().

◆ TryScanForWands()

static bool TiltFive.Wand.TryScanForWands ( )
staticprivate

Definition at line 605 of file Wand.cs.

606  {
607  var currentTime = System.DateTime.Now;
608  var timeSinceLastScan = currentTime - lastScanAttempt;
609 
610  // Scan for wands if the scan interval has elapsed to catch newly connected wands.
611  if (timeSinceLastScan.TotalSeconds >= wandScanInterval)
612  {
613  int result = NativePlugin.T5_RESULT_UNKNOWN_ERROR;
614 
615  try
616  {
617  result = NativePlugin.ScanForWands();
618  }
619  catch (System.DllNotFoundException e)
620  {
621  Log.Info(
622  "Could not connect to Tilt Five plugin to scan for wands: {0}",
623  e);
624  }
625  catch (Exception e)
626  {
627  Log.Error(e.Message);
628  }
629 
630  lastScanAttempt = currentTime;
631  return (result == NativePlugin.T5_RESULT_SUCCESS);
632  }
633 
634  return false;
635  }
static readonly double wandScanInterval
Definition: Wand.cs:98
static DateTime lastScanAttempt
Definition: Wand.cs:95

References TiltFive.Logging.Log.Error(), TiltFive.Logging.Log.Info(), TiltFive.Wand.lastScanAttempt, and TiltFive.Wand.wandScanInterval.

◆ TrySendImpulse()

static bool TiltFive.Wand.TrySendImpulse ( float  amplitude,
float  duration,
PlayerIndex  playerIndex = PlayerIndex.One,
ControllerIndex  controllerIndex = ControllerIndex.Right 
)
static

Try to send a haptics impulse to the specified wand

Parameters
amplitudeThe amplitude of the impulse, between [0.0,1.0].
durationThe duration of the impulse, between 0.0 and 0.320 s.
playerIndex
controllerIndex
Returns
Returns false if something went wrong while attempting to send the impulse command

Definition at line 267 of file Wand.cs.

268  {
269  if (!Player.TryGetGlassesHandle(playerIndex, out var glassesHandle)
270  || !Instance.wandCores.TryGetValue(glassesHandle, out var wandPair)
271  || !wandPair.TryGet(controllerIndex, out var wandCore))
272  {
273  return false;
274  }
275 
276  try
277  {
278  if (NativePlugin.SendImpulse(glassesHandle, controllerIndex, amplitude, (UInt16)(Mathf.Clamp(duration, 0.0f, 0.320f) * 1000)) == 0)
279  {
280  return true;
281  }
282  else
283  {
284  return false;
285  }
286  }
287  catch (DllNotFoundException e)
288  {
289  Log.Info("Tilt Five library missing. Could not connect to wand: {0}", e.Message);
290  return false;
291  }
292  catch (Exception e)
293  {
294  Log.Error(
295  "Failed to send impulse to wand: {0}",
296  e.ToString());
297  return false;
298  }
299  }

References TiltFive.Logging.Log.Error(), TiltFive.Logging.Log.Info(), and TiltFive.Singleton< Wand >.Instance.

◆ Update()

static void TiltFive.Wand.Update ( WandSettings  wandSettings,
ScaleSettings  scaleSettings,
GameBoardSettings  gameBoardSettings,
PlayerIndex  playerIndex = PlayerIndex.One 
)
static

Definition at line 305 of file Wand.cs.

306  {
307  Update(playerIndex, wandSettings, scaleSettings, gameBoardSettings);
308  }
static void Update(WandSettings wandSettings, ScaleSettings scaleSettings, GameBoardSettings gameBoardSettings, PlayerIndex playerIndex=PlayerIndex.One)
Definition: Wand.cs:305

Referenced by TiltFive.TiltFiveManager.GetLatestPoseData(), and TiltFive.Player.PlayerCore.GetLatestPoseData().

Member Data Documentation

◆ currentFrame

int TiltFive.Wand.currentFrame = -1
staticprivate

Definition at line 104 of file Wand.cs.

◆ DEFAULT_WAND_HANDEDNESS_OFFSET_GAME_BOARD_SPACE

readonly Vector3 TiltFive.Wand.DEFAULT_WAND_HANDEDNESS_OFFSET_GAME_BOARD_SPACE = new Vector3(0.125f, 0f, 0f)
staticprivate

A left/right offset to the default wand position, depending on handedness.

Definition at line 74 of file Wand.cs.

Referenced by TiltFive.Wand.WandCore.GetDefaultPoseGameboardSpace().

◆ DEFAULT_WAND_POSITION_GAME_BOARD_SPACE

readonly Vector3 TiltFive.Wand.DEFAULT_WAND_POSITION_GAME_BOARD_SPACE = new Vector3(0f, 0.25f, -0.25f)
staticprivate

The default position of the wand relative to the board.

The wand GameObject will snap back to this position if the glasses and/or wand are unavailable.

Definition at line 70 of file Wand.cs.

Referenced by TiltFive.Wand.WandCore.GetDefaultPoseGameboardSpace().

◆ DEFAULT_WAND_ROTATION_GAME_BOARD_SPACE

readonly Quaternion TiltFive.Wand.DEFAULT_WAND_ROTATION_GAME_BOARD_SPACE = Quaternion.Euler(new Vector3(-33f, 0f, 0f))
staticprivate

The default rotation of the wand relative to the board.

The wand GameObject will snap back to this rotation if the glasses are unavailable. If different behavior is desired in this scenario, a different camera should be used.

Definition at line 83 of file Wand.cs.

Referenced by TiltFive.Wand.WandCore.GetDefaultPoseGameboardSpace().

◆ incomingHandles

HashSet<GlassesHandle> TiltFive.Wand.incomingHandles = new HashSet<GlassesHandle>()
private

Definition at line 87 of file Wand.cs.

◆ lastScanAttempt

DateTime TiltFive.Wand.lastScanAttempt = System.DateTime.MinValue
staticprivate

Definition at line 95 of file Wand.cs.

Referenced by TiltFive.Wand.TryScanForWands().

◆ lostHandles

HashSet<GlassesHandle> TiltFive.Wand.lostHandles = new HashSet<GlassesHandle>()
private

Definition at line 89 of file Wand.cs.

◆ lostWands

HashSet<WandCore> TiltFive.Wand.lostWands = new HashSet<WandCore>()
private

Definition at line 91 of file Wand.cs.

Referenced by TiltFive.Wand.ObtainWandCore().

◆ wandAvailabilityErroredOnce

bool TiltFive.Wand.wandAvailabilityErroredOnce = false
staticprivate

◆ wandCores

Dictionary<GlassesHandle, WandPair> TiltFive.Wand.wandCores = new Dictionary<GlassesHandle, WandPair>()
private

The collection of WandCores. GlassesHandles are mapped to pairs of right/left WandCores.

Definition at line 62 of file Wand.cs.

Referenced by TiltFive.Wand.ObtainWandCore().

◆ wandScanInterval

readonly double TiltFive.Wand.wandScanInterval = 0.5d
staticprivate

Definition at line 98 of file Wand.cs.

Referenced by TiltFive.Wand.TryScanForWands().


The documentation for this class was generated from the following file: