Changeset 7221 in orxonox.OLD for trunk/src/lib/graphics/importer
- Timestamp:
- Mar 15, 2006, 3:10:45 PM (19 years ago)
- Location:
- trunk/src/lib/graphics/importer
- Files:
-
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/importer/height_map.cc
r7193 r7221 333 333 } 334 334 335 HeightMap::HeightMap(const char* height_map_name = NULL) : VertexArrayModel() 335 HeightMap::HeightMap(const std::string& height_map_name = "") 336 : VertexArrayModel() 336 337 { 337 338 this->setClassID(CL_HEIGHT_MAP, "HeightMap"); 338 heightMap = IMG_Load(height_map_name );339 heightMap = IMG_Load(height_map_name.c_str()); 339 340 if(heightMap!=NULL) { 340 341 341 PRINTF(0)("loading Image %s\n", height_map_name);342 PRINTF(0)("loading Image %s\n", height_map_name.c_str()); 342 343 PRINTF(0)("width : %i\n", heightMap->w); 343 344 PRINTF(0)("height : %i\n", heightMap->h); … … 350 351 } 351 352 352 else PRINTF(4)("oops! couldn't load %s for some reason.\n", height_map_name);353 else PRINTF(4)("oops! couldn't load %s for some reason.\n", height_map_name.c_str()); 353 354 354 355 … … 361 362 } 362 363 363 HeightMap::HeightMap(const char* height_map_name = NULL, const char* colour_map_name = NULL) : VertexArrayModel() 364 HeightMap::HeightMap(const std::string& height_map_name = NULL, const std::string& colour_map_name = NULL) 365 : VertexArrayModel() 364 366 { 365 367 this->setClassID(CL_HEIGHT_MAP, "HeightMap"); 366 368 367 heightMap = IMG_Load(height_map_name );369 heightMap = IMG_Load(height_map_name.c_str()); 368 370 if(heightMap!=NULL) { 369 371 370 PRINTF(0)("loading Image %s\n", height_map_name);372 PRINTF(0)("loading Image %s\n", height_map_name.c_str()); 371 373 PRINTF(0)("width : %i\n", heightMap->w); 372 374 PRINTF(0)("height : %i\n", heightMap->h); … … 379 381 } 380 382 381 else PRINTF(4)("oops! couldn't load %s for some reason.\n", height_map_name);383 else PRINTF(4)("oops! couldn't load %s for some reason.\n", height_map_name.c_str()); 382 384 383 385 … … 385 387 386 388 colourMap=NULL; 387 if(colour_map_name != NULL)389 if(colour_map_name != "") 388 390 { 389 colourMap = IMG_Load(colour_map_name);391 colourMap = IMG_Load(colour_map_name.c_str()); 390 392 } 391 393 392 394 if(colourMap != NULL) 393 395 { 394 PRINTF(0)("loading Image %s\n", colour_map_name);396 PRINTF(0)("loading Image %s\n", colour_map_name.c_str()); 395 397 PRINTF(0)("width : %i\n", colourMap->w); 396 398 PRINTF(0)("height : %i\n", colourMap->h); -
trunk/src/lib/graphics/importer/height_map.h
r6981 r7221 59 59 void load(); 60 60 void load(int Mode); 61 void load(const char*, int Mode);61 void load(const std::string&, int Mode); 62 62 void scale( Vector V); 63 63 void setAbsCoor(Vector V); … … 65 65 float getNormal(float x, float y); 66 66 HeightMap(); 67 HeightMap(const char*);68 HeightMap(const char*, const char*);67 HeightMap(const std::string&); 68 HeightMap(const std::string&, const std::string&); 69 69 virtual ~HeightMap(); 70 70 -
trunk/src/lib/graphics/importer/material.cc
r7193 r7221 34 34 * @param mtlName Name of the Material to be added to the Material List 35 35 */ 36 Material::Material (const char*mtlName)36 Material::Material (const std::string& mtlName) 37 37 { 38 38 this->setClassID(CL_MATERIAL, "Material"); … … 278 278 * @param pathName The Path to add. 279 279 */ 280 void Material::addTexturePath(const char*pathName)280 void Material::addTexturePath(const std::string& pathName) 281 281 { 282 282 ResourceManager::getInstance()->addImageDir(pathName); … … 289 289 * @param dMap the Name of the Image to Use 290 290 */ 291 void Material::setDiffuseMap(const char*dMap, GLenum target)291 void Material::setDiffuseMap(const std::string& dMap, GLenum target) 292 292 { 293 293 PRINTF(5)("setting Diffuse Map %s\n", dMap); … … 297 297 //! @todo check if RESOURCE MANAGER is availiable 298 298 //! @todo Textures from .mtl-file need special care. 299 if ( dMap != NULL)299 if (!dMap.empty()) 300 300 this->diffuseTexture = (Texture*)ResourceManager::getInstance()->load(dMap, IMAGE, RP_GAME, (int)target); 301 301 else … … 308 308 @todo implement this 309 309 */ 310 void Material::setAmbientMap(const char*aMap, GLenum target)310 void Material::setAmbientMap(const std::string& aMap, GLenum target) 311 311 { 312 312 SDL_Surface* ambientMap; … … 319 319 @todo implement this 320 320 */ 321 void Material::setSpecularMap(const char*sMap, GLenum target)321 void Material::setSpecularMap(const std::string& sMap, GLenum target) 322 322 { 323 323 SDL_Surface* specularMap; … … 330 330 @todo implemet this 331 331 */ 332 void Material::setBump(const char*bump)333 { 334 335 } 332 void Material::setBump(const std::string& bump) 333 { 334 335 } -
trunk/src/lib/graphics/importer/material.h
r7057 r7221 26 26 { 27 27 public: 28 Material (const char* mtlName = NULL);28 Material (const std::string& mtlName = ""); 29 29 virtual ~Material (); 30 30 … … 49 49 50 50 // MAPPING // 51 void setDiffuseMap(const char*dMap, GLenum target = GL_TEXTURE_2D);52 void setAmbientMap(const char*aMap, GLenum target = GL_TEXTURE_2D);53 void setSpecularMap(const char*sMap, GLenum target = GL_TEXTURE_2D);54 void setBump(const char*bump);51 void setDiffuseMap(const std::string& dMap, GLenum target = GL_TEXTURE_2D); 52 void setAmbientMap(const std::string& aMap, GLenum target = GL_TEXTURE_2D); 53 void setSpecularMap(const std::string& sMap, GLenum target = GL_TEXTURE_2D); 54 void setBump(const std::string& bump); 55 55 GLuint getDiffuseTexture() const { return (this->diffuseTexture)? this->diffuseTexture->getTexture() : 0; }; 56 56 57 static void addTexturePath(const char*pathName);57 static void addTexturePath(const std::string& pathName); 58 58 59 59 private: -
trunk/src/lib/graphics/importer/md2Model.cc
r7193 r7221 75 75 \brief simple constructor initializing all variables 76 76 */ 77 MD2Model::MD2Model(const char* modelFileName, const char*skinFileName, float scale)77 MD2Model::MD2Model(const std::string& modelFileName, const std::string& skinFileName, float scale) 78 78 { 79 79 this->setClassID(CL_MD2_MODEL, "MD2Model"); 80 80 /* this creates the data container via ressource manager */ 81 this->data = (MD2Data*)ResourceManager::getInstance()->load(modelFileName, MD2, RP_GAME, skinFileName, scale); 81 if (!modelFileName.empty()) 82 this->data = (MD2Data*)ResourceManager::getInstance()->load(modelFileName, MD2, RP_GAME, skinFileName, scale); 82 83 if( unlikely(this->data == NULL)) 83 84 PRINTF(0)("The model was not found, MD2Model Loader finished abnormaly. Update the data-repos\n"); … … 352 353 { 353 354 PRINT(0)("\n==========================| MD2Model::debug() |===\n"); 354 PRINT(0)("= Model FileName:\t%s\n", this->data->fileName );355 PRINT(0)("= Skin FileName:\t%s\n", this->data->skinFileName );355 PRINT(0)("= Model FileName:\t%s\n", this->data->fileName.c_str()); 356 PRINT(0)("= Skin FileName:\t%s\n", this->data->skinFileName.c_str()); 356 357 PRINT(0)("= Size in Memory:\t%i Bytes\n", this->data->header->frameSize * this->data->header->numFrames + 64); // 64bytes is the header size 357 358 PRINT(0)("= Number of Vertices:\t%i\n", this->data->header->numVertices); … … 370 371 \brief simple constructor 371 372 */ 372 MD2Data::MD2Data(const char* modelFileName, const char*skinFileName, float scale)373 MD2Data::MD2Data(const std::string& modelFileName, const std::string& skinFileName, float scale) 373 374 { 374 375 scale *= 0.1f; … … 387 388 this->scaleFactor = scale; 388 389 389 this->fileName = NULL;390 this->skinFileName = NULL;390 this->fileName = ""; 391 this->skinFileName = ""; 391 392 this->loadModel(modelFileName); 392 393 this->loadSkin(skinFileName); … … 401 402 MD2Data::~MD2Data() 402 403 { 403 delete [] this->fileName;404 delete [] this->skinFileName;405 404 delete this->header; 406 405 … … 419 418 \return true if success 420 419 */ 421 bool MD2Data::loadModel(const char*fileName)420 bool MD2Data::loadModel(const std::string& fileName) 422 421 { 423 422 FILE *pFile; //file stream … … 428 427 429 428 //! @todo this chek should include deleting a loaded model (eventually) 430 if (fileName == NULL)429 if (fileName.empty()) 431 430 return false; 432 431 433 pFile = fopen(fileName , "rb");432 pFile = fopen(fileName.c_str(), "rb"); 434 433 if( unlikely(!pFile)) 435 434 { … … 442 441 if( unlikely(this->header->version != MD2_VERSION) && unlikely(this->header->ident != MD2_IDENT)) 443 442 { 444 PRINTF(1)("Couldn't load file %s: invalid file format: stop loading\n", fileName );443 PRINTF(1)("Couldn't load file %s: invalid file format: stop loading\n", fileName.c_str()); 445 444 return false; 446 445 } 447 446 448 this->fileName = new char[strlen(fileName)+1]; 449 strcpy(this->fileName, fileName); 447 this->fileName =fileName; 450 448 /* got the data: map it to locals */ 451 449 this->numFrames = this->header->numFrames; … … 507 505 \return true if success 508 506 */ 509 bool MD2Data::loadSkin(const char*fileName)510 { 511 if( fileName == NULL)512 { 513 this->skinFileName = NULL;507 bool MD2Data::loadSkin(const std::string& fileName) 508 { 509 if( fileName.empty()) 510 { 511 this->skinFileName = ""; 514 512 return false; 515 513 } 516 514 517 this->skinFileName = new char[strlen(fileName)+1]; 518 strcpy(this->skinFileName, fileName); 515 this->skinFileName = fileName; 519 516 520 517 this->material.setName("md2ModelMaterial"); -
trunk/src/lib/graphics/importer/md2Model.h
r7123 r7221 189 189 { 190 190 public: 191 MD2Data(const char* modelFileName, const char*skinFileName, float scale = 1.0f);191 MD2Data(const std::string& modelFileName, const std::string& skinFileName, float scale = 1.0f); 192 192 virtual ~MD2Data(); 193 193 194 194 private: 195 bool loadModel(const char*fileName);196 bool loadSkin(const char* fileName = NULL);195 bool loadModel(const std::string& fileName); 196 bool loadSkin(const std::string& fileName = ""); 197 197 198 198 public: … … 202 202 int numTexCoor; //!< number of texture coordinates 203 203 int numGLCommands; //!< number of gl commands in the glList (tells how to draw) 204 char*fileName; //!< file name of the model File205 char*skinFileName; //!< file name of the skin file204 std::string fileName; //!< file name of the model File 205 std::string skinFileName; //!< file name of the skin file 206 206 MD2Header* header; //!< the header file 207 207 … … 223 223 224 224 public: 225 MD2Model(const char* modelFileName, const char* skinFileName = NULL, float scale = 1.0f);225 MD2Model(const std::string& modelFileName, const std::string& skinFileName = "", float scale = 1.0f); 226 226 virtual ~MD2Model(); 227 227 -
trunk/src/lib/graphics/importer/media_container.cc
r7193 r7221 34 34 * Default constructor 35 35 */ 36 MediaContainer::MediaContainer(const char*filename)36 MediaContainer::MediaContainer(const std::string& filename) 37 37 { 38 38 // set the class id for the base object … … 41 41 fps = 0; 42 42 mediaLoaded = false; 43 44 this->loadMedia(filename);43 if (!filename.empty()) 44 this->loadMedia(filename); 45 45 } 46 46 … … 84 84 } 85 85 86 bool MediaContainer::loadMedia(const char*filename)86 bool MediaContainer::loadMedia(const std::string& filename) 87 87 { 88 88 this->unloadMedia(); 89 89 90 if(filename == NULL)90 if(filename.empty()) 91 91 return false; 92 92 // check whether file exists 93 93 if(!ResourceManager::isInDataDir(filename)) 94 94 { 95 PRINTF(1)("Could not find %s\n", filename );95 PRINTF(1)("Could not find %s\n", filename.c_str()); 96 96 return false; 97 97 } … … 101 101 102 102 // Open video file 103 if (av_open_input_file(&format_context, ResourceManager::getFullName(filename) , NULL, 0, NULL) !=0 )104 { 105 PRINTF(1)("Could not open %s\n", ResourceManager::getFullName(filename) );103 if (av_open_input_file(&format_context, ResourceManager::getFullName(filename).c_str(), NULL, 0, NULL) !=0 ) 104 { 105 PRINTF(1)("Could not open %s\n", ResourceManager::getFullName(filename).c_str()); 106 106 return false; 107 107 } … … 110 110 if (av_find_stream_info(format_context) < 0) 111 111 { 112 PRINTF(1)("Could not find stream information in %s\n", ResourceManager::getFullName(filename) );112 PRINTF(1)("Could not find stream information in %s\n", ResourceManager::getFullName(filename).c_str()); 113 113 return false; 114 114 } … … 116 116 // Find the first video stream and take it 117 117 video_stream = av_find_default_stream_index(format_context); 118 118 119 119 if(video_stream == -1) 120 120 { 121 PRINTF(1)("Could not find a video stream in %s\n", ResourceManager::getFullName(filename) );121 PRINTF(1)("Could not find a video stream in %s\n", ResourceManager::getFullName(filename).c_str()); 122 122 return false; 123 123 } … … 202 202 // Free the packet that was allocated by av_read_frame 203 203 av_free_packet(&packet); 204 204 205 205 // Did we get a video frame? 206 206 if(frame_finished) … … 216 216 memcpy(&data[i*codec_context->width*3], 217 217 ((AVPicture*)RGB_frame)->data[0]+i * 218 ((AVPicture*)RGB_frame)->linesize[0], 218 ((AVPicture*)RGB_frame)->linesize[0], 219 219 codec_context->width*sizeof(uint8_t)*3); 220 220 … … 258 258 } 259 259 else 260 return NULL;261 } 260 return 0; 261 } -
trunk/src/lib/graphics/importer/media_container.h
r6981 r7221 44 44 public: 45 45 46 MediaContainer(const char* filename = NULL);46 MediaContainer(const std::string& filename = ""); 47 47 virtual ~MediaContainer(); 48 48 49 bool loadMedia(const char*filename);49 bool loadMedia(const std::string& filename); 50 50 void loadFrames(); 51 51 -
trunk/src/lib/graphics/importer/movie_player.cc
r7193 r7221 31 31 32 32 33 MoviePlayer::MoviePlayer(const char*filename)33 MoviePlayer::MoviePlayer(const std::string& filename) 34 34 { 35 35 // set the class id for the base object … … 42 42 mediaLoaded = false; 43 43 44 this->loadMovie(filename);45 44 if (!filename.empty()) 45 this->loadMovie(filename); 46 46 } 47 47 … … 83 83 84 84 85 bool MoviePlayer::loadMovie(const char*filename)85 bool MoviePlayer::loadMovie(const std::string& filename) 86 86 { 87 87 this->unloadMedia(); 88 88 89 if(filename == NULL)89 if(filename.empty()) 90 90 return false; 91 91 // check whether file exists 92 92 if(!ResourceManager::isInDataDir(filename)) 93 93 { 94 PRINTF(1)("Could not find %s\n", filename );94 PRINTF(1)("Could not find %s\n", filename.c_str()); 95 95 return false; 96 96 } … … 100 100 101 101 // Open video file 102 if (av_open_input_file(&format_context, ResourceManager::getFullName(filename) , NULL, 0, NULL) !=0 )103 { 104 PRINTF(1)("Could not open %s\n", ResourceManager::getFullName(filename) );102 if (av_open_input_file(&format_context, ResourceManager::getFullName(filename).c_str(), NULL, 0, NULL) !=0 ) 103 { 104 PRINTF(1)("Could not open %s\n", ResourceManager::getFullName(filename).c_str()); 105 105 return false; 106 106 } … … 109 109 if (av_find_stream_info(format_context) < 0) 110 110 { 111 PRINTF(1)("Could not find stream information in %s\n", ResourceManager::getFullName(filename) );111 PRINTF(1)("Could not find stream information in %s\n", ResourceManager::getFullName(filename).c_str()); 112 112 return false; 113 113 } … … 118 118 if(video_stream == -1) 119 119 { 120 PRINTF(1)("Could not find a video stream in %s\n", ResourceManager::getFullName(filename) );120 PRINTF(1)("Could not find a video stream in %s\n", ResourceManager::getFullName(filename).c_str()); 121 121 return false; 122 122 } -
trunk/src/lib/graphics/importer/movie_player.h
r6981 r7221 58 58 public: 59 59 60 MoviePlayer(const char* filename = NULL);60 MoviePlayer(const std::string& filename = ""); 61 61 virtual ~MoviePlayer(); 62 62 63 bool loadMovie(const char*filename);63 bool loadMovie(const std::string& filename); 64 64 65 65 void start(float start_time); -
trunk/src/lib/graphics/importer/objModel.cc
r6162 r7221 32 32 * @param scaling The factor that the model will be scaled with. 33 33 */ 34 OBJModel::OBJModel(const char* fileName, float scaling) : StaticModel(fileName) 34 OBJModel::OBJModel(const std::string& fileName, float scaling) 35 : StaticModel(fileName) 35 36 { 36 37 this->setClassID(CL_OBJ_MODEL, "OBJModel"); … … 51 52 */ 52 53 OBJModel::~OBJModel() 53 { 54 PRINTF(4)("Deleting the obj-names\n"); 55 if (this->objPath) 56 delete []this->objPath; 57 } 54 { } 58 55 59 56 /** … … 63 60 Splits the FileName from the DirectoryName 64 61 */ 65 bool OBJModel::importFile (const char* fileName) 66 { 62 bool OBJModel::importFile (const std::string& fileNameInput) 63 { 64 const char* fileName = fileNameInput.c_str(); 67 65 PRINTF(4)("preparing to read in file: %s\n", fileName); 68 66 // splitting the … … 74 72 { 75 73 int len = split - fileName+1; 76 this->objPath = new char[len +2];77 strncpy(this->objPath, fileName, len);74 this->objPath = fileName; 75 this->objPath.erase(len, this->objPath.size()); 78 76 this->objPath[len] = '\0'; 79 77 PRINTF(4)("Resolved file %s to Path %s.\n", fileName, this->objPath); … … 91 89 This function does read the file, parses it for the occurence of things like vertices, faces and so on, and executes the specific tasks 92 90 */ 93 bool OBJModel::readFromObjFile(const char*fileName)91 bool OBJModel::readFromObjFile(const std::string& fileName) 94 92 { 95 93 FILE* stream; 96 if( (stream = fopen (fileName , "r")) == NULL)97 { 98 PRINTF(2)("Object File Could not be Opened %s\n", fileName );94 if( (stream = fopen (fileName.c_str(), "r")) == NULL) 95 { 96 PRINTF(2)("Object File Could not be Opened %s\n", fileName.c_str()); 99 97 return false; 100 98 } … … 162 160 * that a material does not have to be able to read itself in from a File. 163 161 */ 164 bool OBJModel::readMtlLib (const char* mtlFile) 165 { 166 char* fileName = new char [strlen(this->objPath) + strlen(mtlFile)+1]; 167 sprintf(fileName, "%s%s", this->objPath, mtlFile); 162 bool OBJModel::readMtlLib (const std::string& mtlFile) 163 { 164 std::string fileName = this->objPath + mtlFile; 168 165 169 166 FILE* stream; 170 if( (stream = fopen (fileName, "r")) == NULL) 171 { 172 PRINTF(2)("MaterialLibrary could not be opened %s\n", fileName); 173 delete[] fileName; 167 if( (stream = fopen (fileName.c_str(), "r")) == NULL) 168 { 169 PRINTF(2)("MaterialLibrary could not be opened %s\n", fileName.c_str()); 174 170 return false; 175 171 } … … 258 254 } 259 255 fclose(stream); 260 delete []fileName;261 256 return true; 262 257 } -
trunk/src/lib/graphics/importer/objModel.h
r6022 r7221 13 13 { 14 14 public: 15 OBJModel(const char*fileName, float scaling = 1.0);15 OBJModel(const std::string& fileName, float scaling = 1.0); 16 16 virtual ~OBJModel(); 17 17 18 18 private: 19 19 ///// readin ///// 20 bool importFile (const char*fileName);21 bool readFromObjFile (const char*fileName);22 bool readMtlLib (const char*matFile);20 bool importFile (const std::string& fileName); 21 bool readFromObjFile (const std::string& fileName); 22 bool readMtlLib (const std::string& matFile); 23 23 24 24 private: 25 char*objPath; //!< The Path where the obj and mtl-file are located.25 std::string objPath; //!< The Path where the obj and mtl-file are located. 26 26 }; 27 27 -
trunk/src/lib/graphics/importer/static_model.cc
r6423 r7221 23 23 #include <stdarg.h> 24 24 25 #include "vector.h"26 27 25 using namespace std; 28 26 … … 86 84 { 87 85 PRINTF(4)("Adding new Group\n"); 88 this->name = NULL;86 this->name = ""; 89 87 this->faceMode = -1; 90 88 this->faceCount = 0; … … 109 107 if (this->listNumber != 0) 110 108 glDeleteLists(this->listNumber, 1); 111 112 if (this->name != NULL)113 delete[] this->name;114 109 115 110 if (this->next !=NULL) … … 142 137 * assigns it a Name and a Type 143 138 */ 144 StaticModel::StaticModel(const char*modelName)139 StaticModel::StaticModel(const std::string& modelName) 145 140 { 146 141 this->setClassID(CL_STATIC_MODEL, "StaticModel"); … … 230 225 ModelGroup* tmpGroup = this->firstGroup; 231 226 while (tmpGroup != NULL) 232 233 234 235 236 227 { 228 PRINTF(5)("Drawing model %s\n", tmpGroup->name); 229 glCallList (tmpGroup->listNumber); 230 tmpGroup = tmpGroup->next; 231 } 237 232 } 238 233 … … 247 242 { 248 243 if (unlikely(groupNumber >= this->groupCount)) 249 250 251 252 244 { 245 PRINTF(2)("You requested model number %i, but this File only contains of %i Models.\n", groupNumber-1, this->groupCount); 246 return; 247 } 253 248 PRINTF(4)("drawing the requested 3D-Models if found.\n"); 254 249 ModelGroup* tmpGroup = this->firstGroup; 255 250 int counter = 0; 256 251 while (tmpGroup != NULL) 252 { 253 if (counter == groupNumber) 257 254 { 258 if (counter == groupNumber) 259 { 260 PRINTF(4)("Drawing model number %i named %s\n", counter, tmpGroup->name); 261 glCallList (tmpGroup->listNumber); 262 return; 263 } 264 ++counter; 265 tmpGroup = tmpGroup->next; 255 PRINTF(4)("Drawing model number %i named %s\n", counter, tmpGroup->name); 256 glCallList (tmpGroup->listNumber); 257 return; 266 258 } 259 ++counter; 260 tmpGroup = tmpGroup->next; 261 } 267 262 PRINTF(2)("Model number %i in %s not Found.\n", groupNumber, this->getName()); 268 263 return; … … 276 271 * It does this by just calling the List that must have been created earlier. 277 272 */ 278 void StaticModel::draw (char* groupName) const 279 { 280 if (groupName == NULL) 281 return; 273 void StaticModel::draw (const std::string& groupName) const 274 { 282 275 PRINTF(4)("drawing the requested 3D-Models if found.\n"); 283 276 ModelGroup* tmpGroup = this->firstGroup; 284 277 while (tmpGroup != NULL) 278 { 279 if (tmpGroup->name == groupName) 285 280 { 286 if (tmpGroup->name != NULL && !strcmp(tmpGroup->name, groupName)) 287 { 288 PRINTF(4)("Drawing model %s\n", tmpGroup->name); 289 glCallList (tmpGroup->listNumber); 290 return; 291 } 292 tmpGroup = tmpGroup->next; 281 PRINTF(4)("Drawing model %s\n", tmpGroup->name.c_str()); 282 glCallList (tmpGroup->listNumber); 283 return; 293 284 } 294 PRINTF(2)("Model Named %s in %s not Found.\n", groupName, this->getName()); 285 tmpGroup = tmpGroup->next; 286 } 287 PRINTF(2)("Model Named %s in %s not Found.\n", groupName.c_str(), this->getName()); 295 288 return; 296 289 } … … 341 334 * @returns the added material 342 335 */ 343 Material* StaticModel::addMaterial(const char*materialName)336 Material* StaticModel::addMaterial(const std::string& materialName) 344 337 { 345 338 ModelMaterial* modMat = new ModelMaterial; … … 357 350 * @returns the Material if found, NULL otherwise 358 351 */ 359 Material* StaticModel::findMaterialByName(const char*materialName)352 Material* StaticModel::findMaterialByName(const std::string& materialName) 360 353 { 361 354 list<ModelMaterial*>::iterator modMat; 362 355 for (modMat = this->materialList.begin(); modMat != this->materialList.end(); modMat++) 363 if ( !strcmp((*modMat)->material->getName(), materialName))356 if (materialName == (*modMat)->material->getName()) 364 357 return (*modMat)->material; 365 358 return NULL; … … 373 366 * With it you should be able to create Models with more than one SubModel inside 374 367 */ 375 bool StaticModel::addGroup(const char*groupString)368 bool StaticModel::addGroup(const std::string& groupString) 376 369 { 377 370 PRINTF(5)("Read Group: %s.\n", groupString); 378 371 if (this->groupCount != 0 && this->currentGroup->faceCount > 0) 379 380 381 382 372 { 373 // finalizeGroup(currentGroup); 374 this->currentGroup = this->currentGroup->next = new ModelGroup; 375 } 383 376 // setting the group name if not default. 384 if (strcmp(groupString, "default")) 385 { 386 this->currentGroup->name = new char [strlen(groupString)+1]; 387 strcpy(this->currentGroup->name, groupString); 388 } 377 if (groupString == "default") 378 { 379 this->currentGroup->name = groupString; 380 } 389 381 ++this->groupCount; 390 382 } … … 396 388 * If a vertex line is found this function will inject it into the vertex-Array 397 389 */ 398 bool StaticModel::addVertex (const char*vertexString)390 bool StaticModel::addVertex (const std::string& vertexString) 399 391 { 400 392 float subbuffer1; 401 393 float subbuffer2; 402 394 float subbuffer3; 403 sscanf (vertexString , "%f %f %f", &subbuffer1, &subbuffer2, &subbuffer3);395 sscanf (vertexString.c_str(), "%f %f %f", &subbuffer1, &subbuffer2, &subbuffer3); 404 396 this->vertices.push_back(subbuffer1*scaleFactor); 405 397 this->vertices.push_back(subbuffer2*scaleFactor); … … 431 423 * If a vertexNormal line is found this function will inject it into the vertexNormal-Array 432 424 */ 433 bool StaticModel::addVertexNormal (const char*normalString)425 bool StaticModel::addVertexNormal (const std::string& normalString) 434 426 { 435 427 float subbuffer1; 436 428 float subbuffer2; 437 429 float subbuffer3; 438 sscanf (normalString , "%f %f %f", &subbuffer1, &subbuffer2, &subbuffer3);430 sscanf (normalString.c_str(), "%f %f %f", &subbuffer1, &subbuffer2, &subbuffer3); 439 431 this->normals.push_back(subbuffer1); 440 432 this->normals.push_back(subbuffer2); … … 471 463 * !! WARNING THIS IS DIFFERNT FROM addVervexTexture(float, float); because it changes the second entry to 1-v !! 472 464 */ 473 bool StaticModel::addVertexTexture (const char*vTextureString)465 bool StaticModel::addVertexTexture (const std::string& vTextureString) 474 466 { 475 467 float subbuffer1; 476 468 float subbuffer2; 477 sscanf (vTextureString , "%f %f", &subbuffer1, &subbuffer2);469 sscanf (vTextureString.c_str(), "%f %f", &subbuffer1, &subbuffer2); 478 470 this->vTexture.push_back(subbuffer1); 479 471 this->vTexture.push_back(1 - subbuffer2); … … 507 499 * String is different from the argument addFace, 508 500 * in this, that the first Vertex/Normal/Texcoord is 1 instead of 0 509 */ 510 bool StaticModel::addFace (const char* faceString) 511 { 501 * 502 * @TODO make it std::string conform 503 */ 504 bool StaticModel::addFace (const std::string& faceStringInput) 505 { 506 const char* faceString = faceStringInput.c_str(); 512 507 if (this->currentGroup->faceCount >0) 513 508 this->currentGroup->currentFace = this->currentGroup->currentFace->next = new ModelFace; … … 516 511 tmpElem->next = NULL; 517 512 while(strcmp (faceString, "\0")) 513 { 514 if (this->currentGroup->currentFace->vertexCount>0) 515 tmpElem = tmpElem->next = new ModelFaceElement; 516 tmpElem->next = NULL; 517 518 char tmpValue [50]; 519 int tmpLen; 520 char* vertex = NULL; 521 char* texture = NULL; 522 char* normal = NULL; 523 524 sscanf (faceString, "%s", tmpValue); 525 tmpLen = strlen(tmpValue); 526 vertex = tmpValue; 527 528 if ((texture = strstr (vertex, "/")) != NULL) 518 529 { 519 if (this->currentGroup->currentFace->vertexCount>0) 520 tmpElem = tmpElem->next = new ModelFaceElement; 521 tmpElem->next = NULL; 522 523 char tmpValue [50]; 524 int tmpLen; 525 char* vertex = NULL; 526 char* texture = NULL; 527 char* normal = NULL; 528 529 sscanf (faceString, "%s", tmpValue); 530 tmpLen = strlen(tmpValue); 531 vertex = tmpValue; 532 533 if ((texture = strstr (vertex, "/")) != NULL) 534 { 535 texture[0] = '\0'; 536 texture ++; 537 538 if ((normal = strstr (texture, "/")) !=NULL) 539 { 540 normal[0] = '\0'; 541 normal ++; 542 } 543 } 544 if (vertex) 545 tmpElem->vertexNumber = atoi(vertex)-1; 546 if (texture) 547 tmpElem->texCoordNumber = atoi(texture)-1; 548 if (normal) 549 tmpElem->normalNumber = atoi(normal)-1; 550 551 faceString += tmpLen; 552 if (strcmp (faceString, "\0")) 553 faceString++; 554 this->currentGroup->currentFace->vertexCount++; 530 texture[0] = '\0'; 531 texture ++; 532 533 if ((normal = strstr (texture, "/")) !=NULL) 534 { 535 normal[0] = '\0'; 536 normal ++; 537 } 555 538 } 539 if (vertex) 540 tmpElem->vertexNumber = atoi(vertex)-1; 541 if (texture) 542 tmpElem->texCoordNumber = atoi(texture)-1; 543 if (normal) 544 tmpElem->normalNumber = atoi(normal)-1; 545 546 faceString += tmpLen; 547 if (strcmp (faceString, "\0")) 548 faceString++; 549 this->currentGroup->currentFace->vertexCount++; 550 } 556 551 557 552 this->currentGroup->faceCount += this->currentGroup->currentFace->vertexCount -2; … … 575 570 576 571 for (int i = 0; i < faceElemCount; i++) 577 578 579 580 581 582 583 584 585 586 587 572 { 573 if (this->currentGroup->currentFace->vertexCount > 0) 574 tmpElem = tmpElem->next = new ModelFaceElement; 575 576 tmpElem->vertexNumber = va_arg (itemlist, int); 577 if (type & TEXCOORD) 578 tmpElem->texCoordNumber = va_arg (itemlist, int); 579 if (type & NORMAL) 580 tmpElem->normalNumber = va_arg(itemlist, int); 581 this->currentGroup->currentFace->vertexCount++; 582 } 588 583 va_end(itemlist); 589 584 … … 596 591 * @param matString the Material that will be set. 597 592 */ 598 bool StaticModel::setMaterial(const char*matString)593 bool StaticModel::setMaterial(const std::string& matString) 599 594 { 600 595 if (this->currentGroup->faceCount > 0) … … 647 642 ModelGroup* tmpGroup = firstGroup; 648 643 while (tmpGroup != NULL) 644 { 645 ModelFace* tmpFace = tmpGroup->firstFace; 646 while (tmpFace != NULL) 649 647 { 650 ModelFace* tmpFace = tmpGroup->firstFace; 651 while (tmpFace != NULL) 648 if (tmpFace->firstElem != NULL) 649 { 650 ModelFaceElement* firstElem = tmpFace->firstElem; 651 ModelFaceElement* prevElem; 652 ModelFaceElement* curElem = firstElem; 653 ModelFaceElement* nextElem; 654 ModelFaceElement* lastElem; 655 // find last Element of the Chain. !! IMPORTANT:the last Element of the Chain must point to NULL, or it will resolv into an infinity-loop. 656 while (curElem != NULL) 652 657 { 653 if (tmpFace->firstElem != NULL) 654 { 655 ModelFaceElement* firstElem = tmpFace->firstElem; 656 ModelFaceElement* prevElem; 657 ModelFaceElement* curElem = firstElem; 658 ModelFaceElement* nextElem; 659 ModelFaceElement* lastElem; 660 // find last Element of the Chain. !! IMPORTANT:the last Element of the Chain must point to NULL, or it will resolv into an infinity-loop. 661 while (curElem != NULL) 662 { 663 prevElem = curElem; 664 curElem = curElem->next; 665 } 666 lastElem = prevElem; 667 668 curElem = firstElem; 669 for (int j=0; j<tmpFace->vertexCount; j++) 670 { 671 if (!(nextElem = curElem->next)) 672 nextElem = firstElem; 673 curElem->normalNumber = curElem->vertexNumber; 674 675 curV = Vector (this->vertices[curElem->vertexNumber*3], 676 this->vertices[curElem->vertexNumber*3+1], 677 this->vertices[curElem->vertexNumber*3+2]); 678 679 prevV = Vector (this->vertices[prevElem->vertexNumber*3], 680 this->vertices[prevElem->vertexNumber*3+1], 681 this->vertices[prevElem->vertexNumber*3+2]) - curV; 682 683 nextV = Vector (this->vertices[nextElem->vertexNumber*3], 684 this->vertices[nextElem->vertexNumber*3+1], 685 this->vertices[nextElem->vertexNumber*3+2]) - curV; 686 normArray[curElem->vertexNumber] = normArray[curElem->vertexNumber] + nextV.cross(prevV); 687 688 prevElem = curElem; 689 curElem = curElem->next; 690 } 691 } 692 tmpFace = tmpFace->next; 658 prevElem = curElem; 659 curElem = curElem->next; 693 660 } 694 tmpGroup = tmpGroup->next; 661 lastElem = prevElem; 662 663 curElem = firstElem; 664 for (int j=0; j<tmpFace->vertexCount; j++) 665 { 666 if (!(nextElem = curElem->next)) 667 nextElem = firstElem; 668 curElem->normalNumber = curElem->vertexNumber; 669 670 curV = Vector (this->vertices[curElem->vertexNumber*3], 671 this->vertices[curElem->vertexNumber*3+1], 672 this->vertices[curElem->vertexNumber*3+2]); 673 674 prevV = Vector (this->vertices[prevElem->vertexNumber*3], 675 this->vertices[prevElem->vertexNumber*3+1], 676 this->vertices[prevElem->vertexNumber*3+2]) - curV; 677 678 nextV = Vector (this->vertices[nextElem->vertexNumber*3], 679 this->vertices[nextElem->vertexNumber*3+1], 680 this->vertices[nextElem->vertexNumber*3+2]) - curV; 681 normArray[curElem->vertexNumber] = normArray[curElem->vertexNumber] + nextV.cross(prevV); 682 683 prevElem = curElem; 684 curElem = curElem->next; 685 } 686 } 687 tmpFace = tmpFace->next; 695 688 } 689 tmpGroup = tmpGroup->next; 690 } 696 691 697 692 for (int i=0; i < this->vertices.size()/3;i++) 698 699 700 701 702 703 704 693 { 694 normArray[i].normalize(); 695 PRINTF(5)("Found Normale number %d: (%f; %f, %f).\n", i, normArray[i].x, normArray[i].y, normArray[i].z); 696 697 this->addVertexNormal(normArray[i].x, normArray[i].y, normArray[i].z); 698 699 } 705 700 delete[] normArray; 706 701 } … … 721 716 722 717 while (this->currentGroup != NULL) 718 { 719 720 // creating a glList for the Group 721 if ((this->currentGroup->listNumber = glGenLists(1)) == 0) 723 722 { 724 725 // creating a glList for the Group 726 if ((this->currentGroup->listNumber = glGenLists(1)) == 0) 723 PRINTF(2)("glList could not be created for this Model\n"); 724 return false; 725 } 726 glNewList (this->currentGroup->listNumber, GL_COMPILE); 727 728 // Putting Faces to GL 729 ModelFace* tmpFace = this->currentGroup->firstFace; 730 while (tmpFace != NULL) 731 { 732 if (tmpFace->vertexCount == 0 && tmpFace->material != NULL) 733 { 734 if (this->currentGroup->faceMode != -1) 735 glEnd(); 736 this->currentGroup->faceMode = 0; 737 Material* tmpMat; 738 if (tmpFace->material != NULL) 727 739 { 728 PRINTF(2)("glList could not be created for this Model\n");729 return false;740 tmpFace->material->select(); 741 PRINTF(5)("using material %s for coming Faces.\n", tmpFace->material->getName()); 730 742 } 731 glNewList (this->currentGroup->listNumber, GL_COMPILE);732 733 // Putting Faces to GL734 ModelFace* tmpFace = this->currentGroup->firstFace;735 while (tmpFace != NULL)743 } 744 745 else if (tmpFace->vertexCount == 3) 746 { 747 if (this->currentGroup->faceMode != 3) 736 748 { 737 if (tmpFace->vertexCount == 0 && tmpFace->material != NULL) 738 { 739 if (this->currentGroup->faceMode != -1) 740 glEnd(); 741 this->currentGroup->faceMode = 0; 742 Material* tmpMat; 743 if (tmpFace->material != NULL) 744 { 745 tmpFace->material->select(); 746 PRINTF(5)("using material %s for coming Faces.\n", tmpFace->material->getName()); 747 } 748 } 749 750 else if (tmpFace->vertexCount == 3) 751 { 752 if (this->currentGroup->faceMode != 3) 753 { 754 if (this->currentGroup->faceMode != -1) 755 glEnd(); 756 glBegin(GL_TRIANGLES); 757 } 758 759 this->currentGroup->faceMode = 3; 760 PRINTF(5)("found triag.\n"); 761 } 762 763 else if (tmpFace->vertexCount == 4) 764 { 765 if (this->currentGroup->faceMode != 4) 766 { 767 if (this->currentGroup->faceMode != -1) 768 glEnd(); 769 glBegin(GL_QUADS); 770 } 771 this->currentGroup->faceMode = 4; 772 PRINTF(5)("found quad.\n"); 773 } 774 775 else if (tmpFace->vertexCount > 4) 776 { 777 if (this->currentGroup->faceMode != -1) 778 glEnd(); 779 glBegin(GL_POLYGON); 780 PRINTF(5)("Polygon with %i faces found.", tmpFace->vertexCount); 781 this->currentGroup->faceMode = tmpFace->vertexCount; 782 } 783 784 ModelFaceElement* tmpElem = tmpFace->firstElem; 785 while (tmpElem != NULL) 786 { 787 // PRINTF(2)("%s\n", tmpElem->value); 788 this->addGLElement(tmpElem); 789 tmpElem = tmpElem->next; 790 } 791 tmpFace = tmpFace->next; 749 if (this->currentGroup->faceMode != -1) 750 glEnd(); 751 glBegin(GL_TRIANGLES); 792 752 } 793 glEnd(); 794 glEndList(); 795 796 this->currentGroup = this->currentGroup->next; 753 754 this->currentGroup->faceMode = 3; 755 PRINTF(5)("found triag.\n"); 756 } 757 758 else if (tmpFace->vertexCount == 4) 759 { 760 if (this->currentGroup->faceMode != 4) 761 { 762 if (this->currentGroup->faceMode != -1) 763 glEnd(); 764 glBegin(GL_QUADS); 765 } 766 this->currentGroup->faceMode = 4; 767 PRINTF(5)("found quad.\n"); 768 } 769 770 else if (tmpFace->vertexCount > 4) 771 { 772 if (this->currentGroup->faceMode != -1) 773 glEnd(); 774 glBegin(GL_POLYGON); 775 PRINTF(5)("Polygon with %i faces found.", tmpFace->vertexCount); 776 this->currentGroup->faceMode = tmpFace->vertexCount; 777 } 778 779 ModelFaceElement* tmpElem = tmpFace->firstElem; 780 while (tmpElem != NULL) 781 { 782 // PRINTF(2)("%s\n", tmpElem->value); 783 this->addGLElement(tmpElem); 784 tmpElem = tmpElem->next; 785 } 786 tmpFace = tmpFace->next; 797 787 } 788 glEnd(); 789 glEndList(); 790 791 this->currentGroup = this->currentGroup->next; 792 } 798 793 } 799 794 … … 814 809 ModelFace* tmpFace; //!< the temporary face referece 815 810 811 bool warned = false; 812 816 813 /* count the number of triangles */ 817 814 /* now iterate through all groups and build up the triangle list */ … … 834 831 else if( tmpFace->vertexCount > 4) 835 832 { 836 PRINTF(1)("This model (%s) got over 4 vertices per face <=> conflicts in the CD engine!\n", this->getName()); 837 //exit(0); 833 if (!warned) 834 { 835 PRINTF(2)("This model (%s) got over 4 vertices per face <=> conflicts in the CD engine!\n", this->getName()); 836 warned = true; 837 } 838 //exit(0); 838 839 } 839 840 tmpFace = tmpFace->next; … … 858 859 while( this->currentGroup != NULL) 859 860 { 860 861 // Putting Faces to GL 861 862 tmpFace = this->currentGroup->firstFace; 862 863 while( tmpFace != NULL) … … 931 932 932 933 if (elem->texCoordNumber != -1) 933 934 935 936 937 938 939 934 { 935 if (likely(elem->texCoordNumber < this->pModelInfo.numTexCoor)) 936 glTexCoord2fv(&this->vTexture[0] + elem->texCoordNumber * 2); 937 else 938 PRINTF(2)("TextureCoordinate %d is not in the List (max: %d)\nThe Model might be incomplete\n", 939 elem->texCoordNumber, this->pModelInfo.numTexCoor); 940 } 940 941 if (elem->normalNumber != -1) 941 942 { 942 943 if (likely(elem->normalNumber < this->pModelInfo.numNormals)) 943 944 glNormal3fv(&this->normals[0] + elem->normalNumber * 3); 944 945 else 945 946 947 946 PRINTF(2)("Normal %d is not in the List (max: %d)\nThe Model might be incomplete", 947 elem->normalNumber, this->pModelInfo.numNormals); 948 } 948 949 if (elem->vertexNumber != -1) 949 950 951 952 953 954 955 950 { 951 if (likely(elem->vertexNumber < this->pModelInfo.numVertices)) 952 glVertex3fv(&this->vertices[0]+ elem->vertexNumber * 3); 953 else 954 PRINTF(2)("Vertex %d is not in the List (max: %d)\nThe Model might be incomplete", 955 elem->vertexNumber, this->pModelInfo.numVertices); 956 } 956 957 957 958 } -
trunk/src/lib/graphics/importer/static_model.h
r6423 r7221 13 13 #include <vector> 14 14 #include <list> 15 16 // FORWARD DECLARATION //17 template<class T> class tArray;18 15 19 16 // definition of different modes for setting up Faces … … 70 67 void cleanup(); 71 68 72 char* name; //!< the Name of the Group. this is an identifier, that can be accessed via the draw (char*name) function.69 std::string name; //!< the Name of the Group. this is an identifier, that can be accessed via the draw (std::string name) function. 73 70 GLubyte* indices; //!< The indices of the Groups. Needed for vertex-arrays 74 71 GLuint listNumber; //!< The number of the GL-List this Group gets. … … 98 95 { 99 96 public: 100 StaticModel(const char* modelName = NULL);97 StaticModel(const std::string& modelName = ""); 101 98 virtual ~StaticModel(); 102 99 103 100 virtual void draw() const; 104 101 void draw(int groupNumber) const; 105 void draw(c har*groupName) const;102 void draw(const std::string& groupName) const; 106 103 107 104 void rebuild(); 108 105 109 106 Material* addMaterial(Material* material); 110 Material* addMaterial(const char*materialName);107 Material* addMaterial(const std::string& materialName); 111 108 112 bool addGroup(const char*groupString);109 bool addGroup(const std::string& groupString); 113 110 114 bool addVertex(const char*vertexString);111 bool addVertex(const std::string& vertexString); 115 112 bool addVertex(float x, float y, float z); 116 113 117 bool addFace(const char*faceString);114 bool addFace(const std::string& faceString); 118 115 bool addFace(int faceElemCount, VERTEX_FORMAT type, ...); 119 116 120 bool addVertexNormal(const char*normalString);117 bool addVertexNormal(const std::string& normalString); 121 118 bool addVertexNormal(float x, float y, float z); 122 119 123 bool addVertexTexture(const char*vTextureString);120 bool addVertexTexture(const std::string& vTextureString); 124 121 bool addVertexTexture(float u, float v); 125 122 126 bool setMaterial(const char*mtlString);123 bool setMaterial(const std::string& mtlString); 127 124 bool setMaterial(Material* mtl); 128 125 … … 133 130 void cubeModel(); 134 131 135 Material* findMaterialByName(const char*materialName);132 Material* findMaterialByName(const std::string& materialName); 136 133 137 134 protected: -
trunk/src/lib/graphics/importer/texture.cc
r6871 r7221 32 32 * Constructor for a Texture 33 33 */ 34 Texture::Texture(const char*imageName, GLenum target)34 Texture::Texture(const std::string& imageName, GLenum target) 35 35 { 36 36 this->setClassID(CL_TEXTURE, "Texture"); … … 41 41 this->priority = 0.5; 42 42 43 if ( imageName != NULL)43 if (!imageName.empty()) 44 44 { 45 45 this->setName(imageName); … … 67 67 * @param imageName The image to load 68 68 */ 69 bool Texture::loadImage(const char*imageName, GLenum target)69 bool Texture::loadImage(const std::string& imageName, GLenum target) 70 70 { 71 71 if (Texture::texturesEnabled) … … 81 81 this->texture = 0; 82 82 } 83 if ( imageName != NULL)83 if (!imageName.empty()) 84 84 { 85 85 SDL_Surface* tmpSurf; … … 87 87 glDeleteTextures(1, &this->texture); 88 88 // load the new Image to memory 89 tmpSurf = IMG_Load(imageName );89 tmpSurf = IMG_Load(imageName.c_str()); 90 90 if(tmpSurf != NULL) 91 91 { -
trunk/src/lib/graphics/importer/texture.h
r6981 r7221 18 18 { 19 19 public: 20 Texture(const char* imageName = NULL, GLenum target = GL_TEXTURE_2D);20 Texture(const std::string& imageName = "", GLenum target = GL_TEXTURE_2D); 21 21 // Texture(TEXTURE_TYPE type, int resolution); 22 22 virtual ~Texture(); 23 23 24 bool loadImage(const char*imageName, GLenum target = GL_TEXTURE_2D);24 bool loadImage(const std::string& imageName, GLenum target = GL_TEXTURE_2D); 25 25 virtual bool rebuild(); 26 26 -
trunk/src/lib/graphics/importer/texture_sequence.cc
r6624 r7221 124 124 * @returns true on success 125 125 */ 126 bool TextureSequence::addFrame(const char*imageName)126 bool TextureSequence::addFrame(const std::string& imageName) 127 127 { 128 if (imageName == NULL) 129 return false; 130 131 SDL_Surface* addSurface = IMG_Load(imageName); 128 SDL_Surface* addSurface = IMG_Load(imageName.c_str()); 132 129 bool success = this->addFrame(addSurface); 133 130 delete addSurface; -
trunk/src/lib/graphics/importer/texture_sequence.h
r7195 r7221 23 23 bool loadImageSeries(unsigned int count, ...); 24 24 bool loadImageSeries(unsigned int count, va_list textureNames); 25 bool addFrame(const char*image);25 bool addFrame(const std::string& image); 26 26 bool addFrame(SDL_Surface* surface); 27 27 bool addFrame(GLuint texture);
Note: See TracChangeset
for help on using the changeset viewer.