Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 204 | chris | 1 | #ifdef _WIN32 |
| 2 | # include <windows.h> |
||
| 3 | #endif |
||
| 4 | #include <stdio.h> |
||
| 5 | #include <stdlib.h> |
||
| 6 | #include <string.h> |
||
| 7 | #include <math.h> |
||
| 8 | |||
| 9 | #ifndef __APPLE__ |
||
| 10 | # include <GL/glut.h> |
||
| 11 | #else |
||
| 12 | # include <GLUT/glut.h> |
||
| 13 | #endif |
||
| 14 | #include <AR/gsub.h> |
||
| 15 | #include <AR/video.h> |
||
| 16 | #include <AR/param.h> |
||
| 17 | #include <AR/matrix.h> |
||
| 18 | #include <AR/ar.h> |
||
| 19 | #include <AR/arMulti.h> |
||
| 20 | |||
| 21 | /* set up the video format globals */ |
||
| 22 | |||
| 23 | #ifdef _WIN32 |
||
| 24 | char *vconf = "Data\\WDM_camera_flipV.xml"; |
||
| 25 | #else |
||
| 26 | char *vconf = ""; |
||
| 27 | #endif |
||
| 28 | |||
| 29 | #define TARGET_NUM 5 |
||
| 30 | |||
| 31 | #include "paddle.h" |
||
| 32 | #include "command_sub.h" |
||
| 33 | |||
| 34 | PaddleItemInfo myPaddleItem; |
||
| 35 | ItemList myListItem; |
||
| 36 | |||
| 37 | int xsize, ysize; |
||
| 38 | int thresh = 100; |
||
| 39 | int count = 0; |
||
| 40 | |||
| 41 | char *cparam_name = "Data/camera_para.dat"; |
||
| 42 | ARParam cparam; |
||
| 43 | |||
| 44 | char *config_name = "Data/multi/marker.dat"; |
||
| 45 | ARMultiMarkerInfoT *config; |
||
| 46 | |||
| 47 | /* paddle information */ |
||
| 48 | int marker_flag[AR_SQUARE_MAX]; |
||
| 49 | ARPaddleInfo *paddleInfo; |
||
| 50 | char *paddle_name = "Data/paddle_data"; |
||
| 51 | |||
| 52 | GLfloat light_position[] = {100.0,-200.0,200.0,0.0}; |
||
| 53 | GLfloat ambi[] = {0.1, 0.1, 0.1, 0.1}; |
||
| 54 | GLfloat lightZeroColor[] = {0.9, 0.9, 0.9, 0.1}; |
||
| 55 | |||
| 56 | |||
| 57 | PaddleItemInfo myPaddleItem; |
||
| 58 | ItemList myListItem; |
||
| 59 | |||
| 60 | static int draw_paddle( ARPaddleInfo *paddleInfo, PaddleItemInfo *myPaddleItem); |
||
| 61 | static void init(void); |
||
| 62 | static void cleanup(void); |
||
| 63 | static void keyEvent( unsigned char key, int x, int y); |
||
| 64 | static void mainLoop(void); |
||
| 65 | static int draw_paddle( ARPaddleInfo *paddleInfo, PaddleItemInfo *myPaddleItem); |
||
| 66 | static int drawGroundGrid( double trans[3][4], int divisions, float x, float y, float height); |
||
| 67 | static void findPaddlePosition(float curPaddlePos[], double card_trans[3][4],double base_trans[3][4]); |
||
| 68 | static void drawItems(double trans[3][4],ItemList* list); |
||
| 69 | |||
| 70 | int main(int argc, char **argv) |
||
| 71 | { |
||
| 72 | //initialize applications |
||
| 73 | glutInit(&argc, argv); |
||
| 74 | init(); |
||
| 75 | |||
| 76 | arVideoCapStart(); |
||
| 77 | //start the main event loop |
||
| 78 | argMainLoop( NULL, keyEvent, mainLoop ); |
||
| 79 | |||
| 80 | return 0; |
||
| 81 | } |
||
| 82 | |||
| 83 | /* keyboard events */ |
||
| 84 | static void keyEvent( unsigned char key, int x, int y) |
||
| 85 | { |
||
| 86 | /* quit if the ESC key is pressed */ |
||
| 87 | if( key == 0x1b ) { |
||
| 88 | printf("*** %f (frame/sec)\n", (double)count/arUtilTimer()); |
||
| 89 | cleanup(); |
||
| 90 | exit(0); |
||
| 91 | } |
||
| 92 | |||
| 93 | /* change the threshold value when 't' key pressed */ |
||
| 94 | if( key == 't' ) { |
||
| 95 | printf("Enter new threshold value (default = 100): "); |
||
| 96 | scanf("%d",&thresh); while( getchar()!='\n' ); |
||
| 97 | printf("\n"); |
||
| 98 | } |
||
| 99 | |||
| 100 | /* turn on and off the debug mode with d key */ |
||
| 101 | if( key == 'd' ) { |
||
| 102 | printf("*** %f (frame/sec)\n", (double)count/arUtilTimer()); |
||
| 103 | arDebug = 1 - arDebug; |
||
| 104 | if( arDebug == 0 ) { |
||
| 105 | glClearColor( 0.0, 0.0, 0.0, 0.0 ); |
||
| 106 | glClear(GL_COLOR_BUFFER_BIT); |
||
| 107 | argSwapBuffers(); |
||
| 108 | glClear(GL_COLOR_BUFFER_BIT); |
||
| 109 | argSwapBuffers(); |
||
| 110 | } |
||
| 111 | count = 0; |
||
| 112 | } |
||
| 113 | } |
||
| 114 | |||
| 115 | /* main loop */ |
||
| 116 | static void mainLoop(void) |
||
| 117 | { |
||
| 118 | ARUint8 *dataPtr; |
||
| 119 | ARMarkerInfo *marker_info; |
||
| 120 | int marker_num; |
||
| 121 | float curPaddlePos[3]; |
||
| 122 | int i; |
||
| 123 | double err; |
||
| 124 | double angle; |
||
| 125 | |||
| 126 | err=0.; |
||
| 127 | /* grab a video frame */ |
||
| 128 | if( (dataPtr = (ARUint8 *)arVideoGetImage()) == NULL ) { |
||
| 129 | arUtilSleep(2); |
||
| 130 | return; |
||
| 131 | } |
||
| 132 | |||
| 133 | if( count == 0 ) arUtilTimerReset(); |
||
| 134 | count++; |
||
| 135 | |||
| 136 | /* detect the markers in the video frame */ |
||
| 137 | if( arDetectMarkerLite(dataPtr, thresh, &marker_info, &marker_num) < 0 ) { |
||
| 138 | cleanup(); |
||
| 139 | exit(0); |
||
| 140 | } |
||
| 141 | |||
| 142 | argDrawMode2D(); |
||
| 143 | if( !arDebug ) { |
||
| 144 | argDispImage( dataPtr, 0,0 ); |
||
| 145 | } |
||
| 146 | else { |
||
| 147 | argDispImage( dataPtr, 1, 1 ); |
||
| 148 | if( arImageProcMode == AR_IMAGE_PROC_IN_HALF ) |
||
| 149 | argDispHalfImage( arImage, 0, 0 ); |
||
| 150 | else |
||
| 151 | argDispImage( arImage, 0, 0); |
||
| 152 | |||
| 153 | glColor3f( 1.0, 0.0, 0.0 ); |
||
| 154 | glLineWidth( 1.0 ); |
||
| 155 | for( i = 0; i < marker_num; i++ ) { |
||
| 156 | argDrawSquare( marker_info[i].vertex, 0, 0 ); |
||
| 157 | } |
||
| 158 | glLineWidth( 1.0 ); |
||
| 159 | } |
||
| 160 | |||
| 161 | arVideoCapNext(); |
||
| 162 | |||
| 163 | for( i = 0; i < marker_num; i++ ) |
||
| 164 | marker_flag[i] = 0; |
||
| 165 | |||
| 166 | /* get the paddle position */ |
||
| 167 | paddleGetTrans(paddleInfo, marker_info, marker_flag, |
||
| 168 | marker_num, &cparam); |
||
| 169 | /* draw the 3D models */ |
||
| 170 | glClearDepth( 1.0 ); |
||
| 171 | glClear(GL_DEPTH_BUFFER_BIT); |
||
| 172 | |||
| 173 | |||
| 174 | /* get the translation from the multimarker pattern */ |
||
| 175 | if( (err=arMultiGetTransMat(marker_info, marker_num, config)) < 0 ) { |
||
| 176 | argSwapBuffers(); |
||
| 177 | return; |
||
| 178 | } |
||
| 179 | |||
| 180 | // printf("err = %f\n", err); |
||
| 181 | if(err > 100.0 ) { |
||
| 182 | argSwapBuffers(); |
||
| 183 | return; |
||
| 184 | } |
||
| 185 | |||
| 186 | //draw a red ground grid |
||
| 187 | drawGroundGrid( config->trans, 15, 150.0, 110.0, 0.0); |
||
| 188 | |||
| 189 | /* find the paddle position relative to the base */ |
||
| 190 | if (paddleInfo->active) |
||
| 191 | findPaddlePosition(curPaddlePos,paddleInfo->trans,config->trans); |
||
| 192 | |||
| 193 | /* checking for paddle gesture */ |
||
| 194 | if( paddleInfo->active) |
||
| 195 | { |
||
| 196 | int findItem=-1; |
||
| 197 | if (myPaddleItem.item!=-1) |
||
| 198 | { |
||
| 199 | |||
| 200 | if( check_incline(paddleInfo->trans, config->trans, &angle) ) { |
||
| 201 | myPaddleItem.x += 2.0 * cos(angle); |
||
| 202 | myPaddleItem.y += 2.0 * sin(angle); |
||
| 203 | if( myPaddleItem.x*myPaddleItem.x + |
||
| 204 | myPaddleItem.y*myPaddleItem.y > 900.0 ) { |
||
| 205 | myPaddleItem.x -= 2.0 * cos(angle); |
||
| 206 | myPaddleItem.y -= 2.0 * sin(angle); |
||
| 207 | myListItem.item[myPaddleItem.item].onpaddle=0; |
||
| 208 | myListItem.item[myPaddleItem.item].pos[0]=curPaddlePos[0]; |
||
| 209 | myListItem.item[myPaddleItem.item].pos[1]=curPaddlePos[1]; |
||
| 210 | myPaddleItem.item = -1; |
||
| 211 | } |
||
| 212 | } |
||
| 213 | } |
||
| 214 | else |
||
| 215 | { |
||
| 216 | if ((findItem=check_pickup(paddleInfo->trans, config->trans,&myListItem, &angle))!=-1) { |
||
| 217 | |||
| 218 | myPaddleItem.item=findItem; |
||
| 219 | myPaddleItem.x =0.0; |
||
| 220 | myPaddleItem.y =0.0; |
||
| 221 | myPaddleItem.angle = 0.0; |
||
| 222 | myListItem.item[myPaddleItem.item].onpaddle=1; |
||
| 223 | } |
||
| 224 | } |
||
| 225 | } |
||
| 226 | |||
| 227 | /* draw the item */ |
||
| 228 | drawItems(config->trans,&myListItem); |
||
| 229 | |||
| 230 | /* draw the paddle */ |
||
| 231 | if( paddleInfo->active ){ |
||
| 232 | draw_paddle(paddleInfo,&myPaddleItem); |
||
| 233 | } |
||
| 234 | |||
| 235 | argSwapBuffers(); |
||
| 236 | } |
||
| 237 | |||
| 238 | static void init( void ) |
||
| 239 | { |
||
| 240 | ARParam wparam; |
||
| 241 | |||
| 242 | /* open the video path */ |
||
| 243 | if( arVideoOpen( vconf ) < 0 ) exit(0); |
||
| 244 | /* find the size of the window */ |
||
| 245 | if( arVideoInqSize(&xsize, &ysize) < 0 ) exit(0); |
||
| 246 | printf("Image size (x,y) = (%d,%d)\n", xsize, ysize); |
||
| 247 | |||
| 248 | /* set the initial camera parameters */ |
||
| 249 | if( arParamLoad(cparam_name, 1, &wparam) < 0 ) { |
||
| 250 | printf("Camera parameter load error !!\n"); |
||
| 251 | exit(0); |
||
| 252 | } |
||
| 253 | arParamChangeSize( &wparam, xsize, ysize, &cparam ); |
||
| 254 | arInitCparam( &cparam ); |
||
| 255 | printf("*** Camera Parameter ***\n"); |
||
| 256 | arParamDisp( &cparam ); |
||
| 257 | |||
| 258 | /* load the paddle marker file */ |
||
| 259 | if( (paddleInfo = paddleInit(paddle_name)) == NULL ) { |
||
| 260 | printf("paddleInit error!!\n"); |
||
| 261 | exit(0); |
||
| 262 | } |
||
| 263 | printf("Loaded Paddle File\n"); |
||
| 264 | |||
| 265 | if( (config = arMultiReadConfigFile(config_name)) == NULL ) { |
||
| 266 | printf("config data load error !!\n"); |
||
| 267 | exit(0); |
||
| 268 | } |
||
| 269 | printf("Loaded Multi Marker File\n"); |
||
| 270 | |||
| 271 | /* init items */ |
||
| 272 | myListItem.itemnum=4; |
||
| 273 | myListItem.item[0].pos[0]=0.;myListItem.item[0].pos[1]=0.;myListItem.item[0].onpaddle=0; |
||
| 274 | myListItem.item[1].pos[0]=100.;myListItem.item[1].pos[1]=-100.;myListItem.item[1].onpaddle=0; |
||
| 275 | myListItem.item[2].pos[0]=200.;myListItem.item[2].pos[1]=0.;myListItem.item[2].onpaddle=0; |
||
| 276 | myListItem.item[3].pos[0]=0.;myListItem.item[3].pos[1]=0.;myListItem.item[3].onpaddle=1; |
||
| 277 | |||
| 278 | /* set up the initial paddle contents */ |
||
| 279 | myPaddleItem.item = 3; |
||
| 280 | myPaddleItem.angle = 0.0; |
||
| 281 | myPaddleItem.x = 0.0; |
||
| 282 | myPaddleItem.y = 0.0; |
||
| 283 | |||
| 284 | /* open the graphics window */ |
||
| 285 | argInit( &cparam, 1.0, 0, 0, 0, 0 ); |
||
| 286 | } |
||
| 287 | |||
| 288 | /* cleanup function called when program exits */ |
||
| 289 | static void cleanup(void) |
||
| 290 | { |
||
| 291 | arVideoCapStop(); |
||
| 292 | arVideoClose(); |
||
| 293 | argCleanup(); |
||
| 294 | } |
||
| 295 | |||
| 296 | /* find the position of the paddle card relative to the base and set the dropped blob position to this */ |
||
| 297 | static void findPaddlePosition(float curPaddlePos[], double card_trans[3][4],double base_trans[3][4]) |
||
| 298 | { |
||
| 299 | int i,j; |
||
| 300 | |||
| 301 | ARMat *mat_a, *mat_b, *mat_c; |
||
| 302 | double x, y, z; |
||
| 303 | |||
| 304 | //get card position relative to base pattern |
||
| 305 | mat_a = arMatrixAlloc( 4, 4 ); |
||
| 306 | mat_b = arMatrixAlloc( 4, 4 ); |
||
| 307 | mat_c = arMatrixAlloc( 4, 4 ); |
||
| 308 | for( j = 0; j < 3; j++ ) { |
||
| 309 | for( i = 0; i < 4; i++ ) { |
||
| 310 | mat_b->m[j*4+i] = base_trans[j][i]; |
||
| 311 | } |
||
| 312 | } |
||
| 313 | mat_b->m[3*4+0] = 0.0; |
||
| 314 | mat_b->m[3*4+1] = 0.0; |
||
| 315 | mat_b->m[3*4+2] = 0.0; |
||
| 316 | mat_b->m[3*4+3] = 1.0; |
||
| 317 | for( j = 0; j < 3; j++ ) { |
||
| 318 | for( i = 0; i < 4; i++ ) { |
||
| 319 | mat_a->m[j*4+i] = card_trans[j][i]; |
||
| 320 | } |
||
| 321 | } |
||
| 322 | mat_a->m[3*4+0] = 0.0; |
||
| 323 | mat_a->m[3*4+1] = 0.0; |
||
| 324 | mat_a->m[3*4+2] = 0.0; |
||
| 325 | mat_a->m[3*4+3] = 1.0; |
||
| 326 | arMatrixSelfInv( mat_b ); |
||
| 327 | arMatrixMul( mat_c, mat_b, mat_a ); |
||
| 328 | |||
| 329 | //x,y,z is card position relative to base pattern |
||
| 330 | x = mat_c->m[0*4+3]; |
||
| 331 | y = mat_c->m[1*4+3]; |
||
| 332 | z = mat_c->m[2*4+3]; |
||
| 333 | |||
| 334 | curPaddlePos[0] = x; |
||
| 335 | curPaddlePos[1] = y; |
||
| 336 | curPaddlePos[2] = z; |
||
| 337 | |||
| 338 | // printf("Position: %3.2f %3.2f %3.2f\n",x,y,z); |
||
| 339 | |||
| 340 | arMatrixFree( mat_a ); |
||
| 341 | arMatrixFree( mat_b ); |
||
| 342 | arMatrixFree( mat_c ); |
||
| 343 | |||
| 344 | } |
||
| 345 | |||
| 346 | |||
| 347 | /* draw the paddle */ |
||
| 348 | int draw_paddle( ARPaddleInfo *paddleInfo, PaddleItemInfo *paddleItemInfo ) |
||
| 349 | { |
||
| 350 | double gl_para[16]; |
||
| 351 | int i; |
||
| 352 | |||
| 353 | argDrawMode3D(); |
||
| 354 | glEnable(GL_DEPTH_TEST); |
||
| 355 | glDepthFunc(GL_LEQUAL); |
||
| 356 | |||
| 357 | argDraw3dCamera( 0, 0 ); |
||
| 358 | argConvGlpara(paddleInfo->trans, gl_para); |
||
| 359 | |||
| 360 | glMatrixMode(GL_MODELVIEW); |
||
| 361 | glLoadMatrixd( gl_para ); |
||
| 362 | |||
| 363 | glColor3f( 1.0, 0.0, 0.0 ); |
||
| 364 | glLineWidth(4.0); |
||
| 365 | glBegin(GL_LINE_LOOP); |
||
| 366 | glVertex2f( -25.0, -25.0 ); |
||
| 367 | glVertex2f( 25.0, -25.0 ); |
||
| 368 | glVertex2f( 25.0, 25.0 ); |
||
| 369 | glVertex2f( -25.0, 25.0 ); |
||
| 370 | glEnd(); |
||
| 371 | |||
| 372 | glColor3f( 0.0, 0.0, 1.0); |
||
| 373 | glBegin(GL_LINE_LOOP); |
||
| 374 | for( i = 0; i < 16; i++ ) { |
||
| 375 | double x, y; |
||
| 376 | x = PADDLE_RADIUS * cos(i*3.141592*2/16); |
||
| 377 | y = PADDLE_RADIUS * sin(i*3.141592*2/16); |
||
| 378 | glVertex2d( x, y ); |
||
| 379 | } |
||
| 380 | glEnd(); |
||
| 381 | glBegin(GL_LINE_LOOP); |
||
| 382 | glVertex2f( -7.5, 0.0 ); |
||
| 383 | glVertex2f( 7.5, 0.0 ); |
||
| 384 | glVertex2f( 7.5, -105.0 ); |
||
| 385 | glVertex2f( -7.5, -105.0 ); |
||
| 386 | glEnd(); |
||
| 387 | |||
| 388 | glEnable(GL_BLEND); |
||
| 389 | glBlendFunc(GL_ZERO,GL_ONE); |
||
| 390 | |||
| 391 | glColor4f(1,1,1,0); |
||
| 392 | glBegin(GL_POLYGON); |
||
| 393 | for( i = 0; i < 16; i++ ) { |
||
| 394 | double x, y; |
||
| 395 | x = 40.0 * cos(i*3.141592*2/16); |
||
| 396 | y = 40.0 * sin(i*3.141592*2/16); |
||
| 397 | glVertex2d( x, y ); |
||
| 398 | } |
||
| 399 | glEnd(); |
||
| 400 | glBegin(GL_POLYGON); |
||
| 401 | glVertex2f( -7.5, 0.0 ); |
||
| 402 | glVertex2f( 7.5, 0.0 ); |
||
| 403 | glVertex2f( 7.5, -105.0 ); |
||
| 404 | glVertex2f( -7.5, -105.0 ); |
||
| 405 | glEnd(); |
||
| 406 | glDisable(GL_BLEND); |
||
| 407 | |||
| 408 | /* draw any objects on the paddle */ |
||
| 409 | if( (i=paddleItemInfo->item) !=-1) { |
||
| 410 | |||
| 411 | glPushMatrix(); |
||
| 412 | glTranslatef( paddleItemInfo->x, paddleItemInfo->y, 10.0 ); |
||
| 413 | glRotatef( paddleItemInfo->angle * 180.0/3.141592, 0.0, 0.0, 1.0 ); |
||
| 414 | glColor3f(0.0,1.0,0.0); |
||
| 415 | glutSolidSphere(10,10,10); |
||
| 416 | // glutSolidTeapot(10.); |
||
| 417 | glPopMatrix(); |
||
| 418 | } |
||
| 419 | |||
| 420 | glDisable(GL_DEPTH_TEST); |
||
| 421 | argDrawMode2D(); |
||
| 422 | return 0; |
||
| 423 | } |
||
| 424 | |||
| 425 | /* draw the items on the ground */ |
||
| 426 | void drawItems(double trans[3][4], ItemList* itlist) |
||
| 427 | { |
||
| 428 | int i; |
||
| 429 | double gl_para[16]; |
||
| 430 | GLfloat light_position[] = {100.0,-200.0,200.0,0.0}; |
||
| 431 | GLfloat ambi[] = {0.1, 0.1, 0.1, 0.1}; |
||
| 432 | GLfloat lightZeroColor[] = {0.9, 0.9, 0.9, 0.1}; |
||
| 433 | GLfloat mat_ambient[] = {0.0, 1.0, 0.0, 1.0}; |
||
| 434 | GLfloat mat_flash2[] = {0.0, 1.0, 1.0, 1.0}; |
||
| 435 | GLfloat mat_flash_shiny2[]= {50.0}; |
||
| 436 | |||
| 437 | argDrawMode3D(); |
||
| 438 | argDraw3dCamera( 0, 0 ); |
||
| 439 | glEnable(GL_DEPTH_TEST); |
||
| 440 | glDepthFunc(GL_LEQUAL); |
||
| 441 | |||
| 442 | glEnable(GL_LIGHTING); |
||
| 443 | glEnable(GL_LIGHT0); |
||
| 444 | glLightfv(GL_LIGHT0, GL_POSITION, light_position); |
||
| 445 | glLightfv(GL_LIGHT0, GL_AMBIENT, ambi); |
||
| 446 | glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor); |
||
| 447 | glMaterialfv(GL_FRONT, GL_SPECULAR, mat_flash2); |
||
| 448 | glMaterialfv(GL_FRONT, GL_SHININESS, mat_flash_shiny2); |
||
| 449 | glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); |
||
| 450 | |||
| 451 | /* load the camera transformation matrix */ |
||
| 452 | glMatrixMode(GL_MODELVIEW); |
||
| 453 | argConvGlpara(trans, gl_para); |
||
| 454 | glLoadMatrixd( gl_para ); |
||
| 455 | for(i = 0; i < itlist->itemnum; i ++ ) |
||
| 456 | { |
||
| 457 | if (!itlist->item[i].onpaddle) |
||
| 458 | { |
||
| 459 | glPushMatrix(); |
||
| 460 | glTranslatef(itlist->item[i].pos[0],itlist->item[i].pos[1], 10.0 ); |
||
| 461 | glColor3f(0.0,1.0,0.0); |
||
| 462 | glutSolidSphere(10,10,10); |
||
| 463 | glPopMatrix(); |
||
| 464 | } |
||
| 465 | } |
||
| 466 | glDisable( GL_LIGHTING ); |
||
| 467 | glDisable( GL_DEPTH_TEST ); |
||
| 468 | argDrawMode2D(); |
||
| 469 | } |
||
| 470 | |||
| 471 | /************************************************************************************* |
||
| 472 | ** |
||
| 473 | ** drawGroundGrid - draws a ground plane |
||
| 474 | ** |
||
| 475 | ***************************************************************************************/ |
||
| 476 | int drawGroundGrid( double trans[3][4], int divisions, float x, float y, float height) |
||
| 477 | { |
||
| 478 | double gl_para[16]; |
||
| 479 | int i; |
||
| 480 | float x0,x1,y0,y1; |
||
| 481 | float deltaX, deltaY; |
||
| 482 | |||
| 483 | argDrawMode3D(); |
||
| 484 | argDraw3dCamera( 0, 0 ); |
||
| 485 | glEnable(GL_DEPTH_TEST); |
||
| 486 | glDepthFunc(GL_LEQUAL); |
||
| 487 | |||
| 488 | /* load the camera transformation matrix */ |
||
| 489 | glMatrixMode(GL_MODELVIEW); |
||
| 490 | argConvGlpara(trans, gl_para); |
||
| 491 | glLoadMatrixd( gl_para ); |
||
| 492 | |||
| 493 | glTranslatef(x/2.,-y/2.,0.); |
||
| 494 | //draw the grid |
||
| 495 | glColor3f(1,0,0); |
||
| 496 | glLineWidth(6.0); |
||
| 497 | glBegin(GL_LINE_LOOP); |
||
| 498 | glVertex3f( -x, y, height ); |
||
| 499 | glVertex3f( x, y, height ); |
||
| 500 | glVertex3f( x, -y, height ); |
||
| 501 | glVertex3f( -x, -y, height ); |
||
| 502 | glEnd(); |
||
| 503 | glLineWidth(3.0); |
||
| 504 | |||
| 505 | //draw a grid of lines |
||
| 506 | //X direction |
||
| 507 | x0 = -x; x1 = -x; |
||
| 508 | y0 = -y; y1 = y; |
||
| 509 | deltaX = (2*x)/divisions; |
||
| 510 | |||
| 511 | for(i=0;i<divisions;i++){ |
||
| 512 | x0 = x0 + deltaX; |
||
| 513 | glBegin(GL_LINES); |
||
| 514 | glVertex3f(x0,y0,height); |
||
| 515 | glVertex3f(x0,y1,height); |
||
| 516 | glEnd(); |
||
| 517 | } |
||
| 518 | |||
| 519 | x0 = -x; x1 = x; |
||
| 520 | deltaY = (2*y)/divisions; |
||
| 521 | |||
| 522 | for(i=0;i<divisions;i++){ |
||
| 523 | y0 = y0 + deltaY; |
||
| 524 | glBegin(GL_LINES); |
||
| 525 | glVertex3f(x0,y0,height); |
||
| 526 | glVertex3f(x1,y0,height); |
||
| 527 | glEnd(); |
||
| 528 | } |
||
| 529 | |||
| 530 | glLineWidth(1.0); |
||
| 531 | |||
| 532 | glEnable(GL_LIGHTING); |
||
| 533 | glEnable(GL_LIGHT0); |
||
| 534 | glLightfv(GL_LIGHT0, GL_POSITION, light_position); |
||
| 535 | glLightfv(GL_LIGHT0, GL_AMBIENT, ambi); |
||
| 536 | glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor); |
||
| 537 | |||
| 538 | glDisable( GL_LIGHTING ); |
||
| 539 | glDisable( GL_DEPTH_TEST ); |
||
| 540 | argDrawMode2D(); |
||
| 541 | return 0; |
||
| 542 | } |