forked from XRTK/com.xrtk.oculus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOculusApi.cs
1393 lines (1238 loc) · 54.4 KB
/
OculusApi.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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) XRTK. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
using System;
using System.Runtime.InteropServices;
using UnityEngine;
using XRTK.Definitions.Utilities;
namespace XRTK.Oculus
{
public static class OculusApi
{
#region Oculus API Properties
private static Version _versionZero = new Version(0, 0, 0);
private static readonly Version OVRP_1_38_0_version = new Version(1, 38, 0);
private const string pluginName = "OVRPlugin";
private static Version _version;
public static Version Version
{
get
{
if (_version == null)
{
try
{
string pluginVersion = ovrp_GetVersion();
if (pluginVersion != null)
{
// Truncate unsupported trailing version info for System.Version. Original string is returned if not present.
pluginVersion = pluginVersion.Split('-')[0];
_version = new Version(pluginVersion);
}
else
{
_version = _versionZero;
}
}
catch
{
_version = _versionZero;
}
}
return _version;
}
}
internal static readonly float AXIS_AS_BUTTON_THRESHOLD = 0.5f;
internal static readonly float AXIS_DEADZONE_THRESHOLD = 0.2f;
internal static Step stepType = Step.Render;
private static OVRControllerBase[] controllers;
internal static OVRControllerBase[] Controllers
{
get
{
if (controllers == null)
{
controllers = new OVRControllerBase[]
{
#if UNITY_ANDROID && !UNITY_EDITOR
new OVRControllerGamepadAndroid(),
new OVRControllerTouchpad(),
new OVRControllerLTrackedRemote(),
new OVRControllerRTrackedRemote(),
new OVRControllerLTouch(),
new OVRControllerRTouch(),
new OVRControllerTouch(),
#elif UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX
new OVRControllerGamepadMac(),
#else
new OVRControllerGamepadPC(),
new OVRControllerLTouch(),
new OVRControllerRTouch(),
new OVRControllerRemote(),
new OVRControllerTouch(),
#endif
};
}
return controllers;
}
set { controllers = value; }
}
internal static Controller activeControllerType = Controller.None;
internal static Controller connectedControllerTypes = Controller.None;
#endregion Oculus API Properties
#region Oculus API import
[DllImport(pluginName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ovrp_GetVersion")]
private static extern IntPtr _ovrp_GetVersion();
public static string ovrp_GetVersion() { return Marshal.PtrToStringAnsi(_ovrp_GetVersion()); }
[DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
public static extern Result ovrp_GetControllerState4(uint controllerMask, ref ControllerState4 controllerState);
[DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
public static extern PoseStatef ovrp_GetNodePoseState(Step stepId, Node nodeId);
[DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
public static extern Result ovrp_GetDominantHand(out Handedness dominantHand);
[DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
public static extern Bool ovrp_GetNodePresent(Node nodeId);
[DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
public static extern Bool ovrp_GetNodeOrientationTracked(Node nodeId);
[DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
public static extern Bool ovrp_GetNodePositionTracked(Node nodeId);
[DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
public static extern Result ovrp_GetNodeOrientationValid(Node nodeId, ref Bool nodeOrientationValid);
[DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
public static extern Result ovrp_GetNodePositionValid(Node nodeId, ref Bool nodePositionValid);
[DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
public static extern Bool ovrp_GetBoundaryGeometry2(BoundaryType boundaryType, IntPtr points, ref int pointsCount);
[DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3f ovrp_GetBoundaryDimensions(BoundaryType boundaryType);
[DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
public static extern Bool ovrp_GetBoundaryVisible();
[DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
public static extern Bool ovrp_SetBoundaryVisible(bool value);
[DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
public static extern SystemHeadset ovrp_GetSystemHeadsetType();
[DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
public static extern Controller ovrp_GetActiveController();
[DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
public static extern Controller ovrp_GetConnectedControllers();
[DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
public static extern Bool ovrp_Update2(int stateId, int frameIndex, double predictionSeconds);
[DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
public static extern HapticsDesc ovrp_GetControllerHapticsDesc(uint controllerMask);
[DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
public static extern HapticsState ovrp_GetControllerHapticsState(uint controllerMask);
[DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
public static extern Bool ovrp_SetControllerHaptics(uint controllerMask, HapticsBuffer hapticsBuffer);
[DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
public static extern Bool ovrp_RecenterTrackingOrigin(uint flags);
[DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
public static extern Bool ovrp_SetControllerVibration(uint controllerMask, float frequency, float amplitude);
#endregion Oculus API import
#region Oculus Data Types
/// <summary>
/// Oculus API result states
/// </summary>
public enum Result
{
/// Success
Success = 0,
/// Failure
Failure = -1000,
Failure_InvalidParameter = -1001,
Failure_NotInitialized = -1002,
Failure_InvalidOperation = -1003,
Failure_Unsupported = -1004,
Failure_NotYetImplemented = -1005,
Failure_OperationFailed = -1006,
Failure_InsufficientSize = -1007
}
/// <summary>
/// Oculus native Bool type, overridden from base .NET bool
/// </summary>
public enum Bool
{
False = 0,
True
}
/// <summary>
/// Oculus API native Vector2
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct Vector2f
{
public float x;
public float y;
}
/// <summary>
/// Oculus API native Vector3
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct Vector3f
{
public float x;
public float y;
public float z;
public static readonly Vector3f zero = new Vector3f { x = 0.0f, y = 0.0f, z = 0.0f };
public override string ToString()
{
return $"{x}, {y}, {z}";
}
}
/// <summary>
/// Oculus API native Quaternion
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct Quatf
{
public float x;
public float y;
public float z;
public float w;
public static readonly Quatf identity = new Quatf { x = 0.0f, y = 0.0f, z = 0.0f, w = 1.0f };
public override string ToString()
{
return $"{x}, {y}, {z}, {w}";
}
}
/// <summary>
/// Oculus API native Pose (Position + Rotation)
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct Posef
{
public Quatf Orientation;
public Vector3f Position;
public static readonly Posef identity = new Posef { Orientation = Quatf.identity, Position = Vector3f.zero };
public override string ToString()
{
return $"Position ({Position}), Orientation({Orientation})";
}
}
/// <summary>
/// Oculus native pose extension, for velocity definitions
/// </summary>
/// <remarks>For future use</remarks>
[StructLayout(LayoutKind.Sequential)]
public struct PoseStatef
{
public Posef Pose;
public Vector3f Velocity;
public Vector3f Acceleration;
public Vector3f AngularVelocity;
public Vector3f AngularAcceleration;
public double Time;
public static readonly PoseStatef identity = new PoseStatef
{
Pose = Posef.identity,
Velocity = Vector3f.zero,
Acceleration = Vector3f.zero,
AngularVelocity = Vector3f.zero,
AngularAcceleration = Vector3f.zero
};
}
/// <summary>
/// Oculus native node definition, detailing tracking objects
/// </summary>
public enum Node
{
None = -1,
EyeLeft = 0,
EyeRight = 1,
EyeCenter = 2,
HandLeft = 3,
HandRight = 4,
TrackerZero = 5,
TrackerOne = 6,
TrackerTwo = 7,
TrackerThree = 8,
Head = 9,
DeviceObjectZero = 10,
Count
}
/// <summary>
/// Oculus native controller data, combines all input in to a single state
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct ControllerState4
{
public uint ConnectedControllers;
public uint Buttons;
public uint Touches;
public uint NearTouches;
public float LIndexTrigger;
public float RIndexTrigger;
public float LHandTrigger;
public float RHandTrigger;
public Vector2f LThumbstick;
public Vector2f RThumbstick;
public Vector2f LTouchpad;
public Vector2f RTouchpad;
public byte LBatteryPercentRemaining;
public byte RBatteryPercentRemaining;
public byte LRecenterCount;
public byte RRecenterCount;
public byte Reserved_27;
public byte Reserved_26;
public byte Reserved_25;
public byte Reserved_24;
public byte Reserved_23;
public byte Reserved_22;
public byte Reserved_21;
public byte Reserved_20;
public byte Reserved_19;
public byte Reserved_18;
public byte Reserved_17;
public byte Reserved_16;
public byte Reserved_15;
public byte Reserved_14;
public byte Reserved_13;
public byte Reserved_12;
public byte Reserved_11;
public byte Reserved_10;
public byte Reserved_09;
public byte Reserved_08;
public byte Reserved_07;
public byte Reserved_06;
public byte Reserved_05;
public byte Reserved_04;
public byte Reserved_03;
public byte Reserved_02;
public byte Reserved_01;
public byte Reserved_00;
}
/// <summary>
/// Oculus native haptics buffer management
/// </summary>
/// <remarks>For future use</remarks>
[StructLayout(LayoutKind.Sequential)]
public struct HapticsBuffer
{
public IntPtr Samples;
public int SamplesCount;
}
/// <summary>
/// Oculus native haptics state management
/// </summary>
/// <remarks>For future use</remarks>
[StructLayout(LayoutKind.Sequential)]
public struct HapticsState
{
public int SamplesAvailable;
public int SamplesQueued;
}
/// <summary>
/// Oculus native haptics descriptive data
/// </summary>
/// <remarks>For future use</remarks>
[StructLayout(LayoutKind.Sequential)]
public struct HapticsDesc
{
public int SampleRateHz;
public int SampleSizeInBytes;
public int MinimumSafeSamplesQueued;
public int MinimumBufferSamplesCount;
public int OptimalBufferSamplesCount;
public int MaximumBufferSamplesCount;
}
/// <summary>
/// Oculus native button definitions
/// </summary>
/// <remarks>Oculus API only uses RAW definitions. Oculus Asset also uses Virtual mappings, but it's not clear why
/// (Oculus) Raw button mappings that can be used to directly query the state of a controller.</remarks>
[Flags]
public enum RawButton
{
/// <summary>
/// Maps to Physical Button: [Gamepad, Touch, LTouch, RTouch, LTrackedRemote, RTrackedRemote, Touchpad, Remote: None]
/// </summary>
None = 0,
/// <summary>
/// Maps to Physical Button: [Gamepad, Touch, RTouch: A], [LTrackedRemote: LIndexTrigger], [RTrackedRemote: RIndexTrigger], [LTouch, Touchpad, Remote: None]
/// </summary>
A = 0x00000001,
/// <summary>
/// Maps to Physical Button: [Gamepad, Touch, RTouch: B], [LTouch, LTrackedRemote, RTrackedRemote, Touchpad, Remote: None]
/// </summary>
B = 0x00000002,
/// <summary>
/// Maps to Physical Button: [Gamepad, Touch, LTouch: X], [RTouch, LTrackedRemote, RTrackedRemote, Touchpad, Remote: None]
/// </summary>
X = 0x00000100,
/// <summary>
/// Maps to Physical Button: [Gamepad, Touch, LTouch: Y], [RTouch, LTrackedRemote, RTrackedRemote, Touchpad, Remote: None]
/// </summary>
Y = 0x00000200,
/// <summary>
/// Maps to Physical Button: [Gamepad, Touch, LTouch, LTrackedRemote, RTrackedRemote, Touchpad, Remote: Start], [RTouch: None]
/// </summary>
Start = 0x00100000,
/// <summary>
/// Maps to Physical Button: [Gamepad, LTrackedRemote, RTrackedRemote, Touchpad, Remote: Back], [Touch, LTouch, RTouch: None]
/// </summary>
Back = 0x00200000,
/// <summary>
/// Maps to Physical Button: [Gamepad: LShoulder], [Touch, LTouch, RTouch, LTrackedRemote, RTrackedRemote, Touchpad, Remote: None]
/// </summary>
LShoulder = 0x00000800,
/// <summary>
/// Maps to Physical Button: [Gamepad, Touch, LTouch, LTrackedRemote: LIndexTrigger], [RTouch, RTrackedRemote, Touchpad, Remote: None]
/// </summary>
LIndexTrigger = 0x10000000,
/// <summary>
/// Maps to Physical Button: [Touch, LTouch: LHandTrigger], [Gamepad, RTouch, LTrackedRemote, RTrackedRemote, Touchpad, Remote: None]
/// </summary>
LHandTrigger = 0x20000000,
/// <summary>
/// Maps to Physical Button: [Gamepad, Touch, LTouch: LThumbstick], [RTouch, LTrackedRemote, RTrackedRemote, Touchpad, Remote: None]
/// </summary>
LThumbstick = 0x00000400,
/// <summary>
/// Maps to Physical Button: [Gamepad, Touch, LTouch: LThumbstickUp], [RTouch, LTrackedRemote, RTrackedRemote, Touchpad, Remote: None]
/// </summary>
LThumbstickUp = 0x00000010,
/// <summary>
/// Maps to Physical Button: [Gamepad, Touch, LTouch: LThumbstickDown], [RTouch, LTrackedRemote, RTrackedRemote, Touchpad, Remote: None]
/// </summary>
LThumbstickDown = 0x00000020,
/// <summary>
/// Maps to Physical Button: [Gamepad, Touch, LTouch: LThumbstickLeft], [RTouch, LTrackedRemote, RTrackedRemote, Touchpad, Remote: None]
/// </summary>
LThumbstickLeft = 0x00000040,
/// <summary>
/// Maps to Physical Button: [Gamepad, Touch, LTouch: LThumbstickRight], [RTouch, LTrackedRemote, RTrackedRemote, Touchpad, Remote: None]
/// </summary>
LThumbstickRight = 0x00000080,
/// <summary>
/// Maps to Physical Button: [LTrackedRemote: LTouchpad], [Gamepad, Touch, LTouch, RTouch, RTrackedRemote, Touchpad, Remote: None]
/// </summary>
LTouchpad = 0x40000000,
/// <summary>
/// Maps to Physical Button: [Gamepad: RShoulder], [Touch, LTouch, RTouch, LTrackedRemote, RTrackedRemote, Touchpad, Remote: None]
/// </summary>
RShoulder = 0x00000008,
/// <summary>
/// Maps to Physical Button: [Gamepad, Touch, RTouch, RTrackedRemote: RIndexTrigger], [LTouch, LTrackedRemote, Touchpad, Remote: None]
/// </summary>
RIndexTrigger = 0x04000000,
/// <summary>
/// Maps to Physical Button: [Touch, RTouch: RHandTrigger], [Gamepad, LTouch, LTrackedRemote, RTrackedRemote, Touchpad, Remote: None]
/// </summary>
RHandTrigger = 0x08000000,
/// <summary>
/// Maps to Physical Button: [Gamepad, Touch, RTouch: RThumbstick], [LTouch, LTrackedRemote, RTrackedRemote, Touchpad, Remote: None]
/// </summary>
RThumbstick = 0x00000004,
/// <summary>
/// Maps to Physical Button: [Gamepad, Touch, RTouch: RThumbstickUp], [LTouch, LTrackedRemote, RTrackedRemote, Touchpad, Remote: None]
/// </summary>
RThumbstickUp = 0x00001000,
/// <summary>
/// Maps to Physical Button: [Gamepad, Touch, RTouch: RThumbstickDown], [LTouch, LTrackedRemote, RTrackedRemote, Touchpad, Remote: None]
/// </summary>
RThumbstickDown = 0x00002000,
/// <summary>
/// Maps to Physical Button: [Gamepad, Touch, RTouch: RThumbstickLeft], [LTouch, LTrackedRemote, RTrackedRemote, Touchpad, Remote: None]
/// </summary>
RThumbstickLeft = 0x00004000,
/// <summary>
/// Maps to Physical Button: [Gamepad, Touch, RTouch: RThumbstickRight], [LTouch, LTrackedRemote, RTrackedRemote, Touchpad, Remote: None]
/// </summary>
RThumbstickRight = 0x00008000,
/// <summary>
/// Maps to Physical Button: [Gamepad, Touch, LTouch, RTouch, LTrackedRemote, RTrackedRemote, Touchpad, Remote: None]
/// </summary>
RTouchpad = unchecked((int)0x80000000),
/// <summary>
/// Maps to Physical Button: [Gamepad, LTrackedRemote, RTrackedRemote, Touchpad, Remote: DpadUp], [Touch, LTouch, RTouch: None]
/// </summary>
DpadUp = 0x00010000,
/// <summary>
/// Maps to Physical Button: [Gamepad, LTrackedRemote, RTrackedRemote, Touchpad, Remote: DpadDown], [Touch, LTouch, RTouch: None]
/// </summary>
DpadDown = 0x00020000,
/// <summary>
/// Maps to Physical Button: [Gamepad, LTrackedRemote, RTrackedRemote, Touchpad, Remote: DpadLeft], [Touch, LTouch, RTouch: None]
/// </summary>
DpadLeft = 0x00040000,
/// <summary>
/// Maps to Physical Button: [Gamepad, LTrackedRemote, RTrackedRemote, Touchpad, Remote: DpadRight], [Touch, LTouch, RTouch: None]
/// </summary>
DpadRight = 0x00080000,
/// <summary>
/// Maps to Physical Button: [Gamepad, Touch, LTouch, RTouch, LTrackedRemote, RTrackedRemote, Touchpad, Remote: Any]
/// </summary>
Any = ~None
}
/// <summary>
/// Oculus native touch definitions
/// </summary>
/// <remarks>Oculus API only uses RAW definitions. Oculus Asset also uses Virtual mappings, but it's not clear why
/// (Oculus) Raw capacitive touch mappings that can be used to directly query the state of a controller.</remarks>
[Flags]
public enum RawTouch
{
/// <summary>
/// Maps to Physical Touch: [Gamepad, Touch, LTouch, RTouch, LTrackedRemote, RTrackedRemote, Touchpad, Remote: None]
/// </summary>
None = 0,
/// <summary>
/// Maps to Physical Touch: [Touch, RTouch: A], [Gamepad, LTouch, LTrackedRemote, RTrackedRemote, Touchpad, Remote: None]
/// </summary>
A = RawButton.A,
/// <summary>
/// Maps to Physical Touch: [Touch, RTouch: B], [Gamepad, LTouch, LTrackedRemote, RTrackedRemote, Touchpad, Remote: None]
/// </summary>
B = RawButton.B,
/// <summary>
/// Maps to Physical Touch: [Touch, LTouch: X], [Gamepad, RTouch, LTrackedRemote, RTrackedRemote, Touchpad, Remote: None]
/// </summary>
X = RawButton.X,
/// <summary>
/// Maps to Physical Touch: [Touch, LTouch: Y], [Gamepad, RTouch, LTrackedRemote, RTrackedRemote, Touchpad, Remote: None]
/// </summary>
Y = RawButton.Y,
/// <summary>
/// Maps to Physical Touch: [Touch, LTouch: LIndexTrigger], [Gamepad, RTouch, LTrackedRemote, RTrackedRemote, Touchpad, Remote: None]
/// </summary>
LIndexTrigger = 0x00001000,
/// <summary>
/// Maps to Physical Touch: [Touch, LTouch: LThumbstick], [Gamepad, RTouch, LTrackedRemote, RTrackedRemote, Touchpad, Remote: None]
/// </summary>
LThumbstick = RawButton.LThumbstick,
/// <summary>
/// Maps to Physical Touch: [Touch, LTouch: LThumbRest], [Gamepad, RTouch, LTrackedRemote, RTrackedRemote, Touchpad, Remote: None]
/// </summary>
LThumbRest = 0x00000800,
/// <summary>
/// Maps to Physical Touch: [LTrackedRemote, Touchpad: LTouchpad], [Gamepad, Touch, LTouch, RTouch, RTrackedRemote, Remote: None]
/// </summary>
LTouchpad = RawButton.LTouchpad,
/// <summary>
/// Maps to Physical Touch: [Touch, RTouch: RIndexTrigger], [Gamepad, LTouch, LTrackedRemote, RTrackedRemote, Touchpad, Remote: None]
/// </summary>
RIndexTrigger = 0x00000010,
/// <summary>
/// Maps to Physical Touch: [Touch, RTouch: RThumbstick], [Gamepad, LTouch, LTrackedRemote, RTrackedRemote, Touchpad, Remote: None]
/// </summary>
RThumbstick = RawButton.RThumbstick,
/// <summary>
/// Maps to Physical Touch: [Touch, RTouch: RThumbRest], [Gamepad, LTouch, LTrackedRemote, RTrackedRemote, Touchpad, Remote: None]
/// </summary>
RThumbRest = 0x00000008,
/// <summary>
/// Maps to Physical Touch: [RTrackedRemote: RTouchpad], [Gamepad, Touch, LTouch, RTouch, LTrackedRemote, Touchpad, Remote: None]
/// </summary>
RTouchpad = RawButton.RTouchpad,
/// <summary>
/// Maps to Physical Touch: [Touch, LTouch, RTouch, LTrackedRemote, RTrackedRemote, Touchpad: Any], [Gamepad, Remote: None]
/// </summary>
Any = ~None
}
/// <summary>
/// Oculus native near touch definitions
/// </summary>
/// <remarks>Oculus API only uses RAW definitions. Oculus Asset also uses Virtual mappings, but it's not clear why
/// (Oculus) Raw near touch mappings that can be used to directly query the state of a controller.</remarks>
[Flags]
public enum RawNearTouch
{
/// <summary>
/// Maps to Physical NearTouch: [Gamepad, Touch, LTouch, RTouch, LTrackedRemote, RTrackedRemote, Touchpad, Remote: None]
/// </summary>
None = 0,
/// <summary>
/// Maps to Physical NearTouch: [Touch, LTouch: Implies finger is in close proximity to LIndexTrigger.], [Gamepad, RTouch, LTrackedRemote, RTrackedRemote, Touchpad, Remote: None]
/// </summary>
LIndexTrigger = 0x00000001,
/// <summary>
/// Maps to Physical NearTouch: [Touch, LTouch: Implies thumb is in close proximity to LThumbstick OR X/Y buttons.], [Gamepad, RTouch, LTrackedRemote, RTrackedRemote, Touchpad, Remote: None]
/// </summary>
LThumbButtons = 0x00000002,
/// <summary>
/// Maps to Physical NearTouch: [Touch, RTouch: Implies finger is in close proximity to RIndexTrigger.], [Gamepad, LTouch, LTrackedRemote, RTrackedRemote, Touchpad, Remote: None]
/// </summary>
RIndexTrigger = 0x00000004,
/// <summary>
/// Maps to Physical NearTouch: [Touch, RTouch: Implies thumb is in close proximity to RThumbstick OR A/B buttons.], [Gamepad, LTouch, LTrackedRemote, RTrackedRemote, Touchpad, Remote: None]
/// </summary>
RThumbButtons = 0x00000008,
/// <summary>
/// Maps to Physical NearTouch: [Touch, LTouch, RTouch: Any], [Gamepad, LTrackedRemote, RTrackedRemote, Touchpad, Remote: None]
/// </summary>
Any = ~None
}
/// <summary>
/// Oculus native single axis definitions
/// </summary>
/// <remarks>Oculus API only uses RAW definitions. Oculus Asset also uses Virtual mappings, but it's not clear why
/// (Oculus) Raw 1-dimensional axis (float) mappings that can be used to directly query the state of a controller.</remarks>
[Flags]
public enum RawAxis1D
{
/// <summary>
/// Maps to Physical Axis1D: [Gamepad, Touch, LTouch, RTouch, LTrackedRemote, RTrackedRemote, Touchpad, Remote: None]
/// </summary>
None = 0,
/// <summary>
/// Maps to Physical Axis1D: [Gamepad, Touch, LTouch: LIndexTrigger], [RTouch, LTrackedRemote, RTrackedRemote, Touchpad, Remote: None]
/// </summary>
LIndexTrigger = 0x01,
/// <summary>
/// Maps to Physical Axis1D: [Touch, LTouch: LHandTrigger], [Gamepad, RTouch, LTrackedRemote, RTrackedRemote, Touchpad, Remote: None]
/// </summary>
LHandTrigger = 0x04,
/// <summary>
/// Maps to Physical Axis1D: [Gamepad, Touch, RTouch: RIndexTrigger], [LTouch, LTrackedRemote, RTrackedRemote, Touchpad, Remote: None]
/// </summary>
RIndexTrigger = 0x02,
/// <summary>
/// Maps to Physical Axis1D: [Touch, RTouch: RHandTrigger], [Gamepad, LTouch, LTrackedRemote, RTrackedRemote, Touchpad, Remote: None]
/// </summary>
RHandTrigger = 0x08,
/// <summary>
/// Maps to Physical Axis1D: [Gamepad, Touch, LTouch, RTouch: Any], [LTrackedRemote, RTrackedRemote, Touchpad, Remote: None]
/// </summary>
Any = ~None
}
/// <summary>
/// Oculus native dual axis definitions
/// </summary>
/// <remarks>Oculus API only uses RAW definitions. Oculus Asset also uses Virtual mappings, but it's not clear why
/// (Oculus) Raw 2-dimensional axis (Vector2) mappings that can be used to directly query the state of a controller.</remarks>
[Flags]
public enum RawAxis2D
{
/// <summary>
/// Maps to Physical Axis2D: [Gamepad, Touch, LTouch, RTouch, LTrackedRemote, RTrackedRemote, Touchpad, Remote: None]
/// </summary>
None = 0,
/// <summary>
/// Maps to Physical Axis2D: [Gamepad, Touch, LTouch: LThumbstick], [RTouch, LTrackedRemote, RTrackedRemote, Touchpad, Remote: None]
/// </summary>
LThumbstick = 0x01,
/// <summary>
/// Maps to Physical Axis2D: [LTrackedRemote, Touchpad: LTouchpad], [Gamepad, Touch, LTouch, RTouch, RTrackedRemote, Remote: None]
/// </summary>
LTouchpad = 0x04,
/// <summary>
/// Maps to Physical Axis2D: [Gamepad, Touch, RTouch: RThumbstick], [LTouch, LTrackedRemote, RTrackedRemote, Touchpad, Remote: None]
/// </summary>
RThumbstick = 0x02,
/// <summary>
/// Maps to Physical Axis2D: [RTrackedRemote: RTouchpad], [Gamepad, Touch, LTouch, RTouch, LTrackedRemote, Touchpad, Remote: None]
/// </summary>
RTouchpad = 0x08,
/// <summary>
/// Maps to Physical Axis2D: [Gamepad, Touch, LTouch, RTouch, LTrackedRemote, RTrackedRemote: Any], [Touchpad, Remote: None]
/// </summary>
Any = ~None
}
/// <summary>
/// Oculus native controller type definitions
/// </summary>
/// <remarks>(Oculus) Identifies a controller which can be used to query the virtual or raw input state.</remarks>
[Flags]
public enum Controller
{
None = 0,
LTouch = 0x00000001,
RTouch = 0x00000002,
Touch = LTouch | RTouch,
Remote = 0x00000004,
Gamepad = 0x00000010,
Touchpad = 0x08000000,
LTrackedRemote = 0x01000000,
RTrackedRemote = 0x02000000,
Active = unchecked((int)0x80000000),
All = ~None
}
/// <summary>
/// Oculus native controller Handedness definitions
/// </summary>
public enum Handedness
{
Unsupported = 0,
LeftHanded = 1,
RightHanded = 2
}
/// <summary>
/// Oculus native controller Render/Physics step definitions. Used by the API when calculating feedback.
/// </summary>
public enum Step
{
Render = -1,
Physics = 0
}
/// <summary>
/// Oculus native controller Tracking definitions
/// </summary>
/// <remarks>For future use</remarks>
public enum TrackingOrigin
{
EyeLevel = 0,
FloorLevel = 1,
Stage = 2,
Count
}
/// <summary>
/// Oculus native controller re-centering parameters
/// </summary>
/// <remarks>For future use</remarks>
public enum RecenterFlags
{
Default = 0,
Controllers = 0x40000000,
IgnoreAll = unchecked((int)0x80000000),
Count
}
/// <summary>
/// Oculus native battery status
/// </summary>
/// <remarks>For future use</remarks>
public enum BatteryStatus
{
Charging = 0,
Discharging,
Full,
NotCharging,
Unknown
}
/// <summary>
/// Oculus native boundary type setting
/// </summary>
/// <remarks>For future use</remarks>
public enum BoundaryType
{
OuterBoundary = 0x0001,
PlayArea = 0x0100
}
/// <summary>
/// Oculus native boundary collision test results
/// </summary>
/// <remarks>For future use</remarks>
[StructLayout(LayoutKind.Sequential)]
public struct BoundaryTestResult
{
public Bool IsTriggering;
public float ClosestDistance;
public Vector3f ClosestPoint;
public Vector3f ClosestPointNormal;
}
/// <summary>
/// Oculus native boundary geometry data
/// </summary>
/// <remarks>For future use</remarks>
[StructLayout(LayoutKind.Sequential)]
public struct BoundaryGeometry
{
public BoundaryType BoundaryType;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
public Vector3f[] Points;
public int PointsCount;
}
/// <summary>
/// Type of headset detected by the Oculus API
/// </summary>
public enum SystemHeadset
{
None = 0,
GearVR_R320, // Note4 Innovator
GearVR_R321, // S6 Innovator
GearVR_R322, // Commercial 1
GearVR_R323, // Commercial 2 (USB Type C)
GearVR_R324, // Commercial 3 (USB Type C)
GearVR_R325, // Commercial 4 (USB Type C)
Oculus_Go,
Oculus_Quest,
Rift_DK1 = 0x1000,
Rift_DK2,
Rift_CV1,
Rift_CB,
Rift_S
}
#endregion Oculus Data Types
#region Oculus Controller Definition
internal abstract class OVRControllerBase
{
public Controller controllerType = Controller.None;
public ControllerState4 previousState = new ControllerState4();
public ControllerState4 currentState = new ControllerState4();
public bool shouldApplyDeadzone = true;
public virtual void SetControllerVibration(float frequency, float amplitude)
{
OculusApi.SetControllerVibration((uint)controllerType, frequency, amplitude);
}
public virtual void RecenterController()
{
RecenterTrackingOrigin(RecenterFlags.Controllers);
}
public virtual bool WasRecentered()
{
return false;
}
public virtual byte GetRecenterCount()
{
return 0;
}
public virtual byte GetBatteryPercentRemaining()
{
return 0;
}
}
private class OVRControllerTouch : OVRControllerBase
{
public OVRControllerTouch()
{
controllerType = Controller.Touch;
}
public override bool WasRecentered()
{
return ((currentState.LRecenterCount + currentState.RRecenterCount) != (previousState.LRecenterCount + previousState.RRecenterCount));
}
public override byte GetRecenterCount()
{
return (byte)(currentState.LRecenterCount + currentState.RRecenterCount);
}
public override byte GetBatteryPercentRemaining()
{
byte leftBattery = currentState.LBatteryPercentRemaining;
byte rightBattery = currentState.RBatteryPercentRemaining;
byte minBattery = (leftBattery <= rightBattery) ? leftBattery : rightBattery;
return minBattery;
}
}
private class OVRControllerLTouch : OVRControllerBase
{
public OVRControllerLTouch()
{
controllerType = Controller.LTouch;
}
public override bool WasRecentered()
{
return (currentState.LRecenterCount != previousState.LRecenterCount);
}
public override byte GetRecenterCount()
{
return currentState.LRecenterCount;
}
public override byte GetBatteryPercentRemaining()
{
return currentState.LBatteryPercentRemaining;
}
}
private class OVRControllerRTouch : OVRControllerBase
{
public OVRControllerRTouch()
{
controllerType = Controller.RTouch;
}
public override bool WasRecentered()
{
return (currentState.RRecenterCount != previousState.RRecenterCount);
}
public override byte GetRecenterCount()
{
return currentState.RRecenterCount;
}
public override byte GetBatteryPercentRemaining()
{
return currentState.RBatteryPercentRemaining;
}
}
private class OVRControllerRemote : OVRControllerBase
{
public OVRControllerRemote()
{
controllerType = Controller.Remote;
}
}
private class OVRControllerGamepadPC : OVRControllerBase
{
public OVRControllerGamepadPC()
{
controllerType = Controller.Gamepad;
}
}
private class OVRControllerGamepadMac : OVRControllerBase
{
public OVRControllerGamepadMac()
{
controllerType = Controller.Gamepad;
}
}
private class OVRControllerGamepadAndroid : OVRControllerBase
{
public OVRControllerGamepadAndroid()
{
controllerType = Controller.Gamepad;
}
}
private class OVRControllerTouchpad : OVRControllerBase
{
public OVRControllerTouchpad()
{
controllerType = Controller.Touchpad;
}
}
private class OVRControllerLTrackedRemote : OVRControllerBase
{
public OVRControllerLTrackedRemote()
{
controllerType = Controller.LTrackedRemote;
}
public override bool WasRecentered()
{
return (currentState.LRecenterCount != previousState.LRecenterCount);
}
public override byte GetRecenterCount()
{
return currentState.LRecenterCount;
}
public override byte GetBatteryPercentRemaining()
{
return currentState.LBatteryPercentRemaining;
}
}
private class OVRControllerRTrackedRemote : OVRControllerBase
{
public OVRControllerRTrackedRemote()
{
controllerType = Controller.RTrackedRemote;
}
public override bool WasRecentered()