MaxstARSDK  3.5.0
WearableCalibration.cs
1 /*==============================================================================
2 Copyright 2017 Maxst, Inc. All Rights Reserved.
3 ==============================================================================*/
4 
5 using UnityEngine;
6 using System;
7 using System.Linq;
8 using System.Runtime.InteropServices;
9 
10 namespace maxstAR
11 {
15  public class WearableCalibration
16  {
20  public enum EyeType
21  {
25  EYE_LEFT = 0,
26 
30  EYE_RIGHT = 1,
31 
35  EYE_NUM = 2,
36  };
37 
41  public enum WearableType
42  {
46  None = 0,
47 
51  OpticalSeeThrough = 1,
52  };
53 
54  private static WearableCalibration instance = null;
55 
61  {
62  if (instance == null)
63  {
64  instance = new WearableCalibration();
65  }
66  return instance;
67  }
68 
69  public string activeProfile { get; set; }
70 
71  private WearableCalibration()
72  {
73  }
74 
79  public bool IsActivated()
80  {
81  if (Application.platform == RuntimePlatform.IPhonePlayer)
82  {
83  return NativeStaticAPI.WearableCalibration_isActivated();
84  }
85  else
86  {
87  return NativeSharedAPI.WearableCalibration_isActivated();
88  }
89  }
90 
98  public bool Init(string modelName, int width, int height)
99  {
100  bool result = false;
101 
102  if (Application.platform == RuntimePlatform.IPhonePlayer)
103  {
104  result = NativeStaticAPI.WearableCalibration_init(modelName);
105  }
106  else
107  {
108  result = NativeSharedAPI.WearableCalibration_init(modelName);
109  }
110 
111  Debug.Log("Wearable Init is " + result.ToString());
112 
113  AndroidJavaClass javaUnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
114  AndroidJavaObject currentActivity = javaUnityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
115 
116  AndroidJavaClass javaClass = new AndroidJavaClass("com.maxst.ar.WearableCalibration");
117  AndroidJavaObject javaObject = javaClass.CallStatic<AndroidJavaObject>("getInstance");
118 
119  if (!javaObject.Call<bool>("readActiveProfile", currentActivity, modelName))
120  {
121  Debug.Log("Read Default Profile.");
122  }
123 
124  activeProfile = javaObject.Call<string>("getActiveProfileName");
125 
126  javaObject.Call("setSurfaceSize", Screen.width, Screen.height);
127 
128  currentActivity.Dispose();
129  javaUnityPlayer.Dispose();
130 
131  return result;
132  }
133 
137  public void Deinit()
138  {
139  if (Application.platform == RuntimePlatform.IPhonePlayer)
140  {
141  NativeStaticAPI.WearableCalibration_deinit();
142  }
143  else
144  {
145  NativeSharedAPI.WearableCalibration_deinit();
146  }
147  }
148 
154  //public void SetSurfaceSize(int width, int height)
155  //{
156  // if (Application.platform == RuntimePlatform.IPhonePlayer)
157  // {
158  // NativeStaticAPI.WearableCalibration_setSurfaceSize(width, height);
159  // }
160  // else
161  // {
162  // NativeSharedAPI.WearableCalibration_setSurfaceSize(width, height);
163  // }
164  //}
165 
171  public float[] GetViewport(EyeType eyeType)
172  {
173  float[] viewport = new float[4];
174  if (Application.platform == RuntimePlatform.IPhonePlayer)
175  {
176  viewport[0] = 0.0f;
177  viewport[1] = 0.0f;
178  viewport[2] = 0.5f;
179  viewport[3] = 1.0f;
180  }
181  else
182  {
183  viewport[0] = 0.5f;
184  viewport[1] = 0.0f;
185  viewport[2] = 0.5f;
186  viewport[3] = 1.0f;
187  }
188  return viewport;
189  }
190 
196  public float[] GetProjectionMatrix(EyeType eyeType)
197  {
198  float[] projection = new float[16];
199  if (Application.platform == RuntimePlatform.IPhonePlayer)
200  {
201  NativeStaticAPI.WearableCalibration_getProjectionMatrix(projection, (int)eyeType);
202  }
203  else
204  {
205  NativeSharedAPI.WearableCalibration_getProjectionMatrix(projection, (int)eyeType);
206  }
207  return projection;
208  }
209  }
210 }
bool Init(string modelName, int width, int height)
Initialize the HMD device.
float [] GetViewport(EyeType eyeType)
Get HMD screen viewport.
WearableType
Wearable Device Type
float [] GetProjectionMatrix(EyeType eyeType)
Get calibrated HMD projection matrix.
API for wearable calibration.
bool IsActivated()
Confirm that the HMD unit is initialized.
static WearableCalibration GetInstance()
Get a WearableCalibration instance.
void Deinit()
Deinitialize the HMD device.