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