MaxstARSDK  3.5.0
Trackable.cs
1 /*==============================================================================
2 Copyright 2017 Maxst, Inc. All Rights Reserved.
3 ==============================================================================*/
4 
5 using UnityEngine;
6 using System;
7 using System.Collections.Generic;
8 using System.Linq;
9 using System.Text;
10 using System.Runtime.InteropServices;
11 
12 namespace maxstAR
13 {
17  public class Trackable
18  {
19  private ulong cPtr;
20  private float[] glPoseMatrix = new float[16];
21  private byte[] idBytes = new byte[100];
22  private byte[] nameBytes = new byte[100];
23 
24  internal Trackable(ulong cPtr)
25  {
26  this.cPtr = cPtr;
27  }
28 
31  public string GetId()
32  {
33  Array.Clear(idBytes, 0, idBytes.Length);
34 
35  if (Application.platform == RuntimePlatform.IPhonePlayer)
36  {
37  NativeStaticAPI.Trackable_getId(cPtr, idBytes);
38  }
39  else
40  {
41  NativeSharedAPI.Trackable_getId(cPtr, idBytes);
42  }
43 
44  return Encoding.UTF8.GetString(idBytes).TrimEnd('\0');
45  }
46 
50  public string GetName()
51  {
52  Array.Clear(nameBytes, 0, nameBytes.Length);
53 
54  if (Application.platform == RuntimePlatform.IPhonePlayer)
55  {
56  NativeStaticAPI.Trackable_getName(cPtr, nameBytes);
57  }
58  else
59  {
60  NativeSharedAPI.Trackable_getName(cPtr, nameBytes);
61  }
62 
63  return Encoding.UTF8.GetString(nameBytes).TrimEnd('\0');
64  }
65 
68  public Matrix4x4 GetPose()
69  {
70  if (Application.platform == RuntimePlatform.IPhonePlayer)
71  {
72  NativeStaticAPI.Trackable_getPose(cPtr, glPoseMatrix);
73  }
74  else
75  {
76  NativeSharedAPI.Trackable_getPose(cPtr, glPoseMatrix);
77  }
78 
81  {
82  //Quaternion rotation = Quaternion.Euler(90, 0, 0);
83  //Matrix4x4 tempPose = Matrix4x4.identity;
84  //Matrix4x4 m = Matrix4x4.TRS(new Vector3(0, 0, 0), rotation, new Vector3(1, 1, 1));
85  //tempPose = m * tempPose;
86  //rotation = Quaternion.Euler(-90, 0, 0);
87  //m = Matrix4x4.TRS(Vector3.zero, rotation, new Vector3(1, 1, 1));
88  //tempPose = tempPose * m;
89  //return tempPose;
90  return Matrix4x4.identity;
91  }
92  else
93  {
94  Matrix4x4 tempPose = MatrixUtils.GetUnityPoseMatrix(glPoseMatrix);
95  Quaternion rotation = Quaternion.Euler(90, 0, 0);
96  Matrix4x4 m = Matrix4x4.TRS(Camera.main.transform.position, rotation, new Vector3(1, 1, 1));
97 
98  // First. Change world matrix
99  tempPose = m * tempPose;
100 
101  rotation = Quaternion.Euler(-90, 0, 0);
102  m = Matrix4x4.TRS(Vector3.zero, rotation, new Vector3(1, 1, 1));
103 
104  // Second. Change local matrix
105  tempPose = tempPose * m;
106 
107  return tempPose;
108  //return MatrixUtils.GetUnityPoseMatrix(glPoseMatrix);
109  }
110  }
111 
112  // Get target pose for camera transform (When world center mode is TARGET)
113  internal Matrix4x4 GetTargetPose()
114  {
115  if (Application.platform == RuntimePlatform.IPhonePlayer)
116  {
117  NativeStaticAPI.Trackable_getPose(cPtr, glPoseMatrix);
118  }
119  else
120  {
121  NativeSharedAPI.Trackable_getPose(cPtr, glPoseMatrix);
122  }
123 
124  return MatrixUtils.GetUnityPoseMatrix(glPoseMatrix);
125  }
126 
127  //public float GetDistance()
128  //{
129  // if (Application.platform == RuntimePlatform.IPhonePlayer)
130  // {
131  // return NativeStaticAPI.Trackable_getDistance(index);
132  // }
133  // else
134  // {
135  // return NativeSharedAPI.Trackable_getDistance(index);
136  // }
137  //}
138 
139  //public float GetWidth()
140  //{
141  // if (Application.platform == RuntimePlatform.IPhonePlayer)
142  // {
143  // return NativeStaticAPI.Trackable_getWidth(index);
144  // }
145  // else
146  // {
147  // return NativeSharedAPI.Trackable_getWidth(index);
148  // }
149  //}
150 
151  //public float GetHeight()
152  //{
153  // if (Application.platform == RuntimePlatform.IPhonePlayer)
154  // {
155  // return NativeStaticAPI.Trackable_getHeight(index);
156  // }
157  // else
158  // {
159  // return NativeSharedAPI.Trackable_getHeight(index);
160  // }
161  //}
162  }
163 }
WorldCenterMode
The world center mode defines what is the center in game view. If camera is world center then trackab...
WorldCenterMode WorldCenterModeSetting
Get world center mode value
Initialize system environment with app key, screen size and orientation
Matrix4x4 GetPose()
Definition: Trackable.cs:68
string GetName()
Definition: Trackable.cs:50
string GetId()
Definition: Trackable.cs:31
Container for individual tracking information
Definition: Trackable.cs:17