コード例 #1
0
ファイル: draw.cpp プロジェクト: Evans22/talktotom
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 );
}
コード例 #2
0
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_ambient2[]    = {0.0, 1.0, 1.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_flash2[]      = {0.0, 1.0, 1.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 if(mode == 3){
        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_shiny1);
        glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient2);
    }
    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 (mode == 2) glScalef(1.0,1.0,5);
    if (mode == 3) glScalef(1.0,0.3,0.5);
    if( !arDebug ) glutSolidCube(50.0);
     else          glutWireCube(50.0);
    glDisable( GL_LIGHTING );

    glDisable( GL_DEPTH_TEST );
}
コード例 #3
0
ファイル: arToolKit.c プロジェクト: DavidWon/AndAR
/*
 * Class:     edu_dhbw_andar_MarkerInfo
 * Method:    artoolkit_detectmarkers
 * Signature: ([B[D)I
 */
JNIEXPORT jint JNICALL Java_edu_dhbw_andar_ARToolkit_artoolkit_1detectmarkers
(JNIEnv *env, jobject object, jbyteArray image, jobject transMatMonitor) {
    ARUint8         *dataPtr;
    ARMarkerInfo    *marker_info;
    double 	    *matrixPtr;
    int             marker_num;
    int             j, k=-1;
    Object* curObject;

    /* grab a vide frame */
    dataPtr = (*env)->GetByteArrayElements(env, image, JNI_FALSE);
    if( count == 0 ) arUtilTimerReset();
    count++;

    /* detect the markers in the video frame */
    if( arDetectMarker(dataPtr, thresh, &marker_info, &marker_num) < 0 ) {
        __android_log_write(ANDROID_LOG_ERROR,"AR native","arDetectMarker failed!!");
        jclass exc = (*env)->FindClass( env, "edu/dhbw/andar/exceptions/AndARException" );
        if ( exc != NULL )
            (*env)->ThrowNew( env, exc, "failed to detect marker" );
    }
#ifdef DEBUG_LOGGING
    __android_log_print(ANDROID_LOG_INFO,"AR native","detected %d markers",marker_num);
#endif


    //lock the matrix
    /*(*env)->MonitorEnter(env, transMatMonitor);
    cur_marker_id = k;
    argConvGlpara(patt_trans, gl_para);
    (*env)->MonitorExit(env, transMatMonitor);*/

    static jfieldID visibleField = NULL;
    static jfieldID glMatrixField = NULL;
    static jfieldID transMatField = NULL;
    jclass arObjectClass = NULL;
    jfloatArray glMatrixArrayObj = NULL;
    jdoubleArray transMatArrayObj = NULL;

#ifdef DEBUG_LOGGING
    __android_log_write(ANDROID_LOG_INFO,"AR native","done detecting markers, going to iterate over markers now");
#endif
    //iterate over objects:
    list_iterator_start(&objects);        /* starting an iteration "session" */
    int itCount = 0;
    while (list_iterator_hasnext(&objects)) { /* tell whether more values available */
        curObject = (Object *)list_iterator_next(&objects);     /* get the next value */
#ifdef DEBUG_LOGGING
        __android_log_print(ANDROID_LOG_INFO,"AR native","now handling object with id %d, in %d iteration",curObject->name, itCount);
#endif
        itCount++;
        // //get field ID'
        if(visibleField == NULL) {
            if(arObjectClass == NULL) {
                if(curObject->objref != NULL)
                    arObjectClass = (*env)->GetObjectClass(env, curObject->objref);
            }
            if(arObjectClass != NULL) {
                visibleField = (*env)->GetFieldID(env, arObjectClass, "visible", "Z");//Z means boolean
            }
        }
        if(glMatrixField == NULL) {
            if(arObjectClass == NULL) {
                if(curObject->objref != NULL)
                    arObjectClass = (*env)->GetObjectClass(env, curObject->objref);
            }
            if(arObjectClass != NULL) {
                glMatrixField = (*env)->GetFieldID(env, arObjectClass, "glMatrix", "[F");//[F means array of floats
            }
        }

        if(transMatField == NULL) {
            if(arObjectClass == NULL) {
                if(curObject->objref != NULL)
                    arObjectClass = (*env)->GetObjectClass(env, curObject->objref);
            }
            if(arObjectClass != NULL) {
                transMatField = (*env)->GetFieldID(env, arObjectClass, "transMat", "[D");//[D means array of doubles
            }
        }

        if(visibleField == NULL || glMatrixField == NULL || transMatField == NULL) {
            //something went wrong..
#ifdef DEBUG_LOGGING
            __android_log_write(ANDROID_LOG_INFO,"AR native","error: either visibleField or glMatrixField or transMatField null");
#endif
            continue;
        }

        // check for object visibility
        k = -1;
        for( j = 0; j < marker_num; j++ ) {
#ifdef DEBUG_LOGGING
            __android_log_print(ANDROID_LOG_INFO,"AR native","marker with id: %d", marker_info[j].id);
#endif
            if( curObject->id == marker_info[j].id ) {
                if( k == -1 ) {
                    k = j;
#ifdef DEBUG_LOGGING
                    __android_log_print(ANDROID_LOG_INFO,"AR native","detected object %d with marker %d and object marker %d",curObject->name,k,curObject->id);
#endif
                }
                else if( marker_info[k].cf < marker_info[j].cf )  {
#ifdef DEBUG_LOGGING
                    __android_log_print(ANDROID_LOG_INFO,"AR native","detected better object %d with marker %d and object marker %d",curObject->name,k,curObject->id);
#endif
                    k = j;
                }
            }
        }
        if( k == -1 ) {
            //object not visible
            curObject->contF = 0;
            (*env)->SetBooleanField(env, curObject->objref, visibleField, JNI_FALSE);
#ifdef DEBUG_LOGGING
            __android_log_print(ANDROID_LOG_INFO,"AR native","object %d  not visible, with marker ID %d",curObject->name,curObject->id);
#endif
            continue;
        }
        //object visible

        //lock the object
#ifdef DEBUG_LOGGING
        __android_log_write(ANDROID_LOG_INFO,"AR native","locking object");
#endif
        (*env)->MonitorEnter(env, curObject->objref);
#ifdef DEBUG_LOGGING
        __android_log_write(ANDROID_LOG_INFO,"AR native","done locking object...obtaining arrays");
#endif
        //access the arrays of the current object
        glMatrixArrayObj = (*env)->GetObjectField(env, curObject->objref, glMatrixField);
        transMatArrayObj = (*env)->GetObjectField(env, curObject->objref, transMatField);
        if(transMatArrayObj == NULL || glMatrixArrayObj == NULL) {
#ifdef DEBUG_LOGGING
            __android_log_write(ANDROID_LOG_INFO,"AR native","failed to fetch the matrix arrays objects");
#endif
            continue;//something went wrong
        }
        float *glMatrix = (*env)->GetFloatArrayElements(env, glMatrixArrayObj, JNI_FALSE);
        if(glMatrix == NULL ) {
#ifdef DEBUG_LOGGING
            __android_log_write(ANDROID_LOG_INFO,"AR native","failed to fetch the matrix arrays");
#endif
            continue;//something went wrong
        }
        double* transMat = (*env)->GetDoubleArrayElements(env, transMatArrayObj, JNI_FALSE);
        if(transMat == NULL) {
#ifdef DEBUG_LOGGING
            __android_log_write(ANDROID_LOG_INFO,"AR native","failed to fetch the matrix arrays");
#endif
            continue;//something went wrong
        }
#ifdef DEBUG_LOGGING
        __android_log_write(ANDROID_LOG_INFO,"AR native","calculating trans mat now");
#endif
        // get the transformation between the marker and the real camera
        if( curObject->contF == 0 ) {
            arGetTransMat(&marker_info[k], curObject->marker_center, curObject->marker_width, transMat);
        } else {
            arGetTransMatCont(&marker_info[k], transMat, curObject->marker_center, curObject->marker_width, transMat);
        }
        curObject->contF = 1;
#ifdef DEBUG_LOGGING
        __android_log_write(ANDROID_LOG_INFO,"AR native","calculating OpenGL trans mat now");
#endif
        argConvGlpara(transMat, glMatrix);
        //argConvGlpara(patt_trans, gl_para);
#ifdef DEBUG_LOGGING
        __android_log_write(ANDROID_LOG_INFO,"AR native","releasing arrays");
#endif
        (*env)->ReleaseFloatArrayElements(env, glMatrixArrayObj, glMatrix, 0);
        (*env)->ReleaseDoubleArrayElements(env, transMatArrayObj, transMat, 0);

        (*env)->SetBooleanField(env, curObject->objref, visibleField, JNI_TRUE);
#ifdef DEBUG_LOGGING
        __android_log_write(ANDROID_LOG_INFO,"AR native","releasing lock");
#endif
        //release the lock on the object
        (*env)->MonitorExit(env, curObject->objref);
#ifdef DEBUG_LOGGING
        __android_log_write(ANDROID_LOG_INFO,"AR native","done releasing lock");
#endif
    }
    list_iterator_stop(&objects);         /* starting the iteration "session" */
#ifdef DEBUG_LOGGING
    __android_log_write(ANDROID_LOG_INFO,"AR native","releasing image array");
#endif
    (*env)->ReleaseByteArrayElements(env, image, dataPtr, 0);
#ifdef DEBUG_LOGGING
    __android_log_write(ANDROID_LOG_INFO,"AR native","releasing image array");
#endif
    return marker_num;
}
コード例 #4
0
ファイル: arSound.c プロジェクト: ei08047/soundAR
/* draw the the AR objects */
static int draw(ObjectData_T *object, int objectnum)
{
	int     i;
	double  gl_para[16];

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

	/* calculate the viewing parameters - gl_para */

	int count = 0;
	
	float x1, x2,x3;
	float y1, y2,y3;
	float z1, z2,z3;


	for (i = 0; i < objectnum; i++) {
		if (object[i].visible == 0)continue;
		count++;
		argConvGlpara(object[i].trans, gl_para);
		draw_object(object[i].id, gl_para);
	}	


	x1 = object[0].trans[0][3], x2 = object[1].trans[0][3],x3 = object[2].trans[0][3];
	y1 = object[0].trans[1][3], y2 = object[1].trans[1][3], y3 = object[2].trans[1][3];
	z1 = object[0].trans[2][3], z2 = object[1].trans[2][3], z3 = object[2].trans[2][3];

	int grid = object[0].visible && object[1].visible;

	if (grid == 1){

		distX = fabs(x2 - x1);
		distY = fabs(y2 - y1);
		distZ = fabs(z2 - z1);

		//printf("grid distance %f %f %f \n ", distX, distY, distZ);
	}
	int controler =  object[2].visible;
	if (object[0].visible && controler){
		distX1 = fabs(x3 - x1);
		distY1 = fabs(y3 - y1);

		distX0 = fabs(x3 - x2);
		 distY0 = fabs(y3 - y2);
	}

	if (nFrame++ == 50) {
		nFrame = 0;

		if (controler){

			//calculate distance
			//printf("object id = %d ||  x = %f    || y =  %f     ||  z =  %f    ||\n", object[0].id, x1, y1, z1);
			//printf("object id = %d ||  x = %f    || y =  %f     ||  z =  %f    ||\n", object[1].id, x2, y2, z2);
			//printf("object id = %d ||  x = %f    || y =  %f     ||  z =  %f    ||\n", object[2].id, x3, y3, z3);

			printf(" distancia  0 - - 1    x = %f    || y =  %f     ||  z =  %f    ||\n", distX, distY, distZ);
			printf(" distancia  0-2 0-1 ||  x = %f  - - %f   || y =  %f - - %f       ||\n", distX1,distX0 ,  distY1, distY0);

			double x_send = distX1 / distX;
			double y_send = distY1 / distY;

			printf(" distancia norma   x = %f    || y =  %f    \n", x_send, y_send);
			
			/*
			// treat overflow
			if (x_send < 0.0)
				x_send = 0.0;
			else{
				if (y_send < 0.0)
					y_send = 0.0;
				else{
					if (x_send > 1.0)
						x_send = 1.0;
					else{
						if (y_send > 1.0)
							y_send = 1.0;
					}
				}
			}
			*/
			//printf(" distancia  normalizada   x = %f    || y =  %f    ||\n", x_send, y_send);

          	prepare_msg(x_send, y_send);

			udpSend(buf2);

			// if relevante change in distance then udpSend
		}
	}



	glDisable(GL_LIGHTING);
	glDisable(GL_DEPTH_TEST);
	return(0);
}
コード例 #5
0
/*
* Class:     com_clab_artoolkit_port_JARToolkit
* Method:    JARGetTransMatrixCont
* Signature: (IIFF[D)[D
*/
JNIEXPORT jdoubleArray JNICALL Java_net_sourceforge_jartoolkit_core_JARToolKit_getTransMatrixCont__IIFF_3D(JNIEnv *env, jobject, jint patternID, jint patt_width, jfloat patt_centerX, jfloat patt_centerY, jdoubleArray conv)
{
	double patt_trans[3][4];
	int k, j, i;
	double patt_center[2] = {patt_centerX, patt_centerY};
	double prev_conv[3][4];

	jdoubleArray matrix = env->NewDoubleArray(16);

	jdouble *buffer = env->GetDoubleArrayElements(matrix, 0);

	for (i=1 ;i<15; i++)
		buffer[i] = 0.0;

	buffer[0] = 1.0;
	buffer[5] = 1.0;
	buffer[10] = 1.0;
	buffer[15] = 1.0;

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

	if (k == -1) 
	{
		env->ReleaseDoubleArrayElements(matrix, buffer, 0);
		return matrix;
	}

	jdouble *pre_conv = env->GetDoubleArrayElements(conv, 0);
	for (j=0; j < 3; j++)
	{
		for (i=0; i < 4; i++)
		{
			prev_conv[j][i] = pre_conv[i*4+j];
		}
	}
	env->ReleaseDoubleArrayElements(conv, pre_conv, 0);
	if (arGetTransMatCont(&marker_info[k], prev_conv, patt_center,patt_width, patt_trans) < 0)
	{
		env->ReleaseDoubleArrayElements(matrix, buffer, 0);
		return matrix;
	}
	/*
	for( j = 0; j < 3; j++ )
	{
	for( i = 0; i < 4; i++ )
	{
	buffer[i*4+j] = patt_trans[j][i];
	}
	}

	buffer[0*4+3] = buffer[1*4+3] = buffer[2*4+3] = 0.0;
	buffer[3*4+3] = 1.0;
	*/
	argConvGlpara(patt_trans, buffer);
	env->ReleaseDoubleArrayElements(matrix, buffer, 0);
	return matrix;
}
コード例 #6
0
//=======================================================
// 3Dオブジェクトの描画を行う関数
//=======================================================
void DrawObject( int mark_id,double (&patt_trans)[3][4] ,int i)
{
	double gl_para[16];	// ARToolKit->OpenGL変換行列

	// 陰面消去
	glEnable( GL_DEPTH_TEST );			// 陰面消去・有効
	glDepthFunc( GL_LEQUAL );			// デプステスト

	// 変換行列の適用
	argConvGlpara( patt_trans, gl_para );	// ARToolKitからOpenGLの行列に変換
	glMatrixMode( GL_MODELVIEW );			// 行列変換モード・モデルビュー
	glLoadMatrixd( gl_para );				// 読み込む行列を指定

	switch( mark_id ){
		case MARK1_MARK_ID:
			// ライティング
			SetupLighting1();			// ライトの定義
			glEnable( GL_LIGHTING );	// ライティング・有効
			glEnable( GL_LIGHT0 );		// ライト0・オン
			// オブジェクトの材質
			SetupMaterial1();

			// 3Dオブジェクトの描画
			if (movex[i] < 20.0){
			movez[i] = -pow(10.0-movex[i],2.0)+100;
			}else{
			movez[i] = -pow(10.0-(movex[i]-20.0),2.0)+100;
			}

			/* 3次元オブジェクトの描画 */
			glTranslatef(-5*movex[i], 0.0 , 25+movez[i]);		// オブジェクトの平行移動(z軸方向に25mm移動)
			glRotatef(90, 0.0, 0.0, 1.0);		// オブジェクトをz軸まわりに回転 元はyが0でzが1だった

			glPushMatrix();
				glRotatef( 90, 1.0, 0.0, 0.0 );	// モデルを立たせる もとは始めが90だったから立ってた
				mqoCallModel( model[i] );				// モデルの描画
			glPopMatrix();

			break;

		case MARK2_MARK_ID:
			// ライティング
			SetupLighting2();			// ライトの定義
			glEnable( GL_LIGHTING );	// ライティング・有効
			glEnable( GL_LIGHT0 );		// ライト0・オン
			// オブジェクトの材質
			SetupMaterial2();

			// 3Dオブジェクトの描画
			if (movex[i] < 20.0){
			movez[i] = -pow(10.0-movex[i],2.0)+100;
			}else{
			movez[i] = -pow(10.0-(movex[i]-20.0),2.0)+100;
			}

			/* 3次元オブジェクトの描画 */
			glTranslatef(-5*movex[i], 0.0 , 25+movez[i]);		// オブジェクトの平行移動(z軸方向に25mm移動)
			glRotatef(90, 0.0, 0.0, 1.0);		// オブジェクトをz軸まわりに回転 元はyが0でzが1だった

			glPushMatrix();
				glRotatef( 90, 1.0, 0.0, 0.0 );	// モデルを立たせる もとは始めが90だったから立ってた
				mqoCallModel( model[i] );				// モデルの描画
			glPopMatrix();


			break;

		case MARK3_MARK_ID:
			// ライティング
			SetupLighting1();			// ライトの定義
			glEnable( GL_LIGHTING );	// ライティング・有効
			glEnable( GL_LIGHT0 );		// ライト0・オン
			// オブジェクトの材質
			SetupMaterial2();

			// 3Dオブジェクトの描画
			if (movex[i] < 20.0){
			movez[i] = -pow(10.0-movex[i],2.0)+100;
			}else{
			movez[i] = -pow(10.0-(movex[i]-20.0),2.0)+100;
			}

			/* 3次元オブジェクトの描画 */
			glTranslatef(-5*movex[i], 0.0 , 25+movez[i]);		// オブジェクトの平行移動(z軸方向に25mm移動)
			glRotatef(90, 0.0, 0.0, 1.0);		// オブジェクトをz軸まわりに回転 元はyが0でzが1だった

			glPushMatrix();
				glRotatef( 90, 1.0, 0.0, 0.0 );	// モデルを立たせる もとは始めが90だったから立ってた
				mqoCallModel( model[i] );				// モデルの描画
			glPopMatrix();


			break;
		case MARK4_MARK_ID:
			// ライティング
			SetupLighting1();			// ライトの定義
			glEnable( GL_LIGHTING );	// ライティング・有効
			glEnable( GL_LIGHT0 );		// ライト0・オン
			// オブジェクトの材質
			SetupMaterial1();

			// 3Dオブジェクトの描画
			if (movex[i] < 20.0){
			movez[i] = -pow(10.0-movex[i],2.0)+100;
			}else{
			movez[i] = -pow(10.0-(movex[i]-20.0),2.0)+100;
			}

			/* 3次元オブジェクトの描画 */
			glTranslatef(-5*movex[i], 0.0 , 25+movez[i]);		// オブジェクトの平行移動(z軸方向に25mm移動)
			glRotatef(90, 0.0, 0.0, 1.0);		// オブジェクトをz軸まわりに回転 元はyが0でzが1だった

			glPushMatrix();
				glRotatef( 90, 1.0, 0.0, 0.0 );	// モデルを立たせる もとは始めが90だったから立ってた
				mqoCallModel( model[i]);				// モデルの描画
			glPopMatrix();

			break;

		case MARK5_MARK_ID:
			// ライティング
			SetupLighting2();			// ライトの定義
			glEnable( GL_LIGHTING );	// ライティング・有効
			glEnable( GL_LIGHT0 );		// ライト0・オン
			// オブジェクトの材質
			SetupMaterial2();

			// 3Dオブジェクトの描画
			if (movex[i] < 20.0){
			movez[i] = -pow(10.0-movex[i],2.0)+100;
			}else{
			movez[i] = -pow(10.0-(movex[i]-20.0),2.0)+100;
			}

			/* 3次元オブジェクトの描画 */
			glTranslatef(-5*movex[i], 0.0 , 25+movez[i]);		// オブジェクトの平行移動(z軸方向に25mm移動)
			glRotatef(90, 0.0, 0.0, 1.0);		// オブジェクトをz軸まわりに回転 元はyが0でzが1だった

			glPushMatrix();
				glRotatef( 90, 1.0, 0.0, 0.0 );	// モデルを立たせる もとは始めが90だったから立ってた
				mqoCallModel( model[i] );				// モデルの描画
			glPopMatrix();

			break;
		case MARK6_MARK_ID:
			// ライティング
			SetupLighting1();			// ライトの定義
			glEnable( GL_LIGHTING );	// ライティング・有効
			glEnable( GL_LIGHT0 );		// ライト0・オン
			// オブジェクトの材質
			SetupMaterial2();

			// 3Dオブジェクトの描画
			if (movex[i] < 20.0){
			movez[i] = -pow(10.0-movex[i],2.0)+100;
			}else{
			movez[i] = -pow(10.0-(movex[i]-20.0),2.0)+100;
			}

			/* 3次元オブジェクトの描画 */
			glTranslatef(-5*movex[i], 0.0 , 25+movez[i]);		// オブジェクトの平行移動(z軸方向に25mm移動)
			glRotatef(90, 0.0, 0.0, 1.0);		// オブジェクトをz軸まわりに回転 元はyが0でzが1だった

			glPushMatrix();
				glRotatef( 90, 1.0, 0.0, 0.0 );	// モデルを立たせる もとは始めが90だったから立ってた
				mqoCallModel( model[i] );				// モデルの描画
			glPopMatrix();

			break;

		case MARK7_MARK_ID:
			// ライティング
			SetupLighting1();			// ライトの定義
			glEnable( GL_LIGHTING );	// ライティング・有効
			glEnable( GL_LIGHT0 );		// ライト0・オン
			// オブジェクトの材質
			SetupMaterial1();

			// 3Dオブジェクトの描画
			if (movex[i] < 20.0){
			movez[i] = -pow(10.0-movex[i],2.0)+100;
			}else{
			movez[i] = -pow(10.0-(movex[i]-20.0),2.0)+100;
			}

			/* 3次元オブジェクトの描画 */
			glTranslatef(-5*movex[i], 0.0 , 25+movez[i]);		// オブジェクトの平行移動(z軸方向に25mm移動)
			glRotatef(90, 0.0, 0.0, 1.0);		// オブジェクトをz軸まわりに回転 元はyが0でzが1だった

			glPushMatrix();
				glRotatef( 90, 1.0, 0.0, 0.0 );	// モデルを立たせる もとは始めが90だったから立ってた
				mqoCallModel( model[i] );				// モデルの描画
			glPopMatrix();

			break;

			case MARK8_MARK_ID:
			// ライティング
			SetupLighting1();			// ライトの定義
			glEnable( GL_LIGHTING );	// ライティング・有効
			glEnable( GL_LIGHT0 );		// ライト0・オン
			// オブジェクトの材質
			SetupMaterial1();

			// 3Dオブジェクトの描画
			if (movex[i] < 20.0){
			movez[i] = -pow(10.0-movex[i],2.0)+100;
			}else{
			movez[i] = -pow(10.0-(movex[i]-20.0),2.0)+100;
			}

			/* 3次元オブジェクトの描画 */
			glTranslatef(-5*movex[i], 0.0 , 25+movez[i]);		// オブジェクトの平行移動(z軸方向に25mm移動)
			glRotatef(90, 0.0, 0.0, 1.0);		// オブジェクトをz軸まわりに回転 元はyが0でzが1だった

			glPushMatrix();
				glRotatef( 90, 1.0, 0.0, 0.0 );	// モデルを立たせる もとは始めが90だったから立ってた
				mqoCallModel( model[i] );				// モデルの描画
			glPopMatrix();

			break;
	}
	// 終了処理
	glDisable( GL_LIGHTING );		// ライティング・無効
	glDisable( GL_DEPTH_TEST );		// デプステスト・無効
}
コード例 #7
0
/*************************************************************************************
**
** 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;
}
コード例 #8
0
/* 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;
}