Game Development Reference
In-Depth Information
The image returned by arVideoGetImage() is an array of bytes representing the pixels
encoded in the default pixel format defined by the toolkit. This format is defined at compile
time. For Android, it should be either RGB32 or RGBA32. Next, it detects any markers in the
video frame obtained from the previous step.
if( arDetectMarker(dataPtr, thresh, &marker_info, &marker_num) < 0 ) {
cleanup();
exit(0);
}
The API call arDetectMarker takes a pointer to the video frame, a threshold value for
detection, and returns information about all markers detected plus the number of detected
markers. With this information, it checks whether the marker (loaded in in the initialization
step and referenced by patt_id ) is present. If not, it renders the frame and returns.
Otherwise, the rendering process continues.
/* check for object visibility */
k = -1;
for( j = 0; j < marker_num; j++ ) {
if( patt_id == marker_info[j].id ) {
if( k == -1 ) k = j;
else if( marker_info[k].cf < marker_info[j].cf ) k = j;
}
}
if( k == -1 ) {
argSwapBuffers();
return;
}
Finally, the OpenGL transformation matrix between the marker and the camera is created.
Only then can the solid cube be drawn. The final step is to swap the OpenGL buffers, thus
rendering the whole thing on screen.
/* get the transformation between the marker and the real camera */
arGetTransMat(&marker_info[k], patt_center, patt_width, patt_trans);
/* draw the cude */
draw();
/* render */
argSwapBuffers();
Notice that the draw() function draws the cube using the call glutSolidCube() . As you can
see, this is a GLUT helper function that doesn't exist in GLES. In Android, the cube will have
to be drawn manually using GL API calls. This should be really simple.
Check out http://freeglut.sourceforge.net/docs/android.php for more information about
GLUT.
 
Search WWH ::




Custom Search