-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVorpX.cs
245 lines (196 loc) · 8.63 KB
/
VorpX.cs
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
using System;
using System.Runtime.InteropServices;
using UnityEngine;
public static class VorpX
{
const string dllName = @"C:\Users\SKIKK\Documents\vorpAPI.dll";
// Import the C API functions as external functions in C#
[DllImport(dllName, CallingConvention = CallingConvention.Cdecl)]
public static extern VPX_RESULT vpxInit();
[DllImport(dllName, CallingConvention = CallingConvention.Cdecl)]
public static extern VPX_RESULT vpxFree();
[DllImport(dllName, CallingConvention = CallingConvention.Cdecl)]
public static extern VPX_BOOL vpxIsActive();
[DllImport(dllName, CallingConvention = CallingConvention.Cdecl)]
public static extern float vpxGetHeadsetFOV();
[DllImport(dllName, CallingConvention = CallingConvention.Cdecl)]
public static extern float vpxVertToHorFOV(float fov_deg, float aspect);
[DllImport(dllName, CallingConvention = CallingConvention.Cdecl)]
public static extern vpxfloat3 vpxGetHeadsetRotationEuler();
[DllImport(dllName, CallingConvention = CallingConvention.Cdecl)]
public static extern vpxfloat4 vpxGetHeadsetRotationQuaternion();
[DllImport(dllName, CallingConvention = CallingConvention.Cdecl)]
public static extern vpxfloat3 vpxGetHeadsetPosition();
[DllImport(dllName, CallingConvention = CallingConvention.Cdecl)]
public static extern VPX_CONTROLLER_STATE vpxGetControllerState(uint controllerNum);
[DllImport(dllName, CallingConvention = CallingConvention.Cdecl)]
public static extern vpxfloat3 vpxGetControllerRotationEuler(uint cotrollerNum);
[DllImport(dllName, CallingConvention = CallingConvention.Cdecl)]
public static extern vpxfloat4 vpxGetControllerRotationQuaternion(uint controllerNum);
[DllImport(dllName, CallingConvention = CallingConvention.Cdecl)]
public static extern vpxfloat3 vpxGetControllerPosition(uint controllerNum);
[DllImport(dllName, CallingConvention = CallingConvention.Cdecl)]
public static extern void vpxForceControllerRendering(VPX_BOOL val);
[DllImport(dllName, CallingConvention = CallingConvention.Cdecl)]
public static extern vpxfloat3 vpxYawCorrection(vpxfloat3 position, float yawInDegrees);
[DllImport(dllName, CallingConvention = CallingConvention.Cdecl)]
public static extern void vpxRequestEdgePeek(VPX_BOOL val);
[DllImport(dllName, CallingConvention = CallingConvention.Cdecl)]
public static extern VPX_BOOL vpxGetEdgePeekRequested();
[DllImport(dllName, CallingConvention = CallingConvention.Cdecl)]
public static extern VPX_BOOL vpxGetEdgePeekActual();
[DllImport(dllName, CallingConvention = CallingConvention.Cdecl)]
public static extern vpxfloat3 vpxGetEyePosition(uint eye, float ipd);
[DllImport(dllName, CallingConvention = CallingConvention.Cdecl)]
public static extern float vpxGetG3DStrength();
[DllImport(dllName, CallingConvention = CallingConvention.Cdecl)]
public static extern int vpxGetCurrentVorpFrame();
[DllImport(dllName, CallingConvention = CallingConvention.Cdecl)]
public static extern VPX_BOOL vpxIsVorpDoing3D();
[DllImport(dllName, CallingConvention = CallingConvention.Cdecl)]
public static extern void vpxSetGameCamRotationDeltaEuler(vpxfloat3 rotation);
[DllImport(dllName, CallingConvention = CallingConvention.Cdecl)]
public static extern void vpxSetStereoReduction(float reduction);
[DllImport(dllName, CallingConvention = CallingConvention.Cdecl)]
public static extern void vpxInitStereo();
[DllImport(dllName, CallingConvention = CallingConvention.Cdecl)]
public static extern void vpxSetGameStereoRenderMode(VPX_GAME_STEREO_MODE stereoMode);
[DllImport(dllName, CallingConvention = CallingConvention.Cdecl)]
public static extern void vpxSetAlternateFrame3DEye(uint eye);
public static float vpxDegToRad(float a)
{
return a * 0.0174532925f;
}
public static float vpxRadToDeg(float a)
{
return a * 57.295795131f;
}
public static Vector3 GetControllerPosition(int controllerNum)
{
var controllerPosition = vpxGetControllerPosition((uint) controllerNum);
return new Vector3(controllerPosition.x, controllerPosition.y, controllerPosition.z);
}
public static Vector3 GetControllerRotationEuler(int controllerNum)
{
var controllerRotation = vpxGetControllerRotationEuler((uint) controllerNum);
return new Vector3(controllerRotation.x, controllerRotation.y, controllerRotation.z);
}
public static Quaternion GetControllerRotationQuaternion(int controllerNum)
{
var controllerRotation = vpxGetControllerRotationQuaternion((uint)controllerNum);
return new Quaternion(controllerRotation.x, controllerRotation.y, controllerRotation.z, controllerRotation.w);
}
public static Vector3 GetHeadsetPosition()
{
var controllerPosition = vpxGetHeadsetPosition();
return new Vector3(controllerPosition.x, controllerPosition.y, controllerPosition.z);
}
public static Vector3 GetHeadsetRotationEuler()
{
var controllerRotation = vpxGetHeadsetRotationEuler();
return new Vector3(controllerRotation.x, controllerRotation.y, controllerRotation.z);
}
public static Quaternion GetHeadsetRotationQuaternion()
{
var controllerRotation = vpxGetHeadsetRotationQuaternion();
return new Quaternion(controllerRotation.x, controllerRotation.y, controllerRotation.z, controllerRotation.w);
}
// Define C# versions of the C structs
[StructLayout(LayoutKind.Sequential)]
public struct vpxint2
{
public int x;
public int y;
}
[StructLayout(LayoutKind.Sequential)]
public struct vpxint3
{
public int x;
public int y;
public int z;
}
[StructLayout(LayoutKind.Sequential)]
public struct vpxint4
{
public int x;
public int y;
public int z;
public int w;
}
[StructLayout(LayoutKind.Sequential)]
public struct vpxfloat2
{
public float x;
public float y;
}
[StructLayout(LayoutKind.Sequential)]
public struct vpxfloat3
{
public float x;
public float y;
public float z;
}
[StructLayout(LayoutKind.Sequential)]
public struct vpxfloat4
{
public float x;
public float y;
public float z;
public float w;
}
[StructLayout(LayoutKind.Sequential)]
public struct vpxmtx4x4
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public float[] m;
}
[StructLayout(LayoutKind.Sequential)]
public struct VPX_CONTROLLER_STATE
{
public bool IsActive; // VPX_TRUE if active, otherwise VPX_FALSE
public float StickX; // Thumbstick/pad x-axis [-1|1]
public float StickY; // Thumbstick/pad y-axis [-1|1]
public float Trigger; // Trigger axis [0|1]
public float Grip; // Grip axis [0|1], on controllers with a grip button (e.g. Vive wands) either 0.0 or 1.0
public float Extra0; // Extra axis (for future use)
public float Extra1; // Extra axis (for future use)
public float Extra2; // Extra axis (for future use)
public float Extra3; // Extra axis (for future use)
public float Finger0; // Finger axis: thumb (for future use)
public float Finger1; // Finger axis: index (for future use)
public float Finger2; // Finger axis: middle (for future use)
public float Finger3; // Finger axis: ring (for future use)
public float Finger4; // Finger axis: pinky (for future use)
public uint ButtonsPressed; // Check with a flag, e.g.: if (ButtonsPressed & VPX_CONTROLLER_BUTTON_0)
public uint ButtonsTouched; // Check with a flag, e.g.: if (ButtonsTouched & VPX_CONTROLLER_BUTTON_0)
}
public enum VPX_GAME_STEREO_MODE
{
VPX_GAME_STEREO_MODE_NONE = 0,
VPX_GAME_STEREO_MODE_SINGLE_FRAME = 1,
VPX_GAME_STEREO_MODE_ALTERNATE_FRAME = 2
}
public enum VPX_BOOL
{
VPX_FALSE = 0,
VPX_TRUE = 1,
}
public enum VPX_RESULT
{
VPX_RES_OK = 0,
VPX_RES_FAIL = 1,
VPX_RES_INVALID_ARGUMENT = 101,
VPX_RES_NULL_POINTER = 102,
VPX_RES_NOT_INITIALIZED = 103,
VPX_RES_FUNCTION_UNAVAILABLE = 104
}
public enum VPX_CONTROLLER_BUTTON
{
VPX_CONTROLLER_BUTTON_0 = 0x001,
VPX_CONTROLLER_BUTTON_1 = 0x002,
VPX_CONTROLLER_BUTTON_MENU = 0x004,
VPX_CONTROLLER_BUTTON_STICK_PAD_0 = 0x008,
VPX_CONTROLLER_BUTTON_TRIGGER = 0x010,
VPX_CONTROLLER_BUTTON_GRIP = 0x020
}
}