Tilt Five™ Unity API  1.4.1
TiltFive.Display Class Reference
Inheritance diagram for TiltFive.Display:
TiltFive.SingletonComponent< Display >

Static Public Member Functions

static bool SetApplicationInfo ()
 
static bool GetGlassesAvailability ()
 Get whether any glasses are available More...
 
static bool PresentStereoImages (PlayerIndex playerIndex, IntPtr leftTexHandle, IntPtr rightTexHandle, int texWidth_PIX, int texHeight_PIX, bool isSrgb, float fovYDegrees, float widthToHeightRatio, Quaternion rotToUGBD_ULVC, Vector3 posOfULVC_UGBD, Quaternion rotToUGBD_URVC, Vector3 posOfURVC_UGBD)
 
static bool GetDisplayDimensions (ref Vector2Int displayDimensions)
 
static bool GetGlassesIPD (UInt64 glassesHandle, ref float glassesIPD)
 

Protected Member Functions

override void Awake ()
 

Private Member Functions

void LogVersion ()
 
bool PresentStereoImagesImpl (UInt64 glassesHandle, IntPtr leftTexHandle, IntPtr rightTexHandle, int texWidth_PIX, int texHeight_PIX, bool isSrgb, float fovYDegrees, float widthToHeightRatio, Quaternion rotToUGBD_ULVC, Vector3 posOfULVC_UGBD, Quaternion rotToUGBD_URVC, Vector3 posOfURVC_UGBD)
 
bool GetDisplayDimensionsImpl (ref Vector2Int displayDimensions)
 
bool GetGlassesIPDImpl (UInt64 glassesHandle, ref float glassesIPD)
 

Private Attributes

int[] _displaySettings = new int[2]
 
IntPtr _sendFrameCallback = IntPtr.Zero
 

Additional Inherited Members

- Properties inherited from TiltFive.SingletonComponent< Display >
static T Instance [get]
 

Detailed Description

Definition at line 65 of file Display.cs.

Member Function Documentation

◆ Awake()

override void TiltFive.Display.Awake ( )
protectedvirtual

Reimplemented from TiltFive.SingletonComponent< Display >.

Definition at line 74 of file Display.cs.

75  {
76  base.Awake();
77 
78  try
79  {
80  _sendFrameCallback = NativePlugin.GetSendFrameCallback();
81  }
82  catch (System.DllNotFoundException e)
83  {
84  Log.Info("Could not connect to Tilt Five plugin to get callback: {0}", e);
85  }
86  catch (Exception e)
87  {
88  Log.Error(e.Message);
89  }
90 
91  LogVersion();
92 
93  QualitySettings.vSyncCount = 0;
94  QualitySettings.maxQueuedFrames = 0;
95  }
void LogVersion()
Definition: Display.cs:97
IntPtr _sendFrameCallback
Definition: Display.cs:72
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

References TiltFive.Display._sendFrameCallback, TiltFive.Logging.Log.Error(), TiltFive.Logging.Log.Info(), and TiltFive.Display.LogVersion().

◆ GetDisplayDimensions()

static bool TiltFive.Display.GetDisplayDimensions ( ref Vector2Int  displayDimensions)
static

Definition at line 326 of file Display.cs.

327  {
328  return Instance.GetDisplayDimensionsImpl(ref displayDimensions);
329  }

References TiltFive.SingletonComponent< Display >.Instance.

Referenced by TiltFive.DisplaySettings.DisplaySettings().

◆ GetDisplayDimensionsImpl()

bool TiltFive.Display.GetDisplayDimensionsImpl ( ref Vector2Int  displayDimensions)
private

Definition at line 331 of file Display.cs.

332  {
333  int result = NativePlugin.T5_RESULT_UNKNOWN_ERROR;
334  try
335  {
336  result = NativePlugin.GetMaxDisplayDimensions(_displaySettings);
337 
338  if(result == NativePlugin.T5_RESULT_SUCCESS)
339  {
340  displayDimensions = new Vector2Int(_displaySettings[0], _displaySettings[1]);
341  }
342  else Log.Warn("Display.cs: Failed to retrieve display settings from plugin.");
343  }
344  catch (Exception e)
345  {
346  Log.Error(e.Message);
347  }
348 
349  return result == NativePlugin.T5_RESULT_SUCCESS;
350  }
int[] _displaySettings
Definition: Display.cs:68
static void Warn(string m, params object[] list)
WARN logging function call.
Definition: Log.cs:166

References TiltFive.Display._displaySettings, TiltFive.Logging.Log.Error(), and TiltFive.Logging.Log.Warn().

◆ GetGlassesAvailability()

static bool TiltFive.Display.GetGlassesAvailability ( )
static

Get whether any glasses are available

If you want to check whether glasses for a specific player index are available, use T:TiltFive.Player.IsConnected instead.

Returns
true if glasses are available, false otherwise.

Definition at line 144 of file Display.cs.

145  {
146  return Player.IsConnected(PlayerIndex.One) || Player.IsConnected(PlayerIndex.Two) ||
147  Player.IsConnected(PlayerIndex.Three) || Player.IsConnected(PlayerIndex.Four);
148  }
PlayerIndex
The Player index (e.g. Player One, Player Two, etc)

References TiltFive.Player.IsConnected().

Referenced by TiltFive.Display.GetGlassesIPDImpl().

◆ GetGlassesIPD()

static bool TiltFive.Display.GetGlassesIPD ( UInt64  glassesHandle,
ref float  glassesIPD 
)
static

Definition at line 352 of file Display.cs.

353  {
354  return Instance.GetGlassesIPDImpl(glassesHandle, ref glassesIPD);
355  }

References TiltFive.SingletonComponent< Display >.Instance.

Referenced by TiltFive.Glasses.GlassesCore.Update().

◆ GetGlassesIPDImpl()

bool TiltFive.Display.GetGlassesIPDImpl ( UInt64  glassesHandle,
ref float  glassesIPD 
)
private

Definition at line 357 of file Display.cs.

358  {
359  int result = NativePlugin.T5_RESULT_UNKNOWN_ERROR;
360  try
361  {
362  result = NativePlugin.GetGlassesIPD(glassesHandle, ref glassesIPD);
363 
364  if(result != NativePlugin.T5_RESULT_SUCCESS && GetGlassesAvailability())
365  {
366  Log.Warn("Display.cs: Failed to retrieve glasses IPD");
367  }
368  }
369  catch (Exception e)
370  {
371  Log.Error(e.Message);
372  }
373 
374  return result == NativePlugin.T5_RESULT_SUCCESS;
375  }
static bool GetGlassesAvailability()
Get whether any glasses are available
Definition: Display.cs:144

References TiltFive.Logging.Log.Error(), TiltFive.Display.GetGlassesAvailability(), and TiltFive.Logging.Log.Warn().

◆ LogVersion()

void TiltFive.Display.LogVersion ( )
private

Definition at line 97 of file Display.cs.

98  {
99  string version = "NOT VERSIONED";
100 
101  // load version file and get the string value
102  TextAsset asset = (TextAsset)Resources.Load("pluginversion", typeof(TextAsset));
103  if (asset != null)
104  {
105  version = asset.text;
106  }
107 
108  // turn on logging if it was turned off
109  bool logEnabled = Debug.unityLogger.logEnabled;
110  if (!logEnabled)
111  {
112  Debug.unityLogger.logEnabled = true;
113  }
114 
115  // get previous setting
116  StackTraceLogType logType = Application.GetStackTraceLogType(LogType.Log);
117 
118  // turn off stacktrace logging for our messaging
119  Application.SetStackTraceLogType(LogType.Log, StackTraceLogType.None);
120 
121  Log.Info("\n********************************" +
122  "\n* Tilt Five: Unity SDK Version - " +
123  version +
124  "\n********************************");
125 
126  // reset to initial log settings
127  Application.SetStackTraceLogType(LogType.Log, logType);
128 
129  // reset logging enabled to previous
130  Debug.unityLogger.logEnabled = logEnabled;
131  }

References TiltFive.Logging.Log.Info().

Referenced by TiltFive.Display.Awake().

◆ PresentStereoImages()

static bool TiltFive.Display.PresentStereoImages ( PlayerIndex  playerIndex,
IntPtr  leftTexHandle,
IntPtr  rightTexHandle,
int  texWidth_PIX,
int  texHeight_PIX,
bool  isSrgb,
float  fovYDegrees,
float  widthToHeightRatio,
Quaternion  rotToUGBD_ULVC,
Vector3  posOfULVC_UGBD,
Quaternion  rotToUGBD_URVC,
Vector3  posOfURVC_UGBD 
)
static

Definition at line 150 of file Display.cs.

162  {
163  return Player.TryGetGlassesHandle(playerIndex, out var glassesHandle)
164  && PresentStereoImages(glassesHandle,
165  leftTexHandle,
166  rightTexHandle,
167  texWidth_PIX,
168  texHeight_PIX,
169  isSrgb,
170  fovYDegrees,
171  widthToHeightRatio,
172  rotToUGBD_ULVC,
173  posOfULVC_UGBD,
174  rotToUGBD_URVC,
175  posOfURVC_UGBD);
176  }
static bool PresentStereoImages(PlayerIndex playerIndex, IntPtr leftTexHandle, IntPtr rightTexHandle, int texWidth_PIX, int texHeight_PIX, bool isSrgb, float fovYDegrees, float widthToHeightRatio, Quaternion rotToUGBD_ULVC, Vector3 posOfULVC_UGBD, Quaternion rotToUGBD_URVC, Vector3 posOfURVC_UGBD)
Definition: Display.cs:150

Referenced by TiltFive.SplitStereoCamera.PresentStereoImages().

◆ PresentStereoImagesImpl()

bool TiltFive.Display.PresentStereoImagesImpl ( UInt64  glassesHandle,
IntPtr  leftTexHandle,
IntPtr  rightTexHandle,
int  texWidth_PIX,
int  texHeight_PIX,
bool  isSrgb,
float  fovYDegrees,
float  widthToHeightRatio,
Quaternion  rotToUGBD_ULVC,
Vector3  posOfULVC_UGBD,
Quaternion  rotToUGBD_URVC,
Vector3  posOfURVC_UGBD 
)
private

Definition at line 206 of file Display.cs.

219  {
220  // Unity reference frames:
221  //
222  // ULVC / URVC - Unity Left/Right Virtual Camera space.
223  // +x right, +y up, +z forward
224  // UGBD - Unity Gameboard space.
225  // +x right, +y up, +z forward
226  //
227  // Tilt Five reference frames:
228  //
229  // DC - Our right-handed version of Unity's default camera space
230  // (the LVC/RVC if there is no transform set on ULVC/URVC).
231  // +x right, +y up, +z backward
232  // LVC / RVC - Left/Right Virtual Camera space.
233  // +x right, +y up, +z backward
234  // GBD - Gameboard space.
235  // +x right, +y forward, +z up
236 
237  Quaternion rotToDC_GBD = Quaternion.AngleAxis(-90f, Vector3.right);
238 
239  // Calculate the VCI (the image rectangle in the normalized (z=1) image space of the virtual cameras)
240  float startY_VCI = -Mathf.Tan(fovYDegrees * (0.5f * Mathf.PI / 180.0f));
241  float startX_VCI = startY_VCI * widthToHeightRatio;
242  float width_VCI = -2f * startX_VCI;
243  float height_VCI = -2f * startY_VCI;
244  Rect vci = new Rect(startX_VCI, startY_VCI, width_VCI, height_VCI);
245 
246  // Swizzle the left-handed Unity-based coordinates into our right-handed reference frames
247  Quaternion rotToLVC_DC = new Quaternion(rotToUGBD_ULVC.x, rotToUGBD_ULVC.y, -rotToUGBD_ULVC.z, rotToUGBD_ULVC.w);
248  Quaternion rotToRVC_DC = new Quaternion(rotToUGBD_URVC.x, rotToUGBD_URVC.y, -rotToUGBD_URVC.z, rotToUGBD_URVC.w);
249 
250  Quaternion rotToLVC_GBD = rotToLVC_DC * rotToDC_GBD;
251  Quaternion rotToRVC_GBD = rotToRVC_DC * rotToDC_GBD;
252 
253  // Swap the Y and Z axes to switch from left-handed to right-handed coords
254  Vector3 posOfLVC_GBD = new Vector3(posOfULVC_UGBD.x, posOfULVC_UGBD.z, posOfULVC_UGBD.y);
255  Vector3 posOfRVC_GBD = new Vector3(posOfURVC_UGBD.x, posOfURVC_UGBD.z, posOfURVC_UGBD.y);
256 
257  // Build our frame info struct now that we're finished converting from Unity's coord space
258  T5_FrameInfo frameInfo = new T5_FrameInfo();
259 
260  frameInfo.LeftTexHandle = leftTexHandle;
261  frameInfo.RightTexHandle = rightTexHandle;
262 
263  frameInfo.TexWidth_PIX = (UInt16) texWidth_PIX;
264  frameInfo.TexHeight_PIX = (UInt16) texHeight_PIX;
265 
266  frameInfo.IsSrgb = isSrgb;
267  frameInfo.IsUpsideDown = false; // False for Unity, but possibly true for other engines
268 
269  frameInfo.VCI = vci;
270 
271  frameInfo.RotToLVC_GBD = rotToLVC_GBD;
272  frameInfo.PosOfLVC_GBD = posOfLVC_GBD;
273 
274  frameInfo.RotToRVC_GBD = rotToRVC_GBD;
275  frameInfo.PosOfRVC_GBD = posOfRVC_GBD;
276 
277  int result = NativePlugin.T5_RESULT_UNKNOWN_ERROR;
278  try
279  {
280  result = NativePlugin.QueueStereoImages(glassesHandle, frameInfo);
281  }
282  catch (Exception e)
283  {
284  Log.Error(e.Message);
285  }
286 
287  if (result != NativePlugin.T5_RESULT_SUCCESS) {
288  return false;
289  }
290 
291  if(_sendFrameCallback == IntPtr.Zero)
292  {
293  // We failed to set _sendFrameCallback during Awake() - let's try again
294  try
295  {
296  _sendFrameCallback = NativePlugin.GetSendFrameCallback();
297  }
298  catch (Exception)
299  {
300  Log.Error("Unable to send frame - the native plugin DLL may be failing to load");
301  return false;
302  }
303 
304  if (_sendFrameCallback == IntPtr.Zero)
305  {
306  // If we reach this point, the native plugin loaded, but erroneously gave us a null callback
307  Log.Error("Unable to send frame - the native plugin returned a null SendFrame callback");
308  return false;
309  }
310  }
311 
312  try
313  {
314  GL.IssuePluginEvent(_sendFrameCallback, 0);
315  GL.InvalidateState();
316  }
317  catch (Exception e)
318  {
319  Log.Error($"Failed to execute sendFrame callback: {e.Message}");
320  return false;
321  }
322 
323  return true;
324  }

References TiltFive.Display._sendFrameCallback, and TiltFive.Logging.Log.Error().

◆ SetApplicationInfo()

static bool TiltFive.Display.SetApplicationInfo ( )
static

Definition at line 134 of file Display.cs.

135  {
136  return SystemControl.SetApplicationInfo();
137  }

Member Data Documentation

◆ _displaySettings

int [] TiltFive.Display._displaySettings = new int[2]
private

Definition at line 68 of file Display.cs.

Referenced by TiltFive.Display.GetDisplayDimensionsImpl().

◆ _sendFrameCallback

IntPtr TiltFive.Display._sendFrameCallback = IntPtr.Zero
private

Definition at line 72 of file Display.cs.

Referenced by TiltFive.Display.Awake(), and TiltFive.Display.PresentStereoImagesImpl().


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