Tilt Five™ Unity API  1.3.0
 
Loading...
Searching...
No Matches
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.
 
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 ()
 
virtual void Awake ()
 

Private Member Functions

void Start ()
 
void Update ()
 
void LogVersion ()
 
bool SetApplicationInfoImpl ()
 
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 66 of file Display.cs.

Member Function Documentation

◆ Awake()

override void TiltFive.Display.Awake ( )
protectedvirtual

Reimplemented from TiltFive.SingletonComponent< Display >.

Definition at line 75 of file Display.cs.

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

◆ GetDisplayDimensions()

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

Definition at line 372 of file Display.cs.

373 {
374 return Instance.GetDisplayDimensionsImpl(ref displayDimensions);
375 }

References TiltFive.SingletonComponent< Display >.Instance.

Referenced by TiltFive.DisplaySettings.DisplaySettings().

◆ GetDisplayDimensionsImpl()

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

Definition at line 377 of file Display.cs.

378 {
379 int result = 1;
380 try
381 {
382 result = NativePlugin.GetMaxDisplayDimensions(_displaySettings);
383
384 if(result == 0)
385 {
386 displayDimensions = new Vector2Int(_displaySettings[0], _displaySettings[1]);
387 }
388 else Log.Warn("Display.cs: Failed to retrieve display settings from plugin.");
389 }
390 catch (Exception e)
391 {
392 Log.Error(e.Message);
393 }
394
395 return (0 == result);
396 }
int[] _displaySettings
Definition: Display.cs:69
static void Warn(string m, params object[] list)
WARN logging function call.
Definition: Log.cs:166

References TiltFive.Display._displaySettings, TiltFive.Logging.Log.Error(), TiltFive.NativePlugin.GetMaxDisplayDimensions(), 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 190 of file Display.cs.

191 {
192 return Player.IsConnected(PlayerIndex.One) || Player.IsConnected(PlayerIndex.Two) ||
193 Player.IsConnected(PlayerIndex.Three) || Player.IsConnected(PlayerIndex.Four);
194 }
$ Player
Definition: Player.cs:93
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 398 of file Display.cs.

399 {
400 return Instance.GetGlassesIPDImpl(glassesHandle, ref glassesIPD);
401 }

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 403 of file Display.cs.

404 {
405 int result = 1;
406 try
407 {
408 result = NativePlugin.GetGlassesIPD(glassesHandle, ref glassesIPD);
409
410 if(result != 0 && GetGlassesAvailability())
411 {
412 Log.Warn("Display.cs: Failed to retrieve glasses IPD");
413 }
414 }
415 catch (Exception e)
416 {
417 Log.Error(e.Message);
418 }
419
420 return (0 == result);
421 }
static bool GetGlassesAvailability()
Get whether any glasses are available.
Definition: Display.cs:190

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

◆ LogVersion()

void TiltFive.Display.LogVersion ( )
private

Definition at line 108 of file Display.cs.

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

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 196 of file Display.cs.

208 {
209 return Player.TryGetGlassesHandle(playerIndex, out var glassesHandle)
210 && PresentStereoImages(glassesHandle,
211 leftTexHandle,
212 rightTexHandle,
213 texWidth_PIX,
214 texHeight_PIX,
215 isSrgb,
216 fovYDegrees,
217 widthToHeightRatio,
218 rotToUGBD_ULVC,
219 posOfULVC_UGBD,
220 rotToUGBD_URVC,
221 posOfURVC_UGBD);
222 }
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:196

References TiltFive.Display.PresentStereoImages().

Referenced by TiltFive.SplitStereoCamera.PresentStereoImages(), and TiltFive.Display.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 252 of file Display.cs.

265 {
266 // Unity reference frames:
267 //
268 // ULVC / URVC - Unity Left/Right Virtual Camera space.
269 // +x right, +y up, +z forward
270 // UGBD - Unity Gameboard space.
271 // +x right, +y up, +z forward
272 //
273 // Tilt Five reference frames:
274 //
275 // DC - Our right-handed version of Unity's default camera space
276 // (the LVC/RVC if there is no transform set on ULVC/URVC).
277 // +x right, +y up, +z backward
278 // LVC / RVC - Left/Right Virtual Camera space.
279 // +x right, +y up, +z backward
280 // GBD - Gameboard space.
281 // +x right, +y forward, +z up
282
283 Quaternion rotToDC_GBD = Quaternion.AngleAxis(-90f, Vector3.right);
284
285 // Calculate the VCI (the image rectangle in the normalized (z=1) image space of the virtual cameras)
286 float startY_VCI = -Mathf.Tan(fovYDegrees * (0.5f * Mathf.PI / 180.0f));
287 float startX_VCI = startY_VCI * widthToHeightRatio;
288 float width_VCI = -2f * startX_VCI;
289 float height_VCI = -2f * startY_VCI;
290 Rect vci = new Rect(startX_VCI, startY_VCI, width_VCI, height_VCI);
291
292 // Swizzle the left-handed Unity-based coordinates into our right-handed reference frames
293 Quaternion rotToLVC_DC = new Quaternion(rotToUGBD_ULVC.x, rotToUGBD_ULVC.y, -rotToUGBD_ULVC.z, rotToUGBD_ULVC.w);
294 Quaternion rotToRVC_DC = new Quaternion(rotToUGBD_URVC.x, rotToUGBD_URVC.y, -rotToUGBD_URVC.z, rotToUGBD_URVC.w);
295
296 Quaternion rotToLVC_GBD = rotToLVC_DC * rotToDC_GBD;
297 Quaternion rotToRVC_GBD = rotToRVC_DC * rotToDC_GBD;
298
299 // Swap the Y and Z axes to switch from left-handed to right-handed coords
300 Vector3 posOfLVC_GBD = new Vector3(posOfULVC_UGBD.x, posOfULVC_UGBD.z, posOfULVC_UGBD.y);
301 Vector3 posOfRVC_GBD = new Vector3(posOfURVC_UGBD.x, posOfURVC_UGBD.z, posOfURVC_UGBD.y);
302
303 // Build our frame info struct now that we're finished converting from Unity's coord space
304 T5_FrameInfo frameInfo = new T5_FrameInfo();
305
306 frameInfo.LeftTexHandle = leftTexHandle;
307 frameInfo.RightTexHandle = rightTexHandle;
308
309 frameInfo.TexWidth_PIX = (UInt16) texWidth_PIX;
310 frameInfo.TexHeight_PIX = (UInt16) texHeight_PIX;
311
312 frameInfo.IsSrgb = isSrgb;
313 frameInfo.IsUpsideDown = false; // False for Unity, but possibly true for other engines
314
315 frameInfo.VCI = vci;
316
317 frameInfo.RotToLVC_GBD = rotToLVC_GBD;
318 frameInfo.PosOfLVC_GBD = posOfLVC_GBD;
319
320 frameInfo.RotToRVC_GBD = rotToRVC_GBD;
321 frameInfo.PosOfRVC_GBD = posOfRVC_GBD;
322
323 int result = 1;
324 try
325 {
326 result = NativePlugin.QueueStereoImages(glassesHandle, frameInfo);
327 }
328 catch (Exception e)
329 {
330 Log.Error(e.Message);
331 }
332
333 if (result != 0) {
334 return false;
335 }
336
337 if(_sendFrameCallback == IntPtr.Zero)
338 {
339 // We failed to set _sendFrameCallback during Awake() - let's try again
340 try
341 {
342 _sendFrameCallback = NativePlugin.GetSendFrameCallback();
343 }
344 catch (Exception)
345 {
346 Log.Error("Unable to send frame - the native plugin DLL may be failing to load");
347 return false;
348 }
349
350 if (_sendFrameCallback == IntPtr.Zero)
351 {
352 // If we reach this point, the native plugin loaded, but erroneously gave us a null callback
353 Log.Error("Unable to send frame - the native plugin returned a null SendFrame callback");
354 return false;
355 }
356 }
357
358 try
359 {
360 GL.IssuePluginEvent(_sendFrameCallback, 0);
361 GL.InvalidateState();
362 }
363 catch (Exception e)
364 {
365 Log.Error($"Failed to execute sendFrame callback: {e.Message}");
366 return false;
367 }
368
369 return true;
370 }

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

◆ SetApplicationInfo()

static bool TiltFive.Display.SetApplicationInfo ( )
static

Definition at line 144 of file Display.cs.

145 {
146 return Instance.SetApplicationInfoImpl();
147 }

References TiltFive.SingletonComponent< Display >.Instance.

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

◆ SetApplicationInfoImpl()

bool TiltFive.Display.SetApplicationInfoImpl ( )
private

Definition at line 149 of file Display.cs.

150 {
151 string applicationName = Application.productName;
152#if UNITY_EDITOR
153 // TODO: Localize
154 applicationName = $"Unity Editor: {applicationName}";
155#endif
156 string applicationId = Application.identifier;
157 string productVersion = Application.version;
158 string engineVersion = Application.unityVersion;
159 TextAsset pluginVersionAsset = (TextAsset)Resources.Load("pluginversion");
160 string applicationVersionInfo = $"App: {productVersion}, Engine: {engineVersion}, T5 SDK: {pluginVersionAsset.text}";
161
162 int result = 1;
163
164 try
165 {
166 using (T5_StringUTF8 appName = applicationName)
167 using (T5_StringUTF8 appId = applicationId)
168 using (T5_StringUTF8 appVersion = applicationVersionInfo)
169 {
170 result = NativePlugin.SetApplicationInfo(appName, appId, appVersion);
171 }
172 }
173 catch (System.DllNotFoundException e)
174 {
175 Log.Info("Could not connect to Tilt Five plugin to register project info: {0}", e);
176 }
177 catch (Exception)
178 {
179 Log.Error("Failed to register project info with the Tilt Five service.");
180 }
181
182 return result == 0;
183 }

References TiltFive.Logging.Log.Error(), TiltFive.Logging.Log.Info(), and TiltFive.NativePlugin.SetApplicationInfo().

◆ Start()

void TiltFive.Display.Start ( )
private

Definition at line 98 of file Display.cs.

99 {
100
101 }

◆ Update()

void TiltFive.Display.Update ( )
private

Definition at line 103 of file Display.cs.

104 {
105
106 }

Member Data Documentation

◆ _displaySettings

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

Definition at line 69 of file Display.cs.

Referenced by TiltFive.Display.GetDisplayDimensionsImpl().

◆ _sendFrameCallback

IntPtr TiltFive.Display._sendFrameCallback = IntPtr.Zero
private

Definition at line 73 of file Display.cs.

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


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