C# Client 0.0.0.7
C# Library to interface with Corelink
Loading...
Searching...
No Matches
CorelinkParser.cs
Go to the documentation of this file.
1using System;
2using UnityEditor;
3using UnityEngine;
4namespace CoreLink
5{
8 public class CorelinkParser
9 {
15 public static Vector3 bytesToVector3(byte[] message)
16 {
17 return new Vector3
18 {
19 x = BitConverter.ToSingle(message, 0),
20 y = BitConverter.ToSingle(message, sizeof(float)),
21 z = BitConverter.ToSingle(message, sizeof(float) * 2)
22 };
23 }
29 public static byte[] vector3ToBytes(Vector3 vector3)
30 {
31 byte[] msg = new byte[12];
32
33 byte[] valsx = BitConverter.GetBytes(vector3.x);
34 byte[] valsy = BitConverter.GetBytes(vector3.y);
35 byte[] valsz = BitConverter.GetBytes(vector3.z);
36 for (int j = 0; j < 4; j++)
37 {
38 msg[j] = valsx[j];
39 msg[4 + j] = valsy[j];
40 msg[8 + j] = valsz[j];
41 }
42 return msg;
43 }
49 public static Quaternion bytesToQuaternion(byte[] message)
50 {
51 return new Quaternion
52 {
53 x = BitConverter.ToSingle(message, 0),
54 y = BitConverter.ToSingle(message, sizeof(float)),
55 z = BitConverter.ToSingle(message, sizeof(float) * 2),
56 w = BitConverter.ToSingle(message, sizeof(float) * 3)
57 };
58 }
64 public static byte[] quaternionToBytes(Quaternion vector3)
65 {
66 byte[] msg = new byte[16];
67
68 byte[] valsx = BitConverter.GetBytes(vector3.x);
69 byte[] valsy = BitConverter.GetBytes(vector3.y);
70 byte[] valsz = BitConverter.GetBytes(vector3.z);
71 byte[] valsw = BitConverter.GetBytes(vector3.w);
72 for (int j = 0; j < 4; j++)
73 {
74 msg[j] = valsx[j];
75 msg[4 + j] = valsy[j];
76 msg[8 + j] = valsz[j];
77 msg[12 + j] = valsw[j];
78 }
79 return msg;
80 }
81 }
82}