static void mdlOutputs(SimStruct * S, int_T tid) { int_T id = ssGetIWorkValue(S, 0); int_T noBytes = ssGetIWorkValue(S, 1); int_T count; uint8_T *buffer = (uint8_T *)ssGetPWorkValue(S, 0); count = udpReceive(id, buffer, noBytes); *(ssGetOutputPortRealSignal(S, 1)) = !count; if (count == 0) memcpy((void *) ssGetOutputPortSignal(S, 0), (void *) (uint8_T *) buffer, noBytes); }
/* main loop */ static void mainLoop(void) { udpReceive(); if (recv_len != -1){ processMessage(); } ARUint8 *dataPtr; ARMarkerInfo *marker_info; int marker_num; int i, j, k; /* grab a video frame */ if ((dataPtr = (ARUint8 *)arVideoGetImage()) == NULL) { arUtilSleep(2); return; } if (count == 0) arUtilTimerReset(); count++; /*draw the video*/ argDrawMode2D(); argDispImage(dataPtr, 0, 0); glColor3f(1.0, 0.0, 0.0); glLineWidth(6.0); /* detect the markers in the video frame */ if (arDetectMarker(dataPtr, thresh, &marker_info, &marker_num) < 0) { cleanup(); exit(0); } for (i = 0; i < marker_num; i++) { argDrawSquare(marker_info[i].vertex, 0, 0); } for (i = 0; i < marker_num; i++) { } /* check for known patterns */ for (i = 0; i < objectnum; i++) { k = -1; for (j = 0; j < marker_num; j++) { if (object[i].id == marker_info[j].id) { /* you've found a pattern */ //printf("Found pattern: %d ",patt_id); glColor3f(0.0, 1.0, 0.0); argDrawSquare(marker_info[j].vertex, 0, 0); if (k == -1) k = j; else /* make sure you have the best pattern (highest confidence factor) */ if (marker_info[k].cf < marker_info[j].cf) k = j; } } if (k == -1) { object[i].visible = 0; //printf("object id = %d visibility - %d \n", object[i].id, object[i].visible); continue; } /* calculate the transform for each marker */ if (object[i].visible == 0) { arGetTransMat(&marker_info[k], object[i].marker_center, object[i].marker_width, object[i].trans); } else { arGetTransMatCont(&marker_info[k], object[i].trans, object[i].marker_center, object[i].marker_width, object[i].trans); } object[i].visible = 1; } ///code here arVideoCapNext(); /* draw the AR graphics */ draw(object, objectnum); /*swap the graphics buffers*/ argSwapBuffers(); }