- Timestamp:
- Nov 10, 2004, 3:54:08 AM (20 years ago)
- Location:
- orxonox/branches/importer/importer
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/importer/importer/material.cc
r2776 r2778 1 1 #include "material.h" 2 3 Material* Material::firstMat = NULL;4 Material* Material::currentMat = NULL;5 2 6 3 Material::Material() 7 4 { 8 5 init(); 6 7 setName (""); 9 8 } 10 9 … … 16 15 } 17 16 17 Material* Material::addMaterial(char* mtlName) 18 { 19 Material* newMat = new Material(mtlName); 20 Material* tmpMat = this; 21 while (tmpMat->nextMat != NULL) 22 { 23 tmpMat = tmpMat->nextMat; 24 } 25 tmpMat->nextMat = newMat; 26 return newMat; 27 28 } 29 18 30 void Material::init(void) 19 31 { 20 if (firstMat == NULL)21 firstMat = this;22 else23 currentMat->nextMat = this;24 currentMat = this;25 32 nextMat = NULL; 33 34 setIllum(1); 35 setDiffuse(0,0,0); 36 setAmbient(0,0,0); 37 setSpecular(0,0,0); 38 setTransparency(0.0); 26 39 } 27 40 … … 29 42 void Material::setName (char* mtlName) 30 43 { 31 name = mtlName;32 // printf ("adding new Material: %s, %p\n", firstMat->name, firstMat);44 strcpy(name, mtlName); 45 // printf ("adding new Material: %s, %p\n", this->getName(), this); 33 46 47 } 48 char* Material::getName (void) 49 { 50 return name; 34 51 } 35 52 … … 50 67 diffuse[1] = g; 51 68 diffuse[2] = b; 52 printf ("setting Diffuse Color to r=%f g=%f b=%f\n", r, g, b);69 // printf ("setting Diffuse Color to r=%f g=%f b=%f\n", r, g, b); 53 70 } 54 71 void Material::setDiffuse (char* rgb) … … 64 81 ambient[1] = g; 65 82 ambient[2] = b; 66 printf ("setting Ambient Color to r=%f g=%f b=%f\n", r, g, b);83 // printf ("setting Ambient Color to r=%f g=%f b=%f\n", r, g, b); 67 84 } 68 85 void Material::setAmbient (char* rgb) … … 78 95 specular[1] = g; 79 96 specular[2] = b; 80 printf ("setting Specular Color to r=%f g=%f b=%f\n", r, g, b);97 //printf ("setting Specular Color to r=%f g=%f b=%f\n", r, g, b); 81 98 } 82 99 void Material::setSpecular (char* rgb) … … 98 115 setTransparency (atof(tr)); 99 116 } 117 118 119 Material* Material::search (char* mtlName) 120 { 121 Material* searcher = this; 122 while (searcher != NULL) 123 { 124 if (!strcmp (searcher->getName(), mtlName)) 125 return searcher; 126 searcher = searcher->nextMat; 127 } 128 return NULL; 129 } 130 131 bool Material::select (void) 132 { 133 glColor3f (diffuse[0], diffuse[1], diffuse[2]); 134 } -
orxonox/branches/importer/importer/material.h
r2776 r2778 11 11 Material (); 12 12 Material (char* mtlName); 13 Material* addMaterial(char* mtlName); 14 13 15 void init(void); 14 16 ~Material (); 15 17 18 16 19 void setName (char* mtlName); 20 char* getName (void); 17 21 void setIllum (int illum); 18 22 void setIllum (char* illum); … … 26 30 void setTransparency (char* trans); 27 31 32 Material* search (char* mtlName); 28 33 29 34 bool select (void); 30 35 36 Material* nextMat; 37 31 38 private: 32 char * name;39 char name [50]; 33 40 int illumModel; 34 41 float diffuse [3]; … … 37 44 float transparency; 38 45 39 Material* nextMat;40 static Material* firstMat;41 static Material* currentMat;42 46 }; 43 47 #endif -
orxonox/branches/importer/importer/object.cc
r2776 r2778 191 191 vertices = new Array(); 192 192 faces = new Array(); 193 193 material = new Material(); 194 Material* tmpMat = material; 194 195 while(!MTL_FILE->eof()) 195 196 { … … 201 202 if (!strncmp(Buffer, "newmtl ", 2)) 202 203 { 203 material = new Material(Buffer+7); 204 tmpMat = tmpMat->addMaterial(Buffer+7); 205 printf ("%s, %p\n", tmpMat->getName(), tmpMat); 204 206 } 205 207 // setting a illumMode 206 208 else if (!strncmp(Buffer, "illum", 5)) 207 209 { 208 material->setIllum(Buffer+6); 210 tmpMat->setIllum(Buffer+6); 211 209 212 } 210 213 // setting Diffuse Color 211 214 else if (!strncmp(Buffer, "Kd", 2)) 212 215 { 213 material->setDiffuse(Buffer+3);216 tmpMat->setDiffuse(Buffer+3); 214 217 } 215 218 // setting Ambient Color 216 219 else if (!strncmp(Buffer, "Ka", 2)) 217 220 { 218 material->setAmbient(Buffer+3);221 tmpMat->setAmbient(Buffer+3); 219 222 } 220 223 // setting Specular Color 221 224 else if (!strncmp(Buffer, "Ks", 2)) 222 225 { 223 material->setSpecular(Buffer+3); 224 } 225 226 227 226 tmpMat->setSpecular(Buffer+3); 227 } 228 228 } 229 229 return true;
Note: See TracChangeset
for help on using the changeset viewer.