AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
UsabilityUtilities.cs
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License. See LICENSE in the project root for license information.
3 
4 using UnityEngine;
5 
6 namespace HoloToolkit.Unity
7 {
11  public static class UsabilityUtilities
12  {
18  public static float GetUsabilityScaleFactor(Camera camera)
19  {
20  float scaleFactor;
21 
22  if (camera == null)
23  {
24  Debug.LogError("camera is required.");
25  scaleFactor = 1f;
26  }
27  else
28  {
29  const float HololensV1PixelHeight = 720f;
30  const float HololensV1FieldOfView = 17.15f;
31  const float HololensV1PixelsPerDegree = (HololensV1PixelHeight / HololensV1FieldOfView);
32 
33  float pixelsPerDegree = (camera.pixelHeight / camera.fieldOfView);
34 
35  // This scaling equation was derived by having a number of people look at a piece of UI with text
36  // on a HoloLens V1 and a few other HMDs. Each person scaled the content up or down until they
37  // reached an "optimal usability" scale for that HMD. Then, the chosen "optimal usability" scales
38  // were plotted against the HMDs' pixels per degree, and an equation was chosen that approximated
39  // the chosen scales across people and HMDs decently well.
40  //
41  // The equation currently places HoloLensV1 at 1x scale, which means content previously designed
42  // for HoloLens will work as expected. Also, it's asymptotic, so HMDs with extremely high pixels
43  // per degree won't shrink content down too quickly.
44  //
45  // All that said, keep in mind that as new HMDs are created with different pixels per degree and
46  // different visual characteristics, the equation may need to be adjusted or reworked to include
47  // those new characteristics as input to make sure it best targets the broad range of devices.
48 
49  float unclampedScaleFactor = Mathf.Sqrt(HololensV1PixelsPerDegree / pixelsPerDegree);
50 
51  const float MinimumScaleFactor = 0.1f;
52  const float MaximumScaleFactor = 10f;
53 
54  scaleFactor = Mathf.Clamp(unclampedScaleFactor, MinimumScaleFactor, MaximumScaleFactor);
55 
56 #if !UNITY_EDITOR
57  Debug.AssertFormat(unclampedScaleFactor == scaleFactor,
58  "Usability scale factor got clamped from {0} to {1}. Are we calculating HMD characteristics correctly?",
59  unclampedScaleFactor,
60  scaleFactor
61  );
62 #endif
63  }
64 
65  return scaleFactor;
66  }
67  }
68 }
static float GetUsabilityScaleFactor(Camera camera)
Gets a factor useful for scaling visual and interactable objects based on a camera's characteristics ...
A helper class for making applications more usable across different devices.