Example #1
0
bool loadObjects(vector<object3DS *> &objs)
{
	Setting &objects=cfg->lookup("application.objects");
	int count=objects.getLength();
	glActiveTexture(GL_TEXTURE0);
	texture *tex=NULL;
	object3DS *object=NULL;
	for (int i=0; i<count; i++)
	{
		vertex _tempVertex;
		string _tempStr;
		objects[i]["color"].lookupValue("r",_tempVertex.color[0]);
		objects[i]["color"].lookupValue("g",_tempVertex.color[1]);
		objects[i]["color"].lookupValue("b",_tempVertex.color[2]);
		objects[i]["position"].lookupValue("x",_tempVertex.coordinate[0]);
		objects[i]["position"].lookupValue("y",_tempVertex.coordinate[1]);
		objects[i]["position"].lookupValue("z",_tempVertex.coordinate[2]);
		objects[i].lookupValue("texture",_tempStr);
		tex=new texture();
		object=new object3DS();
		wchar_t *_tempBuf=new wchar_t[_tempStr.size()];
		int _len=mbstowcs(_tempBuf,_tempStr.c_str(),_tempStr.size());
		wstring _tempWStr(_tempBuf,_len);
		delete []_tempBuf;
		tex->load(_tempWStr,true,true,true);
		objects[i].lookupValue("model",_tempStr);
		_tempBuf=new wchar_t[_tempStr.size()];
		_len=mbstowcs(_tempBuf,_tempStr.c_str(),_tempStr.size());
		_tempWStr.clear();
		_tempWStr=wstring(_tempBuf,_len);
		delete []_tempBuf;
		object->load(_tempWStr);
		_tempWStr.clear();
		object->setPosition(_tempVertex);
		object->setScale(1.0f);
		if (tex!=NULL)
		{
			object->copyTex(tex);
		}
		objs.push_back(object);
	}
	return true;
	//vertex center,tempVertex;
	//bool hasReaded=false;
	//wifstream configFile("config.ini", ios::in);
	//if (!configFile)
	//{
	//	cerr<<"Config file unavailable"<<endl;
	//	return false;
	//}
	//wstring tmp,file;
	//wchar_t c;
	//int kb,kc,kf,ks,kt,posBegin,posEnd;
	//GLfloat scale=1.0f,temp;
	//texture *tex=NULL;
	//object3DS *object=new object3DS();
	//while (!configFile.eof())
	//{
	//	tmp.clear();
	//	configFile>>c;
	//	while (!configFile.eof()&&(c!='\n'))
	//	{
	//		tmp+=c;
	//		configFile.get((wchar_t &)c);
	//	}
	//	try
	//	{
	//		kb=swscanf(tmp.c_str(),L"V = (%f, %f, %f)", &tempVertex.coordinate[0], &tempVertex.coordinate[1], &tempVertex.coordinate[2]);
	//		if (kb==3)
	//		{
	//			center.coordinate[0]=tempVertex.coordinate[0]; center.coordinate[1]=tempVertex.coordinate[1]; center.coordinate[2]=tempVertex.coordinate[2];
	//		}
	//		kc=swscanf(tmp.c_str(),L"C = (%f, %f, %f)", &tempVertex.color[0], &tempVertex.color[1], &tempVertex.color[2]);
	//		if (kc==3)
	//		{
	//			center.color[0]=tempVertex.color[0]; center.color[1]=tempVertex.color[1]; center.color[2]=tempVertex.color[2];
	//		}
	//		kt=swscanf(tmp.c_str(),L"T = \"%c\"", &c);
	//		if (kt==1)
	//		{
	//			posBegin=tmp.find(L"T = \"")+5;
	//			posEnd=tmp.rfind(L'"');
	//			file=tmp.substr(posBegin,posEnd-posBegin);
	//			glActiveTexture(GL_TEXTURE0);
	//			
	//			if (tex)
	//			{
	//				delete tex;
	//				tex=NULL;
	//			};
	//			tex=new texture();
	//			tex->load(file,true,true,true);
	//		}
	//		ks=swscanf(tmp.c_str(),L"S = (%f)", &temp);
	//		if (ks==1)
	//		{
	//			scale=temp;
	//		};
	//		kf=swscanf(tmp.c_str(),L"M = \"%c\"", &c);
	//		if (kf==1)
	//		{
	//			posBegin=tmp.find(L"M = \"")+5;
	//			posEnd=tmp.rfind(L'"');
	//			file=tmp.substr(posBegin,posEnd-posBegin);
	//			object->load(file);
	//			object->setPosition(center);
	//			object->setScale(scale);
	//			if (tex!=NULL)
	//			{
	//				object->copyTex(tex);
	//			}
	//			tex=NULL;
	//			objs.push_back(object);
	//			//delete object;
	//			object=new object3DS();
	//			scale=1.0f;
	//		}
	//	}catch (...)
	//	{
	//	}
	//}
	//if (object)
	//{
	//	delete object;
	//}
	//if (tex)
	//{
	//	delete tex;
	//}
	//return true;
}