#include <GL/glut.h>
#include <stdio.h>
#include <map>
#include <list>
#include <sys/time.h>
#include "outputOpengl.h"
#include "misc.h"
#include "quartz.h"
#include "devices.h"
Go to the source code of this file.
Compounds | |
struct | color |
struct | hullInfo |
struct | Object |
struct | poly |
struct | rawObject |
struct | vertex |
Defines | |
#define | DEBUG_3D |
#define | ROTATESTEP 0.5 |
#define | SIZEOFNAME 64 |
#define | MATRIXSECTORS 6 |
Functions | |
hullInfo* | parseObject ( string str ) |
The parser for the 3Dsia binary format (object description). More... | |
int | collisionDetection ( vertex* position ) |
primitive bounding boxes collision detection. More... | |
void | DrawCursor () |
void | display (void) |
The display function. More... | |
void | ChangeCamPos ( char direction ) |
Change Camera position. More... | |
void | ChangeCamLookTo (int x, int y) |
Change Camera position. More... | |
void | reshape (int x, int y) |
reshape function. More... | |
void | Init (void) |
Init Function. More... | |
void | idlefunc () |
The idle function. More... | |
void* | VisualizationThread ( void* targz ) |
The Visualization Thread. More... | |
Variables | |
GLfloat | m_ambient [] = { 0.5, 0.5, 0.5, 1.0} |
a default ambient value for materials. More... | |
GLfloat | m_diffuse [] = { 1.0, 1.0, 1.0, 1.0} |
a default diffuse value for materials. More... | |
GLfloat | m_specular [] = { 0.0, 0.0, 0.0, 1.0} |
a default specular value for materials. More... | |
GLfloat | m_shininess [] = { 50.0 } |
the shininess of the materials. More... | |
GLfloat | m_emission [] = { 0.0, 0.0, 0.0, 1.0} |
a default emission value for materials. More... | |
GLfloat | m_lamp [] = { 1.0, 0.5, 0.0, 1.0 } |
predefined material-property "lamp" (orange). More... | |
GLfloat | m_green [] = { 0.0, 1.0, 0.0, 1.0 } |
predefined material-property: green. More... | |
GLfloat | l_diffuse [] = { 1.0, 1.0, 1.0, 1.0 } |
diffuse value of the light. More... | |
GLfloat | l_ambient [] = { 0.6, 0.6, 0.6, 1.0 } |
ambient value of the light. More... | |
GLfloat | l_specular [] = { 0.0, 0.0, 0.0, 1.0 } |
specular value of the light. More... | |
GLfloat | l_position [] = {10.0, 300.0, 10.0, 0.0} |
the position of the first lightsource. More... | |
Buffer* | myInBuffer = 0 |
The buffer the idlefunc of the visualThread reads from. More... | |
QuartzClass* | qObj = 0 |
a pointer to an object of the quarzclass. More... | |
Buffer* | coreBufferIn = 0 |
used temporarily to send the coreThread packages of the input-devices - As soon as there is an own thread for the input handler, this will become obsolete. More... | |
string | chatmsg |
used temporarily by the keyboard-device to store the text in. More... | |
string | dismsg |
int | myObjectID |
the ID of the the own avatar in the matrix. More... | |
bool | showme = false |
defines if the own avatar is shown or not. More... | |
map<int,Object> | Objects |
The list of all (possibly) displayed objects. More... | |
int | colObject |
the ID of the object the avatar collided with. More... | |
struct timeval t1 | t2 |
struct timeval | devfreq |
defines the update-frequency. More... | |
int | frametime |
counts the number of frames per second. More... | |
int | devasks |
counts how often the devices have been asked for status in one second. More... | |
Devices | devices |
The devices. More... | |
int | deviceX |
int | deviceY |
simulated cursor position for use with the devices. More... | |
GLuint | Scene |
the displaylist of the matrix-lines. (just for debug-orientation). More... | |
GLuint | environment |
the displaylist for the static environment (not used at the moment). More... | |
bool | haveenvironment = false |
if there is a static environment to be displayed. More... | |
GLfloat | myRotate = 0.0 |
char* | TheOneObject = 0 |
|
Definition at line 35 of file visualThread.cpp.
|
|
Definition at line 166 of file visualThread.cpp.
|
|
Change Camera position.
Definition at line 562 of file visualThread.cpp.
00563 { 00564 float radiusSegX = 2*PI / WINDOWX; 00565 float radiusSegY = PI / WINDOWY; 00566 00567 int split[2]; 00568 #ifdef DEBUG 00569 fprintf(stderr,"chCamLook2 x=%d y=%d \n",x,y); 00570 #endif 00571 float hyp_hor; 00572 00573 x = WINDOWX - x; 00574 split[X] = (WINDOWX/2) - x; 00575 split[Y] = (WINDOWY/2) - y; 00576 00577 float winkel[2]; 00578 winkel[X] = radiusSegX * ( (float) split[X] ); 00579 winkel[Y] = radiusSegY * ( (float) split[Y] ); 00580 00581 lookdir[Y] = sin ( winkel[Y] ); 00582 hyp_hor = ( cos ( winkel[Y] ) * -1.0); 00583 00584 lookdir[X] = cos ( winkel[X] ) * hyp_hor; 00585 lookdir[Z] = sin ( winkel[X] ) * hyp_hor; 00586 00587 vertex temp; 00588 temp.x = lookto[X]; 00589 temp.y = lookto[Y]; 00590 temp.z = lookto[Z]; 00591 00592 colObject = collisionDetection ( &temp ); 00593 }
|
Change Camera position.
Definition at line 525 of file visualThread.cpp.
00526 { 00527 switch (direction) 00528 { 00529 case 'f': 00530 { 00531 campos[X] = campos[X] + lookdir[X]/speed; 00532 campos[Y] = campos[Y] + lookdir[Y]/speed; 00533 campos[Z] = campos[Z] + lookdir[Z]/speed; 00534 break; 00535 } 00536 00537 case 'b': 00538 { 00539 campos[X] = campos[X] - lookdir[X]/speed; 00540 campos[Y] = campos[Y] - lookdir[Y]/speed; 00541 campos[Z] = campos[Z] - lookdir[Z]/speed; 00542 break; 00543 } 00544 } 00545 00546 vertex temp; 00547 temp.x = lookto[X]; 00548 temp.y = lookto[Y]; 00549 temp.z = lookto[Z]; 00550 00551 colObject = collisionDetection ( &temp ); 00552 }
|
Definition at line 376 of file visualThread.cpp.
00377 { 00378 glTranslatef( (GLfloat) campos[X]+lookdir[X]*1.1, 00379 (GLfloat) campos[Y]+lookdir[Y]*1.1, 00380 (GLfloat) campos[Z]+lookdir[Z]*1.1); 00381 00382 DrawHand (); 00383 }
|
Init Function.
Definition at line 627 of file visualThread.cpp.
00628 { 00629 glClearColor (0.0, 0.0, 0.0, 0.0); 00630 glutWarpPointer(WINDOWX/2,WINDOWY/2); 00631 00632 glMatrixMode(GL_PROJECTION); 00633 glLoadIdentity(); 00634 gluPerspective(70.0,1.0*WINDOWX/WINDOWY,1.0,5000.0); 00635 00636 glMatrixMode(GL_MODELVIEW); 00637 00638 glShadeModel (GL_SMOOTH); 00639 00640 glEnable(GL_DEPTH_TEST); 00641 00642 Scene = glGenLists (1); 00643 00644 glNewList(Scene,GL_COMPILE); 00645 #define MATRIXSECTORS 6 00646 DrawMatrix((MATRIXSECTORS*200/2), MATRIXSECTORS); 00647 glEndList(); 00648 00649 glEnable(GL_LIGHTING); 00650 glEnable(GL_LIGHT0); 00651 00652 deviceX = WINDOWX * 3 / 4; 00653 deviceY = WINDOWY / 2; 00654 00655 ChangeCamLookTo(deviceX,deviceY); 00656 }
|
The Visualization Thread.
targz | passes the arguments which came from main |
Definition at line 1019 of file visualThread.cpp.
01020 { 01021 ThreadArgs* targs = (ThreadArgs*) targz; 01022 myInBuffer = targs->in; 01023 01024 fprintf(stderr,"[vT] Visualization Thread started... %p\n",targs->in); 01025 01026 /* i sometimes forget to export the correct DISPLAY.*/ 01027 if (getenv("DISPLAY") == NULL) 01028 { 01029 cerr << "[display-environment-check] DISPLAY not set...\tcontinuing\n"<<endl; 01030 01031 if (putenv("DISPLAY=0:0")) 01032 cerr << "[display-environment-check]\tsetting DISPLAY environement-var to 0:0 failed\n"; 01033 cerr << "[display-environment-check]\tsetting DISPLAY=0:0\n"; 01034 } 01035 01036 devfreq.tv_usec = 1000000 / 26; 01037 01038 01039 while ( !myInBuffer ) usleep (10000); //useless actually 01040 while ( !coreBufferIn ) usleep (10000); 01041 01042 extern Buffer* outputBufferIn; 01043 qObj = new QuartzClass ( outputBufferIn, PROT_GET_ALL_CHANGED, 25 ); 01044 pthread_t qThread; 01045 pthread_create (&qThread, NULL, QuartzThread, qObj); 01046 01047 glutInit(&targs->argc,targs->argv); 01048 WINDOWX = 640; 01049 WINDOWY = 480; 01050 01051 glutInitDisplayMode (GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE ); 01052 glutInitWindowSize ( WINDOWX, WINDOWY ); 01053 glutInitWindowPosition ( 0, 0); 01054 glutCreateWindow ( "[3Dsia] Reference Client" ); 01055 01056 Init (); 01057 01058 cerr << devices.addDevicePlugIn ("client/plugins/deviceMouse.so") << "\n"; 01059 devices.connect (0, 0, MOVE_FORWARD); 01060 devices.connect (0, 1, MOVE_BACKWARD); 01061 devices.connect (0, devices.getDeviceButtons (0), ROTATE_UP); 01062 devices.connect (0, devices.getDeviceButtons (0) + 1, ROTATE_DOWN); 01063 devices.connect (0, devices.getDeviceButtons (0) + 2, ROTATE_LEFT); 01064 devices.connect (0, devices.getDeviceButtons (0) + 3, ROTATE_RIGHT); 01065 01066 cerr << devices.addDevicePlugIn ("client/plugins/deviceKeyboard.so") << "\n"; 01067 devices.connect (1, 0, MOVE_FORWARD); 01068 devices.connect (1, 1, MOVE_BACKWARD); 01069 devices.connect (1, 2, EXIT_CLIENT); 01070 devices.connect (1, 3, INC_SPEED); 01071 devices.connect (1, 4, DEC_SPEED); 01072 devices.connect (1, devices.getDeviceButtons (1), ROTATE_UP); 01073 devices.connect (1, devices.getDeviceButtons (1) + 1, ROTATE_DOWN); 01074 devices.connect (1, devices.getDeviceButtons (1) + 2, ROTATE_LEFT); 01075 devices.connect (1, devices.getDeviceButtons (1) + 3, ROTATE_RIGHT); 01076 devices.connect (1, devices.getDeviceButtons (1) + 4, CHAT_MODE); 01077 01078 glutDisplayFunc (display); 01079 glutReshapeFunc (reshape); 01080 glutIdleFunc (idlefunc); 01081 glutMainLoop (); 01082 01083 return targz; 01084 }
|
primitive bounding boxes collision detection.
position | the position of the object thats has to be checked |
Definition at line 338 of file visualThread.cpp.
00339 { 00340 int cobject = -1; 00341 00342 #ifdef DEBUG5 00343 fprintf(stderr,"[vT.collisionDetection] checking [%f][%f][%f]\n",position->x,position->y,position->z); 00344 #endif 00345 00346 typedef map<int,Object>::const_iterator objectIt; 00347 for ( objectIt o = Objects.begin(); o != Objects.end(); ++o) 00348 { 00349 const hullInfo *hull = o->second.hull; 00350 const double *pos = o->second.pos; 00351 00352 #ifdef DEBUG5 00353 fprintf(stderr,"[collision] HULL = a %f %f %f\n",pos[X] + hull->a.x, pos[Y] + hull->a.y, pos[Z] + hull->a.z); 00354 fprintf(stderr," b %f %f %f\n",pos[X] + hull->b.x, pos[Y] + hull->b.y, pos[Z] + hull->b.z); 00355 #endif 00356 if ( o->first == myObjectID ) 00357 continue; 00358 00359 if ( ( ( ( pos[X] + hull->a.x ) < position->x + 1 ) && ( ( pos[X] + hull->b.x ) > position->x -1 ) ) 00360 && ( ( ( pos[Y] + hull->a.y ) < position->y + 1 ) && ( ( pos[Y] + hull->b.y ) > position->y -1 ) ) 00361 && ( ( ( pos[Z] + hull->a.z ) < position->z + 1 ) && ( ( pos[Z] + hull->b.z ) > position->z -1 ) ) ) 00362 { 00363 cobject = o->first; 00364 #ifdef DEBUG5 00365 fprintf(stderr,"[vT] Collision Detection POSITIVE!! %d\n",cobject); 00366 #endif 00367 break; 00368 } 00369 00370 } 00371 00372 return cobject; 00373 }
|
The display function.
Definition at line 392 of file visualThread.cpp.
00393 { 00394 glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); 00395 00396 glShadeModel( GL_SMOOTH); 00397 00398 glMaterialfv( GL_FRONT, GL_SPECULAR, m_specular ); 00399 glMaterialfv( GL_FRONT, GL_SHININESS, m_shininess ); 00400 glMaterialfv( GL_FRONT, GL_EMISSION, m_emission ); 00401 00402 glLightfv ( GL_LIGHT0, GL_AMBIENT, l_ambient ); 00403 glLightfv ( GL_LIGHT0, GL_DIFFUSE, l_diffuse ); 00404 glLightfv ( GL_LIGHT0, GL_POSITION, l_position ); 00405 glLightfv ( GL_LIGHT0, GL_SPECULAR, l_specular ); 00406 00407 glPushMatrix (); 00408 00409 glDisable(GL_BLEND); 00410 00411 #ifdef DEBUG 00412 fprintf(stderr,"[vT] - %f %f %f\n",campos[X],campos[Y],campos[Z]); 00413 fprintf(stderr,"[vT] - %f %f %f\n",lookto[X],lookto[Y],lookto[Z]); 00414 fprintf(stderr,"[vT] - %f %f %f\n",upvect[X],upvect[Y],upvect[Z]); 00415 #endif 00416 00417 gluLookAt ( campos[X], campos[Y], campos[Z], 00418 lookto[X], lookto[Y], lookto[Z], 00419 upvect[X], upvect[Y], upvect[Z]); 00420 00421 00422 glScalef (1.0, 1.0, 1.0); 00423 00424 glCallList(Scene); 00425 00426 glMaterialfv( GL_FRONT, GL_DIFFUSE, m_green ); 00427 00428 glBegin(GL_TRIANGLE_STRIP); 00429 glNormal3f(1.0,0.0,0.0); 00430 glVertex3f(-50.0,0.0,-50.0); 00431 glVertex3f(50.0,0.0,-50.0); 00432 glNormal3f(0.0,1.0,0.0); 00433 glVertex3f(0.0,50.0,0.0); 00434 glVertex3f(0.0,0.0,50.0); 00435 glNormal3f(0.0,0.0,1.0); 00436 glVertex3f(-50.0,0.0,-50.0); 00437 glEnd(); 00438 00439 if ( !haveenvironment ) 00440 glCallList ( environment ); 00441 00442 typedef map<int,Object>::const_iterator objectIt; 00443 00444 for ( objectIt o = Objects.begin(); o != Objects.end(); ++o) 00445 { 00446 const double *pos = o->second.pos; 00447 00448 #ifdef DEBUG3 00449 fprintf(stderr,"[%d]-[%f][%f][%f]--[%d]\n",o->first,pos[0],pos[1],pos[2],o->second.visualData.length()); 00450 #endif 00451 00452 00453 if ( !o->second.havedata ) continue; 00454 00455 if ( o->first == myObjectID ) 00456 { 00457 if ( !showme ) 00458 continue; 00459 } 00460 00461 glPushMatrix(); 00462 00463 glTranslated(pos[0],pos[1],pos[2]); 00464 glCallList ( o->second.visual); 00465 00466 glRasterPos2i (0,0); 00467 printstring (GLUT_BITMAP_TIMES_ROMAN_24, const_cast<char*>(o->second.chat_msg.c_str())); 00468 00469 glPopMatrix (); 00470 } 00471 00472 00473 glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, m_green ); 00474 00475 // SHOWS LIGHTSOURCES: 00476 #ifdef DEBUG_3D 00477 glPushMatrix(); 00478 glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, m_lamp ); 00479 00480 glTranslatef(l_position[0],l_position[1],l_position[2]); 00481 glRotatef(myRotate,1.0,1.1,1.4); 00482 00483 glutWireSphere ( 20.0, 10, 10 ); 00484 glPopMatrix(); 00485 #endif 00486 00487 DrawCursor(); 00488 00489 glPopMatrix(); 00490 00491 glShadeModel(GL_FLAT); 00492 glMatrixMode(GL_PROJECTION); 00493 00494 glPushMatrix(); 00495 00496 glLoadIdentity(); 00497 glOrtho(-0.5,799.5,-0.5,579.5,-1.0,1.0); 00498 glMatrixMode(GL_MODELVIEW); 00499 glLoadIdentity(); 00500 00501 00502 DrawStat(); 00503 00504 glPushMatrix (); 00505 glColor3f (1.0, 1.0, 1.0); 00506 glRasterPos2i (20,100); 00507 printstring (GLUT_BITMAP_TIMES_ROMAN_24, const_cast<char*>(chatmsg.c_str())); 00508 glPopMatrix (); 00509 00510 glMatrixMode(GL_PROJECTION); 00511 00512 glPopMatrix(); 00513 00514 glMatrixMode(GL_MODELVIEW); 00515 00516 glutSwapBuffers(); 00517 }
|
The idle function.
Definition at line 664 of file visualThread.cpp.
00665 { 00666 gettimeofday(&t1,NULL); 00667 00668 if ( t1.tv_sec - t2.tv_sec > 0 ) 00669 { 00670 frametime = framecounter; 00671 framecounter = 0; 00672 t2.tv_sec = t1.tv_sec; 00673 devasks = 0; 00674 00675 if ( frametime < 25 ) 00676 qObj->setFrequency ( frametime ); //WHY DOES THERE COME A FLOATING POINT EXCEPTION WHEN I USE qObj->setFrequency ( frametime )?? 00677 else 00678 qObj->setFrequency ( 25 ); 00679 00680 } 00681 framecounter++; 00682 00683 devices.update (); 00684 00685 if ( ( devfreq.tv_usec * devasks ) < t1.tv_usec ) 00686 { 00687 if (devices.eventStatus (MOVE_FORWARD)) { 00688 #ifdef DEBUG 00689 cerr << "MOVE_FORWARD\n"; 00690 #endif 00691 00692 if ( colObject < 0 ) 00693 { 00694 packet* pak = new packet; 00695 pak->h.header[0] = PROT_OUTPUT_VISUAL; 00696 pak->h.header[1] = VISUAL_CAMERA_MOVE; 00697 pak->h.header[2] = INPUT_FORWARD; 00698 00699 coreBufferIn->write (pak); 00700 } 00701 }; 00702 00703 if (devices.eventStatus (MOVE_BACKWARD)) { 00704 #ifdef DEBUG 00705 cerr << "MOVE_BACKWARD\n"; 00706 #endif 00707 00708 packet* pak = new packet; 00709 pak->h.header[0] = PROT_OUTPUT_VISUAL; 00710 pak->h.header[1] = VISUAL_CAMERA_MOVE; 00711 pak->h.header[2] = INPUT_BACKWARD; 00712 00713 coreBufferIn->write (pak); 00714 }; 00715 00716 if (devices.eventStatus (ROTATE_UP)) { 00717 #ifdef DEBUG 00718 cerr << "ROTATE_UP\n"; 00719 #endif 00720 00721 deviceY -= (int) (devices.eventStatus (ROTATE_UP) * 5.0); 00722 00723 if ( deviceY <= 0 ) 00724 deviceY = (WINDOWY - deviceY) % WINDOWY; 00725 00726 ChangeCamLookTo(deviceX,deviceY); 00727 }; 00728 00729 if (devices.eventStatus (ROTATE_DOWN)) { 00730 #ifdef DEBUG 00731 cerr << "ROTATE_DOWN\n"; 00732 #endif 00733 00734 deviceY += (int) (devices.eventStatus (ROTATE_DOWN) * 5.0); 00735 00736 if ( deviceY >= WINDOWY ) 00737 deviceY = deviceY % WINDOWY; 00738 00739 ChangeCamLookTo(deviceX,deviceY); 00740 }; 00741 00742 if (devices.eventStatus (ROTATE_LEFT)) { 00743 #ifdef DEBUG 00744 cerr << "ROTATE_LEFT\n"; 00745 #endif 00746 00747 deviceX -= (int) (devices.eventStatus (ROTATE_LEFT) * 5.0); 00748 00749 if ( deviceX <= 0) 00750 deviceX = (WINDOWX + deviceX) % WINDOWX; 00751 00752 ChangeCamLookTo(deviceX,deviceY); 00753 }; 00754 00755 if (devices.eventStatus (ROTATE_RIGHT)) { 00756 #ifdef DEBUG 00757 cerr << "ROTATE_RIGHT\n"; 00758 #endif 00759 00760 deviceX += (int) (devices.eventStatus (ROTATE_RIGHT) * 5.0); 00761 00762 if ( deviceX >= WINDOWX) 00763 deviceX = deviceX % WINDOWX; 00764 00765 ChangeCamLookTo(deviceX,deviceY); 00766 }; 00767 00768 devasks++; 00769 } 00770 00771 00772 if (devices.eventStatus (CHAT_MODE)) { 00773 char c = (char) (devices.eventStatus (CHAT_MODE) * 32767); 00774 c++; 00775 #ifdef DEBUG 00776 cerr << "CHAT_MODE: " << c << " " << (int) c << "\n"; 00777 #endif 00778 00779 if (c == 13) { 00780 packet* pak = new packet; 00781 pak->h.header[0] = PROT_TEXT_MSG; 00782 pak->data = chatmsg; 00783 00784 coreBufferIn->write (pak); 00785 00786 chatmsg = ""; 00787 } else if ((c == 8) && (chatmsg.length () > 0)) { 00788 chatmsg = chatmsg.substr (0, chatmsg.length () - 1); 00789 } else { 00790 chatmsg += c; 00791 }; 00792 00793 }; 00794 00795 if (devices.eventStatus (EXIT_CLIENT)) { 00796 cerr << "EXIT_CLIENT\n"; 00797 00798 packet* pak = new packet; 00799 pak->h.header[0] = PROT_KILL_CLIENT; 00800 00801 coreBufferIn->write (pak); 00802 exit (0); 00803 }; 00804 00805 00806 myRotate += ROTATESTEP; 00807 if ( myRotate >= 360.0 ) myRotate = 0.0; 00808 00809 if ( !myInBuffer->isEmpty() ) 00810 { 00811 #ifdef DEBUG 00812 fprintf(stderr,"[vT] got a packet!\n"); 00813 #endif 00814 packet* pak; 00815 pak = myInBuffer->read (); 00816 00817 switch ( pak->h.header[0] ) 00818 { 00819 case VISUAL_CAMERA_MOVE: 00820 { 00821 #ifdef DEBUG 00822 fprintf(stderr,"[vT] VISUAL_CAMERA_MOVE\n"); 00823 #endif 00824 if ( pak->h.header[1] == INPUT_FORWARD ) 00825 { 00826 ChangeCamPos( 'f' ); 00827 } 00828 else 00829 { 00830 ChangeCamPos( 'b' ); 00831 } 00832 00833 pak = new packet; 00834 00835 char* temp; 00836 double tempPos[3]; 00837 00838 tempPos[0] = campos[0]; 00839 tempPos[1] = campos[1]; 00840 tempPos[2] = campos[2]; 00841 00842 temp = new char[sizeof(double)*3]; 00843 memcpy ( temp, &tempPos, sizeof(double)*3); 00844 00845 00846 pak->h.header[0] = PROT_CHANGE_POSITION; 00847 pak->data.assign (temp, sizeof(double)*3); 00848 00849 coreBufferIn->write (pak); 00850 00851 NeedRedraw = 1; 00852 break; 00853 } 00854 00855 case VISUAL_CAMERA_LOOKTO: 00856 { 00857 #ifdef DEBUG 00858 fprintf(stderr,"[vT] VISUAL_CAMERA_LOOKTO\n"); 00859 #endif 00860 ChangeCamLookTo(pak->h.header[2],pak->h.header[3]); 00861 NeedRedraw = 1; 00862 00863 delete pak; 00864 break; 00865 } 00866 00867 case VISUAL_NEW_OBJECT: 00868 { 00869 /************************************ 00870 h.header[1] ObjectID 00871 data name 00872 ************************************/ 00873 #ifdef DEBUG2 00874 fprintf(stderr,"[vT] getting a new object - %d - %d\n", pak->h.header[1],pak->data.length()); 00875 #endif 00876 00877 Objects[pak->h.header[1]].name = pak->data; 00878 00879 #ifdef DEBUG2 00880 cerr << "Thats the object: \n" << pak->data; 00881 #endif 00882 00883 delete pak; 00884 break; 00885 } 00886 00887 case VISUAL_MY_OBJECT: 00888 { 00889 myObjectID = pak->h.header[2]; 00890 break; 00891 } 00892 00893 case VISUAL_TURN_AVATAR_OFF: 00894 { 00895 showme = !showme; 00896 break; 00897 } 00898 00899 case VISUAL_NEW_ATOM: 00900 { 00901 /************************************** 00902 h.header[1] ObjectID 00903 h.header[2] atomType 00904 h.header[3] atomID 00905 h.header[4] valueType 00906 data The atom data 00907 **************************************/ 00908 00909 #ifdef DEBUG4 00910 fprintf(stderr,"[vT] New Atom (%d) type %d - for object %d - %d\n",pak->h.header[3],pak->h.header[2],pak->h.header[1],pak->data.length()); 00911 #endif 00912 00913 switch ( pak->h.header[2] ) 00914 { 00915 case AT_CHATMSG: 00916 { 00917 dismsg = pak->data; 00918 00919 cerr << dismsg << " ...\n"; 00920 Objects[pak->h.header[1]].chat_msg = pak->data; 00921 00922 delete pak; 00923 break; 00924 } 00925 00926 case AT_POSITION: 00927 { 00928 00929 double *pos = Objects[pak->h.header[1]].pos; 00930 memcpy ( pos, pak->data.data(), sizeof(double)*3 ); 00931 00932 #ifdef DEBUG2 00933 fprintf(stderr,"pos ausgabe:\n"); 00934 fprintf(stderr,"%d %f,%f,%f\n",pak->h.header[1] 00935 ,Objects[pak->h.header[1]].pos[0] 00936 ,Objects[pak->h.header[1]].pos[1] 00937 ,Objects[pak->h.header[1]].pos[2]); 00938 #endif 00939 00940 delete pak; 00941 break; 00942 } 00943 00944 case AT_3DSIAGRAPH: 00945 { 00946 if ( pak->h.header[1] < 0 ) 00947 { 00948 environment = glGenLists (1); 00949 00950 glNewList(environment,GL_COMPILE); 00951 parseObject ( pak->data ); 00952 glEndList(); 00953 00954 haveenvironment = true; 00955 } 00956 else 00957 { 00958 Objects[pak->h.header[1]].visual = glGenLists (1); 00959 00960 glNewList(Objects[pak->h.header[1]].visual,GL_COMPILE); 00961 00962 Objects[pak->h.header[1]].hull = parseObject ( pak->data ); 00963 00964 glEndList(); 00965 00966 Objects[pak->h.header[1]].havedata = true; 00967 } 00968 00969 delete pak; 00970 break; 00971 } 00972 00973 default: 00974 { 00975 fprintf(stderr,"[vT] THIS CANNOT BE!! IT CAN'T!!\n"); 00976 delete pak; 00977 exit(1); 00978 break; 00979 } 00980 } 00981 break; 00982 } 00983 00984 default: 00985 { 00986 #ifdef DEBUG 00987 fprintf(stderr,"[vT] heey, DEFAULT IS BORING!!!!\n"); 00988 #endif 00989 break; 00990 } 00991 00992 } 00993 } 00994 00995 00996 lookto[X] = lookdir[X] + campos[X]; 00997 lookto[Y] = lookdir[Y] + campos[Y]; 00998 lookto[Z] = lookdir[Z] + campos[Z]; 00999 01000 glutPostRedisplay(); 01001 }
|
The parser for the 3Dsia binary format (object description).
str | The binary string |
Definition at line 180 of file visualThread.cpp.
00181 { 00182 #define SIZEOFNAME 64 00183 00184 #ifdef DEBUG 00185 fprintf(stderr,"[parser] 1\n"); 00186 #endif 00187 00188 GLfloat m_diff[4] = { 1.0, 1.0, 1.0, 1.0 }; 00189 00190 hullInfo* hull = new hullInfo; 00191 00192 hull->a.x = 0.0; 00193 hull->a.y = 0.0; 00194 hull->a.y = 0.0; 00195 hull->b.x = 0.0; 00196 hull->b.y = 0.0; 00197 hull->b.y = 0.0; 00198 00199 if ( str.empty () ) return hull; 00200 00201 struct rawObject* o = new rawObject; 00202 00203 int pos; 00204 00205 o->name.assign ( str.c_str(), SIZEOFNAME ); 00206 o->name[63] = '\0'; 00207 pos = 64; 00208 00209 #ifdef DEBUG 00210 fprintf(stderr,"Name: %s\n", o->name.c_str ()); 00211 fprintf(stderr,"%s\n",str.c_str() + pos ); 00212 #endif 00213 00214 memcpy ( &o->numberOfVertices, str.data() + pos, sizeof ( int ) ); 00215 pos += sizeof ( int ); 00216 00217 int tempNumber; 00218 00219 #ifdef DEBUG 00220 fprintf(stderr,"%d\n",o->numberOfVertices); 00221 #endif 00222 for ( int i = 0; i < o->numberOfVertices; i++ ) 00223 { 00224 #ifdef DEBUG 00225 fprintf(stderr,"vertices\n"); 00226 #endif 00227 00228 memcpy ( &tempNumber, str.data() + pos, sizeof(int) ); 00229 pos += sizeof(int); 00230 memcpy ( &o->verteces[tempNumber], str.data() + pos, sizeof(struct vertex) ); 00231 pos += sizeof(vertex); 00232 00233 if (hull->a.x > o->verteces[tempNumber].x ) 00234 hull->a.x = o->verteces[tempNumber].x; 00235 if (hull->a.y > o->verteces[tempNumber].y ) 00236 hull->a.y = o->verteces[tempNumber].y; 00237 if (hull->a.z > o->verteces[tempNumber].z ) 00238 hull->a.z = o->verteces[tempNumber].z; 00239 00240 if (hull->b.x < o->verteces[tempNumber].x ) 00241 hull->b.x = o->verteces[tempNumber].x; 00242 if (hull->b.y < o->verteces[tempNumber].y ) 00243 hull->b.y = o->verteces[tempNumber].y; 00244 if (hull->b.z < o->verteces[tempNumber].z ) 00245 hull->b.z = o->verteces[tempNumber].z; 00246 } 00247 00248 memcpy ( &o->numberOfPolies, str.data() + pos, sizeof(int) ); 00249 pos += sizeof(int); 00250 00251 poly tempPoly; 00252 00253 for ( int i = 0; i < o->numberOfPolies; i++ ) 00254 { 00255 #ifdef DEBUG 00256 fprintf(stderr,"polygons\n"); 00257 #endif 00258 00259 memcpy ( &tempPoly.number, str.data() + pos, sizeof (int) ); 00260 pos += sizeof (int); 00261 memcpy ( &tempPoly.type, str.data() + pos, sizeof (char) ); 00262 pos += sizeof (char); 00263 memcpy ( &tempPoly.col, str.data() + pos, sizeof (color) ); 00264 pos += sizeof (color); 00265 00266 memcpy ( &tempNumber, str.data() + pos, sizeof (int) ); 00267 pos += sizeof (int); 00268 00269 int tempVertexNr; 00270 00271 m_diff[0] = tempPoly.col.R; 00272 m_diff[1] = tempPoly.col.G; 00273 m_diff[2] = tempPoly.col.B; 00274 m_diff[3] = tempPoly.col.A; 00275 00276 glBegin(GL_TRIANGLE_STRIP); 00277 00278 glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, m_diff ); 00279 00280 for ( int j = 0; j < tempNumber; j++ ) 00281 { 00282 memcpy ( &tempVertexNr, str.data() + pos, sizeof (int) ); 00283 pos += sizeof (int); 00284 00285 if ( !(j % 2) ) 00286 { 00287 switch ( j % 6 ) 00288 { 00289 case 0: 00290 glNormal3f(1.0,0.0,0.0); 00291 break; 00292 case 2: 00293 glNormal3f(0.0,1.0,0.0); 00294 break; 00295 case 4: 00296 glNormal3f(0.0,0.0,1.0); 00297 break; 00298 } 00299 } 00300 00301 glVertex3f (o->verteces[tempVertexNr].x,o->verteces[tempVertexNr].y,o->verteces[tempVertexNr].z); 00302 } 00303 glEnd(); 00304 00305 o->polies[tempPoly.number] = tempPoly; 00306 } 00307 00308 #ifdef DEBUG3 00309 fprintf(stderr,"[%f][%f][%f]\n",o->verteces[1].x 00310 ,o->verteces[1].y 00311 ,o->verteces[1].z); 00312 #endif 00313 00314 00315 #ifdef DEBUG 00316 fprintf(stderr,"[parser] finished\n"); 00317 #endif 00318 00319 #ifdef DEBUG5 00320 fprintf(stderr,"[parser] HULL = a %f %f %f\n",hull->a.x,hull->a.y,hull->a.z); 00321 fprintf(stderr," b %f %f %f\n",hull->b.x,hull->b.y,hull->b.z); 00322 #endif 00323 00324 delete o; 00325 return hull; 00326 }
|
reshape function.
Definition at line 600 of file visualThread.cpp.
00601 { 00602 glMatrixMode(GL_PROJECTION); 00603 glLoadIdentity(); 00604 gluPerspective(70.0,1.0*x/y,1.0,5000.0); 00605 glMatrixMode(GL_MODELVIEW); 00606 glLoadIdentity(); 00607 glViewport(0,0,x,y); 00608 00609 float percX = (float)x / (float)WINDOWX; 00610 float percY = (float)y / (float)WINDOWY; 00611 00612 //fix me pleeease!! 00613 WINDOWX = x; 00614 WINDOWY = y; 00615 00616 deviceX = (int)( (float)deviceX * percX); 00617 deviceY = (int)( (float)deviceY * percY); 00618 ChangeCamLookTo(deviceX,deviceY); 00619 }
|
|
the displaylist of the matrix-lines. (just for debug-orientation).
Definition at line 156 of file visualThread.cpp.
|
Definition at line 169 of file visualThread.cpp.
|
used temporarily by the keyboard-device to store the text in.
Definition at line 58 of file visualThread.cpp.
|
|
used temporarily to send the coreThread packages of the input-devices - As soon as there is an own thread for the input handler, this will become obsolete.
Definition at line 56 of file visualThread.cpp.
|
counts how often the devices have been asked for status in one second.
Definition at line 151 of file visualThread.cpp.
|
|
Definition at line 154 of file visualThread.cpp.
|
simulated cursor position for use with the devices.
Definition at line 154 of file visualThread.cpp.
|
|
Definition at line 59 of file visualThread.cpp.
|
the displaylist for the static environment (not used at the moment).
Definition at line 157 of file visualThread.cpp.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The buffer the idlefunc of the visualThread reads from.
Definition at line 52 of file visualThread.cpp.
|
|
Definition at line 167 of file visualThread.cpp.
|
|
|
Definition at line 148 of file visualThread.cpp.