static void geometryout( void )
{
    double    gl_para[16];
    GLfloat   mat_ambient[]     = {0.0, 0.0, 1.0, 1.0};
    GLfloat   mat_flash[]       = {0.0, 0.0, 1.0, 1.0};
    GLfloat   mat_flash_shiny[] = {50.0};
    GLfloat   light_position[]  = {100.0,-200.0,200.0,0.0};
    GLfloat   ambi[]            = {0.1, 0.1, 0.1, 0.1};
    GLfloat   lightZeroColor[]  = {0.9, 0.9, 0.9, 0.1};

   
    argDrawMode3D();
    argDraw3dCamera( 0, 0 );
    glClearDepth( 1.0 );
    glClear(GL_DEPTH_BUFFER_BIT);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);
    
	/* load the camera transformation matrix */
    argConvGlpara(patt_trans, gl_para);
	
	printf("Matrix:\n\t%d\t%d\t%d\t%d\n\t%d\t%d\t%d\t%d\n\t%d\t%d\t%d\t%d\n\t%d\t%d\t%d\t%d\n\n",
											gl_para[0], gl_para[1], gl_para[2], gl_para[3],
											gl_para[4], gl_para[5], gl_para[6], gl_para[7],
											gl_para[8], gl_para[9], gl_para[10], gl_para[11],
											gl_para[12], gl_para[13], gl_para[14], gl_para[15]);

}
Example #2
0
static void draw( ARdouble trans[3][4] )
{
    ARdouble    gl_para[16];
    
    argDrawMode3D(vp);

    /* load the camera transformation matrix */
    argConvGlpara(trans, gl_para);
    glMatrixMode(GL_MODELVIEW);
#ifdef ARDOUBLE_IS_FLOAT
    glLoadMatrixf( gl_para );
#else
    glLoadMatrixd( gl_para );
#endif
    
    glColor3f( 1.0f, 1.0f, 0.0f );
    glBegin(GL_LINES);
    glVertex2f( -50.0f, -50.0f );
    glVertex2f( -50.0f,  50.0f );
    glVertex2f(  50.0f, -50.0f );
    glVertex2f(  50.0f,  50.0f );
    glVertex2f( -50.0f, -50.0f );
    glVertex2f(  50.0f, -50.0f );
    glVertex2f( -50.0f,  50.0f );
    glVertex2f(  50.0f,  50.0f );
    glEnd();
}
Example #3
0
void DrawObject()
{
    char *str1="Score ";
    char *str2="GameOver";
    char buf[16];
    sprintf(buf,"%d",score);
    double gl_para[16];
    argDrawMode3D();
    argDraw3dCamera(0, 0);

    argConvGlpara(patt_trans,gl_para);
    glMatrixMode(GL_MODELVIEW);
    glLoadMatrixd(gl_para);
    SetLight();

    glClear(GL_DEPTH_BUFFER_BIT);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_LIGHTING);
    glTranslatef(-20.0f,0.0f,20.0f);
    //  glRotatef(0.0,1.0,0.0,0.0);
    if(GameOver==false){
	FontRender(str1,0,0);
        FontRender(buf,60,0);
	WallRender();
	p.Render(Box);
	f.Render(Box);
    }
    else{
	FontRender(str2,0,0);
    }
    glDisable(GL_LIGHTING);
    glDisable(GL_DEPTH_TEST);
}
static void draw( double trans1[3][4], double trans2[3][4], int mode )
{
    double    gl_para[16];
    GLfloat   mat_ambient[]     = {0.0, 0.0, 1.0, 1.0};
    GLfloat   mat_ambient1[]    = {1.0, 0.0, 0.0, 1.0};
    GLfloat   mat_flash[]       = {0.0, 0.0, 1.0, 1.0};
    GLfloat   mat_flash1[]      = {1.0, 0.0, 0.0, 1.0};
    GLfloat   mat_flash_shiny[] = {50.0};
    GLfloat   mat_flash_shiny1[]= {50.0};
    GLfloat   light_position[]  = {100.0,-200.0,200.0,0.0};
    GLfloat   ambi[]            = {0.1, 0.1, 0.1, 0.1};
    GLfloat   lightZeroColor[]  = {0.9, 0.9, 0.9, 0.1};
    
    argDrawMode3D();
    argDraw3dCamera( 0, 0 );
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);
    
    /* load the camera transformation matrix */
    glMatrixMode(GL_MODELVIEW);
    argConvGlpara(trans1, gl_para);
    glLoadMatrixd( gl_para );
    argConvGlpara(trans2, gl_para);
    glMultMatrixd( gl_para );

    if( mode == 0 ) {
        glEnable(GL_LIGHTING);
        glEnable(GL_LIGHT0);
        glLightfv(GL_LIGHT0, GL_POSITION, light_position);
        glLightfv(GL_LIGHT0, GL_AMBIENT, ambi);
        glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor);
        glMaterialfv(GL_FRONT, GL_SPECULAR, mat_flash);
        glMaterialfv(GL_FRONT, GL_SHININESS, mat_flash_shiny);	
        glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
    }
    else {
        glEnable(GL_LIGHTING);
        glEnable(GL_LIGHT0);
        glLightfv(GL_LIGHT0, GL_POSITION, light_position);
        glLightfv(GL_LIGHT0, GL_AMBIENT, ambi);
        glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor);
        glMaterialfv(GL_FRONT, GL_SPECULAR, mat_flash1);
        glMaterialfv(GL_FRONT, GL_SHININESS, mat_flash_shiny1);	
        glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient1);
    }
    glMatrixMode(GL_MODELVIEW);
    glTranslatef( 0.0, 0.0, 25.0 );
    if( !arDebug ) glutSolidCube(50.0);
     else          glutWireCube(50.0);
    glDisable( GL_LIGHTING );

    glDisable( GL_DEPTH_TEST );
}
Example #5
0
/* draw the user object */
static int  draw_object(int obj_id, double gl_para[16])
{
	GLfloat   mat_ambient[] = { 0.0, 0.0, 1.0, 1.0 };
	GLfloat   mat_ambient_collide[] = { 1.0, 0.0, 0.0, 1.0 };
	GLfloat   mat_flash[] = { 0.0, 0.0, 1.0, 1.0 };
	GLfloat   mat_flash_collide[] = { 1.0, 0.0, 0.0, 1.0 };
	GLfloat   mat_flash_shiny[] = { 50.0 };
	GLfloat   light_position[] = { 100.0, -200.0, 200.0, 0.0 };
	GLfloat   ambi[] = { 0.1, 0.1, 0.1, 0.1 };
	GLfloat   lightZeroColor[] = { 0.9, 0.9, 0.9, 0.1 };

	argDrawMode3D();
	argDraw3dCamera(0, 0);
	glMatrixMode(GL_MODELVIEW);
	glLoadMatrixd(gl_para);

	/* set the material */
	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);
	glLightfv(GL_LIGHT0, GL_POSITION, light_position);
	glLightfv(GL_LIGHT0, GL_AMBIENT, ambi);
	glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor);

	glMaterialfv(GL_FRONT, GL_SHININESS, mat_flash_shiny);

	switch (obj_id){
	case 0:
		glMaterialfv(GL_FRONT, GL_SPECULAR, mat_flash);
		glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
		glColor3f(1.0, 2.0, 0.0);

		//glTranslated(10.0, 20.0, -100.0);
		draw_scene();
		//glTranslated(-10.0, -20.0, 100.0);
		break;
	case 1:
		glMaterialfv(GL_FRONT, GL_SPECULAR, mat_flash);
		glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
		glColor3f(1.0, 0.0, 0.0);
		//draw piano left
			break;
	case 2:
		
			glMaterialfv(GL_FRONT, GL_SPECULAR, mat_flash);
			glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
			glColor3f(1.0, 2.0, 0.0);
			draw_controller(distX/4, distY/4);
		break;
		}
		argDrawMode2D();

		return 0;
	}
static void draw( int object, double trans[3][4] )
{
    double    gl_para[16];
    GLfloat   mat_ambient[]     = {0.0, 0.0, 1.0, 1.0};
    GLfloat   mat_flash[]       = {0.0, 0.0, 1.0, 1.0};
    GLfloat   mat_flash_shiny[] = {50.0};
    GLfloat   light_position[]  = {100.0,-200.0,200.0,0.0};
    GLfloat   ambi[]            = {0.1, 0.1, 0.1, 0.1};
    GLfloat   lightZeroColor[]  = {0.9, 0.9, 0.9, 0.1};
    
    argDrawMode3D();
    argDraw3dCamera( 0, 0 );
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);
    
    /* load the camera transformation matrix */
    argConvGlpara(trans, gl_para);
    glMatrixMode(GL_MODELVIEW);
    glLoadMatrixd( gl_para );

    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);
    glLightfv(GL_LIGHT0, GL_AMBIENT, ambi);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor);
    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_flash);
    glMaterialfv(GL_FRONT, GL_SHININESS, mat_flash_shiny);	
    glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
    glMatrixMode(GL_MODELVIEW);

    switch( object ) {
      case 0:
        glTranslatef( 0.0, 0.0, 25.0 );
        glutSolidCube(50.0);
        break;
      case 1:
        glTranslatef( 0.0, 0.0, 40.0 );
        glutSolidSphere(40.0, 24, 24);
        break;
      case 2:
        glutSolidCone(25.0, 100.0, 20, 24);
        break;
      default:
        glTranslatef( 0.0, 0.0, 10.0 );
        glutSolidTorus(10.0, 40.0, 24, 24);
        break;
    }

    glDisable( GL_LIGHTING );
    glDisable( GL_DEPTH_TEST );
}
Example #7
0
static void draw(ARdouble trans[3][4])
{
    ARdouble gl_para[16];
    GLfloat  mat_diffuse[]     = {0.0f, 0.0f, 1.0f, 0.0f};
    GLfloat  mat_flash[]       = {1.0f, 1.0f, 1.0f, 0.0f};
    GLfloat  mat_flash_shiny[] = {50.0f};
    GLfloat  light_position[]  = {100.0f, -200.0f, 200.0f, 0.0f};
    GLfloat  light_ambi[]      = {0.1f, 0.1f, 0.1f, 0.0f};
    GLfloat  light_color[]     = {1.0f, 1.0f, 1.0f, 0.0f};

    argSetWindow(w1);
    argDrawMode3D(vp1);
    glClearDepth(1.0);
    glClear(GL_DEPTH_BUFFER_BIT);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);

    /* load the camera transformation matrix */
    argConvGlpara(trans, gl_para);
    glMatrixMode(GL_MODELVIEW);
#ifdef ARDOUBLE_IS_FLOAT
    glLoadMatrixf(gl_para);
#else
    glLoadMatrixd(gl_para);
#endif

    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);
    glLightfv(GL_LIGHT0, GL_AMBIENT,  light_ambi);
    glLightfv(GL_LIGHT0, GL_DIFFUSE,  light_color);
    glLightfv(GL_LIGHT0, GL_SPECULAR, light_color);
    glMaterialfv(GL_FRONT, GL_SPECULAR,  mat_flash);
    glMaterialfv(GL_FRONT, GL_SHININESS, mat_flash_shiny);
    glMaterialfv(GL_FRONT, GL_DIFFUSE,   mat_diffuse);
    glMaterialfv(GL_FRONT, GL_AMBIENT,   mat_diffuse);

#if 0
    glTranslatef(0.0f, 0.0f, 40.0f);
    glutSolidCube(80.0);
#else
    glTranslatef(0.0f, 0.0f, 20.0f);
    glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
    glutSolidTeapot(40.0);
#endif
    glDisable(GL_LIGHT0);
    glDisable(GL_LIGHTING);

    glDisable(GL_DEPTH_TEST);
}
/* draw the targets */
static void draw( targetInfo myTarget, double BaseTrans[3][4])
{
    double    gl_para[16];
    GLfloat   light_position[]  = {100.0,-200.0,200.0,0.0};
    GLfloat   ambi[]            = {0.1, 0.1, 0.1, 0.1};
    GLfloat   lightZeroColor[]  = {0.9, 0.9, 0.9, 0.1};
    GLfloat   mat_ambient2[]    = {0.0, 0.0, 1.0, 1.0};
	GLfloat   mat_ambient[]    = {1.0, 0.0, 0.0, 1.0};
    GLfloat   mat_flash2[]      = {0.0, 1.0, 1.0, 1.0};
    GLfloat   mat_flash_shiny2[]= {50.0};
	
    argDrawMode3D();
    argDraw3dCamera( 0, 0 );
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);
    
    /* load the camera transformation matrix */
    glMatrixMode(GL_MODELVIEW);
    argConvGlpara(BaseTrans, gl_para);
    glLoadMatrixd( gl_para );

	/* set the lighting and the materials */		
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);
    glLightfv(GL_LIGHT0, GL_AMBIENT, ambi);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor);
    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_flash2);
    glMaterialfv(GL_FRONT, GL_SHININESS, mat_flash_shiny2);
	if(myTarget.state == TOUCHED)
		glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
	else 
        glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient2);
    
    glMatrixMode(GL_MODELVIEW);
    glTranslatef( myTarget.pos[0], myTarget.pos[1], myTarget.pos[2] );
    glutSolidCube(40.0);

	if(myTarget.state == TOUCHED){
		glColor3f(1.0,1.0,1.0);	
		glLineWidth(6.0);
		glutWireCube(60.0);
		glLineWidth(1.0);
	}
    
	glDisable( GL_LIGHTING );
    glDisable( GL_DEPTH_TEST );    
    argDrawMode2D();
}
Example #9
0
void DrawObject(void)
{
	double gl_para[16];

	argDrawMode3D();
	argDraw3dCamera(0, 0);

	argConvGlpara(patt_trans, gl_para);
	glMatrixMode(GL_MODELVIEW);
	glLoadMatrixd(gl_para);

	glTranslatef(0.0, 0.0, 20.0);
	glColor3f(0.0, 1.0, 0.0);
	glLineWidth(3.0);
	glutWireCube(40.0);

}
Example #10
0
/* draw the user object */
static int  draw_object( int obj_id, double gl_para[16], int collide_flag )
{
    GLfloat   mat_ambient[]				= {0.0, 0.0, 1.0, 1.0};
    GLfloat   mat_ambient_collide[]     = {1.0, 0.0, 0.0, 1.0};
    GLfloat   mat_flash[]				= {0.0, 0.0, 1.0, 1.0};
    GLfloat   mat_flash_collide[]       = {1.0, 0.0, 0.0, 1.0};
    GLfloat   mat_flash_shiny[] = {50.0};
    GLfloat   light_position[]  = {100.0,-200.0,200.0,0.0};
    GLfloat   ambi[]            = {0.1, 0.1, 0.1, 0.1};
    GLfloat   lightZeroColor[]  = {0.9, 0.9, 0.9, 0.1};

    argDrawMode3D();
    argDraw3dCamera( 0, 0 );
    glMatrixMode(GL_MODELVIEW);
    glLoadMatrixd( gl_para );

    /* set the material */
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);
    glLightfv(GL_LIGHT0, GL_AMBIENT, ambi);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor);

    glMaterialfv(GL_FRONT, GL_SHININESS, mat_flash_shiny);

    if(collide_flag) {
        glMaterialfv(GL_FRONT, GL_SPECULAR, mat_flash_collide);
        glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient_collide);
        /* draw a cube */
        glTranslatef( 0.0, 0.0, 30.0 );
        glutSolidSphere(30,12,6);
    }
    else {
        glMaterialfv(GL_FRONT, GL_SPECULAR, mat_flash);
        glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
        /* draw a cube */
        glTranslatef( 0.0, 0.0, 30.0 );
        glutSolidCube(60);
    }

    argDrawMode2D();

    return 0;
}
/* draw the items on the ground */
void drawItems(double trans[3][4], ItemList* itlist)
{ 
  int i;
  double        gl_para[16];
  GLfloat   light_position[]  = {100.0,-200.0,200.0,0.0};
  GLfloat   ambi[]            = {0.1, 0.1, 0.1, 0.1};
  GLfloat   lightZeroColor[]  = {0.9, 0.9, 0.9, 0.1};
  GLfloat   mat_ambient[]    = {0.0, 1.0, 0.0, 1.0};
  GLfloat   mat_flash2[]      = {0.0, 1.0, 1.0, 1.0};
  GLfloat   mat_flash_shiny2[]= {50.0};

  argDrawMode3D();
  argDraw3dCamera( 0, 0 );
  glEnable(GL_DEPTH_TEST);
  glDepthFunc(GL_LEQUAL);
  
  glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);
    glLightfv(GL_LIGHT0, GL_AMBIENT, ambi);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor);
    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_flash2);
    glMaterialfv(GL_FRONT, GL_SHININESS, mat_flash_shiny2);
    glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);

    /* load the camera transformation matrix */
    glMatrixMode(GL_MODELVIEW);
    argConvGlpara(trans, gl_para);
    glLoadMatrixd( gl_para );
    for(i = 0; i < itlist->itemnum; i ++ )
      {
	if (!itlist->item[i].onpaddle)
	  {
	    glPushMatrix();
	    glTranslatef(itlist->item[i].pos[0],itlist->item[i].pos[1], 10.0 );
	     glColor3f(0.0,1.0,0.0);
	     glutSolidSphere(10,10,10);
	    glPopMatrix();
	  }
      }
    glDisable( GL_LIGHTING );
    glDisable( GL_DEPTH_TEST );    
    argDrawMode2D();
}
Example #12
0
static void draw( void )
{
    double    gl_para[16];
    GLfloat   mat_ambient[]     = {0.0, 0.0, 1.0, 1.0};
    GLfloat   mat_flash[]       = {0.0, 0.0, 1.0, 1.0};
    GLfloat   mat_flash_shiny[] = {50.0};
    GLfloat   light_position[]  = {100.0,-200.0,200.0,0.0};
    GLfloat   ambi[]            = {0.1, 0.1, 0.1, 0.1};
    GLfloat   lightZeroColor[]  = {0.9, 0.9, 0.9, 0.1};
    
    argDrawMode3D();
    argDraw3dCamera( 0, 0 );
    glClearDepth( 1.0 );
    glClear(GL_DEPTH_BUFFER_BIT);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);
    
    /* load the camera transformation matrix */
    argConvGlpara(patt_trans, gl_para);
    glMatrixMode(GL_MODELVIEW);
    glLoadMatrixd( gl_para );

    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);
    glLightfv(GL_LIGHT0, GL_AMBIENT, ambi);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor);
    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_flash);
    glMaterialfv(GL_FRONT, GL_SHININESS, mat_flash_shiny);	
    glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
    glMatrixMode(GL_MODELVIEW);
    glTranslatef( 0.0, 0.0, -25.0 );
    //glutSolidCube(60.0);
    glDisable( GL_LIGHTING );
	/// the position of the laser in the block is below the fiducial
	glTranslatef( 0.0, 0.0, 0.0 );
	glBegin(GL_LINES);
	glVertex3f(0.0,0.0,0.0);
	glVertex3f(0.0,900.0,0.0);
	
	glEnd();

    glDisable( GL_DEPTH_TEST );
}
Example #13
0
static void draw2( void )
{
	static int before_visible[2] = {0, 0};
	static int Wire_count = -1;  // 出力する Wire の選択(0〜4)
	static int flag_first1 = 0;  // 一度でも hiro が見つかったら立つ

	static double begin[3];
		
	/* 3Dオブジェクトを描画するための準備 */
	argDrawMode3D();
	argDraw3dCamera(0, 0);

	/* Zバッファなどの設定 */
	glClear( GL_DEPTH_BUFFER_BIT );	// 陰面処理の設定
	glEnable( GL_DEPTH_TEST );		// 陰面処理の適用

	mySetLight();				// 光源の設定
	glEnable( GL_LIGHTING );	// 光源の適用

	test2();
	

	myMarkSquare(PTT1_MARK_ID); // 動作確認用コード

		/***************************/
		/*                         */
		/*       draw関数をかけ    */
		/*                         */
		/*                         */
		/***************************/






	glDisable( GL_LIGHTING );	// 光源の無効化
	glDisable( GL_DEPTH_TEST );	// 陰面処理の無効化
}
Example #14
0
static void draw( double trans[3][4] )
{
    double    gl_para[16];
    GLfloat   mat_ambient[]     = {0.0, 0.0, 1.0, 1.0};
    GLfloat   mat_flash[]       = {0.0, 0.0, 1.0, 1.0};
    GLfloat   mat_flash_shiny[] = {50.0};
    GLfloat   light_position[]  = {100.0,-200.0,200.0,0.0};
    GLfloat   ambi[]            = {0.1, 0.1, 0.1, 0.1};
    GLfloat   lightZeroColor[]  = {0.9, 0.9, 0.9, 0.1};
    
    argDrawMode3D();
    argDraw3dCamera( 0, 0 );
    glClearDepth( 1.0 );
    glClear(GL_DEPTH_BUFFER_BIT);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);
    
    /* load the camera transformation matrix */
    argConvGlpara(trans, gl_para);
	//printf("%.2f  %.2f  %.2f\n", trans[0][3], trans[1][3], trans[2][3]);
    glMatrixMode(GL_MODELVIEW);
    glLoadMatrixd( gl_para );

    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);
    glLightfv(GL_LIGHT0, GL_AMBIENT, ambi);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor);
    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_flash);
    glMaterialfv(GL_FRONT, GL_SHININESS, mat_flash_shiny);	
    glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
    glMatrixMode(GL_MODELVIEW);
    glTranslatef( 0.0, 0.0, size/2.0f );
    glutSolidCube(size);
    glDisable( GL_LIGHTING );

    glDisable( GL_DEPTH_TEST );
}
	static void draw() {
		double    gl_para[16];
		GLfloat   mat_ambient[] = { 0.0, 0.0, 1.0, 1.0 };
		GLfloat   mat_flash[] = { 0.0, 0.0, 1.0, 1.0 };
		GLfloat   mat_flash_shiny[] = { 50.0 };
		GLfloat   light_position[] = { 100.0, -200.0, 200.0, 0.0 };
		GLfloat   ambi[] = { 0.1, 0.1, 0.1, 0.1 };
		GLfloat   lightZeroColor[] = { 0.9, 0.9, 0.9, 0.1 };

		//Initialise OpenGL renderer
		argDrawMode3D();
		argDraw3dCamera(0, 0);
		glClearDepth(1.0);
		glClear(GL_DEPTH_BUFFER_BIT);
		glEnable(GL_DEPTH_TEST);
		glDepthFunc(GL_LEQUAL);

		/* load the camera transformation matrix */
		argConvGlpara(patt_trans, gl_para);
		glMatrixMode(GL_MODELVIEW);
		glLoadMatrixd(gl_para);

		//Lighting
		glEnable(GL_LIGHTING);
		glEnable(GL_LIGHT0);
		glLightfv(GL_LIGHT0, GL_POSITION, light_position);
		glLightfv(GL_LIGHT0, GL_AMBIENT, ambi);
		glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor);
		glMaterialfv(GL_FRONT, GL_SPECULAR, mat_flash);
		glMaterialfv(GL_FRONT, GL_SHININESS, mat_flash_shiny);
		glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
		glMatrixMode(GL_MODELVIEW);
		glTranslatef(0.0, 0.0, 25.0);
		glutSolidCube(50.0);
		glDisable(GL_LIGHTING);

		glDisable(GL_DEPTH_TEST);
	}
static void draw( void )
{

    GLfloat   mat_ambient[]     = {0.0, 0.0, 1.0, 1.0};
    GLfloat   mat_flash[]       = {0.0, 0.0, 1.0, 1.0};
    GLfloat   mat_flash_shiny[] = {50.0};
    GLfloat   light_position[]  = {100.0,-200.0,200.0,0.0};
    GLfloat   ambi[]            = {0.1, 0.1, 0.1, 0.1};
    GLfloat   lightZeroColor[]  = {0.9, 0.9, 0.9, 0.1};
    
	argDrawMode3D();
    argDraw3dCamera( 0, 0 );
    glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);
    
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);
    glLightfv(GL_LIGHT0, GL_AMBIENT, ambi);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor);
    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_flash);
    glMaterialfv(GL_FRONT, GL_SHININESS, mat_flash_shiny);	
    glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);

    glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
    glTranslatef( 0.0, 0.0, 500.0 );
	glRotatef(rotate_angle,0.,1.,0.);
	glRotatef(180.,1.,0.,0.);
    glutSolidTeapot(100.0);

    glDisable( GL_LIGHTING );

    glDisable( GL_DEPTH_TEST );
}
Example #17
0
static void draw(void) {
	int i,j,k;
	float size = CUBE_SIZE;
	float normals[6][3] = {
		{ 0.0,  0.0, -1.0},
		{ 1.0,  0.0,  0.0},
		{ 0.0,  0.0,  1.0},
		{-1.0,  0.0,  0.0},
		{ 0.0,  1.0,  0.0},
		{ 0.0, -1.0,  0.0}
	};
		
	float cube_points[8][3] ={
		{ -size, -size, -size },
		{  size, -size, -size },
		{  size, -size,  size },
		{ -size, -size,  size },
		{ -size,  size, -size },
		{  size,  size, -size },
		{  size,  size,  size },
		{ -size,  size,  size }
	};

	/* 3Dオブジェクトを描画するための準備 */
	argDrawMode3D();
	argDraw3dCamera(0, 0);


	glClear(GL_DEPTH_BUFFER_BIT); //バッファの消去
	glEnable( GL_DEPTH_TEST );		// 陰面処理の適用

	mySetLight();
	glEnable( GL_LIGHTING );

	myMatrix(object[PTT1_MARK_ID].patt_trans);
	
	renew(); // フレーム毎の更新内容

	// 立方体
	glPushMatrix();
		glTranslated( c_trans[0], c_trans[1], c_trans[2]);//平行移動値の設定
		glRotatef(c_angle[0], 1.0, 0.0, 0.0 );
		glRotatef(c_angle[1], 0.0, 1.0, 0.0 );
		glRotatef(c_angle[2], 0.0, 0.0, 1.0 );
		
		/* 前 */
		glEnable( GL_TEXTURE_2D );
		glBegin( GL_QUADS );
			mySetMaterial( 1.0, 1.0, 1.0 );
			glBindTexture(GL_TEXTURE_2D, texture);
			glNormal3fv(normals[0]);
			glTexCoord2f(0.0, 1.0); glVertex3fv(cube_points[0]);
			glTexCoord2f(1.0, 1.0); glVertex3fv(cube_points[1]);
			glTexCoord2f(1.0, 0.0); glVertex3fv(cube_points[5]);
			glTexCoord2f(0.0, 0.0); glVertex3fv(cube_points[4]);
		glEnd();
		glDisable( GL_TEXTURE_2D );
		
		/* 右 */
		glBegin( GL_QUADS );
			mySetMaterial( 0.0, 1.0, 0.0);
			glNormal3fv(normals[1]);
			glVertex3fv(cube_points[1]);
			glVertex3fv(cube_points[2]);
			glVertex3fv(cube_points[6]);
			glVertex3fv(cube_points[5]);
		glEnd();

		/* 後ろ */
		glBegin( GL_QUADS );
			mySetMaterial( 0.0, 1.0, 1.0);
			glNormal3fv(normals[2]);
			glVertex3fv(cube_points[2]);
			glVertex3fv(cube_points[3]);
			glVertex3fv(cube_points[7]);
			glVertex3fv(cube_points[6]);
		glEnd();

		/* 左 */
		glBegin( GL_QUADS );
			mySetMaterial( 1.0, 0.0, 1.0);
			glNormal3fv(normals[3]);
			glVertex3fv(cube_points[3]);
			glVertex3fv(cube_points[0]);
			glVertex3fv(cube_points[4]);
			glVertex3fv(cube_points[7]);
		glEnd();

		/* 上 */
		glBegin( GL_QUADS );
			mySetMaterial( 0.0, 0.0, 1.0);
			glNormal3fv(normals[4]);
			glVertex3fv(cube_points[4]);
			glVertex3fv(cube_points[5]);
			glVertex3fv(cube_points[6]);
			glVertex3fv(cube_points[7]);
		glEnd();

		/* 下 */
		glBegin( GL_QUADS );
			mySetMaterial( 1.0, 1.0, 0.0);
			glNormal3fv(normals[5]);
			glVertex3fv(cube_points[0]);
			glVertex3fv(cube_points[1]);
			glVertex3fv(cube_points[2]);
			glVertex3fv(cube_points[3]);
		glEnd();

	glPopMatrix();


	glDisable( GL_LIGHTING );
	glDisable( GL_DEPTH_TEST );		// 陰面処理の適用
}
/* 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");
    }
}
Example #19
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
}
Example #20
0
static void draw( void )
{
	static int before_visible[2] = {0, 0};
	static int Wire_count = -1;  // 出力する Wire の選択(0〜4)
	static int flag_first1 = 0;  // 一度でも hiro が見つかったら立つ
	int i;
	static double begin[3];
	double wtrans[3][4];
	double gl_para[16];
		
	/* 3Dオブジェクトを描画するための準備 */
	argDrawMode3D();
	argDraw3dCamera(0, 0);

	/* Zバッファなどの設定 */
	glClear( GL_DEPTH_BUFFER_BIT );	// 陰面処理の設定
	glEnable( GL_DEPTH_TEST );		// 陰面処理の適用

	mySetLight();				// 光源の設定
	glEnable( GL_LIGHTING );	// 光源の適用

	/* マーカの出現と消失の処理 */

	/* マーカ1の処理 */
	if( myCheck_appear(before_visible[PTT1_MARK_ID], object[PTT1_MARK_ID].visible) ){
		begin[0] = object[PTT1_MARK_ID].patt_trans[0][3];
		begin[1] = object[PTT1_MARK_ID].patt_trans[1][3];
		begin[2] = object[PTT1_MARK_ID].patt_trans[2][3];

		points[L_P_count].flag_after_change = 0;
	}
	if( myCheck_disappear(before_visible[PTT1_MARK_ID], object[PTT1_MARK_ID].visible) ){
		myCopyTrans( object[PTT1_MARK_ID].patt_trans, points[L_P_count].trans);
		points[L_P_count].start_point[0] = begin[0] - object[PTT1_MARK_ID].patt_trans[0][3];
		points[L_P_count].start_point[1] = -( begin[1] - object[PTT1_MARK_ID].patt_trans[1][3] ); // Y軸はカメラに対して反転しているので
		points[L_P_count].start_point[2] = -( begin[2] - object[PTT1_MARK_ID].patt_trans[2][3] ); // Z軸はカメラに対して反転しているので
		for(i=0; i<3; i++){
			points[L_P_count].end_point[i] = 0.0;
		}
		myMoveBallInit( &points[L_P_count] );

		L_P_count++;
		if(MAX_LINES <= L_P_count){
			L_P_count = 0;
		}
	}


	
	/* マーカ2の出現と消失 */
	if( myCheck_appear(before_visible[PTT2_MARK_ID], object[PTT2_MARK_ID].visible) ){
		for(i=0; i < L_P_count; i++){
			arUtilMatMul( itrans2, points[i].trans, wtrans);
			myCopyTrans( wtrans, points[i].trans);
			
			points[i].flag_after_change = 1;
		}
	}
	if( myCheck_disappear(before_visible[PTT2_MARK_ID], object[PTT2_MARK_ID].visible) ){
		for(i=0; i < L_P_count; i++){
			arUtilMatMul( object[PTT2_MARK_ID].patt_trans, points[i].trans, wtrans);
			myCopyTrans( wtrans, points[i].trans );
		}
	}

	/* 3Dオブジェクトの描画 */

	/* 過去に描いた線分の描画 */
	if(flag_first1 && L_P_count >= 1 && !(object[PTT2_MARK_ID].visible) ){
		mySelectColor( 1.0, 0.0, 0.0); // 材質特性の設定
		glLineWidth( 5.0);
		for(i=0; i < L_P_count; i++){
			glPushMatrix(); // 念のため
				myMatrix( points[i].trans);
				myLineLoop(i, i+1);
			glPopMatrix();  // 念のため
		}
	}

	/* マーカ1(Hiro) が映ったときの処理 */
	if(object[PTT1_MARK_ID].visible){
		flag_first1 = 1;

		/* 現在書いている線分の描画 */
		myMatrix(object[PTT1_MARK_ID].patt_trans);
		mySelectColor( 1.0, 0.8, 0.0); // 材質特性の設定
		glLineWidth( 5.0);

		glBegin( GL_LINES );
			glVertex3f( begin[0] - object[PTT1_MARK_ID].patt_trans[0][3], -( begin[1] - object[PTT1_MARK_ID].patt_trans[1][3] ),
				-( begin[2] - object[PTT1_MARK_ID].patt_trans[2][3] ) );
			glVertex3f( 0.0, 0.0, 0.0 );
		glEnd();

		/* hiro のマーカを縁取り */
		myMatrix(object[PTT1_MARK_ID].patt_trans);
		mySelectColor( 0.0, 0.0, 1.0); // 材質特性の設定
		glLineWidth( 3.0);
		myMarkSquare (PTT1_MARK_ID);
	}

	/* マーカ2(kanji) が表示されているとき */
	
	if(object[PTT2_MARK_ID].visible){
		/* マーカ2の縁取り */
		myMatrix(object[PTT2_MARK_ID].patt_trans);
		mySelectColor( 0.0, 1.0, 0.0); // 材質特性の設定
		glLineWidth( 3.0);
		myMarkSquare (PTT2_MARK_ID);

		/* 座標変換 */
		glLineWidth( 5.0);

		for(i=0; i < L_P_count; i++){
			glPushMatrix();
				mySelectColor( 0.0, 0.0, 1.0); // 材質特性の設定
				argConvGlpara( points[i].trans, gl_para );
				glMultMatrixd( gl_para );
				myLineLoop(i, i+1);
				if( flag_animation){
					myMoveBall( &points[i] );
				}
				else{
					myMoveBall2( &points[i], i );
				}
			glPopMatrix();
		}
	}

	visible_log(PTT_NUM, before_visible);	// 各マーカの visible 状態の記録
	glDisable( GL_LIGHTING );	// 光源の無効化
	glDisable( GL_DEPTH_TEST );	// 陰面処理の無効化
}
/*************************************************************************************
**
** drawGroundGrid - draws a ground plane
**
***************************************************************************************/
int drawGroundGrid( double trans[3][4], int divisions, float x, float y, float height)
{
	double        gl_para[16];
    int           i;
	float x0,x1,y0,y1;
	float deltaX, deltaY;

    argDrawMode3D();
    argDraw3dCamera( 0, 0 );
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);
    
    /* load the camera transformation matrix */
    glMatrixMode(GL_MODELVIEW); 
    argConvGlpara(trans, gl_para);
    glLoadMatrixd( gl_para );
    glTranslatef(x/2.,-y/2.,0.);
    //draw the grid
    glColor3f(1,0,0);
	glLineWidth(6.0);
	glBegin(GL_LINE_LOOP);
	glVertex3f( -x, y, height );
	glVertex3f(  x, y, height );  
	glVertex3f(  x, -y, height );
	glVertex3f( -x, -y, height );
	glEnd();
	glLineWidth(3.0);
	
	//draw a grid of lines
	//X direction
	x0 = -x; x1 = -x;
	y0 = -y; y1 = y;
	deltaX = (2*x)/divisions;

	for(i=0;i<divisions;i++){
		x0 = x0 + deltaX;
		glBegin(GL_LINES);
		glVertex3f(x0,y0,height);
		glVertex3f(x0,y1,height);
		glEnd();
	}

	x0 = -x; x1 = x;
	deltaY = (2*y)/divisions;

	for(i=0;i<divisions;i++){
		y0 = y0 + deltaY;
		glBegin(GL_LINES);
		glVertex3f(x0,y0,height);
		glVertex3f(x1,y0,height);
		glEnd();
	}

	glLineWidth(1.0);

	glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);
    glLightfv(GL_LIGHT0, GL_AMBIENT, ambi);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor);

	glDisable( GL_LIGHTING );
    glDisable( GL_DEPTH_TEST );    
    argDrawMode2D();
    return 0;
}
Example #22
0
/* draw the user object */
static int  draw_object( int obj_id, double gl_para[16], int collide_flag )
{
    GLfloat   mat_ambient[]				= {0.0, 0.0, 1.0, 1.0};
	GLfloat   mat_ambient_collide[]     = {0.0, 1.0, 0.0, 1.0};
    GLfloat   mat_flash[]				= {0.0, 0.0, 1.0, 1.0};
	GLfloat   mat_flash_collide[]       = {1.0, 0.0, 0.0, 1.0};
    GLfloat   mat_flash_shiny[] = {50.0};
    GLfloat   light_position[]  = {100.0,-200.0,200.0,0.0};
    GLfloat   ambi[]            = {0.0, 0.1, 0.1, 0.1};
    GLfloat   lightZeroColor[]  = {0.9, 0.9, 0.9, 0.1};
 
    argDrawMode3D();
    argDraw3dCamera( 0, 0 );
    glMatrixMode(GL_MODELVIEW);
    glLoadMatrixd( gl_para );

 	/* set the material */
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);
    glLightfv(GL_LIGHT0, GL_AMBIENT, ambi);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor);

    glMaterialfv(GL_FRONT, GL_SHININESS, mat_flash_shiny);	

	if(collide_flag){
		printf("its collided");
		if (obj_id == 0)
		{
			glMaterialfv(GL_FRONT, GL_SPECULAR, mat_flash);
			glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
			/* draw a cube */
			//glTranslatef( 0.0, 0.0, 30.0 );
			//glutSolidSphere(30,12,6);
			electron3();
			
		}
		
	}
	else {
		printf("its not");
		if (obj_id == 0)
		{
			renderBitmapString(0, 0, 0, GLUT_BITMAP_HELVETICA_18, "HYDROGEN");
			glMaterialfv(GL_FRONT, GL_SPECULAR, mat_flash);
			glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
			/* draw a cube */
			//glTranslatef( 0.0, 0.0, 30.0 );
			//glutSolidSphere(30,12,6);
			glTranslatef(-50.0, -50.0, 0.0);
			glScaled(2, 2, 2);
			electron2();
		}
		else if (obj_id == 1)
		{
			glPushMatrix();
			
			renderBitmapString(0, 0, 0, GLUT_BITMAP_HELVETICA_18, "OXYGEN");
			glPopMatrix();
			glMaterialfv(GL_FRONT, GL_SPECULAR, mat_flash);
			glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
		
			glTranslatef(0.0, 0.0, 0.0);
			glScaled(3, 3, 3);
			electron();
		}
	}

    argDrawMode2D();

    return 0;

}
Example #23
0
// Fonction d'affichage (d_screen => affichage pour l'écran ou pour la detection de la colision)
static void display(bool d_screen)
{
	glClearColor(0,0,0,0);
	glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

   // Parametres lumiere et matrice
		
	GLfloat mat_ambient[]     = {0.5, 0.1, 0.1, 1.0};
    GLfloat mat_flash[]       = {0.7, 0.7, 0.7, 1.0};
    GLfloat mat_flash_shiny[] = {50.0};

    GLfloat light_position[]  = {100.0,-200.0,200.0,0.0};
    GLfloat ambi[]            = {0.1, 0.1, 0.1, 0.1};
    GLfloat lightZeroColor[]  = {0.9, 0.9, 0.9, 0.1};
	

    // Passage en mode 3D et activation de la profondeur
    argDrawMode3D();
    argDraw3dCamera(0, 0);

    glClearDepth(1.0);
    glClear(GL_DEPTH_BUFFER_BIT);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);

	
   //alumer Lumieres : il ne faut pas les activer en mode Picking, car on se base sur la couleur de l'objet dans ce mode, et l'activation
   // des lumières ajouterais des ombres et fausserait la sélection
   if(d_screen)
   {
		glEnable(GL_COLOR_MATERIAL);
		glEnable(GL_LIGHTING);
		glEnable(GL_LIGHT0);
   }
   else
   {
	   glDisable(GL_COLOR_MATERIAL);
		glDisable(GL_LIGHTING);
		glDisable(GL_LIGHT0);
   }


    glLightfv(GL_LIGHT0, GL_POSITION, light_position);
    glLightfv(GL_LIGHT0, GL_AMBIENT, ambi);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor);

    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_flash);
    glMaterialfv(GL_FRONT, GL_SHININESS, mat_flash_shiny);
    glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);

	//dessin de la scene en fonction de l'objet vu 
   
	//C'est là que c'est tout nouveau. Au moment du dessin, si on est en picking, pour chaques objet, on lui calcule une valeur de bleu.
	//On fait i+1, car sinon on a un objet qui sera à 0 0 0, soit noir, et du coup, bah il sera pas reconnu, il sera noir
	//sur fond noir
	//si on est en affichage classique, on met les couleurs et texture
   
	for(unsigned int i = 0; i < onscreen_object.size(); i++)
	{
		if(!d_screen)//si on est en mode picking
			{
				glColor3f(0.0, 0.0, (float)(i+1)/onscreen_object.size());
				onscreen_object.at(i).draw(false);
			}
			else
			{	
				onscreen_object.at(i).draw(true);
			}
	}

    glDisable(GL_LIGHTING);
    glDisable(GL_DEPTH_TEST);
}
Example #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 );            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;
    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();
}
/* draw the paddle */
int  draw_paddle( ARPaddleInfo *paddleInfo )
{
    double  gl_para[16];
    int     i;

    argDrawMode3D();
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);
    
    argDraw3dCamera( 0, 0 );
    argConvGlpara(paddleInfo->trans, gl_para);
      
    glMatrixMode(GL_MODELVIEW);
    glLoadMatrixd( gl_para );

    glColor3f( 1.0, 0.0, 0.0 );
    glLineWidth(4.0);
    glBegin(GL_LINE_LOOP);
        glVertex2f( -25.0, -25.0 );
        glVertex2f(  25.0, -25.0 );
        glVertex2f(  25.0,  25.0 );
        glVertex2f( -25.0,  25.0 );
    glEnd();

    glColor3f( 0.0, 0.0, 1.0);
    glBegin(GL_LINE_LOOP);
    for( i = 0; i < 16; i++ ) {
        double  x, y;
        x = PADDLE_RADIUS * cos(i*3.141592*2/16);
        y = PADDLE_RADIUS * sin(i*3.141592*2/16);
        glVertex2d( x, y );
    }
    glEnd();
    glBegin(GL_LINE_LOOP);
        glVertex2f( -7.5,    0.0 );
        glVertex2f(  7.5,    0.0 );
        glVertex2f(  7.5, -105.0 );
        glVertex2f( -7.5, -105.0 );
    glEnd();

    glEnable(GL_BLEND);
    glBlendFunc(GL_ZERO,GL_ONE);
    
    glColor4f(1,1,1,0);    
	glBegin(GL_POLYGON);
    for( i = 0; i < 16; i++ ) {
        double  x, y;
        x = 40.0 * cos(i*3.141592*2/16);
        y = 40.0 * sin(i*3.141592*2/16);
        glVertex2d( x, y );    
	}
    glEnd();
    glBegin(GL_POLYGON);
        glVertex2f( -7.5,    0.0 );
        glVertex2f(  7.5,    0.0 );
        glVertex2f(  7.5, -105.0 );
        glVertex2f( -7.5, -105.0 );
    glEnd();
    glDisable(GL_BLEND);

    glDisable(GL_DEPTH_TEST);
	argDrawMode2D();
    return 0;
}
Example #27
0
void   draw(double xOri, double yOri, double zOri,\
			double xDir, double yDir, double zDir)
{
	double    gl_para[16];
	GLfloat   mat_ambient[]     = {0.0, 0.0, 1.0, 1.0};
	GLfloat   mat_flash[]       = {0.0, 0.0, 1.0, 1.0};
	GLfloat   mat_flash_shiny[] = {50.0};
	GLfloat   light_position[]  = {100.0,-200.0,200.0,0.0};
	GLfloat   ambi[]            = {0.1, 0.1, 0.1, 0.1};
	GLfloat   lightZeroColor[]  = {0.9, 0.9, 0.9, 0.1};

	argDrawMode3D();
	argDraw3dCamera( 0, 0 );
	glClearDepth( 1.0 );
	glClear(GL_DEPTH_BUFFER_BIT);
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);

	/* load the camera transformation matrix */
	argConvGlpara(g_global.patt_trans, gl_para);


	glMatrixMode(GL_MODELVIEW);
	glLoadMatrixd( gl_para );

	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);
	glLightfv(GL_LIGHT0, GL_POSITION, light_position);
	glLightfv(GL_LIGHT0, GL_AMBIENT, ambi);
	glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor);
	glMaterialfv(GL_FRONT, GL_SPECULAR, mat_flash);
	glMaterialfv(GL_FRONT, GL_SHININESS, mat_flash_shiny);	
	glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
	glMatrixMode(GL_MODELVIEW);
	
	// ----------------------
	// by aicro

	// draw what we like
	glTranslatef( 0.0, 0.0, 25.0 );
	glutSolidCube(50.0);


	// ----------------------
	// by aicro

	CCrashTest crashTest;
	crashTest.calculateAABB(-25, 0, -25, 25, 50, 25);
	double t = crashTest.rayIntersect(xOri, yOri, zOri, xDir, yDir, zDir);
 
	if (t != -1)
	{
		
	}

	//// draw out the ray
	//glBegin(GL_LINES);
	//	glVertex3d(xOri,yOri,zOri);
	//	glVertex3d(xDir,yDir,zDir);
	//glEnd();


	// ----------------------

	glDisable( GL_LIGHTING );

	glDisable( GL_DEPTH_TEST );
}
/* draw the paddle */
int  draw_paddle( ARPaddleInfo *paddleInfo, PaddleItemInfo *paddleItemInfo )
{
    double  gl_para[16];
    int     i;

    argDrawMode3D();
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);
    
    argDraw3dCamera( 0, 0 );
    argConvGlpara(paddleInfo->trans, gl_para);
      
    glMatrixMode(GL_MODELVIEW);
    glLoadMatrixd( gl_para );

    glColor3f( 1.0, 0.0, 0.0 );
    glLineWidth(4.0);
    glBegin(GL_LINE_LOOP);
        glVertex2f( -25.0, -25.0 );
        glVertex2f(  25.0, -25.0 );
        glVertex2f(  25.0,  25.0 );
        glVertex2f( -25.0,  25.0 );
    glEnd();

    glColor3f( 0.0, 0.0, 1.0);
    glBegin(GL_LINE_LOOP);
    for( i = 0; i < 16; i++ ) {
        double  x, y;
        x = PADDLE_RADIUS * cos(i*3.141592*2/16);
        y = PADDLE_RADIUS * sin(i*3.141592*2/16);
        glVertex2d( x, y );
    }
    glEnd();
    glBegin(GL_LINE_LOOP);
        glVertex2f( -7.5,    0.0 );
        glVertex2f(  7.5,    0.0 );
        glVertex2f(  7.5, -105.0 );
        glVertex2f( -7.5, -105.0 );
    glEnd();

    glEnable(GL_BLEND);
    glBlendFunc(GL_ZERO,GL_ONE);
    
    glColor4f(1,1,1,0);    
	glBegin(GL_POLYGON);
    for( i = 0; i < 16; i++ ) {
        double  x, y;
        x = 40.0 * cos(i*3.141592*2/16);
        y = 40.0 * sin(i*3.141592*2/16);
        glVertex2d( x, y );    
	}
    glEnd();
    glBegin(GL_POLYGON);
        glVertex2f( -7.5,    0.0 );
        glVertex2f(  7.5,    0.0 );
        glVertex2f(  7.5, -105.0 );
        glVertex2f( -7.5, -105.0 );
    glEnd();
    glDisable(GL_BLEND);

	/* draw any objects on the paddle */
	if( (i=paddleItemInfo->item) !=-1) {

        glPushMatrix();
        glTranslatef( paddleItemInfo->x, paddleItemInfo->y, 10.0 );
        glRotatef( paddleItemInfo->angle * 180.0/3.141592, 0.0, 0.0, 1.0 );
	glColor3f(0.0,1.0,0.0);
	glutSolidSphere(10,10,10);
	//	glutSolidTeapot(10.);
        glPopMatrix();
	}

    glDisable(GL_DEPTH_TEST);
	argDrawMode2D();
    return 0;
}
Example #29
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();
}