struct OBJ_Model * loadObj(char * directory,char * filename /*This does not have a .obj extension*/,int compileDisplayList) { fprintf(stderr,"Starting to load OBJ file %s \n",filename); struct OBJ_Model * obj = ( struct OBJ_Model * ) malloc(sizeof(struct OBJ_Model)); if ( obj == 0 ) { fprintf(stderr,"Could not allocate enough space for model %s \n",filename); return 0; } memset (obj,0,sizeof(struct OBJ_Model)); obj->scale=1.0f; unsigned int directory_length = strlen(directory); if (directory_length > MAX_MODEL_PATHS ) { fprintf(stderr,"Huge directory filename provided , will not loadObject ( %u char limit ) \n",MAX_MODEL_PATHS); free(obj); return 0; } strncpy(obj->directory, directory, MAX_MODEL_PATHS ); unsigned int file_name_length = strlen(filename); if (file_name_length > MAX_MODEL_PATHS ) { fprintf(stderr,"Huge filename provided , will not loadObject ( %u char limit ) \n",MAX_MODEL_PATHS); free(obj); return 0; } strncpy(obj->filename, filename, MAX_MODEL_PATHS ); if (!readOBJ(obj) ) { fprintf(stderr," Could not read object %s \n",filename); unloadObj(obj); return 0;} if (!calculateBoundingBox(obj)) { fprintf(stderr," Could not calculate bounding box for object %s \n",filename); unloadObj(obj); return 0;} if (!prepareObject(obj)) { fprintf(stderr," Could not prepare object %s \n",filename); unloadObj(obj); return 0;} if (!calculateBoundingBox(obj)) { fprintf(stderr," Could not calculate bounding box for object %s \n",filename); unloadObj(obj); return 0;} if (compileDisplayList) { compileOBJList(obj); } return obj; }
void GameObjectManager::insert(int index, GameObject* object) { if (contains(object)) return; if (index < 0) index = 0; else if (index > mGameObjects.size()) index = mGameObjects.size(); prepareObject(object); mGameObjects.insert(index, object); emit objectInserted(index, object); }