예제 #1
0
        public PerceptionClientJsonTest()
        {
            string           demoJson = "{  'TrackingState': 3,  'Camera': {  'Displays': [{  'Frustum': {  'Bottom': [-0.051801, -0.938592, 0.341118, 0.096521],  'Far': [0.161880, -0.108995, -0.980773, -14.932893],  'Left': [-0.978711, 0.035061, 0.202229, -0.001346],  'Near': [-0.161880, 0.108995, 0.980773, 0.229674],  'Right': [0.852517, 0.045374, 0.520726, 0.059935],  'Top': [-0.027835, 0.989556, 0.141437, -0.057139]  },  'FocusPointDisplay': [0.027431, -0.055531, 0.681227],  'FocusPointNormalDisplay': [0.027496, 0.018920, -0.999443],  'Projection': [2.517434, 0.000000, 0.000000, 0.000000, 0.000000, 3.942319, 0.000000, 0.000000, 0.026739, 0.022574, -1.010101, -1.000000, 0.000000, 0.000000, -0.151515, 0.000000],  'View': [0.986714, 0.013233, -0.161879, 0.000000, 0.004548, 0.994024, 0.108994, 0.000000, 0.162359, -0.108279, 0.980768, 0.000000, 0.032239, -0.079692, 0.079658, 1.000000]  }, {  'Frustum': {  'Bottom': [-0.038760, -0.936097, 0.349601, 0.097126],  'Far': [0.151884, -0.110772, -0.982171, -14.933148],  'Left': [-0.972330, 0.027587, 0.231978, 0.060137],  'Near': [-0.151884, 0.110772, 0.982171, 0.230036],  'Right': [0.866618, 0.054504, 0.495987, -0.001130],  'Top': [-0.036070, 0.990279, 0.134340, -0.057670]  },  'FocusPointDisplay': [0.027431, -0.055531, 0.681227],  'FocusPointNormalDisplay': [0.027496, 0.018920, -0.999443],  'Projection': [2.510000, 0.000000, 0.000000, 0.000000, 0.000000, 3.934346, 0.000000, 0.000000, -0.026656, 0.003352, -1.010101, -1.000000, 0.000000, 0.000000, -0.151515, 0.000000],  'View': [0.988389, 0.001509, -0.151883, 0.000000, 0.015503, 0.993717, 0.110772, 0.000000, 0.151101, -0.111838, 0.982167, 0.000000, -0.032242, -0.079922, 0.080020, 1.000000]  }  ]  },  'ControllerData': {},  'LSRPlane': {  'distance': 0.681144,  'x': 0.027496,  'y': 0.018920,  'z': -0.999443  },  'HeadToAttachedFor': [0.987598, 0.010029, 0.156735, 0.000000, -0.005502, 0.999565, -0.029288, 0.000000, -0.156963, 0.028058, 0.987211, 0.000000, 0.013141, 0.070723, -0.087326, 1.000000],  'OriginToAttachedFor': [1.000005, 0.000028, 0.000374, 0.000000, -0.000027, 1.000005, -0.000055, 0.000000, -0.000376, 0.000053, 1.000003, 0.000000, 0.033230, -0.006217, 0.002964, 1.000000] } ";
            PerceptionClient pc       = JsonConvert.DeserializeObject <PerceptionClient>(demoJson);

            Debug.WriteLine(pc.TrackingState);
        }
예제 #2
0
        public DeviceSocket(string userName, string password, string IP)
        {
            this.userName = userName;
            this.password = password;
            this.IP       = IP;

            Result = "";
            // rest call for the head and origin camera position and orientation.
            // notably different from the documented API (/api/holographic/perception/client)
            webSocket = new WebSocket("ws://" + IP + positionCommand);

            //need to specify origin, which would be the home page?
            webSocket.Origin = "http://" + IP;

            bool preAuth = true;

            webSocket.SetCredentials(userName, password, preAuth);

            webSocket.OnError += (sender, e) =>
            {
                Debug.WriteLine("Error: " + e.Message);
                Result = "Error: " + e.Message;
            };

            webSocket.OnMessage += (sender, e) =>
            {
                PerceptionClient perceptionClient = JsonConvert.DeserializeObject <PerceptionClient>(e.Data);

                int           index   = 0;
                StringBuilder results = new StringBuilder();

                //OriginToAttachedFor -> JSON tag for the 4x4 transformation matrix of the origin
                //HeadToAttachedFor -> same, for the head.
                //not sure of the difference really

                //last row of origin is the position vector
                results.Append("Origin position\n\n");
                for (int i = 3; i < 4; i++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        results.Append(string.Format("{0,8:###.00000}", perceptionClient.OriginToAttachedFor[index]));

                        index++;
                    }
                    results.Append("\n");
                }

                results.Append("\n");

                //convert the 4x4 transformation matrix to quaternion (ignore position data)
                float[] HeadQuat = transformToQuaternion(perceptionClient.HeadToAttachedFor);

                results.Append("Head Rotation Quaternion\n\n");

                for (int i = 0; i < 4; i++)
                {
                    results.Append(string.Format("{0,8:###.00000}", HeadQuat[i]));
                }

                Result = results.ToString();
            };

            webSocket.OnClose += (sender, e) =>
            {
                Debug.WriteLine("Closed: " + e.Reason);
                Result = "Closed: " + e.Reason;
            };

            webSocket.Connect();
        }