Changeset 2977 in orxonox.OLD for orxonox/branches/osX/importer
- Timestamp:
- Nov 24, 2004, 12:50:55 PM (20 years ago)
- Location:
- orxonox/branches/osX/importer
- Files:
-
- 7 edited
- 3 copied
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/osX/importer/Makefile.am
r2776 r2977 6 6 7 7 bin_PROGRAMS=importer 8 importer_SOURCES=framework.cc windowHandler.cc object.cc array.cc material.cc8 importer_SOURCES=framework.cc windowHandler.cc vector.cc object.cc array.cc material.cc 9 9 10 noinst_HEADERS= windowHandler.h object.h array.h material.h10 noinst_HEADERS=framework.h windowHandler.h vector.h object.h array.h material.h 11 11 12 12 -
orxonox/branches/osX/importer/Makefile.in
r2776 r2977 53 53 PROGRAMS = $(bin_PROGRAMS) 54 54 am_importer_OBJECTS = framework.$(OBJEXT) windowHandler.$(OBJEXT) \ 55 object.$(OBJEXT) array.$(OBJEXT) material.$(OBJEXT) 55 vector.$(OBJEXT) object.$(OBJEXT) array.$(OBJEXT) \ 56 material.$(OBJEXT) 56 57 importer_OBJECTS = $(am_importer_OBJECTS) 57 58 importer_LDADD = $(LDADD) … … 61 62 @AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/array.Po ./$(DEPDIR)/framework.Po \ 62 63 @AMDEP_TRUE@ ./$(DEPDIR)/material.Po ./$(DEPDIR)/object.Po \ 63 @AMDEP_TRUE@ ./$(DEPDIR)/ windowHandler.Po64 @AMDEP_TRUE@ ./$(DEPDIR)/vector.Po ./$(DEPDIR)/windowHandler.Po 64 65 CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ 65 66 $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) … … 151 152 AM_CXXFLAGS = "-I/usr/X11R6/include" 152 153 AM_LDFLAGS = "-L/usr/Mesa-6.0.1/lib -L/usr/X11R6/lib -lXt -lX11" $(MWINDOWS) 153 importer_SOURCES = framework.cc windowHandler.cc object.cc array.cc material.cc154 noinst_HEADERS = windowHandler.h object.h array.h material.h154 importer_SOURCES = framework.cc windowHandler.cc vector.cc object.cc array.cc material.cc 155 noinst_HEADERS = framework.h windowHandler.h vector.h object.h array.h material.h 155 156 all: all-am 156 157 … … 223 224 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/material.Po@am__quote@ 224 225 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/object.Po@am__quote@ 226 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vector.Po@am__quote@ 225 227 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/windowHandler.Po@am__quote@ 226 228 -
orxonox/branches/osX/importer/framework.cc
r2863 r2977 1 #include "windowHandler.h" // Include the Whandler Basecode 2 #include "object.h" 1 #include "framework.h" 3 2 4 3 int verbose = 1; 5 WindowHandler wHandler; // Create an instance of the whandler basecode class6 Object* obj;7 float rotator = 0.0;8 GLfloat whiteLight[] = {1.0, 1.0, 0.0,1.0};9 4 10 5 void DrawGLScene() 11 6 { 12 rotator +=.001; 13 7 currFrame = SDL_GetTicks(); 8 dt = currFrame - lastFrame; 9 if (dt == 0) 10 dist += (zoomTo-dist)/500; 11 else 12 dist += (zoomTo-dist)/500 *(float)dt; 13 14 rotatorP += rotatorV *(float)dt; 15 16 14 17 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); 15 18 glLoadIdentity(); // Reset the view … … 17 20 glMatrixMode(GL_PROJECTION); 18 21 glLoadIdentity(); 19 gluPerspective(45.0f,500/375,0.1f,100.0f); 20 gluLookAt (5*sin(rotator),7.5,5*cos(rotator), 0,0,0, 0,1,0); 21 whiteLight[1] = .5+.5*sin(rotator*10); 22 whiteLight[2] = .5+.5*sin(rotator*10); 23 24 GLfloat lightPosition[] = {10.0*sin(rotator*10), 10, 19.0, 0.0}; 25 glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); 26 27 glLightfv(GL_LIGHT0, GL_DIFFUSE, whiteLight); 22 gluPerspective(45.0f,500/375,0.1f,dist * 5.0f); 23 gluLookAt (0, dist , dist, 0,0,0, up.x,up.y,up.z); 24 25 glMatrixMode(GL_MODELVIEW); 26 glPushMatrix(); 27 // glRotatef (180, dir.x, dir.y, dir.z); 28 glMultMatrixf (*matQ); 28 29 obj->draw(); 29 30 31 glPopMatrix(); 32 30 33 SDL_GL_SwapBuffers(); // Swap the buffers 34 lastFrame = currFrame; 31 35 } 32 36 … … 46 50 return 0; 47 51 } 52 53 printf ("%i, %i\n", wHandler.screen->w, wHandler.screen->h); 48 54 if (argc>=3) 49 55 obj = new Object (argv[1], atof(argv[2])); … … 53 59 obj = new Object(); 54 60 61 M = Vector(wHandler.screen->w/2, wHandler.screen->h/2, 0); 62 rotAxis = Vector (0.0,1.0,0.0); 63 rotAngle = 0; 64 65 matQ[0][0] = matQ[1][1] = matQ[2][2] = matQ[3][3] = 1; 66 rotQ = Quaternion (rotAngle, rotAxis); 67 rotQlast = rotQ; 68 dir = Vector (0.0, 0.0, 1.0); 69 up = Vector (0.0, 1.0, 0.0); 70 71 glEnable(GL_LIGHTING); 72 glEnable(GL_DEPTH_TEST); 73 74 GLfloat whiteLight[] = {1.0, 1.0, 1.0,1.0}; 75 GLfloat light0Position[] = {10.0, 10.0, 10.0, 0.0}; 76 GLfloat light1Position[] = {-10.0, -7.0, -6.0, 0.0}; 55 77 GLfloat lmodelAmbient[] = {.1, .1, .1, 1.0}; 78 79 glEnable(GL_LIGHT0); 80 glLightfv(GL_LIGHT0, GL_POSITION, light0Position); 56 81 glLightfv(GL_LIGHT0, GL_DIFFUSE, whiteLight); 57 82 glLightfv(GL_LIGHT0, GL_SPECULAR, whiteLight); 58 glEnable(GL_LIGHTING); 59 glEnable(GL_LIGHT0); 60 glEnable(GL_DEPTH_TEST); 61 83 84 glEnable(GL_LIGHT1); 85 glLightfv(GL_LIGHT1, GL_POSITION, light1Position); 86 glLightfv(GL_LIGHT1, GL_DIFFUSE, whiteLight); 87 glLightfv(GL_LIGHT1, GL_SPECULAR, whiteLight); 88 89 rotatorP = .0; 90 rotatorV = .0; 91 dist = 5.0; 92 zoomTo = dist; 62 93 // Build the font from a TGA image font.tga in the data directory 63 94 // Hide the mouse cursor 64 SDL_ShowCursor(0); 95 SDL_ShowCursor(2); 96 mouse1Down = false; 65 97 66 98 // This is the main loop for the entire program and it will run until done==TRUE … … 73 105 while ( SDL_PollEvent(&event) ) { 74 106 switch (event.type) { 107 case SDL_MOUSEMOTION: 108 if (verbose >=3) 109 printf("Mouse motion about %d,%d Pixels to (%d,%d).\n", 110 event.motion.xrel, event.motion.yrel, 111 event.motion.x, event.motion.y); 112 // TRACKBALL 113 if (mouse1Down) 114 { 115 int mX = event.button.x; 116 int mY = event.button.y; 117 int wH = wHandler.screen->h; 118 int wW = wHandler.screen->w; 119 Vector tmpV (mX, mY, sqrt ( (float) abs(wH * wH/4 - (wW/2-mX) * (wW/2-mX) - (wH/2-mY) * (wH/2-mY)) )); 120 // printf ("tmpV: %f, %f, %f\n", tmpV.x, tmpV.y, tmpV.z); 121 p2 = tmpV-M; 122 p2.y = -p2.y; 123 rotAxis = p1.cross(p2); 124 // printf ("rotAxis: %f, %f, %f\n", rotAxis.x, rotAxis.y, rotAxis.z); 125 126 // in case that there is no rotation-axis defined 127 if (rotAxis.x != 0 || rotAxis.y != 0 || rotAxis.z != 0) 128 { 129 rotAxis.normalize(); 130 // printf ("rotAxis: %f, %f, %f\n", rotAxis.x, rotAxis.y, rotAxis.z, rotAngle); 131 132 rotAngle = angle_rad (p1, p2); 133 rotQ = Quaternion (rotAngle, rotAxis); 134 rotQ = rotQ * rotQlast; 135 rotQ.matrix (matQ); 136 // dir = rotQ.apply(dir); 137 // dir.normalize(); 138 // printf ("rotAxis: %f, %f, %f, %f\n", dir.x, dir.y, dir.z, rotAngle); 139 } 140 rotQlast = rotQ; 141 p1 = p2; 142 143 } 144 break; 145 case SDL_MOUSEBUTTONDOWN: 146 if (event.button.button == 4) 147 { 148 printf("MouseWheel up\n"); 149 zoomTo *= .5; 150 } 151 else if (event.button.button == 5) 152 { 153 printf("MouseWheel down\n"); 154 zoomTo *= 2.0; 155 } 156 else if (event.button.button == 1) 157 { 158 mouse1Down = true; 159 int mX = event.button.x; 160 int mY = event.button.y; 161 int wH = wHandler.screen->h; 162 int wW = wHandler.screen->w; 163 Vector tmpV (mX, mY, sqrt ( (float) abs(wH * wH/4 - (wW/2-mX) * (wW/2-mX) - (wH/2-mY) * (wH/2-mY)) )); 164 p1 = tmpV-M; 165 p1.y = -p1.y; 166 167 } 168 else 169 { 170 printf("MouseButton %d pressed at (%d,%d).\n", 171 event.button.button, event.button.x, event.button.y); 172 rotatorV = ( (float)wHandler.screen->w/2 -event.button.x) / (float)wHandler.screen->w / 100.0; 173 } 174 175 break; 176 case SDL_MOUSEBUTTONUP: 177 if (event.button.button == 4); 178 else if (event.button.button == 5); 179 else if (event.button.button == 1) 180 mouse1Down =false; 181 else 182 { 183 printf("MouseButton %d released at (%d,%d).\n", 184 event.button.button, event.button.x, event.button.y); 185 } 186 break; 187 75 188 // If a quit event was recieved 76 189 case SDL_QUIT: … … 81 194 break; 82 195 } 196 197 83 198 } 84 199 -
orxonox/branches/osX/importer/object.cc
r2863 r2977 48 48 \param scaling The factor that the object will be scaled with. 49 49 */ 50 51 50 Object::Object(char* fileName, float scaling) 52 51 { … … 90 89 groupCount = 0; 91 90 92 initGroup ( currentGroup);91 initGroup (firstGroup); 93 92 mtlFileName = ""; 94 93 scaleFactor = 1; 95 94 material = new Material(); 96 95 97 glEnableClientState (GL_VERTEX_ARRAY);96 // glEnableClientState (GL_VERTEX_ARRAY); 98 97 // glEnableClientState (GL_NORMAL_ARRAY); 99 98 // glEnableClientState (GL_TEXTURE_COORD_ARRAY); … … 226 225 group->name = ""; 227 226 group->faceMode = -1; 228 group->faceCount = 0;227 group->faceCount = 0; 229 228 if ((group->listNumber = glGenLists(1)) == 0 ) 230 229 { … … 237 236 group->firstVertex = 0; 238 237 group->firstNormal = 0; 239 group->first Normal= 0;238 group->firstVertexTexture = 0; 240 239 } 241 240 else … … 265 264 glEndList(); 266 265 } 266 267 267 /** 268 268 \brief deletes the Arrays of the Group to save space. … … 295 295 } 296 296 objFileName = fileName; 297 char Buffer[ 500];297 char Buffer[10000]; 298 298 while(!OBJ_FILE->eof()) 299 299 { 300 OBJ_FILE->getline(Buffer, 500);300 OBJ_FILE->getline(Buffer, 10000); 301 301 if (verbose >=4) 302 302 printf ("Read input line: %s\n",Buffer); … … 377 377 { 378 378 currentGroup->vertices->finalizeArray(); 379 glVertexPointer(3, GL_FLOAT, 0, currentGroup->vertices->getArray());379 // glVertexPointer(3, GL_FLOAT, 0, currentGroup->vertices->getArray()); 380 380 currentGroup->normals->finalizeArray(); 381 glNormalPointer(GL_FLOAT, 0, currentGroup->normals->getArray());381 // glNormalPointer(GL_FLOAT, 0, currentGroup->normals->getArray()); 382 382 currentGroup->vTexture->finalizeArray(); 383 383 } … … 385 385 readingVertices = false; 386 386 currentGroup->faceCount++; 387 char subbuffer1[20]; 388 char subbuffer2[20]; 389 char subbuffer3[20]; 390 char subbuffer4[20] =""; 391 sscanf (faceString, "%s %s %s %s", subbuffer1, subbuffer2, subbuffer3, subbuffer4); 392 if (!strcmp(subbuffer4, "")) 387 388 int elemCount = 0; 389 390 FaceElement* firstElem = new FaceElement; 391 FaceElement* tmpElem = firstElem; 392 393 394 while(strcmp (faceString, "\0")) 395 { 396 if (elemCount>0) 397 tmpElem = tmpElem->next = new FaceElement; 398 tmpElem->next = NULL; 399 400 401 sscanf (faceString, "%s", tmpElem->value); 402 faceString += strlen(tmpElem->value); 403 if (strcmp (faceString, "\0")) 404 faceString++; 405 elemCount++; 406 407 408 } 409 410 411 if (elemCount == 3) 393 412 { 394 413 if (currentGroup->faceMode != 3) … … 401 420 currentGroup->faceMode = 3; 402 421 if (verbose >=3) 403 printf ("found triag: %s, %s, %s\n", subbuffer1, subbuffer2, subbuffer3); 404 addGLElement(subbuffer1); 405 addGLElement(subbuffer2); 406 addGLElement(subbuffer3); 407 return true; 408 } 409 else 422 printf ("found triag.\n"); 423 } 424 425 else if (elemCount == 4) 410 426 { 411 427 if (currentGroup->faceMode != 4) … … 417 433 currentGroup->faceMode = 4; 418 434 if (verbose >=3 ) 419 printf ("found quad: %s, %s, %s, %s\n", subbuffer1, subbuffer2, subbuffer3, subbuffer4); 420 addGLElement(subbuffer1); 421 addGLElement(subbuffer2); 422 addGLElement(subbuffer3); 423 addGLElement(subbuffer4); 424 return true; 425 } 435 printf ("found quad.\n"); 436 } 437 438 else if (elemCount > 4) 439 { 440 if (currentGroup->faceMode != -1) 441 glEnd(); 442 glBegin(GL_POLYGON); 443 if (verbose >=3) 444 printf ("Polygon with %i faces found.", elemCount); 445 currentGroup->faceMode = elemCount; 446 } 447 448 tmpElem = firstElem; 449 FaceElement* delElem; 450 while (tmpElem != NULL) 451 { 452 // printf ("%s\n", tmpElem->value); 453 addGLElement(tmpElem->value); 454 delElem = tmpElem; 455 tmpElem = tmpElem->next; 456 delete delElem; 457 } 458 426 459 } 427 460 … … 442 475 443 476 char* texture; 444 texture = strstr (vertex, "/"); 445 texture[0] = '\0'; 446 texture ++; 447 if (verbose>=3) 448 printf ("includeing texture #%i, and mapping it to group texture #%i, textureArray has %i entries.\n", atoi(texture), (atoi(texture)-1 - currentGroup->firstVertexTexture)*3, currentGroup->vTexture->getCount()); 449 glTexCoord2fv(currentGroup->vTexture->getArray()+(atoi(texture)-1 - currentGroup->firstVertexTexture)*2); 450 451 char* normal; 452 if ((normal = strstr (texture, "/")) !=NULL) 453 { 454 normal[0] = '\0'; 455 normal ++; 456 //glArrayElement(atoi(vertex)-1); 457 glNormal3fv(currentGroup->normals->getArray() +(atoi(normal)-1 - currentGroup->firstNormal)*3); 477 if ((texture = strstr (vertex, "/")) != NULL) 478 { 479 texture[0] = '\0'; 480 texture ++; 481 if (verbose>=3) 482 printf ("includeing texture #%i, and mapping it to group texture #%i, textureArray has %i entries.\n", atoi(texture), (atoi(texture)-1 - currentGroup->firstVertexTexture)*2, currentGroup->vTexture->getCount()); 483 glTexCoord2fv(currentGroup->vTexture->getArray()+(atoi(texture)-1 - currentGroup->firstVertexTexture)*2); 484 485 char* normal; 486 if ((normal = strstr (texture, "/")) !=NULL) 487 { 488 normal[0] = '\0'; 489 normal ++; 490 //glArrayElement(atoi(vertex)-1); 491 glNormal3fv(currentGroup->normals->getArray() +(atoi(normal)-1 - currentGroup->firstNormal)*3); 492 } 458 493 } 459 494 if (verbose>=3) … … 603 638 \param matString the Material that will be set. 604 639 */ 605 606 640 bool Object::readUseMtl (char* matString) 607 641 { … … 635 669 readVertex ("-0.500000 -0.500000 -0.500000"); 636 670 readVertex ("0.500000 -0.500000 -0.500000"); 671 637 672 readVertexTexture ("0.000000 0.000000"); 638 673 readVertexTexture ("1.000000 0.000000"); -
orxonox/branches/osX/importer/object.h
r2863 r2977 18 18 extern int verbose; //!< fill be removed and added again as a verbose-class 19 19 20 21 struct FaceElement 22 { 23 char value[20]; 24 FaceElement* next; 25 }; 20 26 21 27 //! Class that handles 3D-Objects. it can also read them in and display them. -
orxonox/branches/osX/importer/windowHandler.cc
r2759 r2977 3 3 #include "windowHandler.h" 4 4 #include <stdio.h> 5 void WindowHandler::ReSizeGLScene(GLsizei width, GLsizei height) 5 void WindowHandler::ReSizeGLScene(GLsizei width, GLsizei height) // Resize And Initialize The GL Window 6 6 { 7 if (height==0) 7 if (height==0) // Prevent A Divide By Zero By 8 8 { 9 height=1; 9 height=1;// Making Height Equal One 10 10 } 11 11 12 glViewport(0,0,width,height); 12 glViewport(0,0,width,height); // Reset The Current Viewport 13 13 14 15 glMatrixMode(GL_PROJECTION); 14 15 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix 16 16 glLoadIdentity(); 17 17 … … 21 21 gluLookAt (0,0,15, 0,0,0, 0,1,0); 22 22 23 glMatrixMode(GL_MODELVIEW); 24 glLoadIdentity(); 23 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix 24 glLoadIdentity(); // Reset The Modelview Matrix 25 25 26 26 } … … 29 29 int WindowHandler::InitGL(GLvoid) // All Setup For OpenGL Goes Here 30 30 { 31 glEnable(GL_TEXTURE_2D); 32 glShadeModel(GL_SMOOTH); 33 glClearColor(0.00f, 0.00f, 0.00f, 0.0f); 34 glClearDepth(1.0f); 35 glEnable(GL_DEPTH_TEST); 36 glDepthFunc(GL_LEQUAL); 37 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); 31 glEnable(GL_TEXTURE_2D); // Enable Texture Mapping 32 glShadeModel(GL_SMOOTH); // Enable Smooth Shading 33 glClearColor(0.00f, 0.00f, 0.00f, 0.0f); // Black Background 34 glClearDepth(1.0f); // Depth Buffer Setup 35 glEnable(GL_DEPTH_TEST); // Enables Depth Testing 36 glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do 37 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations 38 38 39 39 return TRUE; … … 41 41 42 42 43 GLvoid WindowHandler::KillGLWindow(GLvoid) 43 GLvoid WindowHandler::KillGLWindow(GLvoid) // Properly Kill The Window 44 44 { 45 45 SDL_Quit(); … … 63 63 } 64 64 SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, 1 ); 65 if ( SDL_SetVideoMode(width, height, 0, flags) == NULL ) {65 if ( (screen = SDL_SetVideoMode(width, height, 0, flags)) == NULL ) { 66 66 return FALSE; 67 67 } 68 68 SDL_GL_GetAttribute( SDL_GL_STENCIL_SIZE, &size); 69 69 70 ReSizeGLScene(width, height); 70 ReSizeGLScene(width, height); // Set Up Our Perspective GL Screen 71 71 72 if (!InitGL()) 72 if (!InitGL()) // Initialize Our Newly Created GL Window 73 73 { 74 KillGLWindow();// Reset The Display75 return FALSE; // Return FALSE74 KillGLWindow(); // Reset The Display 75 return FALSE; 76 76 } 77 77 78 return TRUE; // Success78 return TRUE; 79 79 } 80 80 -
orxonox/branches/osX/importer/windowHandler.h
r2804 r2977 14 14 #include <math.h> 15 15 16 #ifdef __WIN32__ 17 #include <windows.h> 18 #endif /* __WIN32__ */ 16 19 17 20 #define TRUE 1 … … 26 29 GLvoid KillGLWindow(GLvoid); 27 30 BOOL CreateGLWindow(char* title, int width, int height, int bits, BOOL fullscreenflag); 31 SDL_Surface* screen; 28 32 private: 29 33 int InitGL(GLvoid);
Note: See TracChangeset
for help on using the changeset viewer.