Tilt Five Unity API  1.3.0
Classes | Public Types | Static Public Member Functions | Properties | Static Private Member Functions | Private Attributes | List of all members
TiltFive.Glasses Class Reference

The Glasses API and runtime. More...

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

Classes

class  GlassesCore
 Internal Glasses core runtime. More...
 

Public Types

enum class  AREyes { EYE_LEFT = 0 , EYE_RIGHT , EYE_MAX }
 

Static Public Member Functions

static bool headPoseUpdated (PlayerIndex playerIndex=PlayerIndex.One)
 Returns a boolean indication that the head pose was successfully updated. More...
 
static void Reset (GlassesSettings glassesSettings, SpectatorSettings spectatorSettings=null, PlayerIndex playerIndex=PlayerIndex.None)
 Reset this T:TiltFive.Glasses. More...
 
static bool Validate (GlassesSettings glassesSettings, SpectatorSettings spectatorSettings=null, PlayerIndex playerIndex=PlayerIndex.One)
 Validates the specified glassesSettings with the specified glasses core. More...
 
static void Update (GlassesSettings glassesSettings, ScaleSettings scaleSettings, GameBoardSettings gameBoardSettings)
 Updates this T:TiltFive.Glasses. More...
 
static bool IsTracked (PlayerIndex playerIndex=PlayerIndex.One)
 Indicate if the specified glasses are tracked. More...
 
static bool IsConnected (PlayerIndex playerIndex=PlayerIndex.One)
 Indicate if the specified glasses are connected. More...
 
static bool TryGetFriendlyName (PlayerIndex playerIndex, out string friendlyName)
 
static bool TryGetPose (PlayerIndex playerIndex, out Pose pose)
 Attempts to get the position and orientation of the specified player's glasses. More...
 
static GameObject GetPoseRoot (PlayerIndex playerIndex)
 
static Camera GetLeftEye (PlayerIndex playerIndex)
 
static Camera GetRightEye (PlayerIndex playerIndex)
 
static void ScanForGlasses ()
 

Properties

static bool updated [get]
 Gets a value indicating whether this T:TiltFive.Glasses is updated. More...
 
static bool configured [get]
 Gets a value indicating whether this T:TiltFive.Glasses is configured. More...
 
static Vector3 position [get]
 Gets the head pose position. More...
 
static Quaternion rotation [get]
 Gets the head pose rotation. More...
 
static Vector3 forward [get]
 Gets the head orientation's forward vector. More...
 
static Vector3 right [get]
 Gets the head orientation's right vector. More...
 
static Vector3 up [get]
 Gets the head orientation's up vector. More...
 
static Vector3 leftEyePosition [get]
 Gets the left eye position. More...
 
static Vector3 rightEyePosition [get]
 Gets the right eye position. More...
 
static bool glassesAvailable [get, private set]
 Indicates whether the glasses are plugged in and functioning. More...
 
- Properties inherited from TiltFive.Singleton< Glasses >
static T Instance [get]
 

Static Private Member Functions

static GameObject GetPoseRoot (GlassesHandle glassesHandle)
 
static Camera GetLeftEye (GlassesHandle glassesHandle)
 
static Camera GetRightEye (GlassesHandle glassesHandle)
 
static GlassesCore GetPlayerOneGlassesCore ()
 
static bool TryGetSpectatorSettings (out SpectatorSettings spectatorSettings)
 

Private Attributes

Dictionary< GlassesHandle, GlassesCoreglassesCores = new Dictionary<GlassesHandle, GlassesCore>()
 The glasses core runtimes. More...
 
HashSet< GlassesHandle > incomingHandles = new HashSet<GlassesHandle>()
 
HashSet< GlassesHandle > lostHandles = new HashSet<GlassesHandle>()
 
GlassesHandle? defaultGlassesHandle
 The identifier for the first detected pair of glasses. More...
 

Additional Inherited Members

- Protected Member Functions inherited from TiltFive.Singleton< Glasses >
 Singleton ()
 

Detailed Description

The Glasses API and runtime.

Definition at line 34 of file Glasses.cs.

Member Enumeration Documentation

◆ AREyes

Enumerator
EYE_LEFT 
EYE_RIGHT 
EYE_MAX 

Definition at line 56 of file Glasses.cs.

57  {
58  EYE_LEFT = 0,
59  EYE_RIGHT,
60  EYE_MAX,
61  }

Member Function Documentation

◆ GetLeftEye() [1/2]

static Camera TiltFive.Glasses.GetLeftEye ( GlassesHandle  glassesHandle)
staticprivate

Definition at line 505 of file Glasses.cs.

506  {
507  if (!Instance.glassesCores.TryGetValue(glassesHandle, out var glassesCore))
508  {
509  return null;
510  }
511  return glassesCore.leftEye;
512  }

◆ GetLeftEye() [2/2]

static Camera TiltFive.Glasses.GetLeftEye ( PlayerIndex  playerIndex)
static

Definition at line 287 of file Glasses.cs.

288  {
289  if (!Player.TryGetGlassesHandle(playerIndex, out var glassesHandle))
290  {
291  return null;
292  }
293  return GetLeftEye(glassesHandle);
294  }
static Camera GetLeftEye(PlayerIndex playerIndex)
Definition: Glasses.cs:287
Provides access to player settings and functionality.
Definition: Player.cs:16

Referenced by TiltFive.TiltFiveManager.GetEyeCamera(), and TiltFive.TiltFiveManager2.GetEyeCamera().

◆ GetPlayerOneGlassesCore()

static GlassesCore TiltFive.Glasses.GetPlayerOneGlassesCore ( )
staticprivate

Definition at line 524 of file Glasses.cs.

525  {
526  if(Player.TryGetGlassesHandle(PlayerIndex.One, out var glassesHandle)
527  && Instance.glassesCores.TryGetValue(glassesHandle, out var glassesCore))
528  {
529  return glassesCore;
530  }
531  return null;
532  }
PlayerIndex
The Player index (e.g. Player One, Player Two, etc)

◆ GetPoseRoot() [1/2]

static GameObject TiltFive.Glasses.GetPoseRoot ( GlassesHandle  glassesHandle)
staticprivate

Definition at line 496 of file Glasses.cs.

497  {
498  if (!Instance.glassesCores.TryGetValue(glassesHandle, out var glassesCore))
499  {
500  return null;
501  }
502  return glassesCore.headPose.gameObject;
503  }

◆ GetPoseRoot() [2/2]

static GameObject TiltFive.Glasses.GetPoseRoot ( PlayerIndex  playerIndex)
static

Definition at line 278 of file Glasses.cs.

279  {
280  if(!Player.TryGetGlassesHandle(playerIndex, out var glassesHandle))
281  {
282  return null;
283  }
284  return GetPoseRoot(glassesHandle);
285  }
static GameObject GetPoseRoot(PlayerIndex playerIndex)
Definition: Glasses.cs:278

◆ GetRightEye() [1/2]

static Camera TiltFive.Glasses.GetRightEye ( GlassesHandle  glassesHandle)
staticprivate

Definition at line 514 of file Glasses.cs.

515  {
516  if (!Instance.glassesCores.TryGetValue(glassesHandle, out var glassesCore))
517  {
518  return null;
519  }
520 
521  return glassesCore.rightEye;
522  }

◆ GetRightEye() [2/2]

static Camera TiltFive.Glasses.GetRightEye ( PlayerIndex  playerIndex)
static

Definition at line 296 of file Glasses.cs.

297  {
298  if (!Player.TryGetGlassesHandle(playerIndex, out var glassesHandle))
299  {
300  return null;
301  }
302  return GetRightEye(glassesHandle);
303  }
static Camera GetRightEye(PlayerIndex playerIndex)
Definition: Glasses.cs:296

◆ headPoseUpdated()

static bool TiltFive.Glasses.headPoseUpdated ( PlayerIndex  playerIndex = PlayerIndex.One)
static

Returns a boolean indication that the head pose was successfully updated.

Returns
true, if the head pose was updated, false otherwise.
Parameters
glassesHandleThe specified glasses. If null is provided, this uses the default glasses.

Definition at line 133 of file Glasses.cs.

134  {
135  if(playerIndex == PlayerIndex.None || !Player.TryGetGlassesHandle(playerIndex, out var glassesHandle))
136  {
137  return false;
138  }
139 
140  return Instance.glassesCores.TryGetValue(glassesHandle, out var glassesCore)
141  && glassesCore.TrackingUpdated;
142  }

References TiltFive.Singleton< Glasses >.Instance.

◆ IsConnected()

static bool TiltFive.Glasses.IsConnected ( PlayerIndex  playerIndex = PlayerIndex.One)
static

Indicate if the specified glasses are connected.

Returns
true if the glasses are connected, false otherwise.
Parameters
glassesHandleGlasses handle to check.

Definition at line 231 of file Glasses.cs.

232  {
233  return Player.TryGetGlassesHandle(playerIndex, out var glassesHandle)
234  && IsConnected(glassesHandle);
235  }
static bool IsConnected(PlayerIndex playerIndex=PlayerIndex.One)
Indicate if the specified glasses are connected.
Definition: Glasses.cs:231

Referenced by TiltFive.Display.GetGlassesAvailability().

◆ IsTracked()

static bool TiltFive.Glasses.IsTracked ( PlayerIndex  playerIndex = PlayerIndex.One)
static

Indicate if the specified glasses are tracked.

Returns
true if the glasses are tracked, false otherwise.
Parameters
playerIndexIf not provided, the Player 1's glasses are checked.

Definition at line 220 of file Glasses.cs.

221  {
222  return Player.TryGetGlassesHandle(playerIndex, out var glassesHandle)
223  && IsTracked(glassesHandle);
224  }
static bool IsTracked(PlayerIndex playerIndex=PlayerIndex.One)
Indicate if the specified glasses are tracked.
Definition: Glasses.cs:220

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

◆ Reset()

static void TiltFive.Glasses.Reset ( GlassesSettings  glassesSettings,
SpectatorSettings  spectatorSettings = null,
PlayerIndex  playerIndex = PlayerIndex.None 
)
static

Reset this T:TiltFive.Glasses.

Parameters
glassesSettingsGlasses settings for configuring the specified glassesCore.
playerIndexThe specified player. If None is provided, this resets all glasses.

Definition at line 149 of file Glasses.cs.

150  {
151  if(spectatorSettings == null && !TryGetSpectatorSettings(out spectatorSettings))
152  {
153  Log.Error("Glasses.Reset() could not find any spectator settings.");
154  return;
155  }
156 
157  // If playerIndex is none, reset all glasses
158  if(playerIndex == PlayerIndex.None)
159  {
160  foreach (var glassesCore in Instance.glassesCores.Values)
161  {
162  glassesCore.Reset(glassesSettings, spectatorSettings);
163  }
164  return;
165  }
166 
167  if(Player.TryGetGlassesHandle(playerIndex, out var glassesHandle))
168  {
169  Reset(glassesSettings, spectatorSettings, glassesHandle);
170  }
171  }
static void Reset(GlassesSettings glassesSettings, SpectatorSettings spectatorSettings=null, PlayerIndex playerIndex=PlayerIndex.None)
Reset this T:TiltFive.Glasses.
Definition: Glasses.cs:149
static bool TryGetSpectatorSettings(out SpectatorSettings spectatorSettings)
Definition: Glasses.cs:534
The Logger.
Definition: Log.cs:42
static void Error(string m, params object[] list)
ERROR logging function call.
Definition: Log.cs:127

References TiltFive.Logging.Log.Error(), TiltFive.Singleton< Glasses >.Instance, and TiltFive.Glasses.TryGetSpectatorSettings().

Referenced by TiltFive.TiltFiveManager.OnEnable().

◆ ScanForGlasses()

static void TiltFive.Glasses.ScanForGlasses ( )
static

Definition at line 305 of file Glasses.cs.

306  {
307  // Enumerate the available glasses provided by the native plugin
308  UInt64[] glassesHandles = new UInt64[GlassesSettings.MAX_SUPPORTED_GLASSES_COUNT];
309  Debug.Assert(glassesHandles.Length <= Byte.MaxValue);
310  byte glassesCount = (byte)glassesHandles.Length;
311  int result = 0;
312 
313  try
314  {
315  var refreshResult = NativePlugin.RefreshGlassesAvailable();
316  result = NativePlugin.GetGlassesHandles(ref glassesCount, glassesHandles);
317  }
318  catch (System.Exception e)
319  {
320  Log.Error($"Error getting glasses handles: {e.Message}");
321  }
322 
323  // Add/Remove entries from the glassesCores dictionary
324  var glassesCores = Instance.glassesCores;
325  var incomingHandles = Instance.incomingHandles;
326  var lostHandles = Instance.lostHandles;
327 
328  incomingHandles.Clear();
329  lostHandles.Clear();
330 
331  // If we ran into a problem getting the glasses handles, all bets are off — just tear down the now-useless glasses cores.
332  if (result != 0)
333  {
334  foreach (var keyValuePair in glassesCores)
335  {
336  var lostHandle = keyValuePair.Key;
337  var glassesCore = keyValuePair.Value;
338 
339  glassesCore.Dispose();
340  lostHandles.Add(lostHandle);
341  }
342  glassesCores.Clear();
343  }
344  else
345  {
346  // Add newly connected glasses
347  for (int i = 0; i < glassesCount; i++)
348  {
349  incomingHandles.Add(glassesHandles[i]);
350 
351  // If we don't already have a glassesCore for this handle,
352  // and we still have an available player slot, then create a glassesCore.
353  if (!glassesCores.ContainsKey(glassesHandles[i]) && !Player.AllSupportedPlayersConnected())
354  {
355 #if UNITY_2019_1_OR_NEWER && INPUTSYSTEM_AVAILABLE
356  glassesCores[glassesHandles[i]] = new GlassesDeviceCore(glassesHandles[i]);
357 #else
358  glassesCores[glassesHandles[i]] = new GlassesCore(glassesHandles[i]);
359 #endif
360  }
361  }
362 
363  // Prune disconnected glasses
364  foreach (var currentHandle in glassesCores.Keys)
365  {
366  if (!incomingHandles.Contains(currentHandle))
367  {
368  lostHandles.Add(currentHandle);
369  }
370  }
371  foreach (var lostHandle in lostHandles)
372  {
373  glassesCores[lostHandle].Dispose();
374  glassesCores.Remove(lostHandle);
375  }
376  }
377 
378  // If we don't have a default glasses ID yet, assign the first one we got from the native plugin as the default.
379  if (!Instance.defaultGlassesHandle.HasValue && result == 0 && glassesCount > 0)
380  {
381  Instance.defaultGlassesHandle = glassesHandles[0];
382  }
383 
384  // If defaultGlassesId isn't valid anymore, reset its value.
385  if (Instance.defaultGlassesHandle.HasValue && !glassesCores.ContainsKey(Instance.defaultGlassesHandle.Value))
386  {
387  Instance.defaultGlassesHandle = null;
388  }
389  }
HashSet< GlassesHandle > incomingHandles
Definition: Glasses.cs:43
Dictionary< GlassesHandle, GlassesCore > glassesCores
The glasses core runtimes.
Definition: Glasses.cs:41
HashSet< GlassesHandle > lostHandles
Definition: Glasses.cs:44
GlassesSettings encapsulates all configuration data used by the Glasses' tracking runtime to compute ...
static int RefreshGlassesAvailable()
static int GetGlassesHandles(ref byte handleCount, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex=0)] UInt64[] glassesHandle)

References TiltFive.NativePlugin.GetGlassesHandles(), and TiltFive.NativePlugin.RefreshGlassesAvailable().

◆ TryGetFriendlyName()

static bool TiltFive.Glasses.TryGetFriendlyName ( PlayerIndex  playerIndex,
out string  friendlyName 
)
static

Definition at line 250 of file Glasses.cs.

251  {
252  if(!Player.TryGetGlassesHandle(playerIndex, out var glassesHandle))
253  {
254  friendlyName = null;
255  return false;
256  }
257 
258  return TryGetFriendlyName(glassesHandle, out friendlyName);
259  }
static bool TryGetFriendlyName(PlayerIndex playerIndex, out string friendlyName)
Definition: Glasses.cs:250

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

◆ TryGetPose()

static bool TiltFive.Glasses.TryGetPose ( PlayerIndex  playerIndex,
out Pose  pose 
)
static

Attempts to get the position and orientation of the specified player's glasses.

Parameters
playerIndex
pose
Returns
Returns false along with an empty pose if something goes wrong.

Definition at line 267 of file Glasses.cs.

268  {
269  if(Player.TryGetGlassesHandle(playerIndex, out var glassesHandle) && Instance.glassesCores.TryGetValue(glassesHandle, out var glassesCore))
270  {
271  pose = glassesCore.Pose_UnityWorldSpace;
272  return true;
273  }
274  pose = new Pose();
275  return false;
276  }

References TiltFive.Singleton< Glasses >.Instance.

Referenced by TiltFive.TiltFiveManager.Update(), and TiltFive.TiltFiveManager2.Update().

◆ TryGetSpectatorSettings()

static bool TiltFive.Glasses.TryGetSpectatorSettings ( out SpectatorSettings  spectatorSettings)
staticprivate

Definition at line 534 of file Glasses.cs.

535  {
536  if (TiltFiveSingletonHelper.TryGetISceneInfo(out var sceneInfo))
537  {
538  if (sceneInfo is TiltFiveManager2 tiltFiveManager2)
539  {
540  spectatorSettings = tiltFiveManager2.spectatorSettings;
541  return true;
542  }
543 
544  if (sceneInfo is TiltFiveManager tiltFiveManager)
545  {
546  spectatorSettings = tiltFiveManager.spectatorSettings;
547  return true;
548  }
549  }
550 
551  spectatorSettings = null;
552  return false;
553  }
The Tilt Five manager.
The Tilt Five manager.
static bool TryGetISceneInfo(out ISceneInfo sceneInfo)

References TiltFive.TiltFiveSingletonHelper.TryGetISceneInfo().

Referenced by TiltFive.Glasses.Reset(), TiltFive.Glasses.Update(), and TiltFive.Glasses.Validate().

◆ Update()

static void TiltFive.Glasses.Update ( GlassesSettings  glassesSettings,
ScaleSettings  scaleSettings,
GameBoardSettings  gameBoardSettings 
)
static

Updates this T:TiltFive.Glasses.

Parameters
glassesSettingsGlasses settings for the update.

Definition at line 201 of file Glasses.cs.

202  {
203  if(!TryGetSpectatorSettings(out var spectatorSettings))
204  {
205  return;
206  }
207 
208  // Update the glasses cores
209  foreach (var glassesCore in Instance.glassesCores.Values)
210  {
211  glassesCore.Update(glassesSettings, scaleSettings, gameBoardSettings, spectatorSettings);
212  }
213  }

References TiltFive.Singleton< Glasses >.Instance, and TiltFive.Glasses.TryGetSpectatorSettings().

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

◆ Validate()

static bool TiltFive.Glasses.Validate ( GlassesSettings  glassesSettings,
SpectatorSettings  spectatorSettings = null,
PlayerIndex  playerIndex = PlayerIndex.One 
)
static

Validates the specified glassesSettings with the specified glasses core.

Returns
true, if the glasses core is valid with the given settings, false otherwise.
Parameters
glassesSettingsGlasses settings.
playerIndexThe specified glasses to validate. If None is provided, this uses the default glasses.

Definition at line 182 of file Glasses.cs.

183  {
184  if(!Player.TryGetGlassesHandle(playerIndex, out var glassesHandle))
185  {
186  return false;
187  }
188 
189  if(spectatorSettings == null && !TryGetSpectatorSettings(out spectatorSettings))
190  {
191  return false;
192  }
193 
194  return Validate(glassesSettings, spectatorSettings, glassesHandle);
195  }
static bool Validate(GlassesSettings glassesSettings, SpectatorSettings spectatorSettings=null, PlayerIndex playerIndex=PlayerIndex.One)
Validates the specified glassesSettings with the specified glasses core.
Definition: Glasses.cs:182

References TiltFive.Glasses.TryGetSpectatorSettings().

Member Data Documentation

◆ defaultGlassesHandle

GlassesHandle? TiltFive.Glasses.defaultGlassesHandle
private

The identifier for the first detected pair of glasses.

Definition at line 49 of file Glasses.cs.

◆ glassesCores

Dictionary<GlassesHandle, GlassesCore> TiltFive.Glasses.glassesCores = new Dictionary<GlassesHandle, GlassesCore>()
private

The glasses core runtimes.

Definition at line 41 of file Glasses.cs.

◆ incomingHandles

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

Definition at line 43 of file Glasses.cs.

◆ lostHandles

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

Definition at line 44 of file Glasses.cs.

Property Documentation

◆ configured

bool TiltFive.Glasses.configured
staticget

Gets a value indicating whether this T:TiltFive.Glasses is configured.

true if player 1's glasses are connected and they've been configured; otherwise, false.

Definition at line 79 of file Glasses.cs.

◆ forward

Vector3 TiltFive.Glasses.forward
staticget

Gets the head orientation's forward vector.

The forward vector of player 1's glasses (if connected, otherwise the default forward vector)

Definition at line 94 of file Glasses.cs.

◆ glassesAvailable

bool TiltFive.Glasses.glassesAvailable
staticgetprivate set

Indicates whether the glasses are plugged in and functioning.

Definition at line 120 of file Glasses.cs.

120 { get; private set; }

◆ leftEyePosition

Vector3 TiltFive.Glasses.leftEyePosition
staticget

Gets the left eye position.

The left eye position of player 1's glasses (if connected, otherwise the zero vector)

Definition at line 110 of file Glasses.cs.

◆ position

Vector3 TiltFive.Glasses.position
staticget

Gets the head pose position.

The position of player 1's glasses (if connected, otherwise a zero vector)

Definition at line 84 of file Glasses.cs.

◆ right

Vector3 TiltFive.Glasses.right
staticget

Gets the head orientation's right vector.

The right vector of player 1's glasses (if connected, otherwise the default right vector)

Definition at line 99 of file Glasses.cs.

◆ rightEyePosition

Vector3 TiltFive.Glasses.rightEyePosition
staticget

Gets the right eye position.

The right eye position of player 1's glasses (if connected, otherwise the zero vector)

Definition at line 115 of file Glasses.cs.

◆ rotation

Quaternion TiltFive.Glasses.rotation
staticget

Gets the head pose rotation.

The rotation of player 1's glasses (if connected, otherwise the identity quaternion)

Definition at line 89 of file Glasses.cs.

◆ up

Vector3 TiltFive.Glasses.up
staticget

Gets the head orientation's up vector.

The up vector of player 1's glasses (if connected, otherwise the default up vector)

Definition at line 104 of file Glasses.cs.

◆ updated

bool TiltFive.Glasses.updated
staticget

Gets a value indicating whether this T:TiltFive.Glasses is updated.

true if player 1's glasses are connected and their glasses pose has been updated; otherwise, false.

Definition at line 73 of file Glasses.cs.

Referenced by TiltFive.SplitStereoCamera.SyncTransform().


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