OCULUS Scol plugin
 All Classes Functions Groups Pages
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  OCULUS interface for Scol
27  First version : July 2013
28  Author : Bastien BOURINEAU - I-Maginer
29 */
30 
31 #include "sOculus.h"
32 #include <scolPlugin.h>
33 
35 cbmachine ww;
36 HWND HScol = NULL;
37 int OBJ_OCULUS_SCOL;
38 
39 int OCULUS_CONNECTED_CB;
40 int SCOL_OCULUS_CONNECTED_CB = 0;
41 
42 int OCULUS_DISCONNECTED_CB;
43 int SCOL_OCULUS_DISCONNECTED_CB = 1;
44 
66 int destroyOCULUSObj(mmachine m, int handsys, int handscol)
67 {
68  // Read the first element of a TAB element (table of object)
69  sOculus* oculusObj = (sOculus*) MMfetch(m, MTOP(handscol), 0);
70  if (oculusObj == NULL)
71  {
72  MMset(m, 0, NIL);
73  return 0;
74  }
75 
76  // Write the first element of a TAB element
77  MMstore(m, MTOP(handscol), 0, NULL);
78 
79  // Safely dispose of "oculusObj" pointer
80  SAFE_DELETE(oculusObj);
81 
82  // Display debug message
83  MMechostr(MSKDEBUG, "ObjOculus destroyed.\n");
84  return 0;
85 }
86 
87 
100 int _CRoculusDevice(mmachine m)
101 {
102 #ifdef _SCOL_DEBUG_
103  MMechostr(0,"_CRoculusDevice\n");
104 #endif
105  // Declare local variables
106  int k = 0;
107 
108  int pUserd = MMpull(m);
109  int pCbkd = MMpull(m);
110  int pUserc = MMpull(m);
111  int pCbkc = MMpull(m);
112 
113  // Get the channel without pulling it (first element in the stack)
114  int channel = MMget(m, 0);
115 
116  // Test the channel
117  if (channel == NIL)
118  {
119  MMechostr(MSKDEBUG, "_CRoculusDevice : Channel NIL\n");
120  return 0;
121  }
122 
123  sOculus* oculusObj = new sOculus();
124  if (oculusObj == NULL)
125  {
126  MMechostr(MSKDEBUG, "_CRoculusDevice : oculusObj failed\n");
127  MMset(m, 0, NIL);
128  return 0;
129  }
130 
131  // Allocate a space in the stack for a table of joypad object
132  int oculusTab = MMmalloc(m, 1, TYPETAB);
133  if (oculusTab == NIL)
134  {
135  MMechostr(MSKDEBUG,"_CRoculusDevice : MMmalloc failed\n");
136  SAFE_DELETE(oculusObj);
137  return oculusTab;
138  }
139 
140  // Push the table of joypad objects into the stack
141  MMstore(m, oculusTab, 0, (int)oculusObj);
142  MMpush(m, PTOM(oculusTab));
143 
144  // Create a new scol joypad object
145  k = OBJcreate(m, OBJ_OCULUS_SCOL, (int)oculusObj, NULL, NULL);
146 
147  if ((k = MMpush(m, pCbkc))) return k; /* reading callback */
148  if ((k = MMpush(m, pUserc))) return k; /* user param */
149  if ((k = OBJaddreflex(m, OBJ_OCULUS_SCOL, SCOL_OCULUS_CONNECTED_CB))) return k;
150 
151  if ((k = MMpush(m, pCbkd))) return k; /* reading callback */
152  if ((k = MMpush(m, pUserd))) return k; /* user param */
153  if ((k = OBJaddreflex(m, OBJ_OCULUS_SCOL, SCOL_OCULUS_DISCONNECTED_CB))) return k;
154 
155  oculusObj->Connect();
156 
157 #ifdef _SCOL_DEBUG_
158  MMechostr(0,"ok\n");
159 #endif
160 
161  return k;
162 }
163 
171 int _DSoculusDevice(mmachine m)
172 {
173 #ifdef _SCOL_DEBUG_
174  MMechostr(MSKDEBUG,"_DSoculusDevice\n");
175 #endif
176 
177  int oculusTab = MMget(m, 0);
178  if (oculusTab == NIL)
179  {
180  MMset(m, 0, NIL);
181  return 0;
182  }
183 
184  OBJdelTM(m, OBJ_OCULUS_SCOL, oculusTab);
185  MMset(m, 0, ITOM(0));
186 
187 #ifdef _SCOL_DEBUG_
188  MMechostr(MSKDEBUG,"ok\n");
189 #endif
190  return 0;
191 }
192 
200 int _GetOculusOrientation(mmachine m)
201 {
202 #ifdef _SCOL_DEBUG_
203  MMechostr(MSKDEBUG,"_GetOculusOrientation\n");
204 #endif
205 
206  int oculusTab = MMget(m, 0);
207  if (oculusTab == NIL)
208  {
209  MMset(m, 0, NIL);
210  return 0;
211  }
212 
213  sOculus* oculusObj = (sOculus*) MMfetch(m, MTOP(oculusTab), 0);
214  if (!oculusObj)
215  {
216  MMset(m, 0, NIL);
217  return 0;
218  }
219 
220  Quatf quat = oculusObj->GetSensorOrientation();
221 
222  int tuple = MMmalloc(m, 4, TYPETAB);
223  if(tuple==NIL)
224  {
225  MMset(m, 0, NIL);
226  return MERRMEM;
227  }
228  MMstore(m, tuple, 0, FTOM(quat.x));
229  MMstore(m, tuple, 1, FTOM(quat.y));
230  MMstore(m, tuple, 2, FTOM(quat.z));
231  MMstore(m, tuple, 3, FTOM(quat.w));
232  MMset(m, 0, PTOM(tuple));
233 
234 #ifdef _SCOL_DEBUG_
235  MMechostr(MSKDEBUG,"ok\n");
236 #endif
237  return 0;
238 }
239 
248 {
249 #ifdef _SCOL_DEBUG_
250  MMechostr(MSKDEBUG,"_GetOculusPredictedOrientation\n");
251 #endif
252 
253  int oculusTab = MMget(m, 0);
254  if (oculusTab == NIL)
255  {
256  MMset(m, 0, NIL);
257  return 0;
258  }
259 
260  sOculus* oculusObj = (sOculus*) MMfetch(m, MTOP(oculusTab), 0);
261  if (!oculusObj)
262  {
263  MMset(m, 0, NIL);
264  return 0;
265  }
266 
267  Quatf quat = oculusObj->GetSensorOrientation();
268 
269  int tuple = MMmalloc(m, 4, TYPETAB);
270  if(tuple==NIL)
271  {
272  MMset(m, 0, NIL);
273  return MERRMEM;
274  }
275  MMstore(m, tuple, 0, FTOM(quat.x));
276  MMstore(m, tuple, 1, FTOM(quat.y));
277  MMstore(m, tuple, 2, FTOM(quat.z));
278  MMstore(m, tuple, 3, FTOM(quat.w));
279  MMset(m, 0, PTOM(tuple));
280 
281 #ifdef _SCOL_DEBUG_
282  MMechostr(MSKDEBUG,"ok\n");
283 #endif
284  return 0;
285 }
286 
294 int _GetOculusYawPitchRoll(mmachine m)
295 {
296 #ifdef _SCOL_DEBUG_
297  MMechostr(MSKDEBUG,"_GetOculusYawPitchRoll\n");
298 #endif
299 
300  int oculusTab = MMget(m, 0);
301  if (oculusTab == NIL)
302  {
303  MMset(m, 0, NIL);
304  return 0;
305  }
306 
307  sOculus* oculusObj = (sOculus*) MMfetch(m, MTOP(oculusTab), 0);
308  if (!oculusObj)
309  {
310  MMset(m, 0, NIL);
311  return 0;
312  }
313 
314  Vector3f ypr = oculusObj->GetSensorYawPitchRoll();
315 
316  int tuple = MMmalloc(m, 3, TYPETAB);
317  if(tuple==NIL)
318  {
319  MMset(m, 0, NIL);
320  return MERRMEM;
321  }
322  MMstore(m, tuple, 0, FTOM(ypr.x));
323  MMstore(m, tuple, 1, FTOM(ypr.y));
324  MMstore(m, tuple, 2, FTOM(ypr.z));
325  MMset(m, 0, PTOM(tuple));
326 
327 #ifdef _SCOL_DEBUG_
328  MMechostr(MSKDEBUG,"ok\n");
329 #endif
330  return 0;
331 }
332 
341 {
342 #ifdef _SCOL_DEBUG_
343  MMechostr(MSKDEBUG,"_GetOculusPredictedYawPitchRoll\n");
344 #endif
345 
346  int oculusTab = MMget(m, 0);
347  if (oculusTab == NIL)
348  {
349  MMset(m, 0, NIL);
350  return 0;
351  }
352 
353  sOculus* oculusObj = (sOculus*) MMfetch(m, MTOP(oculusTab), 0);
354  if (!oculusObj)
355  {
356  MMset(m, 0, NIL);
357  return 0;
358  }
359 
360  Vector3f ypr = oculusObj->GetSensorYawPitchRoll();
361 
362  int tuple = MMmalloc(m, 3, TYPETAB);
363  if(tuple==NIL)
364  {
365  MMset(m, 0, NIL);
366  return MERRMEM;
367  }
368  MMstore(m, tuple, 0, FTOM(ypr.x));
369  MMstore(m, tuple, 1, FTOM(ypr.y));
370  MMstore(m, tuple, 2, FTOM(ypr.z));
371  MMset(m, 0, PTOM(tuple));
372 
373 #ifdef _SCOL_DEBUG_
374  MMechostr(MSKDEBUG,"ok\n");
375 #endif
376  return 0;
377 }
378 
386 int _GetOculusAcceleration(mmachine m)
387 {
388 #ifdef _SCOL_DEBUG_
389  MMechostr(MSKDEBUG,"_GetOculusAcceleration\n");
390 #endif
391 
392  int oculusTab = MMget(m, 0);
393  if (oculusTab == NIL)
394  {
395  MMset(m, 0, NIL);
396  return 0;
397  }
398 
399  sOculus* oculusObj = (sOculus*) MMfetch(m, MTOP(oculusTab), 0);
400  if (!oculusObj)
401  {
402  MMset(m, 0, NIL);
403  return 0;
404  }
405 
406  Vector3f acc = oculusObj->GetSensorAcceleration();
407 
408  int tuple = MMmalloc(m, 3, TYPETAB);
409  if(tuple==NIL)
410  {
411  MMset(m, 0, NIL);
412  return MERRMEM;
413  }
414  MMstore(m, tuple, 0, FTOM(acc.x));
415  MMstore(m, tuple, 1, FTOM(acc.y));
416  MMstore(m, tuple, 2, FTOM(acc.z));
417  MMset(m, 0, PTOM(tuple));
418 
419 #ifdef _SCOL_DEBUG_
420  MMechostr(MSKDEBUG,"ok\n");
421 #endif
422  return 0;
423 }
424 
432 int _GetOculusPosition(mmachine m)
433 {
434 #ifdef _SCOL_DEBUG_
435  MMechostr(MSKDEBUG,"_GetOculusPosition\n");
436 #endif
437 
438  int oculusTab = MMget(m, 0);
439  if (oculusTab == NIL)
440  {
441  MMset(m, 0, NIL);
442  return 0;
443  }
444 
445  sOculus* oculusObj = (sOculus*) MMfetch(m, MTOP(oculusTab), 0);
446  if (!oculusObj)
447  {
448  MMset(m, 0, NIL);
449  return 0;
450  }
451 
452  Vector3f pos = oculusObj->GetSensorPosition();
453 
454  int tuple = MMmalloc(m, 3, TYPETAB);
455  if(tuple==NIL)
456  {
457  MMset(m, 0, NIL);
458  return MERRMEM;
459  }
460  MMstore(m, tuple, 0, FTOM(pos.x));
461  MMstore(m, tuple, 1, FTOM(pos.y));
462  MMstore(m, tuple, 2, FTOM(pos.z));
463  MMset(m, 0, PTOM(tuple));
464 
465 #ifdef _SCOL_DEBUG_
466  MMechostr(MSKDEBUG,"ok\n");
467 #endif
468  return 0;
469 }
470 
479 int _GetOculusStereoConfig(mmachine m)
480 {
481 #ifdef _SCOL_DEBUG_
482  MMechostr(MSKDEBUG,"_GetOculusStereoConfig\n");
483 #endif
484 
485  int oculusTab = MMget(m, 0);
486  if (oculusTab == NIL)
487  {
488  MMset(m, 0, NIL);
489  return 0;
490  }
491 
492  sOculus* oculusObj = (sOculus*) MMfetch(m, MTOP(oculusTab), 0);
493  if (!oculusObj)
494  {
495  MMset(m, 0, NIL);
496  return 0;
497  }
498 
499  int distortion = MMmalloc(m, 4, TYPETAB);
500  if(distortion==NIL)
501  {
502  MMset(m, 0, NIL);
503  return MERRMEM;
504  }
505 
506  MMstore(m, distortion, 0, FTOM(1.0f));
507  MMstore(m, distortion, 1, FTOM(0.22f));
508  MMstore(m, distortion, 2, FTOM(0.24f));
509  MMstore(m, distortion, 3, FTOM(0.0f));
510 
511  int chromaAb = MMmalloc(m, 4, TYPETAB);
512  if(chromaAb==NIL)
513  {
514  MMset(m, 0, NIL);
515  return MERRMEM;
516  }
517 
518  MMstore(m, chromaAb, 0, FTOM(0.996f));
519  MMstore(m, chromaAb, 1, FTOM(-0.004f));
520  MMstore(m, chromaAb, 2, FTOM(1.014f));
521  MMstore(m, chromaAb, 3, FTOM(0.0f));
522 
523  int tuple = MMmalloc(m, 7, TYPETAB);
524  if(tuple==NIL)
525  {
526  MMset(m, 0, NIL);
527  return MERRMEM;
528  }
529  MMstore(m, tuple, 0, FTOM(0.14529906f));
530  MMstore(m, tuple, 1, FTOM(oculusObj->GetStereoIPD()));
531  MMstore(m, tuple, 2, FTOM(oculusObj->GetStereoConfigAspect()));
532  MMstore(m, tuple, 3, FTOM(0.041f));
533  MMstore(m, tuple, 4, FTOM(oculusObj->GetStereoConfigFovY()));
534  MMstore(m, tuple, 5, PTOM(distortion));
535  MMstore(m, tuple, 6, PTOM(chromaAb));
536 
537  MMset(m, 0, PTOM(tuple));
538 
539 #ifdef _SCOL_DEBUG_
540  MMechostr(MSKDEBUG,"ok\n");
541 #endif
542  return 0;
543 }
544 
552 int _GetOculusAspectRatio(mmachine m)
553 {
554 #ifdef _SCOL_DEBUG_
555  MMechostr(MSKDEBUG,"_GetOculusAspectRatio\n");
556 #endif
557 
558  int oculusTab = MMget(m, 0);
559  if (oculusTab == NIL)
560  {
561  MMset(m, 0, NIL);
562  return 0;
563  }
564 
565  sOculus* oculusObj = (sOculus*) MMfetch(m, MTOP(oculusTab), 0);
566  if (!oculusObj)
567  {
568  MMset(m, 0, NIL);
569  return 0;
570  }
571 
572  MMset(m, 0, FTOM(oculusObj->GetStereoConfigAspect()));
573 
574 #ifdef _SCOL_DEBUG_
575  MMechostr(MSKDEBUG,"ok\n");
576 #endif
577  return 0;
578 }
579 
587 int _GetOculusIPD(mmachine m)
588 {
589 #ifdef _SCOL_DEBUG_
590  MMechostr(MSKDEBUG,"_GetOculusIPD\n");
591 #endif
592 
593  int oculusTab = MMget(m, 0);
594  if (oculusTab == NIL)
595  {
596  MMset(m, 0, NIL);
597  return 0;
598  }
599 
600  sOculus* oculusObj = (sOculus*) MMfetch(m, MTOP(oculusTab), 0);
601  if (!oculusObj)
602  {
603  MMset(m, 0, NIL);
604  return 0;
605  }
606 
607  MMset(m, 0, FTOM(oculusObj->GetStereoIPD()));
608 
609 #ifdef _SCOL_DEBUG_
610  MMechostr(MSKDEBUG,"ok\n");
611 #endif
612  return 0;
613 }
614 
622 int _GetOculusFovY(mmachine m)
623 {
624 #ifdef _SCOL_DEBUG_
625  MMechostr(MSKDEBUG,"_GetOculusFovY\n");
626 #endif
627 
628  int oculusTab = MMget(m, 0);
629  if (oculusTab == NIL)
630  {
631  MMset(m, 0, NIL);
632  return 0;
633  }
634 
635  sOculus* oculusObj = (sOculus*) MMfetch(m, MTOP(oculusTab), 0);
636  if (!oculusObj)
637  {
638  MMset(m, 0, NIL);
639  return 0;
640  }
641 
642  MMset(m, 0, FTOM(oculusObj->GetStereoConfigFovY()));
643 
644 #ifdef _SCOL_DEBUG_
645  MMechostr(MSKDEBUG,"ok\n");
646 #endif
647  return 0;
648 }
649 
657 int _ResetOculusDevice(mmachine m)
658 {
659 #ifdef _SCOL_DEBUG_
660  MMechostr(MSKDEBUG,"_ResetOculusDevice\n");
661 #endif
662 
663  int oculusTab = MMget(m, 0);
664  if (oculusTab == NIL)
665  {
666  MMset(m, 0, NIL);
667  return 0;
668  }
669 
670  sOculus* oculusObj = (sOculus*) MMfetch(m, MTOP(oculusTab), 0);
671  if (!oculusObj)
672  {
673  MMset(m, 0, NIL);
674  return 0;
675  }
676 
677  oculusObj->ResetSensor();
678 
679  MMset(m, 0, ITOM(0));
680 
681 #ifdef _SCOL_DEBUG_
682  MMechostr(MSKDEBUG,"ok\n");
683 #endif
684  return 0;
685 }
686 
695 int _UpdateOculusLatency(mmachine m)
696 {
697 #ifdef _SCOL_DEBUG_
698  MMechostr(MSKDEBUG,"_UpdateOculusLatency\n");
699 #endif
700 
701  MMset(m, 0, NIL);
702  return 0;
703 }
704 
712 int _StartUpdateOculus(mmachine m)
713 {
714 #ifdef _SCOL_DEBUG_
715  MMechostr(MSKDEBUG,"_StartUpdateOculus\n");
716 #endif
717 
718  int oculusTab = MMget(m, 0);
719  if (oculusTab == NIL)
720  {
721  MMset(m, 0, NIL);
722  return 0;
723  }
724 
725  sOculus* oculusObj = (sOculus*) MMfetch(m, MTOP(oculusTab), 0);
726  if (!oculusObj || !oculusObj->IsConnected())
727  {
728  MMset(m, 0, NIL);
729  return 0;
730  }
731  bool ret = oculusObj->UpdateStart();
732 
733  MMset(m, 0, ITOM((ret) ? 1 : 0));
734  return 0;
735 }
736 
744 int _EndUpdateOculus(mmachine m)
745 {
746 #ifdef _SCOL_DEBUG_
747  MMechostr(MSKDEBUG,"_EndUpdateOculus\n");
748 #endif
749 
750  int oculusTab = MMget(m, 0);
751  if (oculusTab == NIL)
752  {
753  MMset(m, 0, NIL);
754  return 0;
755  }
756 
757  sOculus* oculusObj = (sOculus*) MMfetch(m, MTOP(oculusTab), 0);
758  if (!oculusObj || !oculusObj->IsConnected())
759  {
760  MMset(m, 0, NIL);
761  return 0;
762  }
763  oculusObj->UpdateEnd();
764 
765  MMset(m, 0, ITOM(0));
766  return 0;
767 }
768 
778 {
779 #ifdef _SCOL_DEBUG_
780  MMechostr(MSKDEBUG,"_SetOculusLowPersistance\n");
781 #endif
782 
783  int istate = MMpull(m);
784  int oculusTab = MMget(m, 0);
785  if (oculusTab == NIL)
786  {
787  MMset(m, 0, NIL);
788  return 0;
789  }
790 
791  sOculus* oculusObj = (sOculus*) MMfetch(m, MTOP(oculusTab), 0);
792  if (!oculusObj || !oculusObj->IsConnected())
793  {
794  MMset(m, 0, NIL);
795  return 0;
796  }
797 
798  bool state = false;
799  if (istate != NIL)
800  state = (MTOI(istate) > 0) ? true : false;
801 
802  oculusObj->SetLowPersistance(state);
803 
804  MMset(m, 0, ITOM(0));
805  return 0;
806 }
807 
816 {
817 #ifdef _SCOL_DEBUG_
818  MMechostr(MSKDEBUG,"_GetOculusLowPersistance\n");
819 #endif
820 
821  int oculusTab = MMget(m, 0);
822  if (oculusTab == NIL)
823  {
824  MMset(m, 0, NIL);
825  return 0;
826  }
827 
828  sOculus* oculusObj = (sOculus*) MMfetch(m, MTOP(oculusTab), 0);
829  if (!oculusObj || !oculusObj->IsConnected())
830  {
831  MMset(m, 0, NIL);
832  return 0;
833  }
834 
835  MMset(m, 0, ITOM((oculusObj->GetLowPersistance()) ? 1 : 0));
836  return 0;
837 }
838 
846 int _GetOculusDeviceType(mmachine m)
847 {
848 #ifdef _SCOL_DEBUG_
849  MMechostr(MSKDEBUG,"_GetOculusDeviceType\n");
850 #endif
851 
852  int oculusTab = MMget(m, 0);
853  if (oculusTab == NIL)
854  {
855  MMset(m, 0, NIL);
856  return 0;
857  }
858 
859  sOculus* oculusObj = (sOculus*) MMfetch(m, MTOP(oculusTab), 0);
860  if (!oculusObj || !oculusObj->IsConnected())
861  {
862  MMset(m, 0, NIL);
863  return 0;
864  }
865 
866  MMset(m, 0, ITOM((int)oculusObj->GetType()));
867  return 0;
868 }
869 
880 {
881 #ifdef _SCOL_DEBUG_
882  MMechostr(MSKDEBUG,"_GetOculusProjectionMatrix\n");
883 #endif
884 
885  int ifclip = MMpull(m);
886  int inclip = MMpull(m);
887  int oculusTab = MMget(m, 0);
888  if (oculusTab == NIL)
889  {
890  MMset(m, 0, NIL);
891  return 0;
892  }
893 
894  sOculus* oculusObj = (sOculus*) MMfetch(m, MTOP(oculusTab), 0);
895  if (!oculusObj || !oculusObj->IsConnected())
896  {
897  MMset(m, 0, NIL);
898  return 0;
899  }
900 
901  float nearclip = 0.01f;
902  if (inclip != NIL)
903  nearclip = MTOF(inclip);
904 
905  float farclip = 10000.0f;
906  if (ifclip != NIL)
907  farclip = MTOF(ifclip);
908 
909  ovrMatrix4f lmat;
910  ovrMatrix4f rmat;
911 
912  oculusObj->GetProjectionMatrix(ovrEye_Left, nearclip, farclip, lmat);
913  oculusObj->GetProjectionMatrix(ovrEye_Right, nearclip, farclip, rmat);
914 
915  int tuple = MMmalloc(m, 2, TYPETAB);
916  int ltmat = MMmalloc(m, 4, TYPETAB);
917  int ltmat1 = MMmalloc(m, 4, TYPETAB);
918  int ltmat2 = MMmalloc(m, 4, TYPETAB);
919  int ltmat3 = MMmalloc(m, 4, TYPETAB);
920  int ltmat4 = MMmalloc(m, 4, TYPETAB);
921 
922  int rtmat = MMmalloc(m, 4, TYPETAB);
923  int rtmat1 = MMmalloc(m, 4, TYPETAB);
924  int rtmat2 = MMmalloc(m, 4, TYPETAB);
925  int rtmat3 = MMmalloc(m, 4, TYPETAB);
926  int rtmat4 = MMmalloc(m, 4, TYPETAB);
927 
928  if ((tuple==NIL) || (ltmat==NIL) || (ltmat1==NIL) || (ltmat2==NIL) || (ltmat3==NIL) || (ltmat4==NIL) || (rtmat==NIL) || (rtmat1==NIL) || (rtmat2==NIL) || (rtmat3==NIL) || (rtmat4==NIL))
929  {
930  MMset(m, 0, NIL);
931  return MERRMEM;
932  }
933 
934  MMstore(m, ltmat1, 0, FTOM(lmat.M[0][0]));
935  MMstore(m, ltmat1, 1, FTOM(lmat.M[0][1]));
936  MMstore(m, ltmat1, 2, FTOM(lmat.M[0][2]));
937  MMstore(m, ltmat1, 3, FTOM(lmat.M[0][3]));
938 
939  MMstore(m, ltmat2, 0, FTOM(lmat.M[1][0]));
940  MMstore(m, ltmat2, 1, FTOM(lmat.M[1][1]));
941  MMstore(m, ltmat2, 2, FTOM(lmat.M[1][2]));
942  MMstore(m, ltmat2, 3, FTOM(lmat.M[1][3]));
943 
944  MMstore(m, ltmat3, 0, FTOM(lmat.M[2][0]));
945  MMstore(m, ltmat3, 1, FTOM(lmat.M[2][1]));
946  MMstore(m, ltmat3, 2, FTOM(lmat.M[2][2]));
947  MMstore(m, ltmat3, 3, FTOM(lmat.M[2][3]));
948 
949  MMstore(m, ltmat4, 0, FTOM(lmat.M[3][0]));
950  MMstore(m, ltmat4, 1, FTOM(lmat.M[3][1]));
951  MMstore(m, ltmat4, 2, FTOM(lmat.M[3][2]));
952  MMstore(m, ltmat4, 3, FTOM(lmat.M[3][3]));
953 
954  MMstore(m, ltmat, 0, PTOM(ltmat1));
955  MMstore(m, ltmat, 1, PTOM(ltmat2));
956  MMstore(m, ltmat, 2, PTOM(ltmat3));
957  MMstore(m, ltmat, 3, PTOM(ltmat4));
958 
959  MMstore(m, rtmat1, 0, FTOM(rmat.M[0][0]));
960  MMstore(m, rtmat1, 1, FTOM(rmat.M[0][1]));
961  MMstore(m, rtmat1, 2, FTOM(rmat.M[0][2]));
962  MMstore(m, rtmat1, 3, FTOM(rmat.M[0][3]));
963 
964  MMstore(m, rtmat2, 0, FTOM(rmat.M[1][0]));
965  MMstore(m, rtmat2, 1, FTOM(rmat.M[1][1]));
966  MMstore(m, rtmat2, 2, FTOM(rmat.M[1][2]));
967  MMstore(m, rtmat2, 3, FTOM(rmat.M[1][3]));
968 
969  MMstore(m, rtmat3, 0, FTOM(rmat.M[2][0]));
970  MMstore(m, rtmat3, 1, FTOM(rmat.M[2][1]));
971  MMstore(m, rtmat3, 2, FTOM(rmat.M[2][2]));
972  MMstore(m, rtmat3, 3, FTOM(rmat.M[2][3]));
973 
974  MMstore(m, rtmat4, 0, FTOM(rmat.M[3][0]));
975  MMstore(m, rtmat4, 1, FTOM(rmat.M[3][1]));
976  MMstore(m, rtmat4, 2, FTOM(rmat.M[3][2]));
977  MMstore(m, rtmat4, 3, FTOM(rmat.M[3][3]));
978 
979  MMstore(m, rtmat, 0, PTOM(rtmat1));
980  MMstore(m, rtmat, 1, PTOM(rtmat2));
981  MMstore(m, rtmat, 2, PTOM(rtmat3));
982  MMstore(m, rtmat, 3, PTOM(rtmat4));
983 
984  MMstore(m, tuple, 0, PTOM(ltmat));
985  MMstore(m, tuple, 1, PTOM(rtmat));
986  MMset(m, 0, PTOM(tuple));
987 
988 #ifdef _SCOL_DEBUG_
989  MMechostr(MSKDEBUG,"ok\n");
990 #endif
991  return 0;
992 }
993 
1002 {
1003 #ifdef _SCOL_DEBUG_
1004  MMechostr(MSKDEBUG,"_GetOculusTimeWarpMatrix\n");
1005 #endif
1006 
1007  int oculusTab = MMget(m, 0);
1008  if (oculusTab == NIL)
1009  {
1010  MMset(m, 0, NIL);
1011  return 0;
1012  }
1013 
1014  sOculus* oculusObj = (sOculus*) MMfetch(m, MTOP(oculusTab), 0);
1015  if (!oculusObj || !oculusObj->IsConnected())
1016  {
1017  MMset(m, 0, NIL);
1018  return 0;
1019  }
1020 
1021  ovrMatrix4f lmat[2];
1022  ovrMatrix4f rmat[2];
1023 
1024  //oculusObj->WaitForFrame();
1025  oculusObj->GetTimeWarpMatrix(ovrEye_Left, lmat);
1026  oculusObj->GetTimeWarpMatrix(ovrEye_Right, rmat);
1027 
1028  int k = 0;
1029  MMpull(m);
1030 
1031  MMpush(m, FTOM(lmat[0].M[0][0]));
1032  MMpush(m, FTOM(lmat[0].M[0][1]));
1033  MMpush(m, FTOM(lmat[0].M[0][2]));
1034  MMpush(m, FTOM(lmat[0].M[0][3]));
1035 
1036  MMpush(m, ITOM(4));
1037  if(k=MBdeftab(m))
1038  return k;
1039 
1040  MMpush(m, FTOM(lmat[0].M[1][0]));
1041  MMpush(m, FTOM(lmat[0].M[1][1]));
1042  MMpush(m, FTOM(lmat[0].M[1][2]));
1043  MMpush(m, FTOM(lmat[0].M[1][3]));
1044 
1045  MMpush(m, ITOM(4));
1046  if(k=MBdeftab(m))
1047  return k;
1048 
1049  MMpush(m, FTOM(lmat[0].M[2][0]));
1050  MMpush(m, FTOM(lmat[0].M[2][1]));
1051  MMpush(m, FTOM(lmat[0].M[2][2]));
1052  MMpush(m, FTOM(lmat[0].M[2][3]));
1053 
1054  MMpush(m, ITOM(4));
1055  if(k=MBdeftab(m))
1056  return k;
1057 
1058  MMpush(m, FTOM(lmat[0].M[3][0]));
1059  MMpush(m, FTOM(lmat[0].M[3][1]));
1060  MMpush(m, FTOM(lmat[0].M[3][2]));
1061  MMpush(m, FTOM(lmat[0].M[3][3]));
1062 
1063  MMpush(m, ITOM(4));
1064  if(k=MBdeftab(m))
1065  return k;
1066 
1067  MMpush(m, ITOM(4));
1068  if(k=MBdeftab(m))
1069  return k;
1070 
1071  MMpush(m, FTOM(lmat[1].M[0][0]));
1072  MMpush(m, FTOM(lmat[1].M[0][1]));
1073  MMpush(m, FTOM(lmat[1].M[0][2]));
1074  MMpush(m, FTOM(lmat[1].M[0][3]));
1075 
1076  MMpush(m, ITOM(4));
1077  if(k=MBdeftab(m))
1078  return k;
1079 
1080  MMpush(m, FTOM(lmat[1].M[1][0]));
1081  MMpush(m, FTOM(lmat[1].M[1][1]));
1082  MMpush(m, FTOM(lmat[1].M[1][2]));
1083  MMpush(m, FTOM(lmat[1].M[1][3]));
1084 
1085  MMpush(m, ITOM(4));
1086  if(k=MBdeftab(m))
1087  return k;
1088 
1089  MMpush(m, FTOM(lmat[1].M[2][0]));
1090  MMpush(m, FTOM(lmat[1].M[2][1]));
1091  MMpush(m, FTOM(lmat[1].M[2][2]));
1092  MMpush(m, FTOM(lmat[1].M[2][3]));
1093 
1094  MMpush(m, ITOM(4));
1095  if(k=MBdeftab(m))
1096  return k;
1097 
1098  MMpush(m, FTOM(lmat[1].M[3][0]));
1099  MMpush(m, FTOM(lmat[1].M[3][1]));
1100  MMpush(m, FTOM(lmat[1].M[3][2]));
1101  MMpush(m, FTOM(lmat[1].M[3][3]));
1102 
1103  MMpush(m, ITOM(4));
1104  if(k=MBdeftab(m))
1105  return k;
1106 
1107  MMpush(m, ITOM(4));
1108  if(k=MBdeftab(m))
1109  return k;
1110 
1111 
1112  MMpush(m, FTOM(rmat[0].M[0][0]));
1113  MMpush(m, FTOM(rmat[0].M[0][1]));
1114  MMpush(m, FTOM(rmat[0].M[0][2]));
1115  MMpush(m, FTOM(rmat[0].M[0][3]));
1116 
1117  MMpush(m, ITOM(4));
1118  if(k=MBdeftab(m))
1119  return k;
1120 
1121  MMpush(m, FTOM(rmat[0].M[1][0]));
1122  MMpush(m, FTOM(rmat[0].M[1][1]));
1123  MMpush(m, FTOM(rmat[0].M[1][2]));
1124  MMpush(m, FTOM(rmat[0].M[1][3]));
1125 
1126  MMpush(m, ITOM(4));
1127  if(k=MBdeftab(m))
1128  return k;
1129 
1130  MMpush(m, FTOM(rmat[0].M[2][0]));
1131  MMpush(m, FTOM(rmat[0].M[2][1]));
1132  MMpush(m, FTOM(rmat[0].M[2][2]));
1133  MMpush(m, FTOM(rmat[0].M[2][3]));
1134 
1135  MMpush(m, ITOM(4));
1136  if(k=MBdeftab(m))
1137  return k;
1138 
1139  MMpush(m, FTOM(rmat[0].M[3][0]));
1140  MMpush(m, FTOM(rmat[0].M[3][1]));
1141  MMpush(m, FTOM(rmat[0].M[3][2]));
1142  MMpush(m, FTOM(rmat[0].M[3][3]));
1143 
1144  MMpush(m, ITOM(4));
1145  if(k=MBdeftab(m))
1146  return k;
1147 
1148  MMpush(m, ITOM(4));
1149  if(k=MBdeftab(m))
1150  return k;
1151 
1152  MMpush(m, FTOM(rmat[1].M[0][0]));
1153  MMpush(m, FTOM(rmat[1].M[0][1]));
1154  MMpush(m, FTOM(rmat[1].M[0][2]));
1155  MMpush(m, FTOM(rmat[1].M[0][3]));
1156 
1157  MMpush(m, ITOM(4));
1158  if(k=MBdeftab(m))
1159  return k;
1160 
1161  MMpush(m, FTOM(rmat[1].M[1][0]));
1162  MMpush(m, FTOM(rmat[1].M[1][1]));
1163  MMpush(m, FTOM(rmat[1].M[1][2]));
1164  MMpush(m, FTOM(rmat[1].M[1][3]));
1165 
1166  MMpush(m, ITOM(4));
1167  if(k=MBdeftab(m))
1168  return k;
1169 
1170  MMpush(m, FTOM(rmat[1].M[2][0]));
1171  MMpush(m, FTOM(rmat[1].M[2][1]));
1172  MMpush(m, FTOM(rmat[1].M[2][2]));
1173  MMpush(m, FTOM(rmat[1].M[2][3]));
1174 
1175  MMpush(m, ITOM(4));
1176  if(k=MBdeftab(m))
1177  return k;
1178 
1179  MMpush(m, FTOM(rmat[1].M[3][0]));
1180  MMpush(m, FTOM(rmat[1].M[3][1]));
1181  MMpush(m, FTOM(rmat[1].M[3][2]));
1182  MMpush(m, FTOM(rmat[1].M[3][3]));
1183 
1184  MMpush(m, ITOM(4));
1185  if(k=MBdeftab(m))
1186  return k;
1187 
1188  MMpush(m, ITOM(4));
1189  if(k=MBdeftab(m))
1190  return k;
1191 
1192  //final tuple
1193  MMpush(m, ITOM(4));
1194  if(k=MBdeftab(m))
1195  return k;
1196 
1197 #ifdef _SCOL_DEBUG_
1198  MMechostr(MSKDEBUG,"ok\n");
1199 #endif
1200  return 0;
1201 }
1202 
1211 {
1212 #ifdef _SCOL_DEBUG_
1213  MMechostr(MSKDEBUG,"_GetOculusFovTextureSize\n");
1214 #endif
1215 
1216  int oculusTab = MMget(m, 0);
1217  if (oculusTab == NIL)
1218  {
1219  MMset(m, 0, NIL);
1220  return 0;
1221  }
1222 
1223  sOculus* oculusObj = (sOculus*) MMfetch(m, MTOP(oculusTab), 0);
1224  if (!oculusObj || !oculusObj->IsConnected())
1225  {
1226  MMset(m, 0, NIL);
1227  return 0;
1228  }
1229 
1230  Sizei lsize = oculusObj->GetStereoConfigFovTextureSize(ovrEye_Left);
1231  Sizei rsize = oculusObj->GetStereoConfigFovTextureSize(ovrEye_Right);
1232 
1233  int tuple = MMmalloc(m, 2, TYPETAB);
1234  int ltsize = MMmalloc(m, 2, TYPETAB);
1235  int rtsize = MMmalloc(m, 2, TYPETAB);
1236  if ((tuple==NIL) || (ltsize==NIL) || (rtsize==NIL))
1237  {
1238  MMset(m, 0, NIL);
1239  return MERRMEM;
1240  }
1241 
1242  MMstore(m, ltsize, 0, ITOM(lsize.w));
1243  MMstore(m, ltsize, 1, ITOM(lsize.h));
1244 
1245  MMstore(m, rtsize, 0, ITOM(rsize.w));
1246  MMstore(m, rtsize, 1, ITOM(rsize.h));
1247 
1248  MMstore(m, tuple, 0, PTOM(ltsize));
1249  MMstore(m, tuple, 1, PTOM(rtsize));
1250  MMset(m, 0, PTOM(tuple));
1251 
1252 #ifdef _SCOL_DEBUG_
1253  MMechostr(MSKDEBUG,"ok\n");
1254 #endif
1255  return 0;
1256 }
1257 
1267 int _GetOculusUvConfig(mmachine m)
1268 {
1269 #ifdef _SCOL_DEBUG_
1270  MMechostr(MSKDEBUG,"_GetOculusUvConfig\n");
1271 #endif
1272 
1273  int irsize = MMpull(m);
1274  int ilsize = MMpull(m);
1275  int oculusTab = MMget(m, 0);
1276  if (oculusTab == NIL || irsize == NIL || ilsize == NIL)
1277  {
1278  MMset(m, 0, NIL);
1279  return 0;
1280  }
1281 
1282  sOculus* oculusObj = (sOculus*) MMfetch(m, MTOP(oculusTab), 0);
1283  if (!oculusObj || !oculusObj->IsConnected())
1284  {
1285  MMset(m, 0, NIL);
1286  return 0;
1287  }
1288 
1289  ilsize = MTOP(ilsize);
1290  Sizei ltexsize(MTOI(MMfetch(m, ilsize, 0)), MTOI(MMfetch(m, ilsize, 1)));
1291 
1292  irsize = MTOP(irsize);
1293  Sizei rtexsize(MTOI(MMfetch(m, irsize, 0)), MTOI(MMfetch(m, irsize, 1)));
1294 
1295  Vector2f lscale;
1296  Vector2f loffset;
1297  oculusObj->GetStereoConfigUvScaleOffset(ovrEye_Left, ltexsize, lscale, loffset);
1298 
1299  Vector2f rscale;
1300  Vector2f roffset;
1301  oculusObj->GetStereoConfigUvScaleOffset(ovrEye_Right, rtexsize, rscale, roffset);
1302 
1303  int tuple = MMmalloc(m, 4, TYPETAB);
1304  int ltscale = MMmalloc(m, 2, TYPETAB);
1305  int ltoffset = MMmalloc(m, 2, TYPETAB);
1306  int rtscale = MMmalloc(m, 2, TYPETAB);
1307  int rtoffset = MMmalloc(m, 2, TYPETAB);
1308 
1309  if ((tuple==NIL) || (ltscale==NIL) || (ltoffset==NIL) || (rtscale==NIL) || (rtoffset==NIL))
1310  {
1311  MMset(m, 0, NIL);
1312  return MERRMEM;
1313  }
1314 
1315  MMstore(m, ltscale, 0, FTOM(lscale.x));
1316  MMstore(m, ltscale, 1, FTOM(lscale.y));
1317 
1318  MMstore(m, ltoffset, 0, FTOM(loffset.x));
1319  MMstore(m, ltoffset, 1, FTOM(loffset.y));
1320 
1321  MMstore(m, rtscale, 0, FTOM(rscale.x));
1322  MMstore(m, rtscale, 1, FTOM(rscale.y));
1323 
1324  MMstore(m, rtoffset, 0, FTOM(roffset.x));
1325  MMstore(m, rtoffset, 1, FTOM(roffset.y));
1326 
1327  MMstore(m, tuple, 0, PTOM(ltscale));
1328  MMstore(m, tuple, 1, PTOM(ltoffset));
1329  MMstore(m, tuple, 2, PTOM(rtscale));
1330  MMstore(m, tuple, 3, PTOM(rtoffset));
1331  MMset(m, 0, PTOM(tuple));
1332 
1333 #ifdef _SCOL_DEBUG_
1334  MMechostr(MSKDEBUG,"ok\n");
1335 #endif
1336  return 0;
1337 }
1338 
1347 {
1348 #ifdef _SCOL_DEBUG_
1349  MMechostr(MSKDEBUG,"_GetOculusDeformationMeshes\n");
1350 #endif
1351 
1352  int oculusTab = MMget(m, 0);
1353  if (oculusTab == NIL)
1354  {
1355  MMset(m, 0, NIL);
1356  return 0;
1357  }
1358 
1359  sOculus* oculusObj = (sOculus*) MMfetch(m, MTOP(oculusTab), 0);
1360  if (!oculusObj || !oculusObj->IsConnected())
1361  {
1362  MMset(m, 0, NIL);
1363  return 0;
1364  }
1365 
1366  ovrDistortionMesh lmesh;
1367  ovrDistortionMesh rmesh;
1368  oculusObj->GetStereoConfigDistortionMesh(ovrEye_Left, lmesh);
1369  oculusObj->GetStereoConfigDistortionMesh(ovrEye_Right, rmesh);
1370 
1371  //remove parameter
1372  MMpull(m);
1373 
1374  int k;
1375  for(unsigned int i = 0; i < lmesh.VertexCount; i++ )
1376  {
1377  ovrDistortionVertex v = lmesh.pVertexData[i];
1378  float vig = std::max(v.VignetteFactor, (float)0.0f);
1379 
1380  //vertice
1381  MMpush(m, FTOM(v.ScreenPosNDC.x));
1382  MMpush(m, FTOM(v.ScreenPosNDC.y));
1383  MMpush(m, FTOM(0.0f));
1384  if(MMpush(m, ITOM(3)))
1385  return MERRMEM;
1386  if(k=MBdeftab(m))
1387  return k;
1388 
1389  //uvs list
1390  MMpush(m, FTOM(v.TanEyeAnglesR.x));
1391  MMpush(m, FTOM(v.TanEyeAnglesR.y));
1392  if(MMpush(m, ITOM(2)))
1393  return MERRMEM;
1394  if(k=MBdeftab(m))
1395  return k;
1396 
1397  MMpush(m, FTOM(v.TanEyeAnglesG.x));
1398  MMpush(m, FTOM(v.TanEyeAnglesG.y));
1399  if(MMpush(m, ITOM(2)))
1400  return MERRMEM;
1401  if(k=MBdeftab(m))
1402  return k;
1403 
1404  MMpush(m, FTOM(v.TanEyeAnglesB.x));
1405  MMpush(m, FTOM(v.TanEyeAnglesB.y));
1406  if(MMpush(m, ITOM(2)))
1407  return MERRMEM;
1408  if(k=MBdeftab(m))
1409  return k;
1410 
1411  //end uv list
1412  if(MMpush(m,NIL))
1413  return MERRMEM;
1414 
1415  //uv1
1416  if(MMpush(m, ITOM(2)))
1417  return MERRMEM;
1418  if(k=MBdeftab(m))
1419  return k;
1420 
1421  //uv2
1422  if(MMpush(m, ITOM(2)))
1423  return MERRMEM;
1424  if(k=MBdeftab(m))
1425  return k;
1426 
1427  //uv3
1428  if(MMpush(m, ITOM(2)))
1429  return MERRMEM;
1430  if(k=MBdeftab(m))
1431  return k;
1432 
1433  // vig
1434  if(MMpush(m, FTOM(vig)))
1435  return MERRMEM;
1436 
1437  //warp
1438  if(MMpush(m, FTOM(v.TimeWarpFactor)))
1439  return MERRMEM;
1440 
1441  // vertex uvlist
1442  if(MMpush(m, ITOM(4)))
1443  return MERRMEM;
1444 
1445  if(k=MBdeftab(m))
1446  return k;
1447  }
1448 
1449  //end v list
1450  if(MMpush(m,NIL))
1451  return MERRMEM;
1452 
1453  for(unsigned int i = 0; i < lmesh.VertexCount; i++)
1454  {
1455  if(MMpush(m, ITOM(2)))
1456  return MERRMEM;
1457  if(k=MBdeftab(m))
1458  return k;
1459  }
1460 
1461  for(unsigned int i = 0; i < lmesh.IndexCount; i++ )
1462  {
1463  if(MMpush(m, ITOM(lmesh.pIndexData[i])))
1464  return MERRMEM;
1465  }
1466 
1467  // end index list
1468  if(MMpush(m,NIL))
1469  return MERRMEM;
1470 
1471  for(unsigned int i = 0; i < lmesh.IndexCount; i++ )
1472  {
1473  if(MMpush(m, ITOM(2)))
1474  return MERRMEM;
1475  if(k=MBdeftab(m))
1476  return k;
1477  }
1478 
1479  //end of left mesh tuple
1480  if(MMpush(m, ITOM(2)))
1481  return MERRMEM;
1482  if(k=MBdeftab(m))
1483  return k;
1484 
1485  ovrHmd_DestroyDistortionMesh(&lmesh);
1486 
1487  for(unsigned int i = 0; i < rmesh.VertexCount; i++ )
1488  {
1489  ovrDistortionVertex v = rmesh.pVertexData[i];
1490  float vig = std::max(v.VignetteFactor, (float)0.0f);
1491 
1492  //vertice
1493  MMpush(m, FTOM(v.ScreenPosNDC.x));
1494  MMpush(m, FTOM(v.ScreenPosNDC.y));
1495  MMpush(m, FTOM(0.0f));
1496  if(MMpush(m, ITOM(3)))
1497  return MERRMEM;
1498  if(k=MBdeftab(m))
1499  return k;
1500 
1501  //uvs list
1502  MMpush(m, FTOM(v.TanEyeAnglesR.x));
1503  MMpush(m, FTOM(v.TanEyeAnglesR.y));
1504  if(MMpush(m, ITOM(2)))
1505  return MERRMEM;
1506  if(k=MBdeftab(m))
1507  return k;
1508 
1509  MMpush(m, FTOM(v.TanEyeAnglesG.x));
1510  MMpush(m, FTOM(v.TanEyeAnglesG.y));
1511  if(MMpush(m, ITOM(2)))
1512  return MERRMEM;
1513  if(k=MBdeftab(m))
1514  return k;
1515 
1516  MMpush(m, FTOM(v.TanEyeAnglesB.x));
1517  MMpush(m, FTOM(v.TanEyeAnglesB.y));
1518  if(MMpush(m, ITOM(2)))
1519  return MERRMEM;
1520  if(k=MBdeftab(m))
1521  return k;
1522 
1523  //end uv list
1524  if(MMpush(m,NIL))
1525  return MERRMEM;
1526 
1527  //uv1
1528  if(MMpush(m, ITOM(2)))
1529  return MERRMEM;
1530  if(k=MBdeftab(m))
1531  return k;
1532 
1533  //uv2
1534  if(MMpush(m, ITOM(2)))
1535  return MERRMEM;
1536  if(k=MBdeftab(m))
1537  return k;
1538 
1539  //uv3
1540  if(MMpush(m, ITOM(2)))
1541  return MERRMEM;
1542  if(k=MBdeftab(m))
1543  return k;
1544 
1545  // vig
1546  if(MMpush(m, FTOM(vig)))
1547  return MERRMEM;
1548 
1549  //warp
1550  if(MMpush(m, FTOM(v.TimeWarpFactor)))
1551  return MERRMEM;
1552 
1553  // vertex uvlist
1554  if(MMpush(m, ITOM(4)))
1555  return MERRMEM;
1556 
1557  if(k=MBdeftab(m))
1558  return k;
1559  }
1560 
1561  //end v list
1562  if(MMpush(m,NIL))
1563  return MERRMEM;
1564 
1565  for(unsigned int i = 0; i < rmesh.VertexCount; i++)
1566  {
1567  if(MMpush(m, ITOM(2)))
1568  return MERRMEM;
1569  if(k=MBdeftab(m))
1570  return k;
1571  }
1572 
1573  for(unsigned int i = 0; i < rmesh.IndexCount; i++ )
1574  {
1575  if(MMpush(m, ITOM(rmesh.pIndexData[i])))
1576  return MERRMEM;
1577  }
1578 
1579  // end index list
1580  if(MMpush(m,NIL))
1581  return MERRMEM;
1582 
1583  for(unsigned int i = 0; i < rmesh.IndexCount; i++ )
1584  {
1585  if(MMpush(m, ITOM(2)))
1586  return MERRMEM;
1587  if(k=MBdeftab(m))
1588  return k;
1589  }
1590 
1591  //end of right mesh tuple
1592  if(MMpush(m, ITOM(2)))
1593  return MERRMEM;
1594  if(k=MBdeftab(m))
1595  return k;
1596 
1597  ovrHmd_DestroyDistortionMesh(&rmesh);
1598 
1599  //final tuple
1600  if(MMpush(m, ITOM(2)))
1601  return MERRMEM;
1602  if(k=MBdeftab(m))
1603  return k;
1604 
1605 #ifdef _SCOL_DEBUG_
1606  MMechostr(MSKDEBUG,"ok\n");
1607 #endif
1608  return 0;
1609 }
1610 
1619 {
1620 #ifdef _SCOL_DEBUG_
1621  MMechostr(MSKDEBUG,"_GetOculusWindowSetting\n");
1622 #endif
1623 
1624  int oculusTab = MMget(m, 0);
1625  if (oculusTab == NIL)
1626  {
1627  MMset(m, 0, NIL);
1628  return 0;
1629  }
1630 
1631  sOculus* oculusObj = (sOculus*) MMfetch(m, MTOP(oculusTab), 0);
1632  if (!oculusObj || !oculusObj->IsConnected())
1633  {
1634  MMset(m, 0, NIL);
1635  return 0;
1636  }
1637 
1638  Sizei msize(1280, 1024);
1639  Vector2i mpos(0, 0);
1640  int index = 0;
1641 
1642  oculusObj->GetWindowPosAndSize(mpos, msize, index);
1643 
1644  int tuple = MMmalloc(m, 3, TYPETAB);
1645  int tpos = MMmalloc(m, 2, TYPETAB);
1646  int tsize = MMmalloc(m, 2, TYPETAB);
1647  if ((tuple==NIL) || (tpos==NIL) || (tsize==NIL))
1648  {
1649  MMset(m, 0, NIL);
1650  return MERRMEM;
1651  }
1652 
1653  MMstore(m, tpos, 0, ITOM(mpos.x));
1654  MMstore(m, tpos, 1, ITOM(mpos.y));
1655 
1656  MMstore(m, tsize, 0, ITOM(msize.w));
1657  MMstore(m, tsize, 1, ITOM(msize.h));
1658 
1659  MMstore(m, tuple, 0, PTOM(tpos));
1660  MMstore(m, tuple, 1, PTOM(tsize));
1661  MMstore(m, tuple, 2, ITOM(index));
1662  MMset(m, 0, PTOM(tuple));
1663 
1664 #ifdef _SCOL_DEBUG_
1665  MMechostr(MSKDEBUG,"ok\n");
1666 #endif
1667  return 0;
1668 }
1669 
1670 /* Callbacks */
1671 int getOculusConnectedCb(mmachine m, UINT id, LONG param)
1672 {
1673  int k = 0;
1674  sOculus* oculusObj = (sOculus*)id;
1675 
1676  if (!oculusObj)
1677  return 0;
1678 
1679  // OBJbeginreflex(mmachine, objecttype, objectptr, cbtype)
1680  if (OBJbeginreflex(m, OBJ_OCULUS_SCOL, (int)oculusObj, SCOL_OCULUS_CONNECTED_CB))
1681  return 0;
1682 
1683  k=OBJcallreflex(m, 0);
1684  return k;
1685 }
1686 
1687 int getOculusDisconnectedCb(mmachine m, UINT id, LONG param)
1688 {
1689  int k = 0;
1690  sOculus* oculusObj = (sOculus*)id;
1691 
1692  if (!oculusObj)
1693  return 0;
1694 
1695  // OBJbeginreflex(mmachine, objecttype, objectptr, cbtype)
1696  if (OBJbeginreflex(m, OBJ_OCULUS_SCOL, (int)oculusObj, SCOL_OCULUS_DISCONNECTED_CB))
1697  return 0;
1698 
1699  k=OBJcallreflex(m, 0);
1700  return k;
1701 }
1702 
1706 char* mOCULUSname[]=
1707 {
1708  "ObjOculus",
1709 
1710  "_CRoculusDevice",
1711  "_DSoculusDevice",
1712  "_GetOculusOrientation",
1713  "_GetOculusPredictedOrientation",
1714  "_GetOculusYawPitchRoll",
1715  "_GetOculusPredictedYawPitchRoll",
1716  "_GetOculusAcceleration",
1717  "_GetOculusPosition",
1718  "_GetOculusStereoConfig",
1719  "_GetOculusAspectRatio",
1720  "_GetOculusIPD",
1721  "_GetOculusFovY",
1722  "_GetOculusProjectionMatrix",
1723  "_GetOculusTimeWarpMatrix",
1724  "_GetOculusFovTextureSize",
1725  "_GetOculusUvConfig",
1726  "_GetOculusDeformationMeshes",
1727  "_GetOculusWindowSetting",
1728  "_ResetOculusDevice",
1729  "_UpdateOculusLatency",
1730  "_StartUpdateOculus",
1731  "_EndUpdateOculus",
1732  "_SetOculusLowPersistance",
1733  "_GetOculusLowPersistance",
1734  "_GetOculusDeviceType"
1735 };
1736 
1740 #define NOCULUSPKG (sizeof(mOCULUSname)/sizeof(char*))
1741 
1745 int (*mOCULUSfun[NOCULUSPKG])(mmachine m)=
1746 {
1747  NULL, //ObjOculus
1748 
1759  _GetOculusIPD,
1774 };
1775 
1779 int mOCULUSnarg[NOCULUSPKG]=
1780 {
1781  TYPTYPE, //ObjOculus
1782 
1783  5, //_CRoculusDevice
1784  1, //_DSoculusDevice
1785  1, //_GetOculusOrientation
1786  1, //_GetOculusPredictedOrientation
1787  1, //_GetOculusYawPitchRoll
1788  1, //_GetOculusPredictedYawPitchRoll
1789  1, //_GetOculuAcceleration
1790  1, //_GetOculusPosition
1791  1, //_GetOculusStereoConfig
1792  1, //_GetOculusAspectRatio
1793  1, //_GetOculusIPD
1794  1, //_GetOculusFovY
1795  3, //_GetOculusProjectionMatrix
1796  1, //_GetOculusTimeWarpMatrix
1797  1, //_GetOculusFovTextureSize
1798  3, //_GetOculusUvConfig
1799  1, //_GetOculusDeformationMeshes
1800  1, //_GetOculusWindowSetting
1801  1, //_ResetOculusDevice
1802  1, //_UpdateOculusLatency
1803  1, //_StartUpdateOculus
1804  1, //_EndUpdateOculus
1805  2, //_SetOculusLowPersistance
1806  1, //_GetOculusLowPersistance
1807  1 //_GetOculusDeviceType
1808 };
1809 
1813 char* mOCULUStype[NOCULUSPKG]=
1814 {
1815  NULL, //ObjOculus
1816 
1817  "fun [Chn fun [ObjOculus u0] u1 u0 fun [ObjOculus u2] u3 u2] ObjOculus", //_CRoculusDevice
1818  "fun [ObjOculus] I", //_DSoculusDevice
1819  "fun [ObjOculus] [F F F F]", //_GetOculusOrientation
1820  "fun [ObjOculus] [F F F F]", //_GetOculusPredictedOrientation
1821  "fun [ObjOculus] [F F F]", //_GetOculusYawPitchRoll
1822  "fun [ObjOculus] [F F F]", //_GetOculusPredictedYawPitchRoll
1823  "fun [ObjOculus] [F F F]", //_GetOculuAcceleration
1824  "fun [ObjOculus] [F F F]", //_GetOculusPosition
1825  "fun [ObjOculus] [F F F F F [F F F F] [F F F F]]", //_GetOculusStereoConfig
1826  "fun [ObjOculus] F", //_GetOculusAspectRatio
1827  "fun [ObjOculus] F", //_GetOculusIPD
1828  "fun [ObjOculus] F", //_GetOculusFovY
1829  "fun [ObjOculus 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]]]", //_GetOculusProjectionMatrix
1830  "fun [ObjOculus] [[[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 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]]]", //_GetOculusTimeWarpMatrix
1831  "fun [ObjOculus] [[I I] [I I]]", //_GetOculusFovTextureSize
1832  "fun [ObjOculus [I I] [I I]] [[F F] [F F] [F F] [F F]]", //_GetOculusUvConfig
1833  "fun [ObjOculus] [[[[[F F F] [[F F] r1] F F] r1] [I r1]] [[[[F F F] [[F F] r1] F F] r1] [I r1]]]", //_GetOculusDeformationMeshes
1834  "fun [ObjOculus] [[I I] [I I] I]", //_GetOculusWindowSetting
1835  "fun [ObjOculus] I", //_ResetOculusDevice
1836  "fun [ObjOculus] I", //_UpdateOculusLatency
1837  "fun [ObjOculus] I", //_StartUpdateOculus
1838  "fun [ObjOculus] I", //_EndUpdateOculus
1839  "fun [ObjOculus I] I", //_SetOculusLowPersistance
1840  "fun [ObjOculus] I", //_GetOculusLowPersistance
1841  "fun [ObjOculus] I" //_GetOculusDeviceType
1842 };
1843 
1844 
1845 // Everything inside _cond and _endcond is ignored by doxygen
1847 
1852 int LoadOCULUS(mmachine m)
1853 {
1854  int k = 0;
1855 
1856  MMechostr(MSKDEBUG,"\n" );
1857  MMechostr(MSKDEBUG," > Loading OCULUS Support\n");
1858 
1859  // Declare a new type of object ("ObjOculus")
1860  OBJ_OCULUS_SCOL = OBJregister(2 /*nb of callback*/, 0, destroyOCULUSObj, "OBJ_OCULUS_SCOL");
1861  k = PKhardpak(m, "mOCULUS.pkg-1.0", NOCULUSPKG, mOCULUSname, mOCULUSfun, mOCULUSnarg, mOCULUStype);
1862 
1863  OCULUS_CONNECTED_CB = OBJgetUserEvent();
1864  OBJdefEvent(OCULUS_CONNECTED_CB, (int (__cdecl *)(struct Mmachine*, UINT, LONG))getOculusConnectedCb);
1865 
1866  OCULUS_DISCONNECTED_CB = OBJgetUserEvent();
1867  OBJdefEvent(OCULUS_DISCONNECTED_CB, (int (__cdecl *)(struct Mmachine*, UINT, LONG))getOculusDisconnectedCb);
1868 
1869  MMechostr(MSKDEBUG," > Successfully Loaded\n\n");
1870  return k;
1871 }
1872 
1873 int CloseOCULUS()
1874 {
1875  MMechostr(MSKDEBUG,"\n" );
1876  MMechostr(MSKDEBUG," > Unloading OCULUS Support\n");
1877 
1878  MMechostr(MSKDEBUG," > Successfully unloaded\n\n");
1879  return 0;
1880 }
1881 
1883 
1884 
1889 extern "C"
1890 #if SCOL_PLATFORM == SCOL_PLATFORM_WINDOWS
1891 __declspec (dllexport)
1892 #endif
1893 int ScolLoadPlugin(mmachine m, cbmachine w)
1894 {
1895  SCOLinitplugin(w);
1896 
1897  // Get Scol window handle (for message callback)
1898  HScol = (HWND)SCgetExtra("hscol");
1899 
1900  return LoadOCULUS(m);
1901 }
1902 
1907 extern "C"
1908 #if SCOL_PLATFORM == SCOL_PLATFORM_WINDOWS
1909 __declspec (dllexport)
1910 #endif
1911 int ScolUnloadPlugin()
1912 {
1913  return CloseOCULUS();
1914 }