- Timestamp:
- Nov 11, 2004, 2:41:03 PM (20 years ago)
- Location:
- orxonox/branches/importer/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/importer/src/array.cc
r2795 r2810 3 3 Array::Array () 4 4 { 5 createArray (2000); 6 } 7 Array::Array (unsigned int arraySize) 8 { 9 createArray (arraySize); 5 createArray (); 10 6 } 11 7 12 void Array::createArray ( unsigned int newArraySize)8 void Array::createArray () 13 9 { 14 array = new GLfloat [newArraySize]; 15 entryCount = -1; //0 means one entry 16 arraySize = newArraySize; 10 if (verbose >= 2) 11 printf ("crating new Array\n"); 12 firstEntry = new Entry; 13 firstEntry->next =NULL; 14 currentEntry=firstEntry; 15 finalized = false; 16 entryCount = 0; //0 means one entry 17 17 return; 18 18 } 19 19 20 void Array::resizeArray (unsigned int newSize)21 {22 GLfloat* newArray = new GLfloat [newSize];23 24 for (int i=0; i<=entryCount; i++)25 newArray[i] = array[i];26 27 delete [] array;28 array = newArray;29 arraySize = newSize;30 31 return;32 }33 34 20 void Array::finalizeArray (void) 35 21 { 36 resizeArray (entryCount+1); 22 if (verbose >= 3) 23 printf ("Finalizing array.\n"); 24 if ((array = (GLfloat*)malloc( entryCount* sizeof(GLfloat))) == NULL) 25 printf ("could not allocate %i data Blocks\n", entryCount); 26 Entry* walker = firstEntry; 27 for (int i=0; i<entryCount; i++) 28 { 29 array[i] = walker->value; 30 walker = walker->next; 31 } 32 finalized = true; 37 33 return; 38 34 } … … 41 37 void Array::addEntry (GLfloat entry) 42 38 { 43 entryCount++; 44 45 if (entryCount > arraySize) 46 resizeArray(arraySize+2000); 47 48 array[entryCount] = entry; 49 39 if (!finalized) 40 { 41 if (verbose >= 3) 42 printf ("adding new Entry to Array: %f\n", entry); 43 44 entryCount++; 45 currentEntry->value = entry; 46 currentEntry->next = new Entry; 47 currentEntry = currentEntry->next; 48 currentEntry->next = NULL; 49 } 50 else 51 if (verbose >= 1) 52 printf ("adding failed, because list has been finalized\n"); 50 53 } 51 54 … … 72 75 void Array::debug () 73 76 { 74 printf (" arraySize=%i, entryCount=%i, address=%p\n", arraySize, entryCount, array);77 printf ("entryCount=%i, address=%p\n", entryCount, array); 75 78 } -
orxonox/branches/importer/src/array.h
r2795 r2810 1 1 #ifndef _ARRAY_H 2 2 #define _ARRAY_H 3 4 extern int verbose; 3 5 4 6 #include <GL/gl.h> … … 9 11 public: 10 12 Array (); 11 Array (unsigned int arraySize);12 13 13 void createArray (unsigned int newArraySize); 14 void resizeArray (unsigned int newSize); 14 void createArray (); 15 15 void finalizeArray (void); 16 16 void addEntry (GLfloat entry); … … 21 21 void debug(void); 22 22 private: 23 struct Entry 24 { 25 GLfloat value; 26 Entry* next; 27 }; 28 23 29 GLfloat* array; 24 unsigned int arraySize; 25 unsigned int entryCount; 26 30 int entryCount; 31 bool finalized; 32 Entry* firstEntry; 33 Entry* currentEntry; 34 35 27 36 }; 28 37 -
orxonox/branches/importer/src/material.cc
r2795 r2810 17 17 Material* Material::addMaterial(char* mtlName) 18 18 { 19 if (verbose >=2) 20 printf ("adding Material %s\n", mtlName); 19 21 Material* newMat = new Material(mtlName); 20 22 Material* tmpMat = this; … … 30 32 void Material::init(void) 31 33 { 34 if (verbose >= 3) 35 printf ("initializing new Material\n"); 32 36 nextMat = NULL; 33 37 … … 42 46 void Material::setName (char* mtlName) 43 47 { 48 if (verbose >= 3) 49 printf("setting Material Name to %s", mtlName); 44 50 strcpy(name, mtlName); 45 51 // printf ("adding new Material: %s, %p\n", this->getName(), this); … … 54 60 void Material::setIllum (int illum) 55 61 { 62 if (verbose >= 3) 63 printf("setting illumModel of Material %s to %i", name, illum); 56 64 illumModel = illum; 57 65 // printf ("setting illumModel to: %i\n", illumModel); … … 64 72 void Material::setDiffuse (float r, float g, float b) 65 73 { 74 if (verbose >= 3) 75 printf ("setting Diffuse Color of Material %s to r=%f g=%f b=%f\n", name, r, g, b); 66 76 diffuse[0] = r; 67 77 diffuse[1] = g; … … 69 79 diffuse[3] = 1.0; 70 80 71 // printf ("setting Diffuse Color to r=%f g=%f b=%f\n", r, g, b);72 81 } 73 82 void Material::setDiffuse (char* rgb) … … 80 89 void Material::setAmbient (float r, float g, float b) 81 90 { 91 if (verbose >=3) 92 printf ("setting Ambient Color of Material %s to r=%f g=%f b=%f\n", name, r, g, b); 82 93 ambient[0] = r; 83 94 ambient[1] = g; 84 95 ambient[2] = b; 85 96 ambient[3] = 1.0; 86 // printf ("setting Ambient Color to r=%f g=%f b=%f\n", r, g, b);87 97 } 88 98 void Material::setAmbient (char* rgb) … … 95 105 void Material::setSpecular (float r, float g, float b) 96 106 { 107 if (verbose >= 3) 108 printf ("setting Specular Color of Material %s to r=%f g=%f b=%f\n", name, r, g, b); 97 109 specular[0] = r; 98 110 specular[1] = g; 99 111 specular[2] = b; 100 112 specular[3] = 1.0; 101 //printf ("setting Specular Color to r=%f g=%f b=%f\n", r, g, b); 102 } 113 } 103 114 void Material::setSpecular (char* rgb) 104 115 { … … 111 122 void Material::setTransparency (float trans) 112 123 { 124 if (verbose >= 3) 125 printf ("setting Transparency of Material %s to %f\n", name, trans); 113 126 transparency = trans; 114 127 } … … 123 136 Material* Material::search (char* mtlName) 124 137 { 138 if (verbose >=3) 139 printf ("Searching for material %s", mtlName); 125 140 Material* searcher = this; 126 141 while (searcher != NULL) 127 142 { 143 if (verbose >= 3) 144 printf ("."); 128 145 if (!strcmp (searcher->getName(), mtlName)) 129 return searcher; 146 { 147 if (verbose >= 3) 148 printf ("found.\n"); 149 return searcher; 150 } 130 151 searcher = searcher->nextMat; 131 152 } -
orxonox/branches/importer/src/material.h
r2795 r2810 1 1 #ifndef _MATERIAL_H 2 2 #define _MATERIAL_H 3 4 extern int verbose; 5 3 6 #include <GL/gl.h> 4 7 #include <GL/glu.h> -
orxonox/branches/importer/src/object.cc
r2795 r2810 1 1 #include "object.h" 2 2 3 int verbose = 1; 3 4 Object::Object () 4 5 { … … 22 23 bool Object::importFile (char* fileName) 23 24 { 24 objFile = fileName; 25 this->readFromObjFile (objFile); 25 if (verbose >=3) 26 printf("preparing to read in file: %s\n", fileName); 27 objFileName = fileName; 28 this->readFromObjFile (objFileName); 26 29 return true; 27 30 } … … 29 32 bool Object::initialize (void) 30 33 { 34 if (verbose >=3) 35 printf("new 3D-Object is being created\n"); 31 36 faceMode = -1; 32 37 if ( (listNumber = glGenLists(1)) == 0 ) … … 45 50 bool Object::finalize(void) 46 51 { 52 if (verbose >=3) 53 printf("finalizing the 3D-Object\n"); 47 54 glEndList(); 48 55 return true; … … 51 58 void Object::draw (void) 52 59 { 60 if (verbose >=3) 61 printf("drawing the 3D-Object\n"); 53 62 glCallList (listNumber); 54 63 } … … 60 69 if (!OBJ_FILE->is_open()) 61 70 { 62 printf ("unable to open file: %s\n", fileName); 71 if (verbose >=1) 72 printf ("unable to open .OBJ file: %s\n", fileName); 63 73 return false; 64 74 } 65 75 objFileName = fileName; 66 76 char Buffer[500]; 67 77 vertices = new Array(); … … 70 80 { 71 81 OBJ_FILE->getline(Buffer, 500); 72 // printf("%s\n", Buffer); 82 if (verbose >=4) 83 printf ("Read input line: %s\n",Buffer); 73 84 74 85 … … 125 136 char subbuffer3[20]; 126 137 sscanf (vertexString, "%s %s %s", subbuffer1, subbuffer2, subbuffer3); 138 if (verbose >= 3) 139 printf ("reading in a vertex: %s %s %s\n", subbuffer1, subbuffer2, subbuffer3); 127 140 vertices->addEntry(atof(subbuffer1), atof(subbuffer2), atof(subbuffer3)); 128 141 return true; … … 145 158 char subbuffer4[20] =""; 146 159 sscanf (faceString, "%s %s %s %s", subbuffer1, subbuffer2, subbuffer3, subbuffer4); 147 // printf("%s, %s, %s\n", subbuffer1,subbuffer2,subbuffer3);148 160 if (!strcmp(subbuffer4, "")) 149 161 { … … 156 168 157 169 faceMode = 3; 158 //printf ("triag: %s, %s, %s\n", subbuffer1, subbuffer2, subbuffer3); 170 if (verbose >=3) 171 printf ("found triag: %s, %s, %s\n", subbuffer1, subbuffer2, subbuffer3); 159 172 addGLElement(subbuffer1); 160 173 addGLElement(subbuffer2); … … 171 184 } 172 185 faceMode = 4; 173 // printf ("quad: %s, %s, %s, %s\n", subbuffer1, subbuffer2, subbuffer3, subbuffer4); 186 if (verbose >=3 ) 187 printf ("found quad: %s, %s, %s, %s\n", subbuffer1, subbuffer2, subbuffer3, subbuffer4); 174 188 addGLElement(subbuffer1); 175 189 addGLElement(subbuffer2); … … 191 205 normal[0] = '\0'; 192 206 normal ++; 193 207 if (verbose >= 4) 208 printf ("importing grafical Element.... including to openGL\n"); 194 209 glNormal3fv(normals->getArray() +(atoi(normal)-1)*3); 195 210 glArrayElement(atoi(vertex)-1); // glVertex3fv(vertices->getArray() +(atoi(vertex)-1)*3); … … 204 219 char subbuffer3[20]; 205 220 sscanf (normalString, "%s %s %s", subbuffer1, subbuffer2, subbuffer3); 206 // printf("%s, %s, %s\n", subbuffer1,subbuffer2,subbuffer3); 221 if (verbose >=3 ) 222 printf("found vertex-Normal %s, %s, %s\n", subbuffer1,subbuffer2,subbuffer3); 207 223 normals->addEntry(atof(subbuffer1), atof(subbuffer2), atof(subbuffer3)); 208 224 return true; … … 214 230 if (!MTL_FILE->is_open()) 215 231 { 216 printf ("unable to open file: %s\n", mtlFile); 232 if (verbose >= 1) 233 printf ("unable to open file: %s\n", mtlFile); 217 234 return false; 218 235 } 219 236 mtlFileName = mtlFile; 237 if (verbose >=2) 238 printf ("Opening mtlFile: %s\n", mtlFileName); 220 239 char Buffer[500]; 221 240 vertices = new Array(); … … 225 244 { 226 245 MTL_FILE->getline(Buffer, 500); 227 // printf("%s\n", Buffer); 246 if (verbose >= 4) 247 printf("found line in mtlFile: %s\n", Buffer); 228 248 229 249 … … 264 284 glEnd(); 265 285 faceMode = 0; 266 //printf ("%s\n", matString);267 // glColor3f((float)rand()/2000000000.0,(float)rand()/2000000000.0,(float)rand()/2000000000.0);286 if (verbose >= 2) 287 printf ("using material %s for coming Faces.\n", matString); 268 288 material->search(matString)->select(); 269 289 } -
orxonox/branches/importer/src/object.h
r2795 r2810 30 30 Array* colors; 31 31 Array* normals; 32 char* objFile; 32 char* objFileName; 33 char* mtlFileName; 33 34 int faceMode; 34 35 bool readVertices;
Note: See TracChangeset
for help on using the changeset viewer.