[artoolkit-commits] artoolkit/examples/twoView twoView.c,1.2,1.3
Optical marker tracking and overlay for augmented reality.
Brought to you by:
philip_lamb
From: Philip L. <phi...@us...> - 2004-11-30 04:06:15
|
Update of /cvsroot/artoolkit/artoolkit/examples/twoView In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26636 Modified Files: twoView.c Log Message: Bring twoView and simpleLite to same source base. Index: twoView.c =================================================================== RCS file: /cvsroot/artoolkit/artoolkit/examples/twoView/twoView.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** twoView.c 25 Nov 2004 21:42:30 -0000 1.2 --- twoView.c 30 Nov 2004 04:06:03 -0000 1.3 *************** *** 11,14 **** --- 11,34 ---- * */ + /* + * + * This file is part of ARToolKit. + * + * ARToolKit is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * ARToolKit is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ARToolKit; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + // ============================================================================ *************** *** 61,70 **** static GLuint *gDrawListBox = NULL; ! CONTEXT_INFO gContextsActive[CONTEXTSACTIVECOUNTMAX]; int gContextsActiveCount = 0; - static BOOL gAlwaysVisible = FALSE; // Setting this to true will make the program ignore - // events that tell it it is not visible. - // ARToolKit globals. static long gCallCountGetImage = 0; --- 81,87 ---- static GLuint *gDrawListBox = NULL; ! CONTEXT_INFO *gContextsActive; int gContextsActiveCount = 0; // ARToolKit globals. static long gCallCountGetImage = 0; *************** *** 76,80 **** // Other globals. static BOOL gDrawRotate = FALSE; ! static float gDrawRotateAngle; // For use in drawing. // ============================================================================ --- 93,97 ---- // Other globals. static BOOL gDrawRotate = FALSE; ! static float gDrawRotateAngle = 0; // For use in drawing. // ============================================================================ *************** *** 82,86 **** // ============================================================================ ! BOOL DrawCubeInit(int contextsActiveCountMax) { // Allocate room for display lists for all contexts. --- 99,103 ---- // ============================================================================ ! static BOOL DrawCubeInit(int contextsActiveCountMax) { // Allocate room for display lists for all contexts. *************** *** 93,97 **** } ! BOOL DrawCubeSetup(int contextIndex) { // Colour cube data. --- 110,114 ---- } ! static BOOL DrawCubeSetup(int contextIndex) { // Colour cube data. *************** *** 131,135 **** // Something to look at, draw a rotating colour cube. ! void DrawCube(int contextIndex) { // Draw the colour cube. --- 148,152 ---- // Something to look at, draw a rotating colour cube. ! static void DrawCube(int contextIndex) { // Draw the colour cube. *************** *** 142,146 **** } ! void DrawCubeUpdate(float timeDelta) { if (gDrawRotate) { --- 159,163 ---- } ! static void DrawCubeUpdate(float timeDelta) { if (gDrawRotate) { *************** *** 150,154 **** } ! BOOL DrawCubeCleanup(int contextIndex) { if (contextIndex >= gContextsActiveCount) return (FALSE); // Sanity check. --- 167,171 ---- } ! static BOOL DrawCubeCleanup(int contextIndex) { if (contextIndex >= gContextsActiveCount) return (FALSE); // Sanity check. *************** *** 163,167 **** } ! BOOL DrawCubeFinal(void) { if (!gDrawListBox) { --- 180,184 ---- } ! static BOOL DrawCubeFinal(void) { if (!gDrawListBox) { *************** *** 172,176 **** } ! // Function to clean up and then exit. static void Quit(void) { --- 189,194 ---- } ! // Function to clean up and then exit. Will be ! // installed by atexit() and called when program exit()s. static void Quit(void) { *************** *** 195,208 **** // Library finals (in reverse order to inits.) DrawCubeFinal(); - - // Unless we don't have an atexit() function, terminate by falling off end - // (since Quit is called by exit()'s exitfunc.) - #ifdef NOATEXIT - exit(0); - #endif } // Sets up fields ARTVideo, ARTCparam of gContextsActive[0] through gContextsActive[cameraCount - 1]. ! BOOL demoARSetupCameras(const int cameraCount, const unsigned char *cparam_names[], char *vconfs[]) { int i; --- 213,220 ---- // Library finals (in reverse order to inits.) DrawCubeFinal(); } // Sets up fields ARTVideo, ARTCparam of gContextsActive[0] through gContextsActive[cameraCount - 1]. ! static BOOL demoARSetupCameras(const int cameraCount, const unsigned char *cparam_names[], char *vconfs[]) { int i; *************** *** 242,246 **** } ! BOOL demoARSetupMarker(const unsigned char *patt_name, int *patt_id) { --- 254,258 ---- } ! static BOOL demoARSetupMarker(const unsigned char *patt_name, int *patt_id) { *************** *** 255,259 **** // Report state of ARToolKit global variables arFittingMode, // arImageProcMode, arglDrawMode, arTemplateMatchingMode, arMatchingPCAMode. ! void demoARDebugReportMode(void) { if(arFittingMode == AR_FITTING_TO_INPUT ) { --- 267,271 ---- // Report state of ARToolKit global variables arFittingMode, // arImageProcMode, arglDrawMode, arTemplateMatchingMode, arMatchingPCAMode. ! static void demoARDebugReportMode(void) { if(arFittingMode == AR_FITTING_TO_INPUT ) { *************** *** 311,330 **** } ! void Keyboard(unsigned char key, int x, int y) { ! int modifiers, shift, i; ! ! modifiers = glutGetModifiers(); ! shift = (modifiers & GLUT_ACTIVE_SHIFT); // Get status of shift key. switch (key) { ! case 0x1b: // Quit. case 'Q': case 'q': ! #ifdef NOATEXIT ! Quit(); ! #else ! exit(0); ! #endif // NOATEXIT break; case ' ': --- 323,335 ---- } ! static void Keyboard(unsigned char key, int x, int y) { ! int i; switch (key) { ! case 0x1B: // Quit. case 'Q': case 'q': ! exit(0); break; case ' ': *************** *** 345,414 **** gContextsActive[i].callCountMarkerDetect = 0; } demoARDebugReportMode(); break; case 'R': case 'r': - #ifdef AR_OPENGL_TEXTURE_RECTANGLE arglTexRectangle = !arglTexRectangle; fprintf(stderr, "Toggled arglTexRectangle to %d.\n", arglTexRectangle); - #endif // AR_OPENGL_TEXTURE_RECTANGLE break; ! case 'T': ! case 't': ! #ifdef APPLE_TEXTURE_FAST_TRANSFER ! # ifdef GL_APPLE_client_storage ! arglAppleClientStorage = !arglAppleClientStorage; ! fprintf(stderr, "Toggled arglAppleClientStorage to %d.\n", arglAppleClientStorage); ! # endif ! #endif ! break; ! case 'Y': ! case 'y': ! #ifdef APPLE_TEXTURE_FAST_TRANSFER ! # ifdef GL_APPLE_texture_range ! arglAppleTextureRange = !arglAppleTextureRange; ! fprintf(stderr, "Toggled arglAppleTextureRange to %d.\n", arglAppleTextureRange); ! # endif ! #endif ! break; ! case 'U': ! case 'u': ! #ifdef APPLE_TEXTURE_FAST_TRANSFER ! # ifdef GL_APPLE_texture_range ! fprintf(stderr, "Toggled arglAppleTextureRangeStorageHint to "); ! switch (arglAppleTextureRangeStorageHint) { ! case GL_STORAGE_PRIVATE_APPLE: ! arglAppleTextureRangeStorageHint = GL_STORAGE_SHARED_APPLE; ! fprintf(stderr, "GL_STORAGE_SHARED_APPLE.\n"); ! break; ! case GL_STORAGE_SHARED_APPLE: ! arglAppleTextureRangeStorageHint = GL_STORAGE_CACHED_APPLE; ! fprintf(stderr, "GL_STORAGE_CACHED_APPLE.\n"); ! break; ! case GL_STORAGE_CACHED_APPLE: ! default: ! arglAppleTextureRangeStorageHint = GL_STORAGE_PRIVATE_APPLE; ! fprintf(stderr, "GL_STORAGE_PRIVATE_APPLE.\n"); ! break; ! } ! # endif ! #endif ! break; case '?': case '/': ! fprintf(stderr,"Keys:\n"); ! fprintf(stderr," q or [esc] Quit demo.\n"); ! fprintf(stderr," c Change arglDrawMode and arglTexmapMode.\n"); ! fprintf(stderr," r Toggle arglTexRectangle.\n"); ! fprintf(stderr," ? or / Show this help.\n"); ! #ifdef APPLE_TEXTURE_FAST_TRANSFER ! # ifdef GL_APPLE_client_storage ! fprintf(stderr," t Toggle arglAppleClientStorage.\n"); ! # endif // GL_APPLE_client_storage ! # ifdef GL_APPLE_texture_range ! fprintf(stderr," y Toggle arglAppleTextureRange.\n"); ! fprintf(stderr," u Toggle arglAppleTextureRangeStorageHint.\n"); ! # endif // GL_APPLE_texture_range ! #endif APPLE_TEXTURE_FAST_TRANSFER default: break; --- 350,375 ---- gContextsActive[i].callCountMarkerDetect = 0; } + arUtilTimerReset(); demoARDebugReportMode(); break; + #ifdef AR_OPENGL_TEXTURE_RECTANGLE case 'R': case 'r': arglTexRectangle = !arglTexRectangle; fprintf(stderr, "Toggled arglTexRectangle to %d.\n", arglTexRectangle); break; ! #endif // AR_OPENGL_TEXTURE_RECTANGLE case '?': case '/': ! printf("Keys:\n"); ! printf(" q or [esc] Quit demo.\n"); ! printf(" c Change arglDrawMode and arglTexmapMode.\n"); ! #ifdef AR_OPENGL_TEXTURE_RECTANGLE ! printf(" r Toggle arglTexRectangle.\n"); ! #endif // AR_OPENGL_TEXTURE_RECTANGLE ! printf(" ? or / Show this help.\n"); ! printf("\nAdditionally, the ARVideo library supplied the following help text:\n"); ! arVideoDispOption(); ! break; default: break; *************** *** 416,430 **** } ! void Mouse(int button, int state, int x, int y) ! { ! // Nothing here yet. ! } ! ! void Idle(void) { int i; ! static double timeRecentPast; ! double timeNow; ! float timeDelta; ARUint8 *image; --- 377,386 ---- } ! static void Idle(void) { int i; ! static int ms_prev; ! int ms; ! float s_elapsed; ARUint8 *image; *************** *** 434,447 **** // Find out how long since Idle() last ran. ! timeNow = (double)glutGet(GLUT_ELAPSED_TIME) / 1000.0; // Get the current time. ! timeDelta = (float)(timeNow - timeRecentPast); // Work out how long in seconds since the last epoch. ! if (timeDelta < 0.01f) return; // Don't update more often than 100 Hz. ! timeRecentPast = timeNow; // Update drawing. ! DrawCubeUpdate(timeDelta); ! if (!gCallCountGetImage) arUtilTimerReset(); ! gCallCountGetImage++; // Increment ARToolKit FPS counter. for (i = 0; i < gContextsActiveCount; i++) { --- 390,402 ---- // Find out how long since Idle() last ran. ! ms = glutGet(GLUT_ELAPSED_TIME); ! s_elapsed = (float)(ms - ms_prev) * 0.001; ! if (s_elapsed < 0.01f) return; // Don't update more often than 100 Hz. ! ms_prev = ms; // Update drawing. ! DrawCubeUpdate(s_elapsed); ! gCallCountGetImage++; // Increment Idle() counter. for (i = 0; i < gContextsActiveCount; i++) { *************** *** 487,491 **** static void Visibility(int visible) { ! if (gAlwaysVisible || (visible == GLUT_VISIBLE)) { glutIdleFunc(Idle); } else { --- 442,446 ---- static void Visibility(int visible) { ! if (visible == GLUT_VISIBLE) { glutIdleFunc(Idle); } else { *************** *** 498,502 **** // GLUT window is resized. // ! void Reshape(int w, int h) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); --- 453,457 ---- // GLUT window is resized. // ! static void Reshape(int w, int h) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); *************** *** 511,517 **** } ! static void Draw(const int drawContextIndex) { - int i; GLdouble p[16]; GLdouble m[16]; --- 466,471 ---- } ! static void DisplayPerContext(const int drawContextIndex) { GLdouble p[16]; GLdouble m[16]; *************** *** 541,544 **** --- 495,499 ---- //none + // ARToolKit supplied distance in millimetres, but I want OpenGL to work in metres. arglCameraView(gContextsActive[drawContextIndex].patt_trans, m, VIEW_SCALEFACTOR); glLoadMatrixd(m); *************** *** 548,552 **** gContextsActive[drawContextIndex].patt_found = FALSE; ! } // gPatt_found // Any 2D overlays go here. --- 503,507 ---- gContextsActive[drawContextIndex].patt_found = FALSE; ! } // patt_found // Any 2D overlays go here. *************** *** 574,578 **** if ((contextIndex = getContextIndexForCurrentGLUTWindow()) != -1) { ! Draw(contextIndex); glutSwapBuffers(); } --- 529,533 ---- if ((contextIndex = getContextIndexForCurrentGLUTWindow()) != -1) { ! DisplayPerContext(contextIndex); glutSwapBuffers(); } *************** *** 609,618 **** // Register a cleanup function to be called upon exit(). - #ifndef NOATEXIT if (atexit(Quit) < 0) { fprintf(stderr, "main(): Unable to register exit function.\n"); ! exit (-1); // Bail out if we can't even register our exit function. } - #endif // NOATEXIT // Initialise drawing libraries. --- 564,571 ---- // Register a cleanup function to be called upon exit(). if (atexit(Quit) < 0) { fprintf(stderr, "main(): Unable to register exit function.\n"); ! exit(-1); // Bail out if we can't even register our exit function. } // Initialise drawing libraries. *************** *** 627,631 **** // ! if (!demoARSetupCameras(CONTEXTSACTIVECOUNT, cparam_names, vconfs)) { fprintf(stderr, "main(): Unable to set up %d AR cameras.\n", CONTEXTSACTIVECOUNT); --- 580,584 ---- // ! if ((gContextsActive = (CONTEXT_INFO *)calloc(CONTEXTSACTIVECOUNTMAX, sizeof(CONTEXT_INFO))) == NULL) exit(-1); if (!demoARSetupCameras(CONTEXTSACTIVECOUNT, cparam_names, vconfs)) { fprintf(stderr, "main(): Unable to set up %d AR cameras.\n", CONTEXTSACTIVECOUNT); *************** *** 658,662 **** glutReshapeFunc(Reshape); glutVisibilityFunc(Visibility); - glutMouseFunc(Mouse); glutKeyboardFunc(Keyboard); --- 611,614 ---- *************** *** 668,682 **** } } // Register GLUT event-handling callbacks. ! // NB: MainRunLoop() is registered by Visibility. glutMainLoop(); - // All done. Exit the program now. - #ifdef NOATEXIT - Quit(); - #else return (0); - #endif // NOATEXIT - } --- 620,629 ---- } } + arUtilTimerReset(); // Register GLUT event-handling callbacks. ! // NB: Idle() is registered by Visibility. glutMainLoop(); return (0); } |