Project

General

Profile

OPENVR Scol plugin
scolplugin.cpp
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OpenSpace3D
4 For the latest info, see http://www.openspace3d.com
5 
6 Copyright (c) 2012 I-maginer
7 
8 This program is free software; you can redistribute it and/or modify it under
9 the terms of the GNU Lesser General Public License as published by the Free Software
10 Foundation; either version 2 of the License, or (at your option) any later
11 version.
12 
13 This program is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16 
17 You should have received a copy of the GNU Lesser General Public License along with
18 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20 http://www.gnu.org/copyleft/lesser.txt
21 
22 -----------------------------------------------------------------------------
23 */
24 
25 /*
26  Openvr interface for Scol
27  First version : July 2013
28  Author : Bastien BOURINEAU - I-Maginer
29  */
30 
31 #include "sOpenvr.h"
32 #include <scolPlugin.h>
33 #include <scolMemoryHelper.hpp>
34 
36 #ifdef SCOL_STATIC
37 extern cbmachine ww;
38 extern mmachine mm;
39 #else
40 cbmachine ww;
41 mmachine mm;
42 #endif
43 
44 int OBJ_Openvr_SCOL;
45 
46 int Openvr_QUIT_CB;
47 int SCOL_Openvr_QUIT_CB = 0;
48 
49 int Openvr_IPD_CB;
50 int SCOL_Openvr_IPD_CB = 1;
51 
73 int destroyOpenvrObj(mmachine m, SCOL_PTR_TYPE handsys, int handscol)
74 {
75  // Read the first element of a TAB element (table of object)
76  sOpenvr* openvrObj = MMgetPointer<sOpenvr*>(m, MTOP(handscol));
77  SAFE_DELETE(openvrObj);
78 
79  MMsetPointer<sOpenvr*>(m, MTOP(handscol), 0);
80 
81  // Display debug message
82  MMechostr(MSKDEBUG, "ObjOpenvr destroyed.\n");
83  return 0;
84 }
85 
86 
99 int _CRopenvrDevice(mmachine m)
100 {
101 #ifdef _SCOL_DEBUG_
102  MMechostr(0,"_CRopenvrDevice\n");
103 #endif
104  // Declare local variables
105  int k = 0;
106 
107  int pUserIpd = MMpull(m);
108  int pCbkIpd = MMpull(m);
109  int pUserQuit = MMpull(m);
110  int pCbkQuit = MMpull(m);
111 
112  // Get the channel without pulling it (first element in the stack)
113  int channel = MMget(m, 0);
114 
115  // Test the channel
116  if (channel == NIL)
117  {
118  MMechostr(MSKDEBUG, "_CRopenvrDevice : Channel NIL\n");
119  MMset(m, 0, NIL);
120  return 0;
121  }
122 
123  if (!vr::VR_IsRuntimeInstalled())
124  {
125  MMechostr(MSKRUNTIME, "_CRopenvrDevice : Steam VR not found, please install Steam VR first.\n");
126  MMset(m, 0, NIL);
127  return 0;
128  }
129 
130  if (!vr::VR_IsHmdPresent())
131  {
132  MMechostr(MSKRUNTIME, "_CRopenvrDevice : No VR headset found on the system!\n");
133  MMset(m, 0, NIL);
134  return 0;
135  }
136 
137  std::string inputPath = "scol_VR_input.json";
138  packdir mypack = (packdir)SCgetExtra("FirstPack");
139  std::string pathStd;
140  std::vector<std::string> partitions;
141 
142  while (mypack)
143  {
144  pathStd = mypack->path;
145  for (unsigned int i = 0; i < pathStd.length(); i++)
146  {
147  if (pathStd.substr(i, 1) == "\\")
148  pathStd.replace(i, 1, "/");
149  }
150  partitions.push_back(pathStd);
151  mypack = mypack->next;
152  }
153 
154  sOpenvr* openvrObj = new sOpenvr((partitions[0] + inputPath).c_str());
155  if (openvrObj == NULL)
156  {
157  MMechostr(MSKDEBUG, "_CRopenvrDevice : openvrObj failed\n");
158  MMset(m, 0, NIL);
159  return 0;
160  }
161 
162  if (!openvrObj->Connect())
163  {
164  MMechostr(MSKDEBUG, "_CRopenvrDevice : device not found\n");
165  SAFE_DELETE(openvrObj);
166  MMset(m, 0, NIL);
167  return 0;
168  }
169 
170  // Allocate a space in the stack for a table of joypad object
171  if ((MMpushPointer(m, openvrObj) != 0))
172  {
173  SAFE_DELETE(openvrObj);
174  MMset(m, 0, NIL);
175  return MERRMEM;
176  }
177 
178  // Create a new scol joypad object
179  k = OBJcreate(m, OBJ_Openvr_SCOL, SCOL_PTR openvrObj, NIL, NULL);
180 
181  if ((k = MMpush(m, pCbkQuit))) return k; /* reading callback */
182  if ((k = MMpush(m, pUserQuit))) return k; /* user param */
183  if ((k = OBJaddreflex(m, OBJ_Openvr_SCOL, SCOL_Openvr_QUIT_CB))) return k;
184 
185  if ((k = MMpush(m, pCbkIpd))) return k; /* reading callback */
186  if ((k = MMpush(m, pUserIpd))) return k; /* user param */
187  if ((k = OBJaddreflex(m, OBJ_Openvr_SCOL, SCOL_Openvr_IPD_CB))) return k;
188 
189 #ifdef _SCOL_DEBUG_
190  MMechostr(0,"ok\n");
191 #endif
192 
193  return k;
194 }
195 
203 int _DSopenvrDevice(mmachine m)
204 {
205 #ifdef _SCOL_DEBUG_
206  MMechostr(MSKDEBUG,"_DSopenvrDevice\n");
207 #endif
208 
209  int openvrTab = MMget(m, 0);
210  if (openvrTab == NIL)
211  {
212  MMset(m, 0, NIL);
213  return 0;
214  }
215 
216  OBJdelTM(m, OBJ_Openvr_SCOL, openvrTab);
217  MMset(m, 0, ITOM(0));
218 
219 #ifdef _SCOL_DEBUG_
220  MMechostr(MSKDEBUG,"ok\n");
221 #endif
222  return 0;
223 }
224 
232 int _GetOpenvrVisibility(mmachine m)
233 {
234 #ifdef _SCOL_DEBUG_
235  MMechostr(MSKDEBUG, "_GetOpenvrVisibility\n");
236 #endif
237 
238  int openvrTab = MMget(m, 0);
239  if (openvrTab == NIL)
240  {
241  MMset(m, 0, NIL);
242  return 0;
243  }
244 
245  sOpenvr* openvrObj = MMgetPointer<sOpenvr*>(m, MTOP(openvrTab));
246  if (!openvrObj)
247  {
248  MMset(m, 0, NIL);
249  return 0;
250  }
251 
252  int visible = openvrObj->IsVisible() ? 1 : 0;
253  MMset(m, 0, ITOM(visible));
254 
255 #ifdef _SCOL_DEBUG_
256  MMechostr(MSKDEBUG, "ok\n");
257 #endif
258  return 0;
259 }
260 
268 int _GetOpenvrOrientation(mmachine m)
269 {
270 #ifdef _SCOL_DEBUG_
271  MMechostr(MSKDEBUG,"_GetOpenvrOrientation\n");
272 #endif
273 
274  int openvrTab = MMget(m, 0);
275  if (openvrTab == NIL)
276  {
277  MMset(m, 0, NIL);
278  return 0;
279  }
280 
281  sOpenvr* openvrObj = MMgetPointer<sOpenvr*>(m, MTOP(openvrTab));
282  if (!openvrObj || !openvrObj->IsConnected())
283  {
284  MMset(m, 0, NIL);
285  return 0;
286  }
287 
288  Quaternion quat;
289  if (openvrObj->GetHmdOrientation(quat))
290  {
291  int tuple = MMmalloc(m, 4, TYPETAB);
292  if (tuple == NIL)
293  {
294  MMset(m, 0, NIL);
295  return MERRMEM;
296  }
297  MMstore(m, tuple, 0, FTOM(quat.x));
298  MMstore(m, tuple, 1, FTOM(quat.y));
299  MMstore(m, tuple, 2, FTOM(quat.z));
300  MMstore(m, tuple, 3, FTOM(quat.w));
301  MMset(m, 0, PTOM(tuple));
302  }
303  else
304  {
305  MMset(m, 0, NIL);
306  }
307 
308 #ifdef _SCOL_DEBUG_
309  MMechostr(MSKDEBUG,"ok\n");
310 #endif
311  return 0;
312 }
313 
321 int _GetOpenvrPosition(mmachine m)
322 {
323 #ifdef _SCOL_DEBUG_
324  MMechostr(MSKDEBUG,"_GetOpenvrPosition\n");
325 #endif
326 
327  int openvrTab = MMget(m, 0);
328  if (openvrTab == NIL)
329  {
330  MMset(m, 0, NIL);
331  return 0;
332  }
333 
334  sOpenvr* openvrObj = MMgetPointer<sOpenvr*>(m, MTOP(openvrTab));
335  if (!openvrObj || !openvrObj->IsConnected())
336  {
337  MMset(m, 0, NIL);
338  return 0;
339  }
340 
341  Vector3 pos;
342  if (openvrObj->GetHmdPosition(pos))
343  {
344  int tuple = MMmalloc(m, 3, TYPETAB);
345  if (tuple == NIL)
346  {
347  MMset(m, 0, NIL);
348  return MERRMEM;
349  }
350  MMstore(m, tuple, 0, FTOM(pos.x));
351  MMstore(m, tuple, 1, FTOM(pos.y));
352  MMstore(m, tuple, 2, FTOM(pos.z));
353  MMset(m, 0, PTOM(tuple));
354  }
355  else
356  {
357  MMset(m, 0, NIL);
358  }
359 
360 #ifdef _SCOL_DEBUG_
361  MMechostr(MSKDEBUG,"ok\n");
362 #endif
363  return 0;
364 }
365 
373 int _GetOpenvrAspectRatio(mmachine m)
374 {
375 #ifdef _SCOL_DEBUG_
376  MMechostr(MSKDEBUG,"_GetOpenvrAspectRatio\n");
377 #endif
378 
379  int openvrTab = MMget(m, 0);
380  if (openvrTab == NIL)
381  {
382  MMset(m, 0, NIL);
383  return 0;
384  }
385 
386  sOpenvr* openvrObj = MMgetPointer<sOpenvr*>(m, MTOP(openvrTab));
387  if (!openvrObj || !openvrObj->IsConnected())
388  {
389  MMset(m, 0, NIL);
390  return 0;
391  }
392 
393  MMset(m, 0, FTOM(openvrObj->GetStereoConfigAspect()));
394 
395 #ifdef _SCOL_DEBUG_
396  MMechostr(MSKDEBUG,"ok\n");
397 #endif
398  return 0;
399 }
400 
408 int _GetOpenvrIPD(mmachine m)
409 {
410 #ifdef _SCOL_DEBUG_
411  MMechostr(MSKDEBUG,"_GetOpenvrIPD\n");
412 #endif
413 
414  int openvrTab = MMget(m, 0);
415  if (openvrTab == NIL)
416  {
417  MMset(m, 0, NIL);
418  return 0;
419  }
420 
421  sOpenvr* openvrObj = MMgetPointer<sOpenvr*>(m, MTOP(openvrTab));
422  if (!openvrObj)
423  {
424  MMset(m, 0, NIL);
425  return 0;
426  }
427 
428  MMset(m, 0, FTOM(openvrObj->GetStereoIPD()));
429 
430 #ifdef _SCOL_DEBUG_
431  MMechostr(MSKDEBUG,"ok\n");
432 #endif
433  return 0;
434 }
435 
443 int _GetOpenvrFovY(mmachine m)
444 {
445 #ifdef _SCOL_DEBUG_
446  MMechostr(MSKDEBUG,"_GetOpenvrFovY\n");
447 #endif
448 
449  int openvrTab = MMget(m, 0);
450  if (openvrTab == NIL)
451  {
452  MMset(m, 0, NIL);
453  return 0;
454  }
455 
456  sOpenvr* openvrObj = MMgetPointer<sOpenvr*>(m, MTOP(openvrTab));
457  if (!openvrObj)
458  {
459  MMset(m, 0, NIL);
460  return 0;
461  }
462 
463  MMset(m, 0, FTOM(openvrObj->GetStereoConfigFovY()));
464 
465 #ifdef _SCOL_DEBUG_
466  MMechostr(MSKDEBUG,"ok\n");
467 #endif
468  return 0;
469 }
470 
478 int _ResetOpenvrDevice(mmachine m)
479 {
480 #ifdef _SCOL_DEBUG_
481  MMechostr(MSKDEBUG,"_ResetOpenvrDevice\n");
482 #endif
483 
484  int openvrTab = MMget(m, 0);
485  if (openvrTab == NIL)
486  {
487  MMset(m, 0, NIL);
488  return 0;
489  }
490 
491  sOpenvr* openvrObj = MMgetPointer<sOpenvr*>(m, MTOP(openvrTab));
492  if (!openvrObj)
493  {
494  MMset(m, 0, NIL);
495  return 0;
496  }
497 
498  openvrObj->ResetHmd();
499 
500  MMset(m, 0, ITOM(0));
501 
502 #ifdef _SCOL_DEBUG_
503  MMechostr(MSKDEBUG,"ok\n");
504 #endif
505  return 0;
506 }
507 
515 int _UpdateOpenvr(mmachine m)
516 {
517 #ifdef _SCOL_DEBUG_
518  MMechostr(MSKDEBUG,"_UpdateOpenvr\n");
519 #endif
520 
521  int openvrTab = MMget(m, 0);
522  if (openvrTab == NIL)
523  {
524  MMset(m, 0, NIL);
525  return 0;
526  }
527 
528  sOpenvr* openvrObj = MMgetPointer<sOpenvr*>(m, MTOP(openvrTab));
529  if (!openvrObj || !openvrObj->IsConnected())
530  {
531  MMset(m, 0, NIL);
532  return 0;
533  }
534  bool ret = openvrObj->Update();
535 
536  MMset(m, 0, ITOM((ret) ? 1 : 0));
537  return 0;
538 }
539 
550 int _UpdateOpenvrTextures(mmachine m)
551 {
552 #ifdef _SCOL_DEBUG_
553  MMechostr(MSKDEBUG, "_UpdateOpenvrTextures\n");
554 #endif
555 
556  int iType = MMpull(m);
557  int iRightTex = MMpull(m);
558  int iLeftTex = MMpull(m);
559 
560  int openvrTab = MMget(m, 0);
561  if (openvrTab == NIL || iRightTex == NIL || iLeftTex == NIL)
562  {
563  MMset(m, 0, NIL);
564  return 0;
565  }
566 
567  vr::ETextureType texType = vr::TextureType_OpenGL;
568  if (MTOI(iType) == 1)
569  texType = vr::TextureType_DirectX;
570 
571  sOpenvr* openvrObj = MMgetPointer<sOpenvr*>(m, MTOP(openvrTab));
572  if (!openvrObj || !openvrObj->IsConnected())
573  {
574  MMset(m, 0, NIL);
575  return 0;
576  }
577  void* lptr = MMgetPointer<void*>(m, MMfetch(m, MTOP(iLeftTex), 0));
578  void* rptr = MMgetPointer<void*>(m, MMfetch(m, MTOP(iRightTex), 0));
579 
580  if (!lptr || !rptr)
581  {
582  MMset(m, 0, NIL);
583  return 0;
584  }
585  openvrObj->UpdateTextures(lptr, rptr, texType);
586 
587  MMset(m, 0, ITOM(1));
588  return 0;
589 }
590 
598 int _GetOpenvrDeviceName(mmachine m)
599 {
600 #ifdef _SCOL_DEBUG_
601  MMechostr(MSKDEBUG,"_GetOpenvrDeviceName\n");
602 #endif
603 
604  int openvrTab = MMget(m, 0);
605  if (openvrTab == NIL)
606  {
607  MMset(m, 0, NIL);
608  return 0;
609  }
610 
611  sOpenvr* openvrObj = MMgetPointer<sOpenvr*>(m, MTOP(openvrTab));
612  if (!openvrObj || !openvrObj->IsConnected())
613  {
614  MMset(m, 0, NIL);
615  return 0;
616  }
617 
618  MMpull(m);
619  Mpushstrbloc(m, openvrObj->GetHmdName().c_str());
620  return 0;
621 }
622 
633 {
634 #ifdef _SCOL_DEBUG_
635  MMechostr(MSKDEBUG,"_GetOpenvrProjectionMatrix\n");
636 #endif
637 
638  int ifclip = MMpull(m);
639  int inclip = MMpull(m);
640  int openvrTab = MMget(m, 0);
641  if (openvrTab == NIL)
642  {
643  MMset(m, 0, NIL);
644  return 0;
645  }
646 
647  sOpenvr* openvrObj = MMgetPointer<sOpenvr*>(m, MTOP(openvrTab));
648  if (!openvrObj || !openvrObj->IsConnected())
649  {
650  MMset(m, 0, NIL);
651  return 0;
652  }
653 
654  float nearclip = 0.01f;
655  if (inclip != NIL)
656  nearclip = MTOF(inclip);
657 
658  float farclip = 10000.0f;
659  if (ifclip != NIL)
660  farclip = MTOF(ifclip);
661 
662  Matrix4 lmat;
663  Matrix4 rmat;
664 
665  openvrObj->GetProjectionMatrix(vr::Eye_Left, nearclip, farclip, lmat);
666  openvrObj->GetProjectionMatrix(vr::Eye_Right, nearclip, farclip, rmat);
667 
668  int tuple = MMmalloc(m, 2, TYPETAB);
669  int ltmat = MMmalloc(m, 4, TYPETAB);
670  int ltmat1 = MMmalloc(m, 4, TYPETAB);
671  int ltmat2 = MMmalloc(m, 4, TYPETAB);
672  int ltmat3 = MMmalloc(m, 4, TYPETAB);
673  int ltmat4 = MMmalloc(m, 4, TYPETAB);
674 
675  int rtmat = MMmalloc(m, 4, TYPETAB);
676  int rtmat1 = MMmalloc(m, 4, TYPETAB);
677  int rtmat2 = MMmalloc(m, 4, TYPETAB);
678  int rtmat3 = MMmalloc(m, 4, TYPETAB);
679  int rtmat4 = MMmalloc(m, 4, TYPETAB);
680 
681  if ((tuple == NIL) || (ltmat == NIL) || (ltmat1 == NIL) || (ltmat2 == NIL) || (ltmat3 == NIL) || (ltmat4 == NIL) || (rtmat == NIL) || (rtmat1 == NIL) || (rtmat2 == NIL) || (rtmat3 == NIL) || (rtmat4 == NIL))
682  {
683  MMset(m, 0, NIL);
684  return MERRMEM;
685  }
686 
687  MMstore(m, ltmat1, 0, FTOM(lmat[0][0]));
688  MMstore(m, ltmat1, 1, FTOM(lmat[0][1]));
689  MMstore(m, ltmat1, 2, FTOM(lmat[0][2]));
690  MMstore(m, ltmat1, 3, FTOM(lmat[0][3]));
691 
692  MMstore(m, ltmat2, 0, FTOM(lmat[1][0]));
693  MMstore(m, ltmat2, 1, FTOM(lmat[1][1]));
694  MMstore(m, ltmat2, 2, FTOM(lmat[1][2]));
695  MMstore(m, ltmat2, 3, FTOM(lmat[1][3]));
696 
697  MMstore(m, ltmat3, 0, FTOM(lmat[2][0]));
698  MMstore(m, ltmat3, 1, FTOM(lmat[2][1]));
699  MMstore(m, ltmat3, 2, FTOM(lmat[2][2]));
700  MMstore(m, ltmat3, 3, FTOM(lmat[2][3]));
701 
702  MMstore(m, ltmat4, 0, FTOM(lmat[3][0]));
703  MMstore(m, ltmat4, 1, FTOM(lmat[3][1]));
704  MMstore(m, ltmat4, 2, FTOM(lmat[3][2]));
705  MMstore(m, ltmat4, 3, FTOM(lmat[3][3]));
706 
707  MMstore(m, ltmat, 0, PTOM(ltmat1));
708  MMstore(m, ltmat, 1, PTOM(ltmat2));
709  MMstore(m, ltmat, 2, PTOM(ltmat3));
710  MMstore(m, ltmat, 3, PTOM(ltmat4));
711 
712  MMstore(m, rtmat1, 0, FTOM(rmat[0][0]));
713  MMstore(m, rtmat1, 1, FTOM(rmat[0][1]));
714  MMstore(m, rtmat1, 2, FTOM(rmat[0][2]));
715  MMstore(m, rtmat1, 3, FTOM(rmat[0][3]));
716 
717  MMstore(m, rtmat2, 0, FTOM(rmat[1][0]));
718  MMstore(m, rtmat2, 1, FTOM(rmat[1][1]));
719  MMstore(m, rtmat2, 2, FTOM(rmat[1][2]));
720  MMstore(m, rtmat2, 3, FTOM(rmat[1][3]));
721 
722  MMstore(m, rtmat3, 0, FTOM(rmat[2][0]));
723  MMstore(m, rtmat3, 1, FTOM(rmat[2][1]));
724  MMstore(m, rtmat3, 2, FTOM(rmat[2][2]));
725  MMstore(m, rtmat3, 3, FTOM(rmat[2][3]));
726 
727  MMstore(m, rtmat4, 0, FTOM(rmat[3][0]));
728  MMstore(m, rtmat4, 1, FTOM(rmat[3][1]));
729  MMstore(m, rtmat4, 2, FTOM(rmat[3][2]));
730  MMstore(m, rtmat4, 3, FTOM(rmat[3][3]));
731 
732  MMstore(m, rtmat, 0, PTOM(rtmat1));
733  MMstore(m, rtmat, 1, PTOM(rtmat2));
734  MMstore(m, rtmat, 2, PTOM(rtmat3));
735  MMstore(m, rtmat, 3, PTOM(rtmat4));
736 
737  MMstore(m, tuple, 0, PTOM(ltmat));
738  MMstore(m, tuple, 1, PTOM(rtmat));
739  MMset(m, 0, PTOM(tuple));
740 
741 #ifdef _SCOL_DEBUG_
742  MMechostr(MSKDEBUG,"ok\n");
743 #endif
744  return 0;
745 }
746 
754 int _GetOpenvrTextureSize(mmachine m)
755 {
756 #ifdef _SCOL_DEBUG_
757  MMechostr(MSKDEBUG,"_GetOpenvrTextureSize\n");
758 #endif
759 
760  int openvrTab = MMget(m, 0);
761  if (openvrTab == NIL)
762  {
763  MMset(m, 0, NIL);
764  return 0;
765  }
766 
767  sOpenvr* openvrObj = MMgetPointer<sOpenvr*>(m, MTOP(openvrTab));
768  if (!openvrObj || !openvrObj->IsConnected())
769  {
770  MMset(m, 0, NIL);
771  return 0;
772  }
773 
774  unsigned int w = 0;
775  unsigned int h = 0;
776  openvrObj->GetStereoTextureSize(w, h);
777 
778  int tuple = MMmalloc(m, 2, TYPETAB);
779  if (tuple == NIL)
780  {
781  MMset(m, 0, NIL);
782  return MERRMEM;
783  }
784 
785  MMstore(m, tuple, 0, ITOM(w));
786  MMstore(m, tuple, 1, ITOM(h));
787  MMset(m, 0, PTOM(tuple));
788 
789 #ifdef _SCOL_DEBUG_
790  MMechostr(MSKDEBUG,"ok\n");
791 #endif
792  return 0;
793 }
794 
804 {
805 #ifdef _SCOL_DEBUG_
806  MMechostr(MSKDEBUG, "_GetOpenvrControllerVisibility\n");
807 #endif
808 
809  int iSide = MMpull(m);
810  int openvrTab = MMget(m, 0);
811  if (openvrTab == NIL)
812  {
813  MMset(m, 0, NIL);
814  return 0;
815  }
816 
817  sOpenvr* openvrObj = MMgetPointer<sOpenvr*>(m, MTOP(openvrTab));
818  if (!openvrObj || !openvrObj->IsConnected())
819  {
820  MMset(m, 0, NIL);
821  return 0;
822  }
823 
824  unsigned int id = 0;
825  if (iSide != NIL && MTOI(iSide) > 0)
826  id = MTOI(iSide);
827 
828  sOpenvrController* controller = openvrObj->GetController(id);
829  if (!controller)
830  {
831  MMset(m, 0, NIL);
832  return 0;
833  }
834 
835  int visible = (controller->IsVisible()) ? 1 : 0;
836  MMset(m, 0, ITOM(visible));
837 
838 #ifdef _SCOL_DEBUG_
839  MMechostr(MSKDEBUG, "ok\n");
840 #endif
841  return 0;
842 }
843 
853 {
854 #ifdef _SCOL_DEBUG_
855  MMechostr(MSKDEBUG, "_GetOpenvrControllerPosition\n");
856 #endif
857 
858  int iSide = MMpull(m);
859  int openvrTab = MMget(m, 0);
860  if (openvrTab == NIL)
861  {
862  MMset(m, 0, NIL);
863  return 0;
864  }
865 
866  sOpenvr* openvrObj = MMgetPointer<sOpenvr*>(m, MTOP(openvrTab));
867  if (!openvrObj || !openvrObj->IsConnected())
868  {
869  MMset(m, 0, NIL);
870  return 0;
871  }
872 
873  unsigned int id = 0;
874  if (iSide != NIL && MTOI(iSide) > 0)
875  id = MTOI(iSide);
876 
877  sOpenvrController* controller = openvrObj->GetController(id);
878  if (!controller)
879  {
880  MMset(m, 0, NIL);
881  return 0;
882  }
883 
884  Vector3 pos = controller->GetPosition();
885  int tuple = MMmalloc(m, 3, TYPETAB);
886  if (tuple == NIL)
887  {
888  MMset(m, 0, NIL);
889  return MERRMEM;
890  }
891  MMstore(m, tuple, 0, FTOM(pos.x));
892  MMstore(m, tuple, 1, FTOM(pos.y));
893  MMstore(m, tuple, 2, FTOM(pos.z));
894  MMset(m, 0, PTOM(tuple));
895 
896 #ifdef _SCOL_DEBUG_
897  MMechostr(MSKDEBUG, "ok\n");
898 #endif
899  return 0;
900 }
901 
911 {
912 #ifdef _SCOL_DEBUG_
913  MMechostr(MSKDEBUG, "_GetOpenvrControllerOrientation\n");
914 #endif
915 
916  int iSide = MMpull(m);
917  int openvrTab = MMget(m, 0);
918  if (openvrTab == NIL)
919  {
920  MMset(m, 0, NIL);
921  return 0;
922  }
923 
924  sOpenvr* openvrObj = MMgetPointer<sOpenvr*>(m, MTOP(openvrTab));
925  if (!openvrObj || !openvrObj->IsConnected())
926  {
927  MMset(m, 0, NIL);
928  return 0;
929  }
930 
931  unsigned int id = 0;
932  if (iSide != NIL && MTOI(iSide) > 0)
933  id = MTOI(iSide);
934 
935  sOpenvrController* controller = openvrObj->GetController(id);
936  if (!controller)
937  {
938  MMset(m, 0, NIL);
939  return 0;
940  }
941 
942  Quaternion quat = controller->GetOrientation();
943  int tuple = MMmalloc(m, 4, TYPETAB);
944  if (tuple == NIL)
945  {
946  MMset(m, 0, NIL);
947  return MERRMEM;
948  }
949  MMstore(m, tuple, 0, FTOM(quat.x));
950  MMstore(m, tuple, 1, FTOM(quat.y));
951  MMstore(m, tuple, 2, FTOM(quat.z));
952  MMstore(m, tuple, 3, FTOM(quat.w));
953  MMset(m, 0, PTOM(tuple));
954 
955 #ifdef _SCOL_DEBUG_
956  MMechostr(MSKDEBUG, "ok\n");
957 #endif
958  return 0;
959 }
960 
970 {
971 #ifdef _SCOL_DEBUG_
972  MMechostr(MSKDEBUG, "_GetOpenvrControllerVelocity\n");
973 #endif
974 
975  int iSide = MMpull(m);
976  int openvrTab = MMget(m, 0);
977  if (openvrTab == NIL)
978  {
979  MMset(m, 0, NIL);
980  return 0;
981  }
982 
983  sOpenvr* openvrObj = MMgetPointer<sOpenvr*>(m, MTOP(openvrTab));
984  if (!openvrObj || !openvrObj->IsConnected())
985  {
986  MMset(m, 0, NIL);
987  return 0;
988  }
989 
990  unsigned int id = 0;
991  if (iSide != NIL && MTOI(iSide) > 0)
992  id = MTOI(iSide);
993 
994  sOpenvrController* controller = openvrObj->GetController(id);
995  if (!controller)
996  {
997  MMset(m, 0, NIL);
998  return 0;
999  }
1000 
1001  Vector3 vel = controller->GetVelocity();
1002  int tuple = MMmalloc(m, 3, TYPETAB);
1003  if (tuple == NIL)
1004  {
1005  MMset(m, 0, NIL);
1006  return MERRMEM;
1007  }
1008  MMstore(m, tuple, 0, FTOM(vel.x));
1009  MMstore(m, tuple, 1, FTOM(vel.y));
1010  MMstore(m, tuple, 2, FTOM(vel.z));
1011  MMset(m, 0, PTOM(tuple));
1012 
1013 #ifdef _SCOL_DEBUG_
1014  MMechostr(MSKDEBUG, "ok\n");
1015 #endif
1016  return 0;
1017 }
1018 
1028 {
1029 #ifdef _SCOL_DEBUG_
1030  MMechostr(MSKDEBUG, "_GetOpenvrControllerAngularVelocity\n");
1031 #endif
1032 
1033  int iSide = MMpull(m);
1034  int openvrTab = MMget(m, 0);
1035  if (openvrTab == NIL)
1036  {
1037  MMset(m, 0, NIL);
1038  return 0;
1039  }
1040 
1041  sOpenvr* openvrObj = MMgetPointer<sOpenvr*>(m, MTOP(openvrTab));
1042  if (!openvrObj || !openvrObj->IsConnected())
1043  {
1044  MMset(m, 0, NIL);
1045  return 0;
1046  }
1047 
1048  unsigned int id = 0;
1049  if (iSide != NIL && MTOI(iSide) > 0)
1050  id = MTOI(iSide);
1051 
1052  sOpenvrController* controller = openvrObj->GetController(id);
1053  if (!controller)
1054  {
1055  MMset(m, 0, NIL);
1056  return 0;
1057  }
1058 
1059  Vector3 avel = controller->GetVelocity();
1060  int tuple = MMmalloc(m, 3, TYPETAB);
1061  if (tuple == NIL)
1062  {
1063  MMset(m, 0, NIL);
1064  return MERRMEM;
1065  }
1066  MMstore(m, tuple, 0, FTOM(avel.x));
1067  MMstore(m, tuple, 1, FTOM(avel.y));
1068  MMstore(m, tuple, 2, FTOM(avel.z));
1069  MMset(m, 0, PTOM(tuple));
1070 
1071 #ifdef _SCOL_DEBUG_
1072  MMechostr(MSKDEBUG, "ok\n");
1073 #endif
1074  return 0;
1075 }
1076 
1087 {
1088 #ifdef _SCOL_DEBUG_
1089  MMechostr(MSKDEBUG, "_GetOpenvrControllerButtons\n");
1090 #endif
1091 
1092  int iSide = MMpull(m);
1093  int openvrTab = MMget(m, 0);
1094  if (openvrTab == NIL)
1095  {
1096  MMset(m, 0, NIL);
1097  return 0;
1098  }
1099 
1100  sOpenvr* openvrObj = MMgetPointer<sOpenvr*>(m, MTOP(openvrTab));
1101  if (!openvrObj || !openvrObj->IsConnected())
1102  {
1103  MMset(m, 0, NIL);
1104  return 0;
1105  }
1106 
1107  unsigned int id = 0;
1108  if (iSide != NIL && MTOI(iSide) > 0)
1109  id = MTOI(iSide);
1110 
1111  sOpenvrController* controller = openvrObj->GetController(id);
1112  if (!controller)
1113  {
1114  MMset(m, 0, NIL);
1115  return 0;
1116  }
1117 
1118  std::vector<bool> buttons = controller->GetButtonsState();
1119 
1120  //clean the stack
1121  MMpull(m);
1122 
1123  for (unsigned int i = 0; i < buttons.size(); i++)
1124  {
1125  MMpush(m, ITOM(buttons[i]));
1126  }
1127  MMpush(m, NIL);
1128 
1129  for (unsigned int i = 0; i < buttons.size(); i++)
1130  {
1131  MMpush(m, ITOM(2));
1132  MBdeftab(m);
1133  }
1134 
1135 #ifdef _SCOL_DEBUG_
1136  MMechostr(MSKDEBUG, "ok\n");
1137 #endif
1138  return 0;
1139 }
1140 
1151 {
1152 #ifdef _SCOL_DEBUG_
1153  MMechostr(MSKDEBUG, "_GetOpenvrControllerAxis\n");
1154 #endif
1155 
1156  int iSide = MMpull(m);
1157  int openvrTab = MMget(m, 0);
1158  if (openvrTab == NIL)
1159  {
1160  MMset(m, 0, NIL);
1161  return 0;
1162  }
1163 
1164  sOpenvr* openvrObj = MMgetPointer<sOpenvr*>(m, MTOP(openvrTab));
1165  if (!openvrObj || !openvrObj->IsConnected())
1166  {
1167  MMset(m, 0, NIL);
1168  return 0;
1169  }
1170 
1171  unsigned int id = 0;
1172  if (iSide != NIL && MTOI(iSide) > 0)
1173  id = MTOI(iSide);
1174 
1175  sOpenvrController* controller = openvrObj->GetController(id);
1176  if (!controller)
1177  {
1178  MMset(m, 0, NIL);
1179  return 0;
1180  }
1181 
1182  Vector3 pos = controller->GetAxisValues();
1183  int tuple = MMmalloc(m, 3, TYPETAB);
1184  if (tuple == NIL)
1185  {
1186  MMset(m, 0, NIL);
1187  return MERRMEM;
1188  }
1189  MMstore(m, tuple, 0, FTOM(pos.x));
1190  MMstore(m, tuple, 1, FTOM(pos.y));
1191  MMstore(m, tuple, 2, FTOM(pos.z));
1192  MMset(m, 0, PTOM(tuple));
1193 
1194 #ifdef _SCOL_DEBUG_
1195  MMechostr(MSKDEBUG, "ok\n");
1196 #endif
1197  return 0;
1198 }
1199 
1210 {
1211 #ifdef _SCOL_DEBUG_
1212  MMechostr(MSKDEBUG, "_SetOpenvrControllerRumble\n");
1213 #endif
1214 
1215  int iRumble = MMpull(m);
1216  int iSide = MMpull(m);
1217  int openvrTab = MMget(m, 0);
1218  if (openvrTab == NIL)
1219  {
1220  MMset(m, 0, NIL);
1221  return 0;
1222  }
1223 
1224  sOpenvr* openvrObj = MMgetPointer<sOpenvr*>(m, MTOP(openvrTab));
1225  if (!openvrObj || !openvrObj->IsConnected())
1226  {
1227  MMset(m, 0, NIL);
1228  return 0;
1229  }
1230 
1231  unsigned int id = 0;
1232  if (iSide != NIL && MTOI(iSide) > 0)
1233  id = MTOI(iSide);
1234 
1235  sOpenvrController* controller = openvrObj->GetController(id);
1236  if (!controller)
1237  {
1238  MMset(m, 0, NIL);
1239  return 0;
1240  }
1241 
1242  float rumble = 0.0f;
1243  if (iRumble != NIL)
1244  rumble = MTOF(iRumble);
1245 
1246  controller->Rumble(rumble);
1247  MMset(m, 0, ITOM(1));
1248 
1249 #ifdef _SCOL_DEBUG_
1250  MMechostr(MSKDEBUG, "ok\n");
1251 #endif
1252  return 0;
1253 }
1254 
1263 {
1264 #ifdef _SCOL_DEBUG_
1265  MMechostr(MSKDEBUG, "_IsOpenvrCameraAvailable\n");
1266 #endif
1267 
1268  int openvrTab = MMget(m, 0);
1269  if (openvrTab == NIL)
1270  {
1271  MMset(m, 0, NIL);
1272  return 0;
1273  }
1274 
1275  sOpenvr* openvrObj = MMgetPointer<sOpenvr*>(m, MTOP(openvrTab));
1276  if (!openvrObj || !openvrObj->IsConnected())
1277  {
1278  MMset(m, 0, NIL);
1279  return 0;
1280  }
1281 
1282  int state = (openvrObj->IsCameraEnable()) ? 1 : 0;
1283  MMset(m, 0, ITOM(state));
1284 
1285 #ifdef _SCOL_DEBUG_
1286  MMechostr(MSKDEBUG, "ok\n");
1287 #endif
1288  return 0;
1289 }
1290 
1298 int _OpenOpenvrCamera(mmachine m)
1299 {
1300 #ifdef _SCOL_DEBUG_
1301  MMechostr(MSKDEBUG, "_OpenOpenvrCamera\n");
1302 #endif
1303 
1304  int openvrTab = MMget(m, 0);
1305  if (openvrTab == NIL)
1306  {
1307  MMset(m, 0, NIL);
1308  return 0;
1309  }
1310 
1311  sOpenvr* openvrObj = MMgetPointer<sOpenvr*>(m, MTOP(openvrTab));
1312  if (!openvrObj || !openvrObj->IsConnected())
1313  {
1314  MMset(m, 0, NIL);
1315  return 0;
1316  }
1317 
1318  int state = (openvrObj->StartCamera()) ? 1 : 0;
1319  MMset(m, 0, ITOM(state));
1320 
1321 #ifdef _SCOL_DEBUG_
1322  MMechostr(MSKDEBUG, "ok\n");
1323 #endif
1324  return 0;
1325 }
1326 
1334 int _CloseOpenvrCamera(mmachine m)
1335 {
1336 #ifdef _SCOL_DEBUG_
1337  MMechostr(MSKDEBUG, "_CloseOpenvrCamera\n");
1338 #endif
1339 
1340  int openvrTab = MMget(m, 0);
1341  if (openvrTab == NIL)
1342  {
1343  MMset(m, 0, NIL);
1344  return 0;
1345  }
1346 
1347  sOpenvr* openvrObj = MMgetPointer<sOpenvr*>(m, MTOP(openvrTab));
1348  if (!openvrObj || !openvrObj->IsConnected())
1349  {
1350  MMset(m, 0, NIL);
1351  return 0;
1352  }
1353 
1354  openvrObj->StopCamera();
1355  MMset(m, 0, ITOM(1));
1356 
1357 #ifdef _SCOL_DEBUG_
1358  MMechostr(MSKDEBUG, "ok\n");
1359 #endif
1360  return 0;
1361 }
1362 
1370 int _GetOpenvrCameraSize(mmachine m)
1371 {
1372 #ifdef _SCOL_DEBUG_
1373  MMechostr(MSKDEBUG, "_GetOpenvrCameraSize\n");
1374 #endif
1375 
1376  int openvrTab = MMget(m, 0);
1377  if (openvrTab == NIL)
1378  {
1379  MMset(m, 0, NIL);
1380  return 0;
1381  }
1382 
1383  sOpenvr* openvrObj = MMgetPointer<sOpenvr*>(m, MTOP(openvrTab));
1384  if (!openvrObj || !openvrObj->IsConnected() || !openvrObj->IsCameraEnable())
1385  {
1386  MMset(m, 0, NIL);
1387  return 0;
1388  }
1389 
1390  uint32_t w = 0;
1391  uint32_t h = 0;
1392 
1393  openvrObj->GetCameraSize(w, h);
1394 
1395  int tuple = MMmalloc(m, 2, TYPETAB);
1396  if (tuple == NIL)
1397  {
1398  MMset(m, 0, NIL);
1399  return MERRMEM;
1400  }
1401  MMstore(m, tuple, 0, ITOM(w));
1402  MMstore(m, tuple, 1, ITOM(h));
1403  MMset(m, 0, PTOM(tuple));
1404 
1405 #ifdef _SCOL_DEBUG_
1406  MMechostr(MSKDEBUG, "ok\n");
1407 #endif
1408  return 0;
1409 }
1410 
1420 int _GetOpenvrCameraFrame(mmachine m)
1421 {
1422 #ifdef _SCOL_DEBUG_
1423  MMechostr(MSKDEBUG, "_GetOpenvrCameraFrame\n");
1424 #endif
1425 
1426  int bitmap = MMpull(m);
1427  int openvrTab = MMget(m, 0);
1428  if ((openvrTab == NIL) || (bitmap == NIL))
1429  {
1430  MMset(m, 0, NIL);
1431  return 0;
1432  }
1433 
1434  sOpenvr* openvrObj = MMgetPointer<sOpenvr*>(m, MTOP(openvrTab));
1435  if (!openvrObj || !openvrObj->IsConnected() || !openvrObj->IsCameraEnable())
1436  {
1437  MMset(m, 0, NIL);
1438  return 0;
1439  }
1440 
1441  PtrObjVoid OB = (PtrObjVoid)MMstart(m, MTOP(bitmap));
1442  PtrObjBitmap B = (PtrObjBitmap)MMstart(m, MTOP(OB->Buffer));
1443  if (openvrObj->GetCameraFrame(B))
1444  MMset(m, 0, bitmap);
1445  else
1446  MMset(m, 0, NIL);
1447 
1448 #ifdef _SCOL_DEBUG_
1449  MMechostr(MSKDEBUG, "ok\n");
1450 #endif
1451  return 0;
1452 }
1453 
1454 /* Callbacks */
1455 int getOpenvrIpdCb(mmachine m, SCOL_PTR_TYPE id, SCOL_PTR_TYPE param)
1456 {
1457  int k = 0;
1458  sOpenvr* openvrObj = (sOpenvr*)id;
1459 
1460  if (!openvrObj)
1461  return 0;
1462 
1463  // OBJbeginreflex(mmachine, objecttype, objectptr, cbtype)
1464  if (OBJbeginreflex(m, OBJ_Openvr_SCOL, SCOL_PTR openvrObj, SCOL_Openvr_IPD_CB))
1465  return 0;
1466 
1467  MMpush(m, FTOM(openvrObj->GetStereoIPD()));
1468  k = OBJcallreflex(m, 1);
1469  return k;
1470 }
1471 
1472 int getOpenvrQuitCb(mmachine m, SCOL_PTR_TYPE id, SCOL_PTR_TYPE param)
1473 {
1474  int k = 0;
1475  sOpenvr* openvrObj = (sOpenvr*)id;
1476 
1477  if (!openvrObj)
1478  return 0;
1479 
1480  // OBJbeginreflex(mmachine, objecttype, objectptr, cbtype)
1481  if (OBJbeginreflex(m, OBJ_Openvr_SCOL, SCOL_PTR openvrObj, SCOL_Openvr_QUIT_CB))
1482  return 0;
1483 
1484  k = OBJcallreflex(m, 0);
1485  return k;
1486 }
1487 
1491 char* mOpenvrname[] =
1492 {
1493  "ObjOpenvr",
1494  "OPENVR_CONTROLLER_LEFT",
1495  "OPENVR_CONTROLLER_RIGHT",
1496 
1497  "_CRopenvrDevice",
1498  "_DSopenvrDevice",
1499  "_GetOpenvrVisibility",
1500  "_GetOpenvrOrientation",
1501  "_GetOpenvrPosition",
1502  "_GetOpenvrAspectRatio",
1503  "_GetOpenvrIPD",
1504  "_GetOpenvrFovY",
1505  "_GetOpenvrProjectionMatrix",
1506  "_GetOpenvrTextureSize",
1507  "_ResetOpenvrDevice",
1508  "_UpdateOpenvr",
1509  "_UpdateOpenvrTextures",
1510  "_GetOpenvrDeviceName",
1511  "_GetOpenvrControllerVisibility",
1512  "_GetOpenvrControllerPosition",
1513  "_GetOpenvrControllerOrientation",
1514  "_GetOpenvrControllerVelocity",
1515  "_GetOpenvrControllerAngularVelocity",
1516  "_GetOpenvrControllerButtons",
1517  "_GetOpenvrControllerAxis",
1518  "_SetOpenvrControllerRumble",
1519  "_IsOpenvrCameraAvailable",
1520  "_OpenOpenvrCamera",
1521  "_CloseOpenvrCamera",
1522  "_GetOpenvrCameraSize",
1523  "_GetOpenvrCameraFrame"
1524 };
1525 
1529 #define NOpenvrPKG (sizeof(mOpenvrname)/sizeof(char*))
1530 
1534 int(*mOpenvrfun[NOpenvrPKG])(mmachine m) =
1535 {
1536  NULL, //ObjOpenvr
1537  SCOL_TYPTYPE(VrControllerSide::Left),
1538  SCOL_TYPTYPE(VrControllerSide::Right),
1539 
1546  _GetOpenvrIPD,
1551  _UpdateOpenvr,
1567 };
1568 
1572 int mOpenvrnarg[NOpenvrPKG] =
1573 {
1574  TYPTYPE, //ObjOpenvr
1575  TYPVAR,
1576  TYPVAR,
1577 
1578  5, //_CRopenvrDevice
1579  1, //_DSopenvrDevice
1580  1, //_GetOpenvrVisibility
1581  1, //_GetOpenvrOrientation
1582  1, //_GetOpenvrPosition
1583  1, //_GetOpenvrAspectRatio
1584  1, //_GetOpenvrIPD
1585  1, //_GetOpenvrFovY
1586  3, //_GetOpenvrProjectionMatrix
1587  1, //_GetOpenvrTextureSize
1588  1, //_ResetOpenvrDevice
1589  1, //_UpdateOpenvr
1590  4, //_UpdateOpenvrTextures
1591  1, //_GetOpenvrDeviceName
1592  2, //_GetOpenvrControllerVisibility
1593  2, //_GetOpenvrControllerPosition
1594  2, //_GetOpenvrControllerOrientation
1595  2, //_GetOpenvrControllerVelocity
1596  2, //_GetOpenvrControllerAngularVelocity
1597  2, //_GetOpenvrControllerButtons
1598  2, //_GetOpenvrControllerAxis
1599  3, //_SetOpenvrControllerRumble
1600  1, //_IsOpenvrCameraAvailable
1601  1, //_OpenOpenvrCamera
1602  1, //_CloseOpenvrCamera
1603  1, //_GetOpenvrCameraSize
1604  2 //_GetOpenvrCameraFrame
1605 
1606 };
1607 
1611 char* mOpenvrtype[NOpenvrPKG] =
1612 {
1613  NULL, //ObjOpenvr
1614  "I",
1615  "I",
1616 
1617  "fun [Chn fun [ObjOpenvr u0] u1 u0 fun [ObjOpenvr u2 F] u3 u2] ObjOpenvr", //_CRopenvrDevice
1618  "fun [ObjOpenvr] I", //_DSopenvrDevice
1619  "fun [ObjOpenvr] I", //_GetOpenvrVisibility
1620  "fun [ObjOpenvr] [F F F F]", //_GetOpenvrOrientation
1621  "fun [ObjOpenvr] [F F F]", //_GetOpenvrPosition
1622  "fun [ObjOpenvr] F", //_GetOpenvrAspectRatio
1623  "fun [ObjOpenvr] F", //_GetOpenvrIPD
1624  "fun [ObjOpenvr] F", //_GetOpenvrFovY
1625  "fun [ObjOpenvr 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]]]", //_GetOpenvrProjectionMatrix
1626  "fun [ObjOpenvr] [I I]", //_GetOpenvrTextureSize
1627  "fun [ObjOpenvr] I", //_ResetOpenvrDevice
1628  "fun [ObjOpenvr] I", //_UpdateOpenvr
1629  "fun [ObjOpenvr ObjPtr ObjPtr I] I", //_UpdateOpenvrTextures
1630  "fun [ObjOpenvr] S", //_GetOpenvrDeviceName
1631  "fun [ObjOpenvr I] I", //_GetOpenvrControllerVisibility
1632  "fun [ObjOpenvr I] [F F F]", //_GetOpenvrControllerPosition
1633  "fun [ObjOpenvr I] [F F F F]", //_GetOpenvrControllerOrientation
1634  "fun [ObjOpenvr I] [F F F]", //_GetOpenvrControllerVelocity
1635  "fun [ObjOpenvr I] [F F F]", //_GetOpenvrControllerAngularVelocity
1636  "fun [ObjOpenvr I] [I r1]", //_GetOpenvrControllerButtons
1637  "fun [ObjOpenvr I] [F F F]", //_GetOpenvrControllerAxis
1638  "fun [ObjOpenvr I F] I", //_SetOpenvrControllerRumble
1639  "fun [ObjOpenvr] I", //_IsOpenvrCameraAvailable
1640  "fun [ObjOpenvr] I", //_OpenOpenvrCamera
1641  "fun [ObjOpenvr] I", //_CloseOpenvrCamera
1642  "fun [ObjOpenvr] [I I]", //_GetOpenvrCameraSize
1643  "fun [ObjOpenvr ObjBitmap] ObjBitmap" //_GetOpenvrCameraFrame
1644 };
1645 
1646 
1647 // Everything inside _cond and _endcond is ignored by doxygen
1649 
1654 int LoadOpenvr(mmachine m)
1655 {
1656  int k = 0;
1657 
1658  MMechostr(MSKDEBUG, "\n");
1659  MMechostr(MSKDEBUG, " > Loading Openvr Support\n");
1660 
1661  // Declare a new type of object ("ObjOpenvr")
1662  OBJ_Openvr_SCOL = OBJregister(2 /*nb of callback*/, 0, destroyOpenvrObj, "OBJ_Openvr_SCOL");
1663  k = PKhardpak(m, "mOpenvr.pkg-1.0", NOpenvrPKG, mOpenvrname, mOpenvrfun, mOpenvrnarg, mOpenvrtype);
1664 
1665  Openvr_QUIT_CB = OBJgetUserEvent();
1666  OBJdefEvent(Openvr_QUIT_CB, getOpenvrQuitCb);
1667 
1668  Openvr_IPD_CB = OBJgetUserEvent();
1669  OBJdefEvent(Openvr_IPD_CB, getOpenvrIpdCb);
1670 
1671  MMechostr(MSKDEBUG, " > Successfully Loaded\n\n");
1672  return k;
1673 }
1674 
1675 int CloseOpenvr()
1676 {
1677  MMechostr(MSKDEBUG, "\n");
1678  MMechostr(MSKDEBUG, " > Unloading Openvr Support\n");
1679 
1680  MMechostr(MSKDEBUG, " > Successfully unloaded\n\n");
1681  return 0;
1682 }
1683 
1685 
1686 #ifndef SCOL_STATIC
1687 
1691 extern "C" SCOL_EXPORT int ScolLoadPlugin(mmachine m, cbmachine w)
1692 {
1693  SCOLinitplugin(w);
1694 
1695  return LoadOpenvr(m);
1696 }
1697 
1702 extern "C" SCOL_EXPORT int ScolUnloadPlugin()
1703 {
1704  return CloseOpenvr();
1705 }
1706 #else
1707 
1711 extern "C" SCOL_EXPORT int ScolOpenvrLoadPlugin(mmachine m, cbmachine w)
1712 {
1713  SCOLinitplugin(w);
1714 
1715  return LoadOpenvr(m);
1716 }
1717 
1722 extern "C" SCOL_EXPORT int ScolOpenvrUnloadPlugin()
1723 {
1724  return CloseOpenvr();
1725 }
1726 #endif //SCOL_STATIC
int _GetOpenvrControllerVisibility(mmachine m)
_GetOpenvrControllerVisibility : Get the Openvr controller visibility state
Definition: scolplugin.cpp:803
int _ResetOpenvrDevice(mmachine m)
_ResetOpenvrDevice : Reset Openvr sensor
Definition: scolplugin.cpp:478
int _GetOpenvrControllerOrientation(mmachine m)
_GetOpenvrControllerOrientation : Get the Openvr controller orientation
Definition: scolplugin.cpp:910
int _GetOpenvrTextureSize(mmachine m)
_GetOpenvrTextureSize : Get the Openvr texture size for RTT
Definition: scolplugin.cpp:754
int _UpdateOpenvr(mmachine m)
_UpdateOpenvr : start Openvr update you should call this on each render frame
Definition: scolplugin.cpp:515
int _CRopenvrDevice(mmachine m)
_CRopenvrDevice : This function create a Openvr object
Definition: scolplugin.cpp:99
int _GetOpenvrOrientation(mmachine m)
_GetOpenvrOrientation : Get the Openvr sensor orientation
Definition: scolplugin.cpp:268
int _GetOpenvrControllerPosition(mmachine m)
_GetOpenvrControllerPosition : Get the Openvr controller position
Definition: scolplugin.cpp:852
int _IsOpenvrCameraAvailable(mmachine m)
_IsOpenvrCameraAvailable : Get the Openvr camera availability
int _GetOpenvrVisibility(mmachine m)
_GetOpenvrVisibility : Get the Openvr HMD visibility state
Definition: scolplugin.cpp:232
int _GetOpenvrControllerButtons(mmachine m)
_GetOpenvrControllerButtons : Get the Openvr controller buttons state button order in list is applica...
int _GetOpenvrFovY(mmachine m)
_GetOpenvrFovY : Get the Openvr eye spacing
Definition: scolplugin.cpp:443
int _GetOpenvrCameraSize(mmachine m)
_GetOpenvrCameraSize : Get the Openvr camera frame size, the camera must be openned first ...
int _CloseOpenvrCamera(mmachine m)
_CloseOpenvrCamera : Close the Openvr camera
int _GetOpenvrProjectionMatrix(mmachine m)
_GetOpenvrProjectionMatrix : Get the Openvr camera projection matrix
Definition: scolplugin.cpp:632
int _GetOpenvrIPD(mmachine m)
_GetOpenvrIPD : Get the Openvr eye spacing
Definition: scolplugin.cpp:408
int _DSopenvrDevice(mmachine m)
_DSopenvrDevice : Destroy Openvr object
Definition: scolplugin.cpp:203
int _GetOpenvrControllerAxis(mmachine m)
_GetOpenvrControllerAxis : Get the Openvr controller axis values Axis order is touch pad X...
int _GetOpenvrPosition(mmachine m)
_GetOpenvrPosition : Get the Openvr position from the IR camera
Definition: scolplugin.cpp:321
int _GetOpenvrDeviceName(mmachine m)
_GetOpenvrDeviceName : Get the openvr device type
Definition: scolplugin.cpp:598
int _GetOpenvrAspectRatio(mmachine m)
_GetOpenvrAspectRatio : Get the Openvr camera aspect ratio
Definition: scolplugin.cpp:373
int _GetOpenvrControllerAngularVelocity(mmachine m)
_GetOpenvrControllerAngularVelocity : Get the Openvr controller velocity
int _OpenOpenvrCamera(mmachine m)
_OpenOpenvrCamera : Open the Openvr camera to get size and frames later
int _GetOpenvrCameraFrame(mmachine m)
_GetOpenvrCameraFrame : Get the Openvr camera frame into an existing bitmap the bitmap must have the ...
int _UpdateOpenvrTextures(mmachine m)
_UpdateOpenvrTextures : Update the HMD textures pointer
Definition: scolplugin.cpp:550
int _GetOpenvrControllerVelocity(mmachine m)
_GetOpenvrControllerVelocity : Get the Openvr controller velocity
Definition: scolplugin.cpp:969
int _SetOpenvrControllerRumble(mmachine m)
_SetOpenvrControllerRumble : Set the Openvr controller rumble value