Esempio n. 1
0
//
// This function is called when the window needs redrawing.
//
static void Display(void)
{
	// Select correct buffer for this context.
	glDrawBuffer(GL_BACK);
	glClear(GL_COLOR_BUFFER_BIT); // Clear the buffers for new frame.
	
	arglDispImage(gARTImage, &gARTCparam, 1.0, gArglSettings);	// zoom = 1.0.
	arVideoCapNext();
	gARTImage = NULL; // Image data is no longer valid after calling arVideoCapNext().

	if (gTarget != NULL) {
		glDisable(GL_DEPTH_TEST);
		glDisable(GL_LIGHTING);
		glDisable(GL_TEXTURE_2D);
		beginOrtho2D(gARTCparam.xsize, gARTCparam.ysize);
        glLineWidth(2.0f);
        glColor3d(0.0, 1.0, 0.0);
        lineSeg(gTarget->vertex[0][0], gTarget->vertex[0][1],
				gTarget->vertex[1][0], gTarget->vertex[1][1], gArglSettings, gARTCparam, 1.0);
        lineSeg(gTarget->vertex[3][0], gTarget->vertex[3][1],
				gTarget->vertex[0][0], gTarget->vertex[0][1], gArglSettings, gARTCparam, 1.0);
        glColor3d(1.0, 0.0, 0.0);
        lineSeg(gTarget->vertex[1][0], gTarget->vertex[1][1],
				gTarget->vertex[2][0], gTarget->vertex[2][1], gArglSettings, gARTCparam, 1.0);
        lineSeg(gTarget->vertex[2][0], gTarget->vertex[2][1],
				gTarget->vertex[3][0], gTarget->vertex[3][1], gArglSettings, gARTCparam, 1.0);
		endOrtho2D();
    }

	glutSwapBuffers();
}
Esempio n. 2
0
/* main loop */
static void mainLoop(void)
{
    ARUint8         *dataPtr;
    ARMarkerInfo    *marker_info;
    int             marker_num;
    int             j, k;

    /* grab a vide frame */
    if( (dataPtr = (ARUint8 *)arVideoGetImage()) == NULL ) {
        arUtilSleep(2);
        return;
    }
    if( count == 0 ) arUtilTimerReset();
    count++;

    argDrawMode2D();
    argDispImage( dataPtr, 0,0 );

    /* detect the markers in the video frame */
    if( arDetectMarker(dataPtr, thresh, &marker_info, &marker_num) < 0 ) {
        cleanup();
        exit(0);
    }
	
	
	//additions from sheyne, trying to understand how it is working.
	
	//from documentation on http://artoolkit.sourceforge.net/apidoc/structARMarkerInfo.html
	
	//also look at: http://www.hitl.washington.edu/artoolkit/documentation/devframework.htm
	printf("pos: %f,%f\n", marker_info->pos[0], marker_info->pos[1]);
	for (j=0; j<4; j++) {
		printf("\t vertex: %f, %f\n", marker_info->vertex[j][0],marker_info->vertex[j][1]);
	}
	
    arVideoCapNext();

    /* 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;
    }

    /* get the transformation between the marker and the real camera */
    arGetTransMat(&marker_info[k], patt_center, patt_width, patt_trans);

    draw();

    argSwapBuffers();
}
Esempio n. 3
0
//==============
// 描画時の処理
//==============
void cARTK::display( void )
{
	// カメラ画像を描画
	arglDispImage( m_pARTImage, &m_sCameraParam, 1.0, m_pArglSettings );	// zoom = 1.0.

	// 次のカメラ画像のキャプチャを開始
	arVideoCapNext();

	m_pARTImage = NULL; // arVideoCapNext()の呼出し後はイメージデータポインタは無効になる
}
Esempio n. 4
0
/* main loop */
static void mainLoop(void)
{
    static int      contF = 0;
    ARUint8         *dataPtr;
    ARMarkerInfo    *marker_info;
    int             marker_num;
    int             j, k;

    /* grab a vide frame */
    if( (dataPtr = (ARUint8 *)arVideoGetImage()) == NULL ) {
        arUtilSleep(2);
        return;
    }
    if( count == 0 ) arUtilTimerReset();
    count++;

    argDrawMode2D();
    argDispImage( dataPtr, 0,0 );

    /* detect the markers in the video frame */
    if( arDetectMarker(dataPtr, thresh, &marker_info, &marker_num) < 0 ) {
        cleanup();
        exit(0);
    }

    arVideoCapNext();

    /* 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 ) {
        contF = 0;
        argSwapBuffers();
        return;
    }

    /* get the transformation between the marker and the real camera */
    if( mode == 0 || contF == 0 ) {
        arGetTransMat(&marker_info[k], patt_center, patt_width, patt_trans);
		
    }
    else {
        arGetTransMatCont(&marker_info[k], patt_trans, patt_center, patt_width, patt_trans);
    }
    contF = 1;

    draw( patt_trans );

    argSwapBuffers();
}
	static void mainLoop() {
		ARUint8         *dataPtr;
		ARMarkerInfo    *marker_info;
		int             marker_num;
		int             j, k;

		//Get video frame
		if ((dataPtr = (ARUint8 *)arVideoGetImage()) == NULL) {
			arUtilSleep(2);
			return;
		}
		if (count == 0) {
			arUtilTimerReset();
		}
		count++;

		//Display video stream
		argDrawMode2D();
		argDispImage(dataPtr, 0, 0);

		/* detect the markers in the video frame */
		if (arDetectMarker(dataPtr, thresh, &marker_info, &marker_num) < 0) {
			cleanup();
			exit(0);
		}

		//Get next video frame
		arVideoCapNext();

		/* 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;
			}
		}

		//Don't bother drawing or calculating orientations if no patterns are found
		if (k == -1) {
			argSwapBuffers();
			return;
		}

		/* get the transformation between the marker and the real camera */
		arGetTransMat(&marker_info[k], patt_center, patt_width, patt_trans);

		draw();

		argSwapBuffers();
	}
Esempio n. 6
0
//==================
// マーカー検出処理
//==================
bool cARTK::update( void )
{
	ARUint8			*pImage;
	ARMarkerInfo	*pMarkerInfo;
    int             iNumDetectedMarker;

	// カメラ画像の取得
	if( (pImage = (ARUint8 *)arVideoGetImage()) == NULL ) {
        arUtilSleep(2);
        return false;
    }
	memcpy( m_pARTImage, pImage, m_uiARTImageSize );

	m_bMarkerFound = false;

	// カメラ画像からマーカーを検出
	if( arDetectMarker( m_pARTImage, 130, &pMarkerInfo, &iNumDetectedMarker ) < 0 )
	{
		exit( -1 );
	}

	// 検出されたマーカー情報の中から一番信頼性の高いものを探す
	int		k = -1;
	for( int j = 0 ; j < iNumDetectedMarker ; j++ )
	{
		if( pMarkerInfo[j].id == m_iPattID )
		{
			if( k == -1 || pMarkerInfo[j].cf > pMarkerInfo[k].cf )	k = j;
		}
	}

	if( k != -1 )
	{
		// カメラのトランスフォーム行列を取得
		if( m_bFirstTime )
			arGetTransMat( &(pMarkerInfo[k]), m_dPattCenter, m_dPattWidth, m_dPattTransMat );
		else
			arGetTransMatCont( &(pMarkerInfo[k]), m_dPattTransMat, m_dPattCenter, m_dPattWidth, m_dPattTransMat );

		m_bFirstTime = false;

		m_bMarkerFound = true;
	}

	// 次のカメラ画像のキャプチャを開始
	arVideoCapNext();

	return true;
}
Esempio n. 7
0
static void mainLoop(void)
{
    ARUint8         *dataPtr;
    ARMarkerInfo    *marker_info;
    int             marker_num;
    int             areamax;
    int             i;

    if( (dataPtr = (unsigned char *)arVideoGetImage()) == NULL ) {
        arUtilSleep(2);
        return;
    }
    img_copy( dataPtr, image, xsize*ysize*AR_PIX_SIZE );
    arVideoCapNext();

    if( arDetectMarker(image, thresh, &marker_info, &marker_num) < 0 ) {
        cleanup();
        exit(0);
    }

    areamax = 0;
    target = NULL;
    for( i = 0; i < marker_num; i++ ) {
        if( marker_info[i].area > areamax ) {
            areamax = marker_info[i].area;
            target = &(marker_info[i]);
        }
    }
    argDispImage( image, 0, 0 );


    if( target != NULL ) {
        glLineWidth( 2.0 );
        glColor3d( 0.0, 1.0, 0.0 );
        argLineSeg( target->vertex[0][0], target->vertex[0][1],
                    target->vertex[1][0], target->vertex[1][1], 0, 0 );
        argLineSeg( target->vertex[3][0], target->vertex[3][1],
                    target->vertex[0][0], target->vertex[0][1], 0, 0 );
        glColor3d( 1.0, 0.0, 0.0 );
        argLineSeg( target->vertex[1][0], target->vertex[1][1],
                    target->vertex[2][0], target->vertex[2][1], 0, 0 );
        argLineSeg( target->vertex[2][0], target->vertex[2][1],
                    target->vertex[3][0], target->vertex[3][1], 0, 0 );
    }
    argSwapBuffers();
 
    return;
}
Esempio n. 8
0
//
// This function is called when the window needs redrawing.
//
static void Display(void)
{
    GLdouble p[16];
	GLdouble m[16];

	// Select correct buffer for this context.
	glDrawBuffer(GL_BACK);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear the buffers for new frame.

	arglDispImage(gARTImage, &gARTCparam, 1.0, gArglSettings);	// zoom = 1.0.
	arVideoCapNext();
	gARTImage = NULL; // Image data is no longer valid after calling arVideoCapNext().

	for(std::list<Piece*>::iterator it = pieces.begin(); it != pieces.end(); it++)
	{
		if ((*it)->patt_found) // gPatt_found
		{
			// Projection transformation.
			arglCameraFrustumRH(&gARTCparam, VIEW_DISTANCE_MIN, VIEW_DISTANCE_MAX, p);
			glMatrixMode(GL_PROJECTION);
			glLoadMatrixd(p);
			glMatrixMode(GL_MODELVIEW);

			// Viewing transformation.
			glLoadIdentity();
			// Lighting and geometry that moves with the camera should go here.
			// (I.e. must be specified before viewing transformations.)
			//none

			// ARToolKit supplied distance in millimetres, but I want OpenGL to work in my units.
			arglCameraViewRH((*it)->patt_trans, m, VIEW_SCALEFACTOR);
			glLoadMatrixd(m);

			// All other lighting and geometry goes here.

			(*it)->Draw();

		} 
		
		// Any 2D overlays go here.
		//none
	}

	glutSwapBuffers();
}
Esempio n. 9
0
//
// This function is called when the window needs redrawing.
//
static void Display(void)
{
	int i;
    GLdouble p[16];
	GLdouble m[16];
	
	// Select correct buffer for this context.
	glDrawBuffer(GL_BACK);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear the buffers for new frame.
	
	arglDispImage(gARTImage, &gARTCparam, 1.0, gArglSettings);	// zoom = 1.0.
	arVideoCapNext();
	gARTImage = NULL; // Image data is no longer valid after calling arVideoCapNext().
				
	if (gPatt_found) {
		// Projection transformation.
		arglCameraFrustumRH(&gARTCparam, VIEW_DISTANCE_MIN, VIEW_DISTANCE_MAX, p);
		glMatrixMode(GL_PROJECTION);
		glLoadMatrixd(p);
		glMatrixMode(GL_MODELVIEW);
		
		// Viewing transformation.
		glLoadIdentity();
		// Lighting and geometry that moves with the camera should go here.
		// (I.e. must be specified before viewing transformations.)
		//none
		
		// All other lighting and geometry goes here.
		// Calculate the camera position for each object and draw it.
		for (i = 0; i < gObjectDataCount; i++) {
			if ((gObjectData[i].visible != 0) && (gObjectData[i].vrml_id >= 0)) {
				//fprintf(stderr, "About to draw object %i\n", i);
				arglCameraViewRH(gObjectData[i].trans, m, VIEW_SCALEFACTOR_4);
				glLoadMatrixd(m);

				arVrmlDraw(gObjectData[i].vrml_id);
			}			
		}
	} // gPatt_found
	
	// Any 2D overlays go here.
	//none
	
	glutSwapBuffers();
}
Esempio n. 10
0
//
// This function is called when the window needs redrawing.
//
static void Display(void)
{
    GLdouble p[16];
    GLdouble m[16];

    // Select correct buffer for this context.
    glDrawBuffer(GL_BACK);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear the buffers for new frame.

    //	arglDispImage(gARTImage, &gARTCparam, 1.0, gArglSettings);	// zoom = 1.0.
    arVideoCapNext();
    gARTImage = NULL; // Image data is no longer valid after calling arVideoCapNext().

    // Projection transformation.
    arglCameraFrustumRH(&gARTCparam, VIEW_DISTANCE_MIN, VIEW_DISTANCE_MAX, p);
    glMatrixMode(GL_PROJECTION);
    glLoadMatrixd(p);
    glMatrixMode(GL_MODELVIEW);

    // Viewing transformation.
    glLoadIdentity();
    // Lighting and geometry that moves with the camera should go here.
    // (I.e. must be specified before viewing transformations.)
    //none

    if (gPatt_found) {

        // Calculate the camera position relative to the marker.
        // Replace VIEW_SCALEFACTOR with 1.0 to make one drawing unit equal to 1.0 ARToolKit units (usually millimeters).
        arglCameraViewRH(gPatt_trans, m, VIEW_SCALEFACTOR);
        glLoadMatrixd(m);

        // All lighting and geometry to be drawn relative to the marker goes here.
        DrawCube();

    } // gPatt_found

    // Any 2D overlays go here.
    //none

    glutSwapBuffers();
}
Esempio n. 11
0
void MainLoop(void)
{
	ARUint8 *image;
	ARMarkerInfo *marker_info;
	int marker_num;
	int j, k;

	if ((image = (ARUint8 *)arVideoGetImage()) == NULL) {
		arUtilSleep(2);
		return;

	}

	argDrawMode2D();
	argDispImage(image, 0, 0);

	if (arDetectMarker(image, thresh, &marker_info, &marker_num) < 0) {
		Cleanup();
		exit(0);

	}

	arVideoCapNext();

	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) {
		arGetTransMat(&marker_info[k], patt_center, patt_width, patt_trans);
		DrawObject();
	}

	argSwapBuffers();
}
Esempio n. 12
0
File: exview.c Progetto: SNce/ARMaze
static void mainLoop(void)
{
    ARUint8         *dataPtr;
    ARMarkerInfo    *marker_info;
    int             marker_num;
    int             j, k;

    /* grab a vide frame */
    if( (dataPtr = (ARUint8 *)arVideoGetImage()) == NULL ) {
        arUtilSleep(2);
        return;
    }

    glClearColor( 0.0, 0.0, 0.0, 0.0 );
    glClearDepth( 1.0 );
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    argDrawMode2D();
    if( disp_mode ) {
        argDispImage( dataPtr, 0, 0 );
    }
    else {
        argDispImage( dataPtr, 1, 1 );
    }

    /* detect the markers in the video frame */
    if( arDetectMarker(dataPtr, thresh, &marker_info, &marker_num) < 0 ) {
        cleanup();
        exit(0);
    }
    arVideoCapNext();

    /* if the debug mode is on draw squares 
       around the detected squares in the video image */
    if( arDebug ) {
        if( arImageProcMode == AR_IMAGE_PROC_IN_HALF )
            argDispHalfImage( arImage, 2, 1 );
        else
            argDispImage( arImage, 2, 1);
    }

    /* check for object visibility */
    k = -1;
    for( j = 0; j < marker_num; j++ ) {
        if( marker_info[j].id == target_id ) {
            if( k == -1 ) k = j;
            else {
                if( marker_info[k].cf < marker_info[j].cf ) k = j;
            }
        }
    }
    if( k != -1 ) {
        glDisable(GL_DEPTH_TEST);
        switch( outputMode ) {
            case 0:
                getResultRaw( &marker_info[k] );
                break;
            case 1:
                getResultQuat( &marker_info[k] );
                break;
        }
    }

    argSwapBuffers();
}
/* main loop */
static void mainLoop(void)
{
    ARUint8         *dataPtr;
    ARMarkerInfo    *marker_info;
    int             marker_num;
    int             i, j, k;

    /* grab a vide frame */
    if( (dataPtr = (ARUint8 *)arVideoGetImage()) == NULL ) {
        arUtilSleep(2);
        return;
    }
    if( count == 0 ) arUtilTimerReset();
    count++;

    argDrawMode2D();
    argDispImage( dataPtr, 0,0 );

    /* detect the markers in the video frame */
    if( arDetectMarker(dataPtr, thresh, &marker_info, &marker_num) < 0 ) {
        cleanup();
        exit(0);
    }
    arVideoCapNext();

    argDrawMode3D();
    argDraw3dCamera( 0, 0 );
    glClearDepth( 1.0 );
    glClear(GL_DEPTH_BUFFER_BIT);

    /* check for object visibility */
    for( i = 0; i < 2; i++ ) {
        k = -1;
        for( j = 0; j < marker_num; j++ ) {
            if( object[i].patt_id == marker_info[j].id ) {
                if( k == -1 ) k = j;
                else if( marker_info[k].cf < marker_info[j].cf ) k = j;
            }
        }
        object[i].visible = k;

        if( k >= 0 ) {
            arGetTransMat(&marker_info[k],
                          object[i].center, object[i].width,
                          object[i].trans);
            draw( object[i].model_id, object[i].trans );
        }
    }
    argSwapBuffers();

    if( object[0].visible >= 0
     && object[1].visible >= 0 ) {
        double  wmat1[3][4], wmat2[3][4];

        arUtilMatInv(object[0].trans, wmat1);
        arUtilMatMul(wmat1, object[1].trans, wmat2);

        for( j = 0; j < 3; j++ ) {
            for( i = 0; i < 4; i++ ) printf("%8.4f ", wmat2[j][i]);
            printf("\n");
        }
        printf("\n\n");
    }
}
Esempio n. 14
0
/* main loop */
static void mainLoop(void)
{
    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 );

    /* capture the next video frame */
    arVideoCapNext();

    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);
    }

    /* 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;
            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;
    }

    /*check for object collisions between marker 0 and 1 */
    if(object[0].visible && object[1].visible) {
        if(checkCollisions(object[0],object[1],COLLIDE_DIST)) {
            object[0].collide = 1;
            object[1].collide = 1;
        }
        else {
            object[0].collide = 0;
            object[1].collide = 0;
        }
    }

    /* draw the AR graphics */
    draw( object, objectnum );

    /*swap the graphics buffers*/
    argSwapBuffers();
}
Esempio n. 15
0
/* main loop */
static void mainLoop(void)
{
    static int      contF = 0;
    ARUint8         *dataPtr;
    ARMarkerInfo    *marker_info;
    int             marker_num;
    int             j, k;

	//update new data
	g_MyKinect.Update();

#ifdef USE_USERDETECTOR
	if(g_MyKinect.userStatus.isPlayerVisible())
	{
		XV3 tmp = g_MyKinect.userDetector->getSkeletonJointPosition(XN_SKEL_RIGHT_HAND);
		printf("Right hand position: %.2f %.2f %.2f\n", tmp.X, tmp.Y, tmp.Z);
	}
#endif

	if(drawFromKinect)
	{
		//get image data to detect marker
		if( (dataPtr = (ARUint8 *)g_MyKinect.GetBGRA32Image()) == NULL ) {
			arUtilSleep(2);
			return;
		}
	}
	else
	{
		 /* grab a vide frame */
		if( (dataPtr = (ARUint8 *)arVideoGetImage()) == NULL ) {
		  arUtilSleep(2);
		 return;
		}
	}

    if( count == 0 ) arUtilTimerReset();
    count++;

    /* detect the markers in the video frame */
    if( arDetectMarker(dataPtr, thresh, &marker_info, &marker_num) < 0 ) {
        cleanup();
        exit(0);
    }

	if(drawFromKinect)
	{
		//option . You can choose many display mode. image, Depth by Color, depth mixed image
		if(displayMode == 2)
			dataPtr = (ARUint8 *)g_MyKinect.GetDepthDrewByColor();
		else
			if(displayMode == 3)
				dataPtr = (ARUint8 *)g_MyKinect.GetDepthMixedImage();
	}

	argDrawMode2D();
    argDispImage( dataPtr, 0,0 );

	arVideoCapNext();

    /* 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 ) {
        contF = 0;
        argSwapBuffers();
        return;
    }

    /* get the transformation between the marker and the real camera */
    if( mode == 0 || contF == 0 ) {
        arGetTransMat(&marker_info[k], patt_center, patt_width, patt_trans);
    }
    else {
        arGetTransMatCont(&marker_info[k], patt_trans, patt_center, patt_width, patt_trans);
    }
    contF = 1;

    draw( patt_trans );

    argSwapBuffers();
}
Esempio n. 16
0
/* main loop */
static void mainLoop(void)
{
    ARUint8         *dataPtr;
    ARMarkerInfo    *marker_info;
    int             marker_num;
    double          err;
    int             i;

    /* grab a vide frame */
    if( (dataPtr = (ARUint8 *)arVideoGetImage()) == NULL ) {
        arUtilSleep(2);
        return;
    }
    if( count == 0 ) arUtilTimerReset();
    count++;

    /* detect the markers in the video frame */
    if( arDetectMarkerLite(dataPtr, thresh, &marker_info, &marker_num) < 0 ) {
        cleanup();
        exit(0);
    }

    argDrawMode2D();
    if( !arDebug ) {
        argDispImage( dataPtr, 0,0 );
    }
    else {
        argDispImage( dataPtr, 1, 1 );
        if( arImageProcMode == AR_IMAGE_PROC_IN_HALF )
            argDispHalfImage( arImage, 0, 0 );
        else
            argDispImage( arImage, 0, 0);

        glColor3f( 1.0, 0.0, 0.0 );
        glLineWidth( 1.0 );
        for( i = 0; i < marker_num; i++ ) {
            argDrawSquare( marker_info[i].vertex, 0, 0 );
        }
        glLineWidth( 1.0 );
    }

    arVideoCapNext();

    if( (err=arMultiGetTransMat(marker_info, marker_num, config)) < 0 ) {
        argSwapBuffers();
        return;
    }
    printf("err = %f\n", err);
    if(err > 100.0 ) {
        argSwapBuffers();
        return;
    }
/*
    for(i=0;i<3;i++) {
        for(j=0;j<4;j++) printf("%10.5f ", config->trans[i][j]);
        printf("\n");
    }
    printf("\n");
*/
    argDrawMode3D();
    argDraw3dCamera( 0, 0 );
    glClearDepth( 1.0 );            glScalef(1.0,1.0,5.0);
    glClear(GL_DEPTH_BUFFER_BIT);

    //PRINT DOS PREDIOS FANTASMAS (COM E SEM MARCADORES)
    if (mostraFantasmas == 1)
    {
        desenhaFantasmasSemTag();


        //Desenha predios fantasmas com marcadores identificados
        glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
        for(i = (config->marker_num) - 3; i < config->marker_num; i++ ) {
            if( config->marker[i].visible >= 0 )
            {
                glScalef(1.0,1.0,2.0);
                draw( config->trans, config->marker[i].trans, 0 );
                glScalef(1.0,1.0,0.5);
            }else{
                glScalef(1.0,1.0,2.0);
                draw( config->trans, config->marker[i].trans, 1 );
                glScalef(1.0,1.0,0.5);
            }
        }
        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);

    }

    desenhaCarros();

    for (i = 0; i < (config->marker_num) - 3; i++ ) {
        if( config->marker[i].visible >= 0 ) draw( config->trans, config->marker[i].trans, 0 );
        else                                 draw( config->trans, config->marker[i].trans, 1 );
    }

    argSwapBuffers();
}
/* main loop */
static void mainLoop(void)
{
    ARUint8         *dataPtr;
    ARMarkerInfo    *marker_info;
    int             marker_num;
	float curPaddlePos[3];
    int             i;
    double          err;
    
    /* grab a video frame */
    if( (dataPtr = (ARUint8 *)arVideoGetImage()) == NULL ) {
        arUtilSleep(2); 
        return;
    }
	
    if( count == 0 ) arUtilTimerReset();  
    count++;
   
	/* detect the markers in the video frame */
    if( arDetectMarkerLite(dataPtr, thresh, &marker_info, &marker_num) < 0 ) {
        cleanup();
        exit(0);
    }

    argDrawMode2D();
    if( !arDebug ) {
        argDispImage( dataPtr, 0,0 );
    }
    else {
        argDispImage( dataPtr, 1, 1 );
        if( arImageProcMode == AR_IMAGE_PROC_IN_HALF )
            argDispHalfImage( arImage, 0, 0 );
        else
            argDispImage( arImage, 0, 0);

        glColor3f( 1.0, 0.0, 0.0 );
        glLineWidth( 1.0 );
        for( i = 0; i < marker_num; i++ ) {
            argDrawSquare( marker_info[i].vertex, 0, 0 );
        }
        glLineWidth( 1.0 );
    }
 	arVideoCapNext();

	for( i = 0; i < marker_num; i++ ) marker_flag[i] = 0;
  
	/* get the paddle position */
	paddleGetTrans(paddleInfo, marker_info, marker_flag, 
				marker_num, &cparam);
	
	/* draw the 3D models */
	glClearDepth( 1.0 );
	glClear(GL_DEPTH_BUFFER_BIT);

	/* draw the paddle, base and menu */
	if( paddleInfo->active ){ 
		draw_paddle( paddleInfo);
	}

	/* get the translation from the multimarker pattern */
	if( (err=arMultiGetTransMat(marker_info, marker_num, config)) < 0 ) {
        argSwapBuffers();
        return;
    }	
	
    //printf("err = %f\n", err);
    if(err > 100.0 ) {
        argSwapBuffers();
        return;
    }

	//draw a red ground grid
	drawGroundGrid( config->trans, 20, 150.0f, 105.0f, 0.0f);

	/* find the paddle position relative to the base */
	findPaddlePosition(curPaddlePos, paddleInfo->trans, config->trans);

	/* check for collisions with targets */
	for(i=0;i<TARGET_NUM;i++){
		myTarget[i].state = NOT_TOUCHED;
		if(checkCollision(curPaddlePos, myTarget[i].pos, 20.0f))
		  {
			myTarget[i].state = TOUCHED;
			fprintf(stderr,"touched !!\n");
		  }
	}

	/* draw the targets */
	for(i=0;i<TARGET_NUM;i++){
		draw(myTarget[i],config->trans);
	}

	argSwapBuffers();
}
/* main loop */
static void mainLoop(void)
{
    ARUint8         *dataPtr;
    ARMarkerInfo    *marker_info;
    int             marker_num;
	float curPaddlePos[3];
    int             i;
    double          err;
    double			angle;

	err=0.;
    /* grab a video frame */
    if( (dataPtr = (ARUint8 *)arVideoGetImage()) == NULL ) {
        arUtilSleep(2); 
        return;
    }
	
    if( count == 0 ) arUtilTimerReset();  
    count++;
   
	/* detect the markers in the video frame */
    if( arDetectMarkerLite(dataPtr, thresh, &marker_info, &marker_num) < 0 ) {
        cleanup();
        exit(0);
    }

    argDrawMode2D();
    if( !arDebug ) {
        argDispImage( dataPtr, 0,0 );
    }
    else {
        argDispImage( dataPtr, 1, 1 );
        if( arImageProcMode == AR_IMAGE_PROC_IN_HALF )
            argDispHalfImage( arImage, 0, 0 );
        else
            argDispImage( arImage, 0, 0);

        glColor3f( 1.0, 0.0, 0.0 );
        glLineWidth( 1.0 );
        for( i = 0; i < marker_num; i++ ) {
            argDrawSquare( marker_info[i].vertex, 0, 0 );
        }
        glLineWidth( 1.0 );
    }

    arVideoCapNext();

	for( i = 0; i < marker_num; i++ ) 
		marker_flag[i] = 0;
  
	/* get the paddle position */
	paddleGetTrans(paddleInfo, marker_info, marker_flag, 
				marker_num, &cparam);
	/* draw the 3D models */
	glClearDepth( 1.0 );
	glClear(GL_DEPTH_BUFFER_BIT);


	/* get the translation from the multimarker pattern */
	if( (err=arMultiGetTransMat(marker_info, marker_num, config)) < 0 ) {
        argSwapBuffers();
        return;
    }	
	
	//    printf("err = %f\n", err);
    if(err > 100.0 ) {
        argSwapBuffers();
        return;
    }
	
	//draw a red ground grid
	drawGroundGrid( config->trans, 15, 150.0, 110.0, 0.0);

	/* find the paddle position relative to the base */
	if (paddleInfo->active)
		findPaddlePosition(curPaddlePos,paddleInfo->trans,config->trans);

	/* checking for paddle gesture */
	if( paddleInfo->active) 
	  {
	    int findItem=-1;
	    if (myPaddleItem.item!=-1)
	      {

		  if( check_incline(paddleInfo->trans, config->trans, &angle) ) {
		      myPaddleItem.x += 2.0 * cos(angle);
		      myPaddleItem.y += 2.0 * sin(angle);
		      if( myPaddleItem.x*myPaddleItem.x + 
			  myPaddleItem.y*myPaddleItem.y > 900.0 ) {
			  myPaddleItem.x -= 2.0 * cos(angle);
			  myPaddleItem.y -= 2.0 * sin(angle);
			  myListItem.item[myPaddleItem.item].onpaddle=0;		     
			  myListItem.item[myPaddleItem.item].pos[0]=curPaddlePos[0]; 
			  myListItem.item[myPaddleItem.item].pos[1]=curPaddlePos[1];  
			  myPaddleItem.item = -1;
			}
		  }
	      }
	    else
	      {
		if ((findItem=check_pickup(paddleInfo->trans, config->trans,&myListItem, &angle))!=-1)  {
		    
		    myPaddleItem.item=findItem;
		    myPaddleItem.x =0.0;
		    myPaddleItem.y =0.0;
		    myPaddleItem.angle = 0.0;
		    myListItem.item[myPaddleItem.item].onpaddle=1;
		  }
	      }
	  }

	/* draw the item */
	drawItems(config->trans,&myListItem);

	/* draw the paddle */
	if( paddleInfo->active ){ 
	  draw_paddle(paddleInfo,&myPaddleItem);
	}
	
	argSwapBuffers();
}
Esempio n. 19
0
void MainLoop()
{
    //QueryPerformanceFrequency(&nFreq);
    //QueryPerformanceCounter(&nBefore);
    
    DWORD StartTime,EndTime,PassTime;
    double l_StartTime,l_EndTime,l_PassTime;
#ifdef _WIN32
    StartTime=timeGetTime();
#else
    l_StartTime=gettimeofday_sec();
#endif
    ARUint8		*image;
    ARMarkerInfo	*marker_info;
    int			 marker_num;
    int			 j,k;

    if( (image = (ARUint8*)arVideoGetImage() )==NULL){
	arUtilSleep(2);
	return;
    }

    argDrawMode2D();
    argDispImage(image, 0, 0);


    if(arDetectMarker(image, thresh, &marker_info, &marker_num) < 0){
	CleanUp();
	exit(0);
    }
    arVideoCapNext();

    k=-1;
    for(j=0;j<marker_num;j++){   
	if(patt_id==marker_info[j].id){
	    k = (k==-1)  ?   j : k;
	    k = (marker_info[k].cf < marker_info[j].cf)   ?  j: k;
	}
    }

    if(k!=-1) {
	if(isFirst==true)
	    nyar_NyARTransMat_O2_transMat(nyobj,&marker_info[k],patt_center,patt_width,patt_trans);
	else
	    nyar_NyARTransMat_O2_transMatCont(nyobj,&marker_info[k],patt_trans,patt_center,patt_width,patt_trans);

	isFirst=false;

	if(GameOver==false){
	    if(arUtilTimer()>1.0){
		MovePiece(3,f,p); 
		score+=f.ShiftPiece(f.deletePiece());
		arUtilTimerReset();
		GameOver=GameOverCheck(f,p);
	    }
	}
	else{
	    if(arUtilTimer()>15.0)
		InitGame();
	}
	DrawObject();
    }

    argSwapBuffers();
#ifdef _WIN32
    EndTime=timeGetTime();
    PassTime=EndTime-StartTime;
    (1000/FPS>PassTime)?Wait(1000/FPS-PassTime):Wait(0);
    FPSCount(&fps);
    printf("FPS=%d\n",fps);
#else
l_EndTime=gettimeofday_sec();
l_PassTime=l_EndTime-l_StartTime;
    ((double)(1000/FPS)>l_PassTime)?Wait((double)1000/FPS-l_PassTime):Wait(0);
    FPSCount(&fps);
    printf("FPS=%d\n",fps);
#endif
   
}
Esempio n. 20
0
/* main loop */
static void mainLoop(void)
{
    ARUint8         *dataPtr;
    ARMarkerInfo    *marker_info;
    int             marker_num;
    int             j, k;
	int				i;

    /* grab a vide frame */
    if( (dataPtr = (ARUint8 *)arVideoGetImage()) == NULL ) {
        arUtilSleep(2);
        return;
    }
    if( count == 0 ) arUtilTimerReset();
    count++;

    argDrawMode2D();
    argDispImage( dataPtr, 0,0 );

    /* detect the markers in the video frame */
    if( arDetectMarker(dataPtr, thresh, &marker_info, &marker_num) < 0 ) {
        cleanup();
        exit(0);
    }

    arVideoCapNext();

    /* check for object visibility */
   	for( i = 0; i < PTT_NUM; i++){
		k = -1;
	    for( j = 0; j < marker_num; j++ ) {
	        if( object[i].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 ) { /* not find marker */
			object[i].visible = 0;
			isFirst[i] = 1;
		}
		else{
			/* get the transformation between the marker and the real camera */
			if( isFirst[i]){
				arGetTransMat(&marker_info[k], object[i].patt_center, object[i].patt_width, object[i].patt_trans);
			}else{
				arGetTransMatCont(&marker_info[k], object[i].patt_trans, object[i].patt_center, object[i].patt_width, object[i].patt_trans);
			}
			object[i].visible = 1;
			isFirst[i] = 0;
			
			/* 追加 */
			if(i == PTT2_MARK_ID){
				arUtilMatInv( object[PTT2_MARK_ID].patt_trans, itrans2); // 逆行列の計算
			}
		}
	}

	//Initialize(); // fix me
	draw();

	argSwapBuffers();
}
Esempio n. 21
0
void mainLoop()
{
    ARMarkerInfo *marker_info;
    ARUint8 *dataPtr;
    int marker_num;

	if(!calib)//special paycay florian 
		cvReleaseImage(&image);

	if(!calib)
		detectColision();

    // Recuperation du flux video
    if ( (dataPtr = (ARUint8 *)arVideoGetImage()) == NULL )
    {
        arUtilSleep(2);
        return;
    }

	// Passage en mode 2D pour analyse de l'image capturee
    argDrawMode2D();

	// Récupération de l'image openCV puis conversion en ARImage
	//IplImage* imgTest;
	image = cvCreateImage(cvSize(xsize, ysize), IPL_DEPTH_8U, 4);	
	image->imageData = (char *)dataPtr;

	//sinon l'image est à l'envers
	cvFlip(image, image, 1);
	

	//test si les couleurs ont déjà été calibrée
	// si oui on teste si y a collision, sinon on calibre
		interactionBoutton();
		if(calib)
			calibrage();
		else
		{
			updateColor();
			interactions();
		}

			

    // affichage image à l'ecran
    argDispImage( (unsigned char *)image->imageData, 0,0 );
	// Recuperation d'une autre image car on a fini avec la precedente
	arVideoCapNext();

		if (arDetectMarker(dataPtr, thresh, &marker_info, &marker_num) < 0)
		{
			printf("impossible de detecter le marqueur\n");
			cleanup();
		}


		if(visible == false && !calib) //element IHM : procedure qui permet de savoir si on recherche ou pas + réinit mouvemment des objets précédement affiché
		{
			glEnable(GL_LIGHT0);

			objet1_x =0;objet1_y =0;objet2_x =0;objet2_y =0;

			if(scan.isVisible(0)==true)
				scan.setVisible(false,0);
			if(scan.isVisible(1)==false)
				scan.setVisible(true,1);

			glColor3ub(255,0,0);
			texte(GLUT_BITMAP_HELVETICA_18,(char*)"Searching",cparam.xsize-100,cparam.ysize-30);
			if(alterne1==0 && alterne2 > 20)
			{
				glColor3ub(255,0,0);
				texte(GLUT_BITMAP_HELVETICA_18,(char*)"Searching .",cparam.xsize-100,cparam.ysize-30);
				if(alterne2 > 30){alterne2=0;alterne1=(alterne1+1)%3;}
			}
			if(alterne1==1 && alterne2 > 20 )
			{	
				glColor3ub(255,0,0);
				texte(GLUT_BITMAP_HELVETICA_18,(char*)"Searching ..",cparam.xsize-100,cparam.ysize-30);
				if(alterne2 > 30){alterne2=0;alterne1=(alterne1+1)%3;}
			}
			if(alterne1==2 && alterne2 > 20)
			{	
				glColor3ub(255,0,0);
				texte(GLUT_BITMAP_HELVETICA_18,(char*)"Searching ...",cparam.xsize-100,cparam.ysize-30);
				if(alterne2 > 30){alterne2=0;alterne1=(alterne1+1)%3;}
			}

			alterne2+=1;
			glDisable(GL_LIGHT0);
		}
		else if(calib)
		{
			
			if(couleur == 0)
			{
				glColor3ub(0,0,255);
				texte(GLUT_BITMAP_HELVETICA_18,(char*)"Choose thumb's color",cparam.xsize-220,cparam.ysize-30);
				texte(GLUT_BITMAP_HELVETICA_18,(char*)"then press enter",cparam.xsize-220,cparam.ysize-(30+18));
			}
			else if(couleur == 1)
			{
				glColor3ub(0,255,0);
				texte(GLUT_BITMAP_HELVETICA_18,(char*)"Choose forefinger's color",cparam.xsize-220,cparam.ysize-30);
				texte(GLUT_BITMAP_HELVETICA_18,(char*)"then press enter",cparam.xsize-220,cparam.ysize-(30+18));
				texte(GLUT_BITMAP_HELVETICA_18,(char*)"Press return for thumb",cparam.xsize-220,cparam.ysize-(30+18*2));
			}
			else
			{
				glColor3ub(255,0,0);
				texte(GLUT_BITMAP_HELVETICA_18,(char*)"Choose middle's color",cparam.xsize-220,cparam.ysize-(30));
				texte(GLUT_BITMAP_HELVETICA_18,(char*)"then press enter",cparam.xsize-220,cparam.ysize-(30+18));
				texte(GLUT_BITMAP_HELVETICA_18,(char*)"Press return for forefinger",cparam.xsize-220,cparam.ysize-(30+18*2));

			}


		}
		else //passage mode 3d + init profondeur
		{
			argDrawMode3D();
			argDraw3dCamera(0, 0);
			glClearDepth(1.0);
			glClear(GL_DEPTH_BUFFER_BIT);
		}

		/// Visibilite de l'objet
		if(visible == false ) //si on a jms vu de patron ou qu'on a demandé une recapture des patrons faire
		{
			//recherche objet visible 
			for (int i=0; i<2; i++) //pour chaque patron initialisé faire 
			{
				k = -1; //k renseigne sur la visibilité du marker et son id
				for (int j=0; j<marker_num; j++) // pour chaque marqueur trouver avec arDetectMarker 
				{
					if (object[i].patt_id == marker_info[j].id) 
					{
						if (k == -1)
						{
							k = j;
						}
						else if (marker_info[k].cf < marker_info[j].cf)
						{
							k = j;
						}
					}
				}

				object[i].visible = k;

				if (k >= 0)
				{
					visible = true;
					arGetTransMat(&marker_info[k], object[i].center, object[i].width,object[i].trans);
					printf("object[%d] center[%f, %f]\n", i, marker_info->pos[0], marker_info->pos[1]);
					printf("object[%d] hg[%f, %f]\n", i, marker_info->vertex[0][0], marker_info->vertex[0][1]);
					printf("object[%d] hd[%f, %f]\n", i, marker_info->vertex[1][0], marker_info->vertex[1][1]);
					printf("object[%d] bg[%f, %f]\n", i, marker_info->vertex[2][0], marker_info->vertex[2][1]);
					printf("object[%d] bd[%f, %f]\n", i, marker_info->vertex[3][0], marker_info->vertex[3][1]);


					//changement etat boutton
					if(scan.isVisible(0)==false)
						scan.setVisible(true,0);
					if(scan.isVisible(1)==true)
						scan.setVisible(false,1);

					//si on a vu un patron, on créé une nouvelle instance de l'objet créé par le patron, qu'on stocke dans les objets à l'écran.
					onscreen_object.push_back(Object3D(mesh.at(object[i].model_id), object[i].center, object[i].trans, object[i].width));
				}
			}
		}
		
		//vu qu'on ne gère plus à partir de la variable "visible" d'un patron, on display, dans tout les cas, soit le vecteur est vide, soit 
		//on a un ou plusieurs objets à afficher
		display(true);

		if(menuShow==true)
			menu.show();

		if(!calib)
			scan.show();

		help.show();
		quit.show();


    argSwapBuffers(); /// Affichage de l'image sur l'interface graphique
}
Esempio n. 22
0
static void argCalibMainFunc(void)
{
    ARUint8         *dataPtr;
    ARMarkerInfo    *marker_info;
    int             marker_num;
    int             i, j;
    double          cfmax;
    double          err;

    /* grab a vide frame */
    if( (dataPtr = (ARUint8 *)arVideoGetImage()) == NULL ) {
        arUtilSleep(2);
        return;
    }
    target_visible = 0;

    /* detect the markers in the video frame */
    if( arDetectMarker(dataPtr, thresh,
                       &marker_info, &marker_num) < 0 ) {
        (*gCalibPostFunc)( NULL, NULL );
        arFittingMode = arFittingModeBak;
#ifndef ANDROID		
        glutKeyboardFunc( gKeyFunc );
        glutMouseFunc( gMouseFunc );
        glutIdleFunc( gMainFunc );
        glutDisplayFunc( gMainFunc );
#endif		
        return;
    }
    arVideoCapNext();

    glClearColor( 0.0, 0.0, 0.0, 0.0 );
	
#ifndef ANDROID		    
	glClear(GL_COLOR_BUFFER_BIT);
#endif

    /* if the debug mode is on draw squares
       around the detected squares in the video image */
    if( arDebug && gMiniXnum >= 2 && gMiniYnum >= 1 ) {
        argDispImage( dataPtr, 1, 1 );
        if( arImageProcMode == AR_IMAGE_PROC_IN_HALF )
            argDispHalfImage( arImage, 2, 1 );
        else
            argDispImage( arImage, 2, 1);

        glColor3f( 1.0, 0.0, 0.0 );
        glLineWidth( 3.0 );
        for( i = 0; i < marker_num; i++ ) {
            if( marker_info[i].id < 0 ) continue;
            argDrawSquare( marker_info[i].vertex, 2, 1 );
        }
        glLineWidth( 1.0 );
    }

    if( left_right == 0 ) argDraw2dLeft();
     else                 argDraw2dRight();
    glLineWidth( 3.0 );
    glColor3f( 1.0, 1.0, 1.0 );
    argLineSegHMD( 0, calib_pos[co1][1], AR_HMD_XSIZE, calib_pos[co1][1] );
    argLineSegHMD( calib_pos[co1][0], 0, calib_pos[co1][0], AR_HMD_YSIZE );
    glLineWidth( 1.0 );
    argDrawMode2D();

    cfmax = 0.0;
    j = -1;
    for( i = 0; i < marker_num; i++ ) {
        if( marker_info[i].id != target_id ) continue;

        if( marker_info[i].cf > cfmax ) {
            cfmax = marker_info[i].cf;
            j = i;
        }
    }
    if( j < 0 ) {
        argSwapBuffers();
        return;
    }
    err = arGetTransMat(&marker_info[j], target_center, target_width, target_trans);
    if( err >= 0.0 ) {
        target_visible = 1;

        if( left_right == 0 ) argDraw2dLeft();
         else                 argDraw2dRight();
        argDrawAttention( calib_pos[co1], co2 );
        argDrawMode2D();

        if( arDebug && gMiniXnum >= 2 && gMiniYnum >= 1 ) {
            glColor3f( 0.0, 1.0, 0.0 );
            glLineWidth( 3.0 );
            argDrawSquare( marker_info[j].vertex, 1, 1 );
            glLineWidth( 1.0 );
        }
    }

    argSwapBuffers();
}
Esempio n. 23
0
//
// This function is called when the window needs redrawing.
//
static void Display(void)
{
    GLdouble p[16];
	GLdouble m[16];
	
	// Select correct buffer for this context.
	glDrawBuffer(GL_BACK);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear the buffers for new frame.
	
	arglDispImage(gARTImage, &gARTCparam, 1.0, gArglSettings);	// zoom = 1.0.
	arVideoCapNext();
	gARTImage = NULL; // Image data is no longer valid after calling arVideoCapNext().
				
	// Projection transformation.
	arglCameraFrustumRH(&gARTCparam, VIEW_DISTANCE_MIN, VIEW_DISTANCE_MAX, p);
	glMatrixMode(GL_PROJECTION);
	glLoadMatrixd(p);
	glMatrixMode(GL_MODELVIEW);
		
	// Viewing transformation.
	glLoadIdentity();
	// Lighting and geometry that moves with the camera should go here.
	// (I.e. must be specified before viewing transformations.)
	//none
	
	//Read leap dump
	int koo = read_leap_dump();

	float dx = px1 - px0;
	float dy = py1 - py0;
	float dz = pz1 - pz0;

	printf("dx %f\n", dx);

	px0 = px1;
	py0 = py1;
	pz0 = pz1;

	float stepX = 100.0f / glutGet(GLUT_WINDOW_X);
	float stepY = 100.0f/ glutGet(GLUT_WINDOW_Y);

	PX = stepX*dx + PX;
	PY = stepY*dy + PY;
	PZ = stepX*dz + PZ;

	if (snapToMarker && gPatt_found) {
	
		// Calculate the camera position relative to the marker.
		// Replace VIEW_SCALEFACTOR with 1.0 to make one drawing unit equal to 1.0 ARToolKit units (usually millimeters).
		arglCameraViewRH(gPatt_trans, m, VIEW_SCALEFACTOR);
		glLoadMatrixd(m);

		// All lighting and geometry to be drawn relative to the marker goes here.
		DrawItem();
	
	} // gPatt_found
	else {
		arglCameraViewRH(gPatt_trans, m, VIEW_SCALEFACTOR);
		glLoadMatrixd(m);

		// All lighting and geometry to be drawn relative to the marker goes here.
		DrawItem();

	}
	
	// Any 2D overlays go here.
	//none
	
	glutSwapBuffers();
}
Esempio n. 24
0
/* main loop */
static void mainLoop(void)
{
    ARUint8         *dataPtr;
    ARMarkerInfo    *marker_info;
    int             marker_num;
    double          err;
    int             i;

    /* grab a vide frame */
    if( (dataPtr = (ARUint8 *)arVideoGetImage()) == NULL ) {
        arUtilSleep(2);
        return;
    }
    if( count == 0 ) arUtilTimerReset();
    count++;

    /* detect the markers in the video frame */
    if( arDetectMarkerLite(dataPtr, thresh, &marker_info, &marker_num) < 0 ) {
        cleanup();
        exit(0);
    }

    argDrawMode2D();
    if( !arDebug ) {
        argDispImage( dataPtr, 0,0 );
    }
    else {
        argDispImage( dataPtr, 1, 1 );
        if( arImageProcMode == AR_IMAGE_PROC_IN_HALF )
            argDispHalfImage( arImage, 0, 0 );
        else
            argDispImage( arImage, 0, 0);

        glColor3f( 1.0, 0.0, 0.0 );
        glLineWidth( 1.0 );
        for( i = 0; i < marker_num; i++ ) {
            argDrawSquare( marker_info[i].vertex, 0, 0 );
        }
        glLineWidth( 1.0 );
    }

    arVideoCapNext();

    if( (err=arMultiGetTransMat(marker_info, marker_num, config)) < 0 ) {
        argSwapBuffers();
        return;
    }
    printf("err = %f\n", err);
    if(err > 100.0 ) {
        argSwapBuffers();
        return;
    }
/*
    for(i=0;i<3;i++) {
        for(j=0;j<4;j++) printf("%10.5f ", config->trans[i][j]);
        printf("\n");
    }
    printf("\n");
*/
    argDrawMode3D();
    argDraw3dCamera( 0, 0 );
    glClearDepth( 1.0 );
    glClear(GL_DEPTH_BUFFER_BIT);
    for( i = 0; i < config->marker_num; i++ ) {
        if( config->marker[i].visible >= 0 ) draw( config->trans, config->marker[i].trans, 0 );
        else                                 draw( config->trans, config->marker[i].trans, 1 );
    }
    argSwapBuffers();
}
Esempio n. 25
0
File: main.c Progetto: SNce/ARMaze
static void dispImage(void)
{
    unsigned char  *dataPtr;
    double         x, y;
    int            ssx, eex, ssy, eey;
    int            i;

    if( status == 0 ) {
        if( (dataPtr = (unsigned char *)arVideoGetImage()) == NULL ) {
            arUtilSleep(2);
            return;
        }
        dispImage2( dataPtr );
        arVideoCapNext();
    }

    else if( status == 1 ) {
        dispImage2( patt.savedImage[patt.loop_num-1] );

        for( i = 0; i < point_num; i++ ) {
            x = patt.point[patt.loop_num-1][i].x_coord;
            y = patt.point[patt.loop_num-1][i].y_coord;
            glColor3f( 1.0, 0.0, 0.0 );
            glBegin(GL_LINES);
              glVertex2f( x-10, (ysize-1)-y );
              glVertex2f( x+10, (ysize-1)-y );
              glVertex2f( x, (ysize-1)-(y-10) );
              glVertex2f( x, (ysize-1)-(y+10) );
            glEnd();
        }

        if( sx != -1 && sy != -1 ) {
            if( sx < ex ) { ssx = sx; eex = ex; }
             else         { ssx = ex; eex = sx; }
            if( sy < ey ) { ssy = sy; eey = ey; }
             else         { ssy = ey; eey = sy; }
            dispClipImage( ssx, ysize-1-ssy, eex-ssx+1, eey-ssy+1, clipImage );
#if 0
            glColor3f( 0.0, 0.0, 1.0 );
            glBegin(GL_LINE_LOOP);
              glVertex2f( sx, (ysize-1)-sy );
              glVertex2f( ex, (ysize-1)-sy );
              glVertex2f( ex, (ysize-1)-ey );
              glVertex2f( sx, (ysize-1)-ey );
            glEnd();
#endif
        }
    }

    else if( status == 2 ) {
        dispImage2( patt.savedImage[check_num] );
        for( i = 0; i < patt.h_num*patt.v_num; i++ ) {
            x = patt.point[check_num][i].x_coord;
            y = patt.point[check_num][i].y_coord;
            glColor3f( 1.0, 0.0, 0.0 );
            glBegin(GL_LINES);
              glVertex2f( x-10, (ysize-1)-y );
              glVertex2f( x+10, (ysize-1)-y );
              glVertex2f( x, (ysize-1)-(y-10) );
              glVertex2f( x, (ysize-1)-(y+10) );
            glEnd();
        }
        draw_line();
    }

    glutSwapBuffers();
}
Esempio n. 26
0
//=======================================================
// メインループ関数
//=======================================================
void MainLoop(void)
{
	ARUint8          *image;			// カメラキャプチャ画像
	ARMarkerInfo     *marker_info;		// マーカ情報
	int              marker_num;		// 検出されたマーカの数
	int              i, j, k;

	// カメラ画像の取得
	if( (image = (ARUint8 *)arVideoGetImage()) == NULL ){
		arUtilSleep( 2 );
		return;
	}
	if( count == 0 ) arUtilTimerReset();
	count++;

	// カメラ画像の描画
	argDrawMode2D();
	argDispImage( image, 0, 0 );


	// マーカの検出と認識
	if( arDetectMarker( image, thresh, &marker_info, &marker_num ) < 0 ){
		Cleanup();
		exit(0);
	}

	// 次の画像のキャプチャ指示
	arVideoCapNext();

	// 3Dオブジェクトを描画するための準備
	argDrawMode3D();
	argDraw3dCamera( 0, 0 );
	glClearDepth(1.0);					// デプスバッファの消去値
	glClear( GL_DEPTH_BUFFER_BIT );		// デプスバッファの初期化

	if(movex[0]!=0 && movex[3]!=0 && movex[7]!=0){
		rmove++;
		
		if(rmove!=0){
			Drawnashi( marker[3].mark_id, marker[3].patt_trans);
		}
		if(rmove>40.0){
			rmove=0.0;
			for(int i=0;i<MARK_NUM;i++){
				movex[i]=0;
			}
		}
	}else{
		// マーカの一致度の比較
		for( i=0; i<MARK_NUM; i++ ){
			k = -1;
			for( j=0; j<marker_num; j++ ){
				if( marker[i].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 ){
				if(marker[i].visible != 0){
					midi_out(i+1);
					midi_stop(i+1);
					movex[i]=1;
					marker[i].visible = 0;
				}else if(movex[i]!=0){
					DrawObject( marker[i].mark_id, marker[i].patt_trans,i );
				}
			}else{
				// 座標変換行列を取得
				if( marker[i].visible == 0 ) {
					// 1フレームを使ってマーカの位置・姿勢(座標変換行列)の計算
					arGetTransMat( &marker_info[k], marker[i].patt_center, marker[i].patt_width, marker[i].patt_trans );    //初回の認識ではarGetTransMatを2回目以降ではarGetTransMatContを使うと安定するらしい
					marker[i].visible = 1;

				} else {
					// 前のフレームを使ってマーカの位置・姿勢(座標変換行列)の計算
					arGetTransMatCont( &marker_info[k], marker[i].patt_trans, marker[i].patt_center, marker[i].patt_width, marker[i].patt_trans );
				}

				// 3Dオブジェクトの描画
				if(movex[i]!=0){
					DrawObject( marker[i].mark_id, marker[i].patt_trans,i );
				}
			}
			if(movex[i]>=40.0) movex[i]=0;
			if(movex[i]!=0) movex[i]++;
		}
	}
	// バッファの内容を画面に表示
	argSwapBuffers();
}