Project

General

Profile

OPENXR Scol plugin
scolplugin.cpp
1/*
2-----------------------------------------------------------------------------
3This source file is part of OpenSpace3D
4For the latest info, see http://www.openspace3d.com
5
6Copyright (c) 2022 I-maginer
7
8This program is free software; you can redistribute it and/or modify it under
9the terms of the GNU Lesser General Public License as published by the Free Software
10Foundation; either version 2 of the License, or (at your option) any later
11version.
12
13This program is distributed in the hope that it will be useful, but WITHOUT
14ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public License along with
18this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20http://www.gnu.org/copyleft/lesser.txt
21
22-----------------------------------------------------------------------------
23*/
24
25/*
26 OpenXR SDK interface for Scol
27 First version : September 2022
28 Author : Bastien BOURINEAU - I-Maginer
29 */
30
31
32#include <sOpenXR.h>
33#include <scolMemoryHelper.hpp>
34
36#ifdef SCOL_STATIC
37extern cbmachine ww;
38extern mmachine mm;
39#else
40cbmachine ww;
41mmachine mm;
42#endif
43
44int OBJ_OPENXR_SCOL;
45
67int destroyOpenXrObj(mmachine m, SCOL_PTR_TYPE handsys, int handscol)
68{
69 // Read the first element of a TAB element (table of object)
70 sOpenXr* openxrObj = MMgetPointer<sOpenXr*>(m, MTOP(handscol));
71 openxrObj->Disconnect();
72
73 MMsetPointer<sOpenXr*>(m, MTOP(handscol), 0);
74
75 // Display debug message
76 MMechostr(MSKDEBUG, "ObjOpenXr destroyed.\n");
77 return 0;
78}
79
80
91int _CRopenXrDevice(mmachine m)
92{
93#ifdef _SCOL_DEBUG_
94 MMechostr(0,"_CRopenXrDevice\n");
95#endif
96 // Declare local variables
97 int k = 0;
98
99 // Get the channel without pulling it (first element in the stack)
100 int iratio = MMpull(m);
101 int itype = MMpull(m);
102 int channel = MMget(m, 0);
103
104 // Test the channel
105 if (channel == NIL)
106 {
107 MMechostr(MSKRUNTIME, "_CRopenXrDevice : Channel NIL\n");
108 MMset(m, 0, NIL);
109 return 0;
110 }
111
112 float fratio = 1.0f;
113 if (iratio != NIL)
114 fratio = MTOF(iratio);
115
116 int renderer = (itype == NIL) ? XR_OPENGL_RENDERER : MTOI(itype);
117 if ((renderer > XR_MAX_RENDERER) || (renderer == XR_NONE_RENDER_SYSTEM))
118 renderer = XR_OPENGL_RENDERER;
119
120 if ((renderer != XR_OPENGL_RENDERER) && (renderer != XR_DIRECTX11_RENDERER)/* && (renderer != XR_VULKAN_RENDERER)*/)
121 {
122 MMechostr(MSKRUNTIME, "_CRopenXrDevice : renderer not supported\n");
123 MMset(m, 0, NIL);
124 return 0;
125 }
126
127 sOpenXr* openxrObj = sOpenXr::CreateInstance((RenderSystem)renderer, fratio);
128
129 if (!openxrObj->IsConnected() && !openxrObj->Connect())
130 {
131 MMechostr(MSKRUNTIME, "_CRopenXrDevice : device not found\n");
132 MMset(m, 0, NIL);
133 return 0;
134 }
135
136 // Allocate a space in the stack for a table of joypad object
137 if ((MMpushPointer(m, openxrObj) != 0))
138 {
139 sOpenXr::GetInstance()->Disconnect();
140 MMset(m, 0, NIL);
141 return MERRMEM;
142 }
143
144 // Create a new scol object
145 k = OBJcreate(m, OBJ_OPENXR_SCOL, SCOL_PTR openxrObj, NIL, NULL);
146
147#ifdef _SCOL_DEBUG_
148 MMechostr(0,"ok\n");
149#endif
150
151 return k;
152}
153
161int _DSopenXrDevice(mmachine m)
162{
163#ifdef _SCOL_DEBUG_
164 MMechostr(MSKDEBUG,"_DSopenXrDevice\n");
165#endif
166
167 int openxrTab = MMget(m, 0);
168 if (openxrTab == NIL)
169 {
170 MMset(m, 0, NIL);
171 return 0;
172 }
173
174 OBJdelTM(m, OBJ_OPENXR_SCOL, openxrTab);
175 MMset(m, 0, ITOM(0));
176
177#ifdef _SCOL_DEBUG_
178 MMechostr(MSKDEBUG,"ok\n");
179#endif
180 return 0;
181}
182
190int _GetOpenXrVisibility(mmachine m)
191{
192#ifdef _SCOL_DEBUG_
193 MMechostr(MSKDEBUG, "_GetOpenXrVisibility\n");
194#endif
195
196 int openxrTab = MMget(m, 0);
197 if (openxrTab == NIL)
198 {
199 MMset(m, 0, NIL);
200 return 0;
201 }
202
203 sOpenXr* openxrObj = MMgetPointer<sOpenXr*>(m, MTOP(openxrTab));
204 if (!openxrObj)
205 {
206 MMset(m, 0, NIL);
207 return 0;
208 }
209
210 int visible = openxrObj->IsVisible() ? 1 : 0;
211 MMset(m, 0, ITOM(visible));
212
213#ifdef _SCOL_DEBUG_
214 MMechostr(MSKDEBUG, "ok\n");
215#endif
216 return 0;
217}
218
227{
228#ifdef _SCOL_DEBUG_
229 MMechostr(MSKDEBUG,"_GetOpenXrOrientation\n");
230#endif
231
232 int openxrTab = MMget(m, 0);
233 if (openxrTab == NIL)
234 {
235 MMset(m, 0, NIL);
236 return 0;
237 }
238
239 sOpenXr* openxrObj = MMgetPointer<sOpenXr*>(m, MTOP(openxrTab));
240 if (!openxrObj || !openxrObj->IsConnected())
241 {
242 MMset(m, 0, NIL);
243 return 0;
244 }
245
246 Quaternion quat;
247 if (openxrObj->GetHmdOrientation(quat))
248 {
249 int tuple = MMmalloc(m, 4, TYPETAB);
250 if (tuple == NIL)
251 {
252 MMset(m, 0, NIL);
253 return MERRMEM;
254 }
255 MMstore(m, tuple, 0, FTOM(quat.x));
256 MMstore(m, tuple, 1, FTOM(quat.y));
257 MMstore(m, tuple, 2, FTOM(quat.z));
258 MMstore(m, tuple, 3, FTOM(quat.w));
259 MMset(m, 0, PTOM(tuple));
260 }
261 else
262 {
263 MMset(m, 0, NIL);
264 }
265
266#ifdef _SCOL_DEBUG_
267 MMechostr(MSKDEBUG,"ok\n");
268#endif
269 return 0;
270}
271
279int _GetOpenXrPosition(mmachine m)
280{
281#ifdef _SCOL_DEBUG_
282 MMechostr(MSKDEBUG,"_GetOpenXrPosition\n");
283#endif
284
285 int openxrTab = MMget(m, 0);
286 if (openxrTab == NIL)
287 {
288 MMset(m, 0, NIL);
289 return 0;
290 }
291
292 sOpenXr* openxrObj = MMgetPointer<sOpenXr*>(m, MTOP(openxrTab));
293 if (!openxrObj || !openxrObj->IsConnected())
294 {
295 MMset(m, 0, NIL);
296 return 0;
297 }
298
299 Vector3 pos;
300 if (openxrObj->GetHmdPosition(pos))
301 {
302 int tuple = MMmalloc(m, 3, TYPETAB);
303 if (tuple == NIL)
304 {
305 MMset(m, 0, NIL);
306 return MERRMEM;
307 }
308 MMstore(m, tuple, 0, FTOM(pos.x));
309 MMstore(m, tuple, 1, FTOM(pos.y));
310 MMstore(m, tuple, 2, FTOM(pos.z));
311 MMset(m, 0, PTOM(tuple));
312 }
313 else
314 {
315 MMset(m, 0, NIL);
316 }
317
318#ifdef _SCOL_DEBUG_
319 MMechostr(MSKDEBUG,"ok\n");
320#endif
321 return 0;
322}
323
331int _GetOpenXrFovY(mmachine m)
332{
333#ifdef _SCOL_DEBUG_
334 MMechostr(MSKDEBUG,"_GetOpenXrFovY\n");
335#endif
336
337 int openxrTab = MMget(m, 0);
338 if (openxrTab == NIL)
339 {
340 MMset(m, 0, NIL);
341 return 0;
342 }
343
344 sOpenXr* openxrObj = MMgetPointer<sOpenXr*>(m, MTOP(openxrTab));
345 if (!openxrObj)
346 {
347 MMset(m, 0, NIL);
348 return 0;
349 }
350
351 MMset(m, 0, FTOM(openxrObj->GetStereoConfigFovY()));
352
353#ifdef _SCOL_DEBUG_
354 MMechostr(MSKDEBUG,"ok\n");
355#endif
356 return 0;
357}
358
366int _GetOpenXrIPD(mmachine m)
367{
368#ifdef _SCOL_DEBUG_
369 MMechostr(MSKDEBUG,"_GetOpenXrIPD\n");
370#endif
371
372 int openxrTab = MMget(m, 0);
373 if (openxrTab == NIL)
374 {
375 MMset(m, 0, NIL);
376 return 0;
377 }
378
379 sOpenXr* openxrObj = MMgetPointer<sOpenXr*>(m, MTOP(openxrTab));
380 if (!openxrObj)
381 {
382 MMset(m, 0, NIL);
383 return 0;
384 }
385
386 //MMechostr(MSKRUNTIME, "OpenXR IPD: %f", openxrObj->GetStereoConfigIPD());
387 MMset(m, 0, FTOM(openxrObj->GetStereoConfigIPD()));
388
389#ifdef _SCOL_DEBUG_
390 MMechostr(MSKDEBUG,"ok\n");
391#endif
392 return 0;
393}
394
402int _UpdateOpenXr(mmachine m)
403{
404#ifdef _SCOL_DEBUG_
405 MMechostr(MSKDEBUG,"_UpdateOpenXr\n");
406#endif
407
408 int openxrTab = MMget(m, 0);
409 if (openxrTab == NIL)
410 {
411 MMset(m, 0, NIL);
412 return 0;
413 }
414
415 sOpenXr* openxrObj = MMgetPointer<sOpenXr*>(m, MTOP(openxrTab));
416 if (!openxrObj || !openxrObj->IsConnected())
417 {
418 MMset(m, 0, NIL);
419 return 0;
420 }
421 bool ret = openxrObj->Update();
422
423 MMset(m, 0, ITOM((ret) ? 1 : 0));
424
425 return 0;
426}
427
438{
439#ifdef _SCOL_DEBUG_
440 MMechostr(MSKDEBUG, "_UpdateOpenXrTextures\n");
441#endif
442
443 int iRightTex = MMpull(m);
444 int iLeftTex = MMpull(m);
445
446 int openxrTab = MMget(m, 0);
447 if (openxrTab == NIL || iRightTex == NIL || iLeftTex == NIL)
448 {
449 MMset(m, 0, NIL);
450 return 0;
451 }
452
453 sOpenXr* openxrObj = MMgetPointer<sOpenXr*>(m, MTOP(openxrTab));
454 if (!openxrObj || !openxrObj->IsConnected())
455 {
456 MMset(m, 0, NIL);
457 return 0;
458 }
459 SCOL_PTR_TYPE lptr = MMgetPointer<SCOL_PTR_TYPE>(m, MMfetch(m, MTOP(iLeftTex), 0));
460 SCOL_PTR_TYPE rptr = MMgetPointer<SCOL_PTR_TYPE>(m, MMfetch(m, MTOP(iRightTex), 0));
461
462 openxrObj->UpdateTextures(lptr, rptr);
463
464 MMset(m, 0, ITOM(1));
465
466#ifdef _SCOL_DEBUG_
467 MMechostr(MSKDEBUG, "ok\n");
468#endif
469 return 0;
470}
471
479int _GetOpenXrDeviceName(mmachine m)
480{
481#ifdef _SCOL_DEBUG_
482 MMechostr(MSKDEBUG,"_GetOpenXrDeviceName\n");
483#endif
484
485 int openxrTab = MMget(m, 0);
486 if (openxrTab == NIL)
487 {
488 MMset(m, 0, NIL);
489 return 0;
490 }
491
492 sOpenXr* openxrObj = MMgetPointer<sOpenXr*>(m, MTOP(openxrTab));
493 if (!openxrObj || !openxrObj->IsConnected())
494 {
495 MMset(m, 0, NIL);
496 return 0;
497 }
498
499 MMpull(m);
500 Mpushstrbloc(m, openxrObj->GetHmdName().c_str());
501
502#ifdef _SCOL_DEBUG_
503 MMechostr(MSKDEBUG, "ok\n");
504#endif
505 return 0;
506}
507
518{
519#ifdef _SCOL_DEBUG_
520 MMechostr(MSKDEBUG, "_GetOpenXrProjectionMatrix\n");
521#endif
522
523 int ifclip = MMpull(m);
524 int inclip = MMpull(m);
525
526 int openxrTab = MMget(m, 0);
527 if (openxrTab == NIL)
528 {
529 MMset(m, 0, NIL);
530 return 0;
531 }
532
533 sOpenXr* openxrObj = MMgetPointer<sOpenXr*>(m, MTOP(openxrTab));
534 if (!openxrObj || !openxrObj->IsConnected())
535 {
536 MMset(m, 0, NIL);
537 return 0;
538 }
539
540 float nearclip = 0.01f;
541 if (inclip != NIL)
542 nearclip = MTOF(inclip);
543
544 float farclip = 10000.0f;
545 if (ifclip != NIL)
546 farclip = MTOF(ifclip);
547
548 Matrix4 lmat;
549 Matrix4 rmat;
550
551 if (!openxrObj->GetProjectionMatrix(VrEye::LeftEye, nearclip, farclip, lmat) ||
552 !openxrObj->GetProjectionMatrix(VrEye::RightEye, nearclip, farclip, rmat))
553 {
554 MMset(m, 0, NIL);
555 return 0;
556 }
557
558 int tuple = MMmalloc(m, 2, TYPETAB);
559
560 int ltmat = MMmalloc(m, 4, TYPETAB);
561 int ltmat1 = MMmalloc(m, 4, TYPETAB);
562 int ltmat2 = MMmalloc(m, 4, TYPETAB);
563 int ltmat3 = MMmalloc(m, 4, TYPETAB);
564 int ltmat4 = MMmalloc(m, 4, TYPETAB);
565
566 int rtmat = MMmalloc(m, 4, TYPETAB);
567 int rtmat1 = MMmalloc(m, 4, TYPETAB);
568 int rtmat2 = MMmalloc(m, 4, TYPETAB);
569 int rtmat3 = MMmalloc(m, 4, TYPETAB);
570 int rtmat4 = MMmalloc(m, 4, TYPETAB);
571
572 if ((tuple == NIL) || (ltmat == NIL) || (ltmat1 == NIL) || (ltmat2 == NIL) || (ltmat3 == NIL) || (ltmat4 == NIL) || (rtmat == NIL) || (rtmat1 == NIL) || (rtmat2 == NIL) || (rtmat3 == NIL) || (rtmat4 == NIL))
573 {
574 MMset(m, 0, NIL);
575 return MERRMEM;
576 }
577
578 MMstore(m, ltmat1, 0, FTOM(lmat[0][0]));
579 MMstore(m, ltmat1, 1, FTOM(lmat[0][1]));
580 MMstore(m, ltmat1, 2, FTOM(lmat[0][2]));
581 MMstore(m, ltmat1, 3, FTOM(lmat[0][3]));
582
583 MMstore(m, ltmat2, 0, FTOM(lmat[1][0]));
584 MMstore(m, ltmat2, 1, FTOM(lmat[1][1]));
585 MMstore(m, ltmat2, 2, FTOM(lmat[1][2]));
586 MMstore(m, ltmat2, 3, FTOM(lmat[1][3]));
587
588 MMstore(m, ltmat3, 0, FTOM(lmat[2][0]));
589 MMstore(m, ltmat3, 1, FTOM(lmat[2][1]));
590 MMstore(m, ltmat3, 2, FTOM(lmat[2][2]));
591 MMstore(m, ltmat3, 3, FTOM(lmat[2][3]));
592
593 MMstore(m, ltmat4, 0, FTOM(lmat[3][0]));
594 MMstore(m, ltmat4, 1, FTOM(lmat[3][1]));
595 MMstore(m, ltmat4, 2, FTOM(lmat[3][2]));
596 MMstore(m, ltmat4, 3, FTOM(lmat[3][3]));
597
598 MMstore(m, ltmat, 0, PTOM(ltmat1));
599 MMstore(m, ltmat, 1, PTOM(ltmat2));
600 MMstore(m, ltmat, 2, PTOM(ltmat3));
601 MMstore(m, ltmat, 3, PTOM(ltmat4));
602
603 MMstore(m, rtmat1, 0, FTOM(rmat[0][0]));
604 MMstore(m, rtmat1, 1, FTOM(rmat[0][1]));
605 MMstore(m, rtmat1, 2, FTOM(rmat[0][2]));
606 MMstore(m, rtmat1, 3, FTOM(rmat[0][3]));
607
608 MMstore(m, rtmat2, 0, FTOM(rmat[1][0]));
609 MMstore(m, rtmat2, 1, FTOM(rmat[1][1]));
610 MMstore(m, rtmat2, 2, FTOM(rmat[1][2]));
611 MMstore(m, rtmat2, 3, FTOM(rmat[1][3]));
612
613 MMstore(m, rtmat3, 0, FTOM(rmat[2][0]));
614 MMstore(m, rtmat3, 1, FTOM(rmat[2][1]));
615 MMstore(m, rtmat3, 2, FTOM(rmat[2][2]));
616 MMstore(m, rtmat3, 3, FTOM(rmat[2][3]));
617
618 MMstore(m, rtmat4, 0, FTOM(rmat[3][0]));
619 MMstore(m, rtmat4, 1, FTOM(rmat[3][1]));
620 MMstore(m, rtmat4, 2, FTOM(rmat[3][2]));
621 MMstore(m, rtmat4, 3, FTOM(rmat[3][3]));
622
623 MMstore(m, rtmat, 0, PTOM(rtmat1));
624 MMstore(m, rtmat, 1, PTOM(rtmat2));
625 MMstore(m, rtmat, 2, PTOM(rtmat3));
626 MMstore(m, rtmat, 3, PTOM(rtmat4));
627
628 MMstore(m, tuple, 0, PTOM(ltmat));
629 MMstore(m, tuple, 1, PTOM(rtmat));
630 MMset(m, 0, PTOM(tuple));
631
632#ifdef _SCOL_DEBUG_
633 MMechostr(MSKDEBUG,"ok\n");
634#endif
635 return 0;
636}
637
646{
647#ifdef _SCOL_DEBUG_
648 MMechostr(MSKDEBUG,"_GetOpenXrTextureSize\n");
649#endif
650
651 int openxrTab = MMget(m, 0);
652 if (openxrTab == NIL)
653 {
654 MMset(m, 0, NIL);
655 return 0;
656 }
657
658 sOpenXr* openxrObj = MMgetPointer<sOpenXr*>(m, MTOP(openxrTab));
659 if (!openxrObj || !openxrObj->IsConnected())
660 {
661 MMset(m, 0, NIL);
662 return 0;
663 }
664
665 unsigned int w = 0;
666 unsigned int h = 0;
667 openxrObj->GetStereoTextureSize(w, h);
668
669 int tuple = MMmalloc(m, 2, TYPETAB);
670 if (tuple == NIL)
671 {
672 MMset(m, 0, NIL);
673 return MERRMEM;
674 }
675
676 MMstore(m, tuple, 0, ITOM(w));
677 MMstore(m, tuple, 1, ITOM(h));
678 MMset(m, 0, PTOM(tuple));
679
680#ifdef _SCOL_DEBUG_
681 MMechostr(MSKDEBUG,"ok\n");
682#endif
683 return 0;
684}
685
695{
696#ifdef _SCOL_DEBUG_
697 MMechostr(MSKDEBUG, "_GetOpenXrControllerVisibility\n");
698#endif
699
700 int iSide = MMpull(m);
701
702 int openxrTab = MMget(m, 0);
703 if (openxrTab == NIL)
704 {
705 MMset(m, 0, NIL);
706 return 0;
707 }
708
709 sOpenXr* openxrObj = MMgetPointer<sOpenXr*>(m, MTOP(openxrTab));
710 if (!openxrObj || !openxrObj->IsConnected())
711 {
712 MMset(m, 0, NIL);
713 return 0;
714 }
715
716 unsigned int id = 0;
717 if (iSide != NIL && MTOI(iSide) > 0)
718 id = MTOI(iSide);
719
720 int visible = (openxrObj->GetControllerVisibility(id)) ? 1 : 0;
721 MMset(m, 0, ITOM(visible));
722
723#ifdef _SCOL_DEBUG_
724 MMechostr(MSKDEBUG, "ok\n");
725#endif
726 return 0;
727}
728
738{
739#ifdef _SCOL_DEBUG_
740 MMechostr(MSKDEBUG, "_GetOpenXrControllerPosition\n");
741#endif
742
743 int iSide = MMpull(m);
744
745 int openxrTab = MMget(m, 0);
746 if (openxrTab == NIL)
747 {
748 MMset(m, 0, NIL);
749 return 0;
750 }
751
752 sOpenXr* openxrObj = MMgetPointer<sOpenXr*>(m, MTOP(openxrTab));
753 if (!openxrObj || !openxrObj->IsConnected())
754 {
755 MMset(m, 0, NIL);
756 return 0;
757 }
758
759 unsigned int id = 0;
760 if (iSide != NIL && MTOI(iSide) > 0)
761 id = MTOI(iSide);
762
763 Vector3 pos = openxrObj->GetControllerPosition(id);
764 int tuple = MMmalloc(m, 3, TYPETAB);
765 if (tuple == NIL)
766 {
767 MMset(m, 0, NIL);
768 return MERRMEM;
769 }
770 MMstore(m, tuple, 0, FTOM(pos.x));
771 MMstore(m, tuple, 1, FTOM(pos.y));
772 MMstore(m, tuple, 2, FTOM(pos.z));
773 MMset(m, 0, PTOM(tuple));
774
775#ifdef _SCOL_DEBUG_
776 MMechostr(MSKDEBUG, "ok\n");
777#endif
778 return 0;
779}
780
790{
791#ifdef _SCOL_DEBUG_
792 MMechostr(MSKDEBUG, "_GetOpenXrControllerOrientation\n");
793#endif
794
795 int iSide = MMpull(m);
796
797 int openxrTab = MMget(m, 0);
798 if (openxrTab == NIL)
799 {
800 MMset(m, 0, NIL);
801 return 0;
802 }
803
804 sOpenXr* openxrObj = MMgetPointer<sOpenXr*>(m, MTOP(openxrTab));
805 if (!openxrObj || !openxrObj->IsConnected())
806 {
807 MMset(m, 0, NIL);
808 return 0;
809 }
810
811 unsigned int id = 0;
812 if (iSide != NIL && MTOI(iSide) > 0)
813 id = MTOI(iSide);
814
815 Quaternion quat = openxrObj->GetControllerOrientation(id);
816 int tuple = MMmalloc(m, 4, TYPETAB);
817 if (tuple == NIL)
818 {
819 MMset(m, 0, NIL);
820 return MERRMEM;
821 }
822 MMstore(m, tuple, 0, FTOM(quat.x));
823 MMstore(m, tuple, 1, FTOM(quat.y));
824 MMstore(m, tuple, 2, FTOM(quat.z));
825 MMstore(m, tuple, 3, FTOM(quat.w));
826 MMset(m, 0, PTOM(tuple));
827
828#ifdef _SCOL_DEBUG_
829 MMechostr(MSKDEBUG, "ok\n");
830#endif
831 return 0;
832}
833
843{
844#ifdef _SCOL_DEBUG_
845 MMechostr(MSKDEBUG, "_GetOpenXrControllerVelocity\n");
846#endif
847
848 int iSide = MMpull(m);
849
850 int openxrTab = MMget(m, 0);
851 if (openxrTab == NIL)
852 {
853 MMset(m, 0, NIL);
854 return 0;
855 }
856
857 sOpenXr* openxrObj = MMgetPointer<sOpenXr*>(m, MTOP(openxrTab));
858 if (!openxrObj || !openxrObj->IsConnected())
859 {
860 MMset(m, 0, NIL);
861 return 0;
862 }
863
864 unsigned int id = 0;
865 if (iSide != NIL && MTOI(iSide) > 0)
866 id = MTOI(iSide);
867
868 Vector3 vel = openxrObj->GetControllerVelocity(id);
869 int tuple = MMmalloc(m, 3, TYPETAB);
870 if (tuple == NIL)
871 {
872 MMset(m, 0, NIL);
873 return MERRMEM;
874 }
875 MMstore(m, tuple, 0, FTOM(vel.x));
876 MMstore(m, tuple, 1, FTOM(vel.y));
877 MMstore(m, tuple, 2, FTOM(vel.z));
878 MMset(m, 0, PTOM(tuple));
879
880#ifdef _SCOL_DEBUG_
881 MMechostr(MSKDEBUG, "ok\n");
882#endif
883 return 0;
884}
885
895{
896#ifdef _SCOL_DEBUG_
897 MMechostr(MSKDEBUG, "_GetOpenXrControllerAngularVelocity\n");
898#endif
899
900 int iSide = MMpull(m);
901
902 int openxrTab = MMget(m, 0);
903 if (openxrTab == NIL)
904 {
905 MMset(m, 0, NIL);
906 return 0;
907 }
908
909 sOpenXr* openxrObj = MMgetPointer<sOpenXr*>(m, MTOP(openxrTab));
910 if (!openxrObj || !openxrObj->IsConnected())
911 {
912 MMset(m, 0, NIL);
913 return 0;
914 }
915
916 unsigned int id = 0;
917 if (iSide != NIL && MTOI(iSide) > 0)
918 id = MTOI(iSide);
919
920 Vector3 avel = openxrObj->GetControllerAngularVelocity(id);
921 int tuple = MMmalloc(m, 3, TYPETAB);
922 if (tuple == NIL)
923 {
924 MMset(m, 0, NIL);
925 return MERRMEM;
926 }
927 MMstore(m, tuple, 0, FTOM(avel.x));
928 MMstore(m, tuple, 1, FTOM(avel.y));
929 MMstore(m, tuple, 2, FTOM(avel.z));
930 MMset(m, 0, PTOM(tuple));
931
932#ifdef _SCOL_DEBUG_
933 MMechostr(MSKDEBUG, "ok\n");
934#endif
935 return 0;
936}
937
948{
949#ifdef _SCOL_DEBUG_
950 MMechostr(MSKDEBUG, "_GetOpenXrControllerButtons\n");
951#endif
952
953 int iSide = MMpull(m);
954
955 int openxrTab = MMget(m, 0);
956 if (openxrTab == NIL)
957 {
958 MMset(m, 0, NIL);
959 return 0;
960 }
961
962 sOpenXr* openxrObj = MMgetPointer<sOpenXr*>(m, MTOP(openxrTab));
963 if (!openxrObj || !openxrObj->IsConnected())
964 {
965 MMset(m, 0, NIL);
966 return 0;
967 }
968
969 unsigned int id = 0;
970 if (iSide != NIL && MTOI(iSide) > 0)
971 id = MTOI(iSide);
972
973 std::vector<bool> buttons = openxrObj->GetControllerButtonsState(id);
974
975 //clean the stack
976 MMpull(m);
977
978 for (unsigned int i = 0; i < buttons.size(); i++)
979 {
980 MMpush(m, ITOM(buttons[i]));
981 }
982 MMpush(m, NIL);
983
984 for (unsigned int i = 0; i < buttons.size(); i++)
985 {
986 MMpush(m, ITOM(2));
987 MBdeftab(m);
988 }
989
990#ifdef _SCOL_DEBUG_
991 MMechostr(MSKDEBUG, "ok\n");
992#endif
993 return 0;
994}
995
1006{
1007#ifdef _SCOL_DEBUG_
1008 MMechostr(MSKDEBUG, "_GetOpenXrControllerButtons\n");
1009#endif
1010
1011 int iSide = MMpull(m);
1012
1013 int openxrTab = MMget(m, 0);
1014 if (openxrTab == NIL)
1015 {
1016 MMset(m, 0, NIL);
1017 return 0;
1018 }
1019
1020 sOpenXr* openxrObj = MMgetPointer<sOpenXr*>(m, MTOP(openxrTab));
1021 if (!openxrObj || !openxrObj->IsConnected())
1022 {
1023 MMset(m, 0, NIL);
1024 return 0;
1025 }
1026
1027 unsigned int id = 0;
1028 if (iSide != NIL && MTOI(iSide) > 0)
1029 id = MTOI(iSide);
1030
1031 std::vector<bool> touches = openxrObj->GetControllerTouchesState(id);
1032
1033 //clean the stack
1034 MMpull(m);
1035
1036 for (unsigned int i = 0; i < touches.size(); i++)
1037 {
1038 MMpush(m, ITOM(touches[i]));
1039 }
1040 MMpush(m, NIL);
1041
1042 for (unsigned int i = 0; i < touches.size(); i++)
1043 {
1044 MMpush(m, ITOM(2));
1045 MBdeftab(m);
1046 }
1047
1048#ifdef _SCOL_DEBUG_
1049 MMechostr(MSKDEBUG, "ok\n");
1050#endif
1051 return 0;
1052}
1053
1064{
1065#ifdef _SCOL_DEBUG_
1066 MMechostr(MSKDEBUG, "_GetOpenXrControllerAxis\n");
1067#endif
1068
1069 int iSide = MMpull(m);
1070
1071 int openxrTab = MMget(m, 0);
1072 if (openxrTab == NIL)
1073 {
1074 MMset(m, 0, NIL);
1075 return 0;
1076 }
1077
1078 sOpenXr* openxrObj = MMgetPointer<sOpenXr*>(m, MTOP(openxrTab));
1079 if (!openxrObj || !openxrObj->IsConnected())
1080 {
1081 MMset(m, 0, NIL);
1082 return 0;
1083 }
1084
1085 unsigned int id = 0;
1086 if (iSide != NIL && MTOI(iSide) > 0)
1087 id = MTOI(iSide);
1088
1089
1090 std::vector<float> axisvalue = openxrObj->GetControllerAnalogState(id);
1091 if (axisvalue.size() < 4)
1092 {
1093 MMset(m, 0, NIL);
1094 return 0;
1095 }
1096
1097 int tuple = MMmalloc(m, 4, TYPETAB);
1098 if (tuple == NIL)
1099 {
1100 MMset(m, 0, NIL);
1101 return MERRMEM;
1102 }
1103 MMstore(m, tuple, 0, FTOM(axisvalue[0]));
1104 MMstore(m, tuple, 1, FTOM(axisvalue[1]));
1105 MMstore(m, tuple, 2, FTOM(axisvalue[2]));
1106 MMstore(m, tuple, 3, FTOM(axisvalue[3]));
1107 MMset(m, 0, PTOM(tuple));
1108
1109#ifdef _SCOL_DEBUG_
1110 MMechostr(MSKDEBUG, "ok\n");
1111#endif
1112 return 0;
1113}
1114
1124{
1125#ifdef _SCOL_DEBUG_
1126 MMechostr(MSKDEBUG, "_GetOpenXrControllerType\n");
1127#endif
1128
1129 int iSide = MMpull(m);
1130
1131 int openxrTab = MMget(m, 0);
1132 if (openxrTab == NIL)
1133 {
1134 MMset(m, 0, NIL);
1135 return 0;
1136 }
1137
1138 sOpenXr* openxrObj = MMgetPointer<sOpenXr*>(m, MTOP(openxrTab));
1139 if (!openxrObj || !openxrObj->IsConnected())
1140 {
1141 MMset(m, 0, NIL);
1142 return 0;
1143 }
1144
1145 unsigned int id = 0;
1146 if (iSide != NIL && MTOI(iSide) > 0)
1147 id = MTOI(iSide);
1148
1149 MMset(m, 0, ITOM(openxrObj->GetControllerType(id)));
1150
1151#ifdef _SCOL_DEBUG_
1152 MMechostr(MSKDEBUG, "ok\n");
1153#endif
1154 return 0;
1155}
1156
1166{
1167#ifdef _SCOL_DEBUG_
1168 MMechostr(MSKDEBUG, "_GetOpenXrControllerBonesRotation\n");
1169#endif
1170
1171 int iSide = MMpull(m);
1172
1173 int openxrTab = MMget(m, 0);
1174 if (openxrTab == NIL)
1175 {
1176 MMset(m, 0, NIL);
1177 return 0;
1178 }
1179
1180 sOpenXr* openxrObj = MMgetPointer<sOpenXr*>(m, MTOP(openxrTab));
1181 if (!openxrObj || !openxrObj->IsConnected())
1182 {
1183 MMset(m, 0, NIL);
1184 return 0;
1185 }
1186
1187 unsigned int id = 0;
1188 if (iSide != NIL && MTOI(iSide) > 0)
1189 id = MTOI(iSide);
1190
1191 bool valid = false;
1192 std::array<Position, MAX_HAND_JOINTS> bones = openxrObj->GetControllerBones(id, valid);
1193
1194 if (!valid)
1195 {
1196 MMset(m, 0, NIL);
1197 return 0;
1198 }
1199
1200 //clean the stack
1201 MMpull(m);
1202
1203 int tuple = 0;
1204 Quaternion quat;
1205 for (unsigned int i = 0; i < MAX_HAND_JOINTS; i++)
1206 {
1207 tuple = MMmalloc(m, 4, TYPETAB);
1208 if (tuple == NIL)
1209 return MERRMEM;
1210
1211 if (bones[i].valid)
1212 {
1213 quat = bones[i].rotation;
1214 MMstore(m, tuple, 0, FTOM(quat.x));
1215 MMstore(m, tuple, 1, FTOM(quat.y));
1216 MMstore(m, tuple, 2, FTOM(quat.z));
1217 MMstore(m, tuple, 3, FTOM(quat.w));
1218 MMpush(m, PTOM(tuple));
1219 }
1220 else
1221 {
1222 MMpush(m, NIL);
1223 }
1224 }
1225 MMpush(m, NIL);
1226
1227 for (unsigned int i = 0; i < bones.size(); i++)
1228 {
1229 MMpush(m, ITOM(2));
1230 MBdeftab(m);
1231 }
1232
1233#ifdef _SCOL_DEBUG_
1234 MMechostr(MSKDEBUG, "ok\n");
1235#endif
1236 return 0;
1237}
1238
1249{
1250#ifdef _SCOL_DEBUG_
1251 MMechostr(MSKDEBUG, "_SetOpenXrControllerRumble\n");
1252#endif
1253
1254 int iRumble = MMpull(m);
1255 int iSide = MMpull(m);
1256
1257 int openxrTab = MMget(m, 0);
1258 if (openxrTab == NIL)
1259 {
1260 MMset(m, 0, NIL);
1261 return 0;
1262 }
1263
1264 sOpenXr* openxrObj = MMgetPointer<sOpenXr*>(m, MTOP(openxrTab));
1265 if (!openxrObj || !openxrObj->IsConnected())
1266 {
1267 MMset(m, 0, NIL);
1268 return 0;
1269 }
1270
1271 unsigned int id = 0;
1272 if (iSide != NIL && MTOI(iSide) > 0)
1273 id = MTOI(iSide);
1274
1275 float rumble = 0.0f;
1276 if (iRumble != NIL)
1277 rumble = MTOF(iRumble);
1278
1279 openxrObj->SetControllerVibration(id, rumble);
1280 MMset(m, 0, ITOM(1));
1281
1282#ifdef _SCOL_DEBUG_
1283 MMechostr(MSKDEBUG, "ok\n");
1284#endif
1285 return 0;
1286}
1287
1295int _SetOpenXrAppName(mmachine m)
1296{
1297#ifdef _SCOL_DEBUG_
1298 MMechostr(MSKDEBUG, "_SetOpenXrAppName\n");
1299#endif
1300
1301 int iName = MMget(m, 0);
1302
1303 std::string name = "Scol OpenXR plugin";
1304 if (iName != NIL)
1305 name = MMstartstr(m, MTOP(iName));
1306
1307 sOpenXr::GetInstance()->SetAppName(name);
1308
1309 MMset(m, 0, ITOM(0));
1310
1311#ifdef _SCOL_DEBUG_
1312 MMechostr(MSKDEBUG, "ok\n");
1313#endif
1314 return 0;
1315}
1316
1325{
1326#ifdef _SCOL_DEBUG_
1327 MMechostr(MSKDEBUG, "_SetOpenXrExtensions\n");
1328#endif
1329
1330 int iExtension = MMget(m, 0);
1331
1332 int extension = 0;
1333 if (iExtension != NIL)
1334 extension = MTOI(iExtension);
1335
1336 sOpenXr::GetInstance()->SetExtensions(extension);
1337
1338 MMset(m, 0, ITOM(0));
1339
1340#ifdef _SCOL_DEBUG_
1341 MMechostr(MSKDEBUG, "ok\n");
1342#endif
1343 return 0;
1344}
1345
1353{
1354#ifdef _SCOL_DEBUG_
1355 MMechostr(MSKDEBUG, "_GetOpenXrExtensions\n");
1356#endif
1357
1358 MMpush(m, ITOM(sOpenXr::GetInstance()->GetExtensions()));
1359
1360#ifdef _SCOL_DEBUG_
1361 MMechostr(MSKDEBUG, "ok\n");
1362#endif
1363 return 0;
1364}
1365
1375{
1376#ifdef _SCOL_DEBUG_
1377 MMechostr(MSKDEBUG, "_SetOpenXrControllerRumble\n");
1378#endif
1379
1380 int iState = MMpull(m);
1381 int openxrTab = MMget(m, 0);
1382 if (openxrTab == NIL)
1383 {
1384 MMset(m, 0, NIL);
1385 return 0;
1386 }
1387
1388 sOpenXr* openxrObj = MMgetPointer<sOpenXr*>(m, MTOP(openxrTab));
1389 if (!openxrObj || !openxrObj->IsConnected())
1390 {
1391 MMset(m, 0, NIL);
1392 return 0;
1393 }
1394
1395 bool state = false;
1396 if (iState != NIL)
1397 state = (MTOI(iState) <= 0) ? false : true;
1398
1399 bool support = openxrObj->SetPassthroughState(state);
1400 MMset(m, 0, ITOM(support ? 1 : 0));
1401
1402#ifdef _SCOL_DEBUG_
1403 MMechostr(MSKDEBUG, "ok\n");
1404#endif
1405 return 0;
1406}
1407
1416{
1417#ifdef _SCOL_DEBUG_
1418 MMechostr(MSKDEBUG, "_SetOpenXrControllerRumble\n");
1419#endif
1420
1421 int openxrTab = MMget(m, 0);
1422 if (openxrTab == NIL)
1423 {
1424 MMset(m, 0, NIL);
1425 return 0;
1426 }
1427
1428 sOpenXr* openxrObj = MMgetPointer<sOpenXr*>(m, MTOP(openxrTab));
1429 if (!openxrObj || !openxrObj->IsConnected())
1430 {
1431 MMset(m, 0, NIL);
1432 return 0;
1433 }
1434
1435 bool support = openxrObj->IsPassthroughSupported();
1436 MMset(m, 0, ITOM(support ? 1 : 0));
1437
1438#ifdef _SCOL_DEBUG_
1439 MMechostr(MSKDEBUG, "ok\n");
1440#endif
1441 return 0;
1442}
1443
1444NativeDefinition mOpenXrEngine[] =
1445{
1446 { "ObjOpenXr", TYPTYPE, NULL, NULL },
1447 { "OPENXR_CONTROLLER_LEFT", TYPVAR, "I", SCOL_TYPTYPE(VrController::Left) },
1448 { "OPENXR_CONTROLLER_RIGHT", TYPVAR, "I", SCOL_TYPTYPE(VrController::Right) },
1449
1450 { "OPENXR_NO_EXTENSION", TYPVAR, "I", SCOL_TYPTYPE(ExtensionType::EXTENSION_NONE) },
1451 { "OPENXR_HAND_TRACKING_EXTENSION", TYPVAR, "I", SCOL_TYPTYPE(ExtensionType::EXTENSION_HAND_TRACKING) },
1452 { "OPENXR_PASSTHROUGH_EXTENSION", TYPVAR, "I", SCOL_TYPTYPE(ExtensionType::EXTENSION_PASSTHROUGH) },
1453
1454 { "OPENXR_HAND_JOINT_PALM", TYPVAR, "I", SCOL_TYPTYPE(XR_HAND_JOINT_PALM_EXT) },
1455 { "OPENXR_HAND_JOINT_WRIST", TYPVAR, "I", SCOL_TYPTYPE(XR_HAND_JOINT_WRIST_EXT) },
1456 { "OPENXR_HAND_JOINT_THUMB_METACARPAL", TYPVAR, "I", SCOL_TYPTYPE(XR_HAND_JOINT_THUMB_METACARPAL_EXT) },
1457 { "OPENXR_HAND_JOINT_THUMB_PROXIMAL", TYPVAR, "I", SCOL_TYPTYPE(XR_HAND_JOINT_THUMB_PROXIMAL_EXT) },
1458 { "OPENXR_HAND_JOINT_THUMB_DISTAL", TYPVAR, "I", SCOL_TYPTYPE(XR_HAND_JOINT_THUMB_DISTAL_EXT) },
1459 { "OPENXR_HAND_JOINT_THUMB_TIP", TYPVAR, "I", SCOL_TYPTYPE(XR_HAND_JOINT_THUMB_TIP_EXT) },
1460 { "OPENXR_HAND_JOINT_INDEX_METACARPAL", TYPVAR, "I", SCOL_TYPTYPE(XR_HAND_JOINT_INDEX_METACARPAL_EXT) },
1461 { "OPENXR_HAND_JOINT_INDEX_PROXIMAL", TYPVAR, "I", SCOL_TYPTYPE(XR_HAND_JOINT_INDEX_PROXIMAL_EXT) },
1462 { "OPENXR_HAND_JOINT_INDEX_INTERMEDIATE", TYPVAR, "I", SCOL_TYPTYPE(XR_HAND_JOINT_INDEX_INTERMEDIATE_EXT) },
1463 { "OPENXR_HAND_JOINT_INDEX_DISTAL", TYPVAR, "I", SCOL_TYPTYPE(XR_HAND_JOINT_INDEX_DISTAL_EXT) },
1464 { "OPENXR_HAND_JOINT_INDEX_TIP", TYPVAR, "I", SCOL_TYPTYPE(XR_HAND_JOINT_INDEX_TIP_EXT) },
1465 { "OPENXR_HAND_JOINT_MIDDLE_METACARPAL", TYPVAR, "I", SCOL_TYPTYPE(XR_HAND_JOINT_MIDDLE_METACARPAL_EXT) },
1466 { "OPENXR_HAND_JOINT_MIDDLE_PROXIMAL", TYPVAR, "I", SCOL_TYPTYPE(XR_HAND_JOINT_MIDDLE_PROXIMAL_EXT) },
1467 { "OPENXR_HAND_JOINT_MIDDLE_INTERMEDIATE", TYPVAR, "I", SCOL_TYPTYPE(XR_HAND_JOINT_MIDDLE_INTERMEDIATE_EXT) },
1468 { "OPENXR_HAND_JOINT_MIDDLE_DISTAL", TYPVAR, "I", SCOL_TYPTYPE(XR_HAND_JOINT_MIDDLE_DISTAL_EXT) },
1469 { "OPENXR_HAND_JOINT_MIDDLE_TIP", TYPVAR, "I", SCOL_TYPTYPE(XR_HAND_JOINT_MIDDLE_TIP_EXT) },
1470 { "OPENXR_HAND_JOINT_RING_METACARPAL", TYPVAR, "I", SCOL_TYPTYPE(XR_HAND_JOINT_RING_METACARPAL_EXT) },
1471 { "OPENXR_HAND_JOINT_RING_PROXIMAL", TYPVAR, "I", SCOL_TYPTYPE(XR_HAND_JOINT_RING_PROXIMAL_EXT) },
1472 { "OPENXR_HAND_JOINT_RING_INTERMEDIATE", TYPVAR, "I", SCOL_TYPTYPE(XR_HAND_JOINT_RING_INTERMEDIATE_EXT) },
1473 { "OPENXR_HAND_JOINT_RING_DISTAL", TYPVAR, "I", SCOL_TYPTYPE(XR_HAND_JOINT_RING_DISTAL_EXT) },
1474 { "OPENXR_HAND_JOINT_RING_TIP", TYPVAR, "I", SCOL_TYPTYPE(XR_HAND_JOINT_RING_TIP_EXT) },
1475 { "OPENXR_HAND_JOINT_LITTLE_METACARPAL", TYPVAR, "I", SCOL_TYPTYPE(XR_HAND_JOINT_LITTLE_METACARPAL_EXT) },
1476 { "OPENXR_HAND_JOINT_LITTLE_PROXIMAL", TYPVAR, "I", SCOL_TYPTYPE(XR_HAND_JOINT_LITTLE_PROXIMAL_EXT) },
1477 { "OPENXR_HAND_JOINT_LITTLE_INTERMEDIATE", TYPVAR, "I", SCOL_TYPTYPE(XR_HAND_JOINT_LITTLE_INTERMEDIATE_EXT) },
1478 { "OPENXR_HAND_JOINT_LITTLE_DISTAL", TYPVAR, "I", SCOL_TYPTYPE(XR_HAND_JOINT_LITTLE_DISTAL_EXT) },
1479 { "OPENXR_HAND_JOINT_LITTLE_TIP", TYPVAR, "I", SCOL_TYPTYPE(XR_HAND_JOINT_LITTLE_TIP_EXT) },
1480
1481 { "_CRopenXrDevice", 3, "fun [Chn I F] ObjOpenXr", _CRopenXrDevice },
1482 { "_DSopenXrDevice", 1, "fun [ObjOpenXr] I", _DSopenXrDevice },
1483 { "_GetOpenXrVisibility", 1, "fun [ObjOpenXr] I", _GetOpenXrVisibility },
1484 { "_GetOpenXrOrientation", 1, "fun [ObjOpenXr] [F F F F]", _GetOpenXrOrientation },
1485 { "_GetOpenXrPosition", 1, "fun [ObjOpenXr] [F F F]", _GetOpenXrPosition },
1486 { "_GetOpenXrFovY", 1, "fun [ObjOpenXr] F", _GetOpenXrFovY },
1487 { "_GetOpenXrIPD", 1, "fun [ObjOpenXr] F", _GetOpenXrIPD },
1488 { "_GetOpenXrProjectionMatrix", 3, "fun [ObjOpenXr F F] [[[F F F F] [F F F F] [F F F F] [F F F F]] [[F F F F] [F F F F] [F F F F] [F F F F]]]", _GetOpenXrProjectionMatrix },
1489 { "_GetOpenXrTextureSize", 1, "fun [ObjOpenXr] [I I]", _GetOpenXrTextureSize },
1490 { "_UpdateOpenXr", 1, "fun [ObjOpenXr] I", _UpdateOpenXr },
1491 { "_UpdateOpenXrTextures", 3, "fun [ObjOpenXr ObjPtr ObjPtr] I", _UpdateOpenXrTextures },
1492 { "_GetOpenXrDeviceName", 1, "fun [ObjOpenXr] S", _GetOpenXrDeviceName },
1493 { "_GetOpenXrControllerVisibility", 2, "fun [ObjOpenXr I] I", _GetOpenXrControllerVisibility },
1494 { "_GetOpenXrControllerPosition", 2, "fun [ObjOpenXr I] [F F F]", _GetOpenXrControllerPosition },
1495 { "_GetOpenXrControllerOrientation", 2, "fun [ObjOpenXr I] [F F F F]", _GetOpenXrControllerOrientation },
1496 { "_GetOpenXrControllerVelocity", 2, "fun [ObjOpenXr I] [F F F]", _GetOpenXrControllerVelocity },
1497 { "_GetOpenXrControllerAngularVelocity", 2, "fun [ObjOpenXr I] [F F F]", _GetOpenXrControllerAngularVelocity },
1498 { "_GetOpenXrControllerButtons", 2, "fun [ObjOpenXr I] [I r1]", _GetOpenXrControllerButtons },
1499 { "_GetOpenXrControllerTouches", 2, "fun [ObjOpenXr I] [I r1]", _GetOpenXrControllerTouches },
1500 { "_GetOpenXrControllerAxis", 2, "fun [ObjOpenXr I] [F F F F]", _GetOpenXrControllerAxis },
1501 { "_GetOpenXrControllerType", 2, "fun [ObjOpenXr I] I", _GetOpenXrControllerType },
1502 { "_GetOpenXrControllerBonesRotation", 2, "fun [ObjOpenXr I] [[F F F F] r1]", _GetOpenXrControllerBonesRotation },
1503 { "_SetOpenXrControllerRumble", 3, "fun [ObjOpenXr I F] I", _SetOpenXrControllerRumble },
1504 { "_SetOpenXrPassthroughEnable", 2, "fun [ObjOpenXr I] I", _SetOpenXrPassthroughEnable },
1505 { "_GetOpenXrPassthroughSupported", 1, "fun [ObjOpenXr] I", _GetOpenXrPassthroughSupported },
1506 { "_SetOpenXrExtensions", 1, "fun [I] I", _SetOpenXrExtensions },
1507 { "_GetOpenXrExtensions", 0, "fun [] I", _GetOpenXrExtensions },
1508 { "_SetOpenXrAppName", 1, "fun [S] I", _SetOpenXrAppName }
1509};
1510
1511// Everything inside _cond and _endcond is ignored by doxygen
1513
1517#ifndef SCOL_STATIC
1518extern "C" SCOL_EXPORT void ScolPauseWindowPlugin(mmachine m)
1519#else
1520extern "C" SCOL_EXPORT void ScolOpenXrPauseWindowPlugin(mmachine m)
1521#endif
1522{
1523 MMechostr(MSKDEBUG, ">> _ScolPauseWindowPlugin : call Pause OpenXR\n");
1524 sOpenXr::GetInstance()->SetState(false);
1525}
1526
1530#ifndef SCOL_STATIC
1531extern "C" SCOL_EXPORT void ScolResumeWindowPlugin(mmachine m)
1532#else
1533extern "C" SCOL_EXPORT void ScolOpenXrResumeWindowPlugin(mmachine m)
1534#endif
1535{
1536 MMechostr(MSKDEBUG, ">> ScolResumeWindowPlugin : call Resume OpenXR\n");
1537 sOpenXr::GetInstance()->SetState(true);
1538}
1539
1544int LoadOpenXr(mmachine m)
1545{
1546 int k = 0;
1547
1548 MMechostr(MSKDEBUG, "\n");
1549 MMechostr(MSKDEBUG, " > Loading OpenXr Support\n");
1550
1551 // Declare a new type of object ("ObjOpenXr")
1552 OBJ_OPENXR_SCOL = OBJregister(0 /*nb of callback*/, 0, destroyOpenXrObj, "OBJ_OPENXR_SCOL");
1553 k = PKhardpak2(m, "mOpenXr.pkg", sizeof(mOpenXrEngine) / sizeof(mOpenXrEngine[0]), mOpenXrEngine);
1554
1555 sOpenXr::GetInstance();
1556
1557 MMechostr(MSKDEBUG, " > Successfully Loaded\n\n");
1558 return k;
1559}
1560
1561int CloseOpenXr()
1562{
1563 MMechostr(MSKDEBUG, "\n");
1564 MMechostr(MSKDEBUG, " > Unloading OpenXr Support\n");
1565
1566 sOpenXr::GetInstance()->Kill();
1567
1568 MMechostr(MSKDEBUG, " > Successfully unloaded\n\n");
1569 return 0;
1570}
1571
1573
1574#ifndef SCOL_STATIC
1579extern "C" SCOL_EXPORT int ScolLoadPlugin(mmachine m, cbmachine w)
1580{
1581 SCOLinitplugin(w);
1582
1583 return LoadOpenXr(m);
1584}
1585
1590extern "C" SCOL_EXPORT int ScolUnloadPlugin()
1591{
1592 return CloseOpenXr();
1593}
1594
1595#else
1600extern "C" SCOL_EXPORT int ScolOpenXrLoadPlugin(mmachine m, cbmachine w)
1601{
1602 SCOLinitplugin(w);
1603
1604 return LoadOpenXr(m);
1605}
1606
1611extern "C" SCOL_EXPORT int ScolOpenXrUnloadPlugin()
1612{
1613 return CloseOpenXr();
1614}
1615#endif //SCOL_STATIC
int _UpdateOpenXr(mmachine m)
_UpdateOpenXr : start OpenXr update you should call this on each render frame
int _GetOpenXrPassthroughSupported(mmachine m)
_GetOpenXrPassthroughSupported : Get the OpenXr passthrough support
int _GetOpenXrControllerButtons(mmachine m)
_GetOpenXrControllerButtons : Get the OpenXr controller buttons state button order in list is A,...
int _GetOpenXrPosition(mmachine m)
_GetOpenXrPosition : Get the OpenXr position from the IR camera
int _GetOpenXrControllerVelocity(mmachine m)
_GetOpenXrControllerVelocity : Get the OpenXr controller velocity
int _SetOpenXrPassthroughEnable(mmachine m)
_SetOpenXrPassthroughEnable : Set the OpenXr passthrough enable state
int _DSopenXrDevice(mmachine m)
_DSopenXrDevice : Destroy OpenXr object
int _GetOpenXrControllerPosition(mmachine m)
_GetOpenXrControllerPosition : Get the OpenXr controller position
int _GetOpenXrControllerType(mmachine m)
_GetOpenXrControllerType : Get the OpenXr controller type, controller or hand
int _GetOpenXrExtensions(mmachine m)
_GetOpenXrExtensions : Get the OpenXr extensions that are set to enable
int _GetOpenXrProjectionMatrix(mmachine m)
_GetOpenXrProjectionMatrix : Get the OpenXr camera projection matrix
int _GetOpenXrDeviceName(mmachine m)
_GetOpenXrDeviceName : Get the openXr device type
int _GetOpenXrVisibility(mmachine m)
_GetOpenXrVisibility : Get the OpenXr HMD visibility state
int _CRopenXrDevice(mmachine m)
_CRopenXrDevice : This function create a OpenXr object
int _GetOpenXrControllerAxis(mmachine m)
_GetOpenXrControllerAxis : Get the OpenXr controller axis values Axis order is touch pad X,...
int _GetOpenXrFovY(mmachine m)
_GetOpenXrFovY : Get the OpenXr fovY
int _GetOpenXrOrientation(mmachine m)
_GetOpenXrOrientation : Get the OpenXr sensor orientation
int _GetOpenXrControllerVisibility(mmachine m)
_GetOpenXrControllerVisibility : Get the OpenXr controller visibility state
int _GetOpenXrControllerTouches(mmachine m)
_GetOpenXrControllerTouches : Get the OpenXr controller touch state button order in list is A,...
int _GetOpenXrControllerOrientation(mmachine m)
_GetOpenXrControllerOrientation : Get the OpenXr controller orientation
int _SetOpenXrExtensions(mmachine m)
_SetOpenXrExtensions : Set the OpenXr extensions to enable if this is supported
int _GetOpenXrTextureSize(mmachine m)
_GetOpenXrTextureSize : Get the OpenXr texture size for RTT
int _GetOpenXrIPD(mmachine m)
_GetOpenXrIPD : Get the OpenXr eye spacing
int _UpdateOpenXrTextures(mmachine m)
_UpdateOpenXrTextures : Update the HMD textures pointer
int _GetOpenXrControllerBonesRotation(mmachine m)
_GetOpenXrControllerBonesRotation : Get the OpenXr controller bones rotation
int _SetOpenXrControllerRumble(mmachine m)
_SetOpenXrControllerRumble : Set the OpenXr controller rumble value
int _GetOpenXrControllerAngularVelocity(mmachine m)
_GetOpenXrControllerAngularVelocity : Get the OpenXr controller velocity
int _SetOpenXrAppName(mmachine m)
_SetOpenXrAppName : Set the OpenXr application name