32 #include <scolPlugin.h>
39 int OCULUS_CONNECTED_CB;
40 int SCOL_OCULUS_CONNECTED_CB = 0;
42 int OCULUS_DISCONNECTED_CB;
43 int SCOL_OCULUS_DISCONNECTED_CB = 1;
66 int destroyOCULUSObj(mmachine m,
int handsys,
int handscol)
70 if (oculusObj == NULL)
77 MMstore(m, MTOP(handscol), 0, NULL);
80 SAFE_DELETE(oculusObj);
83 MMechostr(MSKDEBUG,
"ObjOculus destroyed.\n");
103 MMechostr(0,
"_CRoculusDevice\n");
108 int pUserd = MMpull(m);
109 int pCbkd = MMpull(m);
110 int pUserc = MMpull(m);
111 int pCbkc = MMpull(m);
114 int channel = MMget(m, 0);
119 MMechostr(MSKDEBUG,
"_CRoculusDevice : Channel NIL\n");
124 if (oculusObj == NULL)
126 MMechostr(MSKDEBUG,
"_CRoculusDevice : oculusObj failed\n");
132 int oculusTab = MMmalloc(m, 1, TYPETAB);
133 if (oculusTab == NIL)
135 MMechostr(MSKDEBUG,
"_CRoculusDevice : MMmalloc failed\n");
136 SAFE_DELETE(oculusObj);
141 MMstore(m, oculusTab, 0, (
int)oculusObj);
142 MMpush(m, PTOM(oculusTab));
145 k = OBJcreate(m, OBJ_OCULUS_SCOL, (
int)oculusObj, NULL, NULL);
147 if ((k = MMpush(m, pCbkc)))
return k;
148 if ((k = MMpush(m, pUserc)))
return k;
149 if ((k = OBJaddreflex(m, OBJ_OCULUS_SCOL, SCOL_OCULUS_CONNECTED_CB)))
return k;
151 if ((k = MMpush(m, pCbkd)))
return k;
152 if ((k = MMpush(m, pUserd)))
return k;
153 if ((k = OBJaddreflex(m, OBJ_OCULUS_SCOL, SCOL_OCULUS_DISCONNECTED_CB)))
return k;
155 oculusObj->Connect();
174 MMechostr(MSKDEBUG,
"_DSoculusDevice\n");
177 int oculusTab = MMget(m, 0);
178 if (oculusTab == NIL)
184 OBJdelTM(m, OBJ_OCULUS_SCOL, oculusTab);
185 MMset(m, 0, ITOM(0));
188 MMechostr(MSKDEBUG,
"ok\n");
203 MMechostr(MSKDEBUG,
"_GetOculusOrientation\n");
206 int oculusTab = MMget(m, 0);
207 if (oculusTab == NIL)
220 Quatf quat = oculusObj->GetSensorOrientation();
222 int tuple = MMmalloc(m, 4, TYPETAB);
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));
235 MMechostr(MSKDEBUG,
"ok\n");
250 MMechostr(MSKDEBUG,
"_GetOculusPredictedOrientation\n");
253 int oculusTab = MMget(m, 0);
254 if (oculusTab == NIL)
267 Quatf quat = oculusObj->GetSensorOrientation();
269 int tuple = MMmalloc(m, 4, TYPETAB);
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));
282 MMechostr(MSKDEBUG,
"ok\n");
297 MMechostr(MSKDEBUG,
"_GetOculusYawPitchRoll\n");
300 int oculusTab = MMget(m, 0);
301 if (oculusTab == NIL)
314 Vector3f ypr = oculusObj->GetSensorYawPitchRoll();
316 int tuple = MMmalloc(m, 3, TYPETAB);
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));
328 MMechostr(MSKDEBUG,
"ok\n");
343 MMechostr(MSKDEBUG,
"_GetOculusPredictedYawPitchRoll\n");
346 int oculusTab = MMget(m, 0);
347 if (oculusTab == NIL)
360 Vector3f ypr = oculusObj->GetSensorYawPitchRoll();
362 int tuple = MMmalloc(m, 3, TYPETAB);
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));
374 MMechostr(MSKDEBUG,
"ok\n");
389 MMechostr(MSKDEBUG,
"_GetOculusAcceleration\n");
392 int oculusTab = MMget(m, 0);
393 if (oculusTab == NIL)
406 Vector3f acc = oculusObj->GetSensorAcceleration();
408 int tuple = MMmalloc(m, 3, TYPETAB);
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));
420 MMechostr(MSKDEBUG,
"ok\n");
435 MMechostr(MSKDEBUG,
"_GetOculusPosition\n");
438 int oculusTab = MMget(m, 0);
439 if (oculusTab == NIL)
452 Vector3f pos = oculusObj->GetSensorPosition();
454 int tuple = MMmalloc(m, 3, TYPETAB);
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));
466 MMechostr(MSKDEBUG,
"ok\n");
482 MMechostr(MSKDEBUG,
"_GetOculusStereoConfig\n");
485 int oculusTab = MMget(m, 0);
486 if (oculusTab == NIL)
499 int distortion = MMmalloc(m, 4, TYPETAB);
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));
511 int chromaAb = MMmalloc(m, 4, TYPETAB);
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));
523 int tuple = MMmalloc(m, 7, TYPETAB);
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));
537 MMset(m, 0, PTOM(tuple));
540 MMechostr(MSKDEBUG,
"ok\n");
555 MMechostr(MSKDEBUG,
"_GetOculusAspectRatio\n");
558 int oculusTab = MMget(m, 0);
559 if (oculusTab == NIL)
572 MMset(m, 0, FTOM(oculusObj->GetStereoConfigAspect()));
575 MMechostr(MSKDEBUG,
"ok\n");
590 MMechostr(MSKDEBUG,
"_GetOculusIPD\n");
593 int oculusTab = MMget(m, 0);
594 if (oculusTab == NIL)
607 MMset(m, 0, FTOM(oculusObj->GetStereoIPD()));
610 MMechostr(MSKDEBUG,
"ok\n");
625 MMechostr(MSKDEBUG,
"_GetOculusFovY\n");
628 int oculusTab = MMget(m, 0);
629 if (oculusTab == NIL)
642 MMset(m, 0, FTOM(oculusObj->GetStereoConfigFovY()));
645 MMechostr(MSKDEBUG,
"ok\n");
660 MMechostr(MSKDEBUG,
"_ResetOculusDevice\n");
663 int oculusTab = MMget(m, 0);
664 if (oculusTab == NIL)
677 oculusObj->ResetSensor();
679 MMset(m, 0, ITOM(0));
682 MMechostr(MSKDEBUG,
"ok\n");
698 MMechostr(MSKDEBUG,
"_UpdateOculusLatency\n");
715 MMechostr(MSKDEBUG,
"_StartUpdateOculus\n");
718 int oculusTab = MMget(m, 0);
719 if (oculusTab == NIL)
726 if (!oculusObj || !oculusObj->IsConnected())
731 bool ret = oculusObj->UpdateStart();
733 MMset(m, 0, ITOM((ret) ? 1 : 0));
747 MMechostr(MSKDEBUG,
"_EndUpdateOculus\n");
750 int oculusTab = MMget(m, 0);
751 if (oculusTab == NIL)
758 if (!oculusObj || !oculusObj->IsConnected())
763 oculusObj->UpdateEnd();
765 MMset(m, 0, ITOM(0));
780 MMechostr(MSKDEBUG,
"_SetOculusLowPersistance\n");
783 int istate = MMpull(m);
784 int oculusTab = MMget(m, 0);
785 if (oculusTab == NIL)
792 if (!oculusObj || !oculusObj->IsConnected())
800 state = (MTOI(istate) > 0) ?
true :
false;
802 oculusObj->SetLowPersistance(state);
804 MMset(m, 0, ITOM(0));
818 MMechostr(MSKDEBUG,
"_GetOculusLowPersistance\n");
821 int oculusTab = MMget(m, 0);
822 if (oculusTab == NIL)
829 if (!oculusObj || !oculusObj->IsConnected())
835 MMset(m, 0, ITOM((oculusObj->GetLowPersistance()) ? 1 : 0));
849 MMechostr(MSKDEBUG,
"_GetOculusDeviceType\n");
852 int oculusTab = MMget(m, 0);
853 if (oculusTab == NIL)
860 if (!oculusObj || !oculusObj->IsConnected())
866 MMset(m, 0, ITOM((
int)oculusObj->GetType()));
882 MMechostr(MSKDEBUG,
"_GetOculusProjectionMatrix\n");
885 int ifclip = MMpull(m);
886 int inclip = MMpull(m);
887 int oculusTab = MMget(m, 0);
888 if (oculusTab == NIL)
895 if (!oculusObj || !oculusObj->IsConnected())
901 float nearclip = 0.01f;
903 nearclip = MTOF(inclip);
905 float farclip = 10000.0f;
907 farclip = MTOF(ifclip);
912 oculusObj->GetProjectionMatrix(ovrEye_Left, nearclip, farclip, lmat);
913 oculusObj->GetProjectionMatrix(ovrEye_Right, nearclip, farclip, rmat);
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);
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);
928 if ((tuple==NIL) || (ltmat==NIL) || (ltmat1==NIL) || (ltmat2==NIL) || (ltmat3==NIL) || (ltmat4==NIL) || (rtmat==NIL) || (rtmat1==NIL) || (rtmat2==NIL) || (rtmat3==NIL) || (rtmat4==NIL))
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]));
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]));
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]));
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]));
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));
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]));
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]));
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]));
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]));
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));
984 MMstore(m, tuple, 0, PTOM(ltmat));
985 MMstore(m, tuple, 1, PTOM(rtmat));
986 MMset(m, 0, PTOM(tuple));
989 MMechostr(MSKDEBUG,
"ok\n");
1004 MMechostr(MSKDEBUG,
"_GetOculusTimeWarpMatrix\n");
1007 int oculusTab = MMget(m, 0);
1008 if (oculusTab == NIL)
1015 if (!oculusObj || !oculusObj->IsConnected())
1021 ovrMatrix4f lmat[2];
1022 ovrMatrix4f rmat[2];
1025 oculusObj->GetTimeWarpMatrix(ovrEye_Left, lmat);
1026 oculusObj->GetTimeWarpMatrix(ovrEye_Right, rmat);
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]));
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]));
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]));
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]));
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]));
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]));
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]));
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]));
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]));
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]));
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]));
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]));
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]));
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]));
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]));
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]));
1198 MMechostr(MSKDEBUG,
"ok\n");
1213 MMechostr(MSKDEBUG,
"_GetOculusFovTextureSize\n");
1216 int oculusTab = MMget(m, 0);
1217 if (oculusTab == NIL)
1224 if (!oculusObj || !oculusObj->IsConnected())
1230 Sizei lsize = oculusObj->GetStereoConfigFovTextureSize(ovrEye_Left);
1231 Sizei rsize = oculusObj->GetStereoConfigFovTextureSize(ovrEye_Right);
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))
1242 MMstore(m, ltsize, 0, ITOM(lsize.w));
1243 MMstore(m, ltsize, 1, ITOM(lsize.h));
1245 MMstore(m, rtsize, 0, ITOM(rsize.w));
1246 MMstore(m, rtsize, 1, ITOM(rsize.h));
1248 MMstore(m, tuple, 0, PTOM(ltsize));
1249 MMstore(m, tuple, 1, PTOM(rtsize));
1250 MMset(m, 0, PTOM(tuple));
1253 MMechostr(MSKDEBUG,
"ok\n");
1270 MMechostr(MSKDEBUG,
"_GetOculusUvConfig\n");
1273 int irsize = MMpull(m);
1274 int ilsize = MMpull(m);
1275 int oculusTab = MMget(m, 0);
1276 if (oculusTab == NIL || irsize == NIL || ilsize == NIL)
1283 if (!oculusObj || !oculusObj->IsConnected())
1289 ilsize = MTOP(ilsize);
1290 Sizei ltexsize(MTOI(MMfetch(m, ilsize, 0)), MTOI(MMfetch(m, ilsize, 1)));
1292 irsize = MTOP(irsize);
1293 Sizei rtexsize(MTOI(MMfetch(m, irsize, 0)), MTOI(MMfetch(m, irsize, 1)));
1297 oculusObj->GetStereoConfigUvScaleOffset(ovrEye_Left, ltexsize, lscale, loffset);
1301 oculusObj->GetStereoConfigUvScaleOffset(ovrEye_Right, rtexsize, rscale, roffset);
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);
1309 if ((tuple==NIL) || (ltscale==NIL) || (ltoffset==NIL) || (rtscale==NIL) || (rtoffset==NIL))
1315 MMstore(m, ltscale, 0, FTOM(lscale.x));
1316 MMstore(m, ltscale, 1, FTOM(lscale.y));
1318 MMstore(m, ltoffset, 0, FTOM(loffset.x));
1319 MMstore(m, ltoffset, 1, FTOM(loffset.y));
1321 MMstore(m, rtscale, 0, FTOM(rscale.x));
1322 MMstore(m, rtscale, 1, FTOM(rscale.y));
1324 MMstore(m, rtoffset, 0, FTOM(roffset.x));
1325 MMstore(m, rtoffset, 1, FTOM(roffset.y));
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));
1334 MMechostr(MSKDEBUG,
"ok\n");
1349 MMechostr(MSKDEBUG,
"_GetOculusDeformationMeshes\n");
1352 int oculusTab = MMget(m, 0);
1353 if (oculusTab == NIL)
1360 if (!oculusObj || !oculusObj->IsConnected())
1366 ovrDistortionMesh lmesh;
1367 ovrDistortionMesh rmesh;
1368 oculusObj->GetStereoConfigDistortionMesh(ovrEye_Left, lmesh);
1369 oculusObj->GetStereoConfigDistortionMesh(ovrEye_Right, rmesh);
1375 for(
unsigned int i = 0; i < lmesh.VertexCount; i++ )
1377 ovrDistortionVertex v = lmesh.pVertexData[i];
1378 float vig = std::max(v.VignetteFactor, (
float)0.0f);
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)))
1390 MMpush(m, FTOM(v.TanEyeAnglesR.x));
1391 MMpush(m, FTOM(v.TanEyeAnglesR.y));
1392 if(MMpush(m, ITOM(2)))
1397 MMpush(m, FTOM(v.TanEyeAnglesG.x));
1398 MMpush(m, FTOM(v.TanEyeAnglesG.y));
1399 if(MMpush(m, ITOM(2)))
1404 MMpush(m, FTOM(v.TanEyeAnglesB.x));
1405 MMpush(m, FTOM(v.TanEyeAnglesB.y));
1406 if(MMpush(m, ITOM(2)))
1416 if(MMpush(m, ITOM(2)))
1422 if(MMpush(m, ITOM(2)))
1428 if(MMpush(m, ITOM(2)))
1434 if(MMpush(m, FTOM(vig)))
1438 if(MMpush(m, FTOM(v.TimeWarpFactor)))
1442 if(MMpush(m, ITOM(4)))
1453 for(
unsigned int i = 0; i < lmesh.VertexCount; i++)
1455 if(MMpush(m, ITOM(2)))
1461 for(
unsigned int i = 0; i < lmesh.IndexCount; i++ )
1463 if(MMpush(m, ITOM(lmesh.pIndexData[i])))
1471 for(
unsigned int i = 0; i < lmesh.IndexCount; i++ )
1473 if(MMpush(m, ITOM(2)))
1480 if(MMpush(m, ITOM(2)))
1485 ovrHmd_DestroyDistortionMesh(&lmesh);
1487 for(
unsigned int i = 0; i < rmesh.VertexCount; i++ )
1489 ovrDistortionVertex v = rmesh.pVertexData[i];
1490 float vig = std::max(v.VignetteFactor, (
float)0.0f);
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)))
1502 MMpush(m, FTOM(v.TanEyeAnglesR.x));
1503 MMpush(m, FTOM(v.TanEyeAnglesR.y));
1504 if(MMpush(m, ITOM(2)))
1509 MMpush(m, FTOM(v.TanEyeAnglesG.x));
1510 MMpush(m, FTOM(v.TanEyeAnglesG.y));
1511 if(MMpush(m, ITOM(2)))
1516 MMpush(m, FTOM(v.TanEyeAnglesB.x));
1517 MMpush(m, FTOM(v.TanEyeAnglesB.y));
1518 if(MMpush(m, ITOM(2)))
1528 if(MMpush(m, ITOM(2)))
1534 if(MMpush(m, ITOM(2)))
1540 if(MMpush(m, ITOM(2)))
1546 if(MMpush(m, FTOM(vig)))
1550 if(MMpush(m, FTOM(v.TimeWarpFactor)))
1554 if(MMpush(m, ITOM(4)))
1565 for(
unsigned int i = 0; i < rmesh.VertexCount; i++)
1567 if(MMpush(m, ITOM(2)))
1573 for(
unsigned int i = 0; i < rmesh.IndexCount; i++ )
1575 if(MMpush(m, ITOM(rmesh.pIndexData[i])))
1583 for(
unsigned int i = 0; i < rmesh.IndexCount; i++ )
1585 if(MMpush(m, ITOM(2)))
1592 if(MMpush(m, ITOM(2)))
1597 ovrHmd_DestroyDistortionMesh(&rmesh);
1600 if(MMpush(m, ITOM(2)))
1606 MMechostr(MSKDEBUG,
"ok\n");
1621 MMechostr(MSKDEBUG,
"_GetOculusWindowSetting\n");
1624 int oculusTab = MMget(m, 0);
1625 if (oculusTab == NIL)
1632 if (!oculusObj || !oculusObj->IsConnected())
1638 Sizei msize(1280, 1024);
1639 Vector2i mpos(0, 0);
1642 oculusObj->GetWindowPosAndSize(mpos, msize, index);
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))
1653 MMstore(m, tpos, 0, ITOM(mpos.x));
1654 MMstore(m, tpos, 1, ITOM(mpos.y));
1656 MMstore(m, tsize, 0, ITOM(msize.w));
1657 MMstore(m, tsize, 1, ITOM(msize.h));
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));
1665 MMechostr(MSKDEBUG,
"ok\n");
1671 int getOculusConnectedCb(mmachine m, UINT
id, LONG param)
1680 if (OBJbeginreflex(m, OBJ_OCULUS_SCOL, (
int)oculusObj, SCOL_OCULUS_CONNECTED_CB))
1683 k=OBJcallreflex(m, 0);
1687 int getOculusDisconnectedCb(mmachine m, UINT
id, LONG param)
1696 if (OBJbeginreflex(m, OBJ_OCULUS_SCOL, (
int)oculusObj, SCOL_OCULUS_DISCONNECTED_CB))
1699 k=OBJcallreflex(m, 0);
1706 char* mOCULUSname[]=
1712 "_GetOculusOrientation",
1713 "_GetOculusPredictedOrientation",
1714 "_GetOculusYawPitchRoll",
1715 "_GetOculusPredictedYawPitchRoll",
1716 "_GetOculusAcceleration",
1717 "_GetOculusPosition",
1718 "_GetOculusStereoConfig",
1719 "_GetOculusAspectRatio",
1722 "_GetOculusProjectionMatrix",
1723 "_GetOculusTimeWarpMatrix",
1724 "_GetOculusFovTextureSize",
1725 "_GetOculusUvConfig",
1726 "_GetOculusDeformationMeshes",
1727 "_GetOculusWindowSetting",
1728 "_ResetOculusDevice",
1729 "_UpdateOculusLatency",
1730 "_StartUpdateOculus",
1732 "_SetOculusLowPersistance",
1733 "_GetOculusLowPersistance",
1734 "_GetOculusDeviceType"
1740 #define NOCULUSPKG (sizeof(mOCULUSname)/sizeof(char*))
1745 int (*mOCULUSfun[NOCULUSPKG])(mmachine m)=
1779 int mOCULUSnarg[NOCULUSPKG]=
1813 char* mOCULUStype[NOCULUSPKG]=
1817 "fun [Chn fun [ObjOculus u0] u1 u0 fun [ObjOculus u2] u3 u2] ObjOculus",
1818 "fun [ObjOculus] I",
1819 "fun [ObjOculus] [F F F F]",
1820 "fun [ObjOculus] [F F F F]",
1821 "fun [ObjOculus] [F F F]",
1822 "fun [ObjOculus] [F F F]",
1823 "fun [ObjOculus] [F F F]",
1824 "fun [ObjOculus] [F F F]",
1825 "fun [ObjOculus] [F F F F F [F F F F] [F F F F]]",
1826 "fun [ObjOculus] F",
1827 "fun [ObjOculus] F",
1828 "fun [ObjOculus] F",
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]]]",
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]]]",
1831 "fun [ObjOculus] [[I I] [I I]]",
1832 "fun [ObjOculus [I I] [I I]] [[F F] [F F] [F F] [F F]]",
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]]]",
1834 "fun [ObjOculus] [[I I] [I I] I]",
1835 "fun [ObjOculus] I",
1836 "fun [ObjOculus] I",
1837 "fun [ObjOculus] I",
1838 "fun [ObjOculus] I",
1839 "fun [ObjOculus I] I",
1840 "fun [ObjOculus] I",
1852 int LoadOCULUS(mmachine m)
1856 MMechostr(MSKDEBUG,
"\n" );
1857 MMechostr(MSKDEBUG,
" > Loading OCULUS Support\n");
1860 OBJ_OCULUS_SCOL = OBJregister(2 , 0, destroyOCULUSObj,
"OBJ_OCULUS_SCOL");
1861 k = PKhardpak(m,
"mOCULUS.pkg-1.0", NOCULUSPKG, mOCULUSname, mOCULUSfun, mOCULUSnarg, mOCULUStype);
1863 OCULUS_CONNECTED_CB = OBJgetUserEvent();
1864 OBJdefEvent(OCULUS_CONNECTED_CB, (
int (__cdecl *)(
struct Mmachine*, UINT, LONG))getOculusConnectedCb);
1866 OCULUS_DISCONNECTED_CB = OBJgetUserEvent();
1867 OBJdefEvent(OCULUS_DISCONNECTED_CB, (
int (__cdecl *)(
struct Mmachine*, UINT, LONG))getOculusDisconnectedCb);
1869 MMechostr(MSKDEBUG,
" > Successfully Loaded\n\n");
1875 MMechostr(MSKDEBUG,
"\n" );
1876 MMechostr(MSKDEBUG,
" > Unloading OCULUS Support\n");
1878 MMechostr(MSKDEBUG,
" > Successfully unloaded\n\n");
1890 #if SCOL_PLATFORM == SCOL_PLATFORM_WINDOWS
1891 __declspec (dllexport)
1893 int ScolLoadPlugin(mmachine m, cbmachine w)
1898 HScol = (HWND)SCgetExtra(
"hscol");
1900 return LoadOCULUS(m);
1908 #if SCOL_PLATFORM == SCOL_PLATFORM_WINDOWS
1909 __declspec (dllexport)
1911 int ScolUnloadPlugin()
1913 return CloseOCULUS();