logic::CAvatar* CScenariosXmlDao::readAudience(TiXmlElement* pPublicElement) {
		//cout<<"Etiqueta: "<<pPublicElement->Value()<<"\n";

		string id = pPublicElement->Attribute("id");

		string type = "";
		if(pPublicElement->Attribute("type"))
			type = pPublicElement->Attribute("type");

		TiXmlHandle hPublic(pPublicElement);
		TiXmlElement* pPositionElement = hPublic.FirstChild("position").Element();
		TiXmlElement* pOrientationElement = hPublic.FirstChild("orientation").Element();

		float x=0,y=0,z=0;
		pPositionElement->QueryFloatAttribute("x",&x);
		pPositionElement->QueryFloatAttribute("y",&y);
		pPositionElement->QueryFloatAttribute("z",&z);

		float orientation = 0;
		pOrientationElement->QueryFloatAttribute("value",&orientation);

		//cout<<"[ScenariosXmlDao::readScenario] Animado "<<id<<", ["<<x<<", "<<y<<", "<<z<<"], "<<orientation<<"\n";

		logic::CAvatar* audience= new logic::CAvatar("player", id, x, y, z, orientation, true, 10);
		return audience;
	}
	/**
	 * Lee el tag XML static y agrega al escenario la entidad correspondiente
	 * @param pStaticElement
	 * @param scenario
	 */
	logic::CEntity* CScenariosXmlDao::readStaticEntity(TiXmlElement* pStaticElement) {
		TiXmlHandle hStatic(pStaticElement);
		TiXmlElement* pPositionElement = hStatic.FirstChild("position").Element();
		TiXmlElement* pOrientationElement = hStatic.FirstChild("orientation").Element();

		string id = pStaticElement->Attribute("id");

		bool reflect = false;
		logic::tRGBAColor color;
		if(pStaticElement->Attribute("reflect")){
			TiXmlElement* pColorElement = hStatic.FirstChild("color").Element();
			pColorElement->QueryFloatAttribute("r",&color.r);
			pColorElement->QueryFloatAttribute("g",&color.g);
			pColorElement->QueryFloatAttribute("b",&color.b);
			pColorElement->QueryFloatAttribute("a",&color.a);
			//cout<<"[ScenariosXmlDao::readScenario] Elemento: "<<id<<" REFLEJA!!\n";
			reflect = true;
		}

		float x=0,y=0,z=0;
		pPositionElement->QueryFloatAttribute("x",&x);
		pPositionElement->QueryFloatAttribute("y",&y);
		pPositionElement->QueryFloatAttribute("z",&z);

		float orientation = 0;
		pOrientationElement->QueryFloatAttribute("value",&orientation);

		//cout<<"[ScenariosXmlDao::readScenario]Entidad "<<id<<", ["<<x<<", "<<y<<", "<<z<<"], "<<orientation<<"\n";

		logic::CEntity* entity = new logic::CEntity(id, x, y, z, orientation, true);
		entity->setReflection(reflect);
		entity->setColor(color);

		return entity;
	}
Example #3
0
void YafFile::processLights(TiXmlElement* lights)
{
    float location[4], ambient[4], diffuse[4], specular[4];
    float angle = 0, exponent = 0, direction[3];
    bool enabled;
    string type;
    char* id;
    Light* light;
    TiXmlElement* element = lights->FirstChildElement();
    while(element!=NULL)
    {
        element->QueryBoolAttribute("enabled",&enabled);
        id = (char*)element->Attribute("id");
        read3Float("location", element, location[0], location[1], location[2]);
        read4Float("ambient", element, ambient[0], ambient[1], ambient[2],
                   ambient[3]);
        read4Float("diffuse", element, diffuse[0], diffuse[1], diffuse[2],
                   diffuse[3]);
        read4Float("specular", element, specular[0], specular[1], specular[2],
                   specular[3]);
        if(element->Attribute("angle")!=NULL)
        {
            type="spot";
            element->QueryFloatAttribute("angle", &angle);
            element->QueryFloatAttribute("exponent", &exponent);
            read3Float("direction", element, direction[0], direction[1],
                       direction[2]);
        }
        light = new Light(id,enabled,type,location,ambient,diffuse,specular,angle,exponent,direction);
        this->sceneLights.push_back(light);
        element=element->NextSiblingElement();
    }
}
	logic::CQuizShowHost* CScenariosXmlDao::readHost(TiXmlElement* pHostElement) {
		//cout<<"Etiqueta: "<<pHostElement->Value()<<"\n";

		string id = pHostElement->Attribute("id");

		string type = "";
		if(pHostElement->Attribute("type"))
			type = pHostElement->Attribute("type");

		TiXmlHandle hHost(pHostElement);
		TiXmlElement* pPositionElement = hHost.FirstChild("position").Element();
		TiXmlElement* pOrientationElement = hHost.FirstChild("orientation").Element();

		float x=0,y=0,z=0;
		pPositionElement->QueryFloatAttribute("x",&x);
		pPositionElement->QueryFloatAttribute("y",&y);
		pPositionElement->QueryFloatAttribute("z",&z);

		float orientation = 0;
		pOrientationElement->QueryFloatAttribute("value",&orientation);

		//cout<<"[ScenariosXmlDao::readScenario] Animado "<<id<<", ["<<x<<", "<<y<<", "<<z<<"], "<<orientation<<"\n";

		logic::CQuizShowHost* host= new logic::CQuizShowHost(id, id, x, y, z, orientation, true, 9);
		return host;
	}
	logic::CScreen* CScenariosXmlDao::readScreen(TiXmlElement* pScreenElement) {
		TiXmlHandle hScreen(pScreenElement);
		TiXmlElement* pPositionElement = hScreen.FirstChild("position").Element();
		TiXmlElement* pOrientationElement = hScreen.FirstChild("orientation").Element();
		TiXmlElement* pSkinsElement = hScreen.FirstChild("skins").Element();

		string id = pScreenElement->Attribute("id");

		float interval = 0;
		pSkinsElement->QueryFloatAttribute("interval", &interval);

		float x=0,y=0,z=0;
		pPositionElement->QueryFloatAttribute("x",&x);
		pPositionElement->QueryFloatAttribute("y",&y);
		pPositionElement->QueryFloatAttribute("z",&z);

		float orientation = 0;
		pOrientationElement->QueryFloatAttribute("value",&orientation);

		vector<string> skinList = readSkins(pSkinsElement);

		//cout<<"[ScenariosXmlDao::readScreen]Entidad "<<id<<", ["<<x<<", "<<y<<", "<<z<<"], "<<orientation<<"\n";

		logic::CScreen* screen = new logic::CScreen(id, x, y, z, orientation, true);
		screen->setSkinList(skinList);
		screen->setInterval(interval);

		return screen;

	}
Example #6
0
bool CTextureAtlas::Load()
{
    BEATS_ASSERT(!IsLoaded());

    TString fileext = CFilePathTool::GetInstance()->Extension(GetFilePath().c_str());
    if(fileext == _T(".xml"))
    {
        TiXmlDocument doc;
        CSerializer serializer;
        CFilePathTool::GetInstance()->LoadFile(&serializer, GetFilePath().c_str(), _T("rb"));
        if (serializer.GetWritePos() != serializer.GetReadPos())
        {
            doc.Parse((char*)serializer.GetReadPtr());
        }
        TiXmlElement *root = doc.RootElement();
        BEATS_ASSERT(root && strcmp(root->Value(), "Imageset") == 0, 
            _T("TextureAtlas file %s not found or incorrect!"), GetFilePath().c_str());

        const char *textureFile = root->Attribute("Imagefile");
        BEATS_ASSERT(textureFile);
        TCHAR szNameBuffer[MAX_PATH];
        CStringHelper::GetInstance()->ConvertToTCHAR(textureFile, szNameBuffer, MAX_PATH);
        m_texture = CResourceManager::GetInstance()->GetResource<CTexture>(szNameBuffer);
        kmVec2 size;
        kmVec2 point;
        TString strName;
        for(TiXmlElement *elemImage = root->FirstChildElement("Image");
            elemImage != nullptr; elemImage = elemImage->NextSiblingElement("Image"))
        {
            const char *name = elemImage->Attribute("Name");
            BEATS_ASSERT(name);
            kmVec2Fill(&point, 0.f, 0.f);
            kmVec2Fill(&size, 0.f, 0.f);
            elemImage->QueryFloatAttribute("XPos", &point.x);
            elemImage->QueryFloatAttribute("YPos", &point.y);
            elemImage->QueryFloatAttribute("Width", &size.x);
            elemImage->QueryFloatAttribute("Height", &size.y);

            CStringHelper::GetInstance()->ConvertToTCHAR(name, szNameBuffer, MAX_PATH);
            strName.assign(szNameBuffer);
            CreateTextureFrag(strName, point, size);
        }
    }
    else
    {
        m_texture = CResourceManager::GetInstance()->GetResource<CTexture>(GetFilePath());
    }

    m_name = CFilePathTool::GetInstance()->FileName(GetFilePath().c_str());
    super::Load();
    return true;
}
Example #7
0
/**
 *	@method PigManager::loadLevel()
 *	@desc   parse the current level xml and instantiate the pigs in it
 */
void PigManager::loadLevel(TiXmlElement* levelPigElement)
{
	if (numPigs > 0)
	{
		shutdown();
	}

	numPigs = 0;
	TiXmlElement* levelPig = levelPigElement->FirstChildElement();
	while (levelPig != NULL)
	{
		numPigs++;
		levelPig = levelPig->NextSiblingElement();
	}

	pigList = new EnemyPig*[numPigs];
	int i = 0;
	int x, y;
	float wid, ht;

	levelPig = levelPigElement->FirstChildElement();
	ObjectData currentPigData;

	while (levelPig != NULL)
	{
		const char* currentBlockType = levelPig->Attribute("type");
		int j;
		for (j = 0; j < totalPossiblePigs; j++)
		{
			if (strcmp(currentBlockType, allPigsData[j].objectType) == 0)
			{
				currentPigData = allPigsData[j];
				break;
			}
		}
		assert(j < totalPossiblePigs);

		levelPig->QueryIntAttribute("x", &x);
		levelPig->QueryIntAttribute("y", &y);
		levelPig->QueryFloatAttribute("wid", &wid);
		levelPig->QueryFloatAttribute("ht", &ht);

		pigList[i] = new EnemyPig();
		pigList[i]->init(x, y, wid, currentPigData);

		levelPig = levelPig->NextSiblingElement();
		i++;
	}

	CGame::GetInstance()->setPigCount(numPigs);

}
Example #8
0
void StatTracker::Load ( const char* path )
{
	TiXmlDocument doc;

	if ( doc.LoadFile ( path ) == false )
	{
		Reset();
		return;
	}

	TiXmlElement* pRoot = doc.RootElement ();

	if ( pRoot == nullptr )
		return;

	TiXmlElement* pTime = pRoot->FirstChildElement ( "Time" );

	pTime->QueryFloatAttribute	( "Total" , &m_fTimePlayed);
	pTime->QueryFloatAttribute	 ( "Build" , &m_fBuildPhaseTime);
	pTime->QueryFloatAttribute	( "Survival" , &m_fSurvivalTime);

	TiXmlElement* pDistance = pRoot->FirstChildElement ( "General" );

	pDistance->QueryFloatAttribute	 ( "Walking" , &m_fDistanceWalked);
	pDistance->Attribute ( "Rounds" , (int *)&m_uRoundsSurvived);
	pDistance->Attribute ( "RoundSpree" , (int *)&m_uConsecutiveRoundsSurvived);

	TiXmlElement* pViolence = pRoot->FirstChildElement ( "Violence" );

	pViolence->Attribute ( "Kills" , (int *)&m_uTotalKills);
	pViolence->QueryFloatAttribute	 ( "Blood" , &m_fBloodSpilled);
	pViolence->Attribute ( "Grenades" , (int *)&m_uGrenadesThrown);
	pViolence->Attribute ( "TotalShots" , (int *)&m_uTotalShotsFired);
	pViolence->Attribute ( "MachineGun" , (int *)&m_uMachineGunBullets);
	pViolence->Attribute ( "Shotgun" , (int *)&m_uShotgunShells);
	pViolence->Attribute ( "RPG" , (int *)&m_uRPGRounds);
	pViolence->Attribute ( "HatTrick" , (int *)&m_uHatTrickShots);

	TiXmlElement* pExchange = pRoot->FirstChildElement ( "Exchange" );

	pExchange->Attribute ( "WallsPlaced" , (int *)&m_uWallsPlaced);
	pExchange->Attribute ( "WallsPickedUp" , (int *)&m_uWallsPickedUp);
	pExchange->Attribute ( "WindowsPlaced" , (int *)&m_uWindowsPlaced);
	pExchange->Attribute ( "WindowsPickedUp" , (int *)&m_uWindowsPickedUp);
	pExchange->Attribute ( "TowersBought" , (int *)&m_uTowersBought);
	pExchange->Attribute ( "TowersSold" , (int *)&m_uTowersSold);
	pExchange->Attribute ( "TrapsBought" , (int *)&m_uTrapsBought);
	pExchange->Attribute ( "TrapsSold" , (int *)&m_uTrapsSold);
	pExchange->Attribute ( "Money" , (int *)&m_uMoneySpent);

}
Example #9
0
std::vector<osg::Vec3f> loadXMLFile(const char * name){
	TiXmlDocument * document = new TiXmlDocument(name);
	int element_counter = 1; ///< counter used to report xml reading errors
	
	if(!document->LoadFile()){
  		std::cerr << "[ReadXML] Loading Error : " << document->ErrorDesc() << std::endl;
	}
	
	std::vector<osg::Vec3f> result;
	float x,y,z;
	int reading_result;
	
	TiXmlElement * xmlPoint = document->FirstChildElement();
	
	while (xmlPoint){
		
		reading_result = xmlPoint->QueryFloatAttribute("x",&x);
		if(reading_result == TIXML_WRONG_TYPE){
			std::cerr << "[ReadXML] Reading error at element n°"<< element_counter <<": attribute x is not a float" << std::endl;
		}
		else if(reading_result == TIXML_NO_ATTRIBUTE ){
			std::cerr << "[ReadXML] Reading error at element n°"<< element_counter <<": attribute x doesn't exist" << std::endl;
		}
		
		reading_result = xmlPoint->QueryFloatAttribute("y",&y);
		if(reading_result == TIXML_WRONG_TYPE){
			std::cerr << "[ReadXML] Reading error at element n°"<< element_counter <<": attribute y is not a float" << std::endl;
		}
		else if(reading_result == TIXML_NO_ATTRIBUTE ){
			std::cerr << "[ReadXML] Reading error at element n°"<< element_counter <<": attribute y doesn't exist" << std::endl;
		}
		
		reading_result = xmlPoint->QueryFloatAttribute("z",&z);
		if(reading_result == TIXML_WRONG_TYPE){
			std::cerr << "[ReadXML] Reading error at element n°"<< element_counter <<": attribute z is not a float" << std::endl;
		}
		else if(reading_result == TIXML_NO_ATTRIBUTE ){
			std::cerr << "[ReadXML] Reading error at element n°"<< element_counter <<": attribute z doesn't exist" << std::endl;
		}
		
		osg::Vec3f vec3Point(x,y,z);// = new std::vector<float>();
		/*vec3Point.push_back(x);
		vec3Point.push_back(y);
		vec3Point.push_back(z);*/
		result.push_back(vec3Point);
		
		xmlPoint = xmlPoint->NextSiblingElement();
		element_counter++;
	}
	return result;
}
Example #10
0
void Poof::init(TiXmlElement* poofElement)
{
	int totalPoofFrames = 0;
	TiXmlElement* poofSprite = poofElement->FirstChildElement()->FirstChildElement();
	while (poofSprite != NULL)
	{
		poofSprite = poofSprite->NextSiblingElement();
		totalPoofFrames++;
	}

	poofData.numSprites = totalPoofFrames;
	poofData.spriteData = (SpriteStateData *)malloc(poofData.numSprites * sizeof(SpriteStateData));

	int j = 0;
	poofSprite = poofElement->FirstChildElement()->FirstChildElement();
	while (poofSprite != NULL)
	{
		poofData.spriteData[j].spriteState = poofSprite->Attribute("state");
		poofSprite->QueryFloatAttribute("xPosLeft", &poofData.spriteData[j].uLeft);
		poofSprite->QueryFloatAttribute("xPosRight", &poofData.spriteData[j].uRight);
		poofSprite->QueryFloatAttribute("yPosTop", &poofData.spriteData[j].vTop);
		poofSprite->QueryFloatAttribute("yPosBottom", &poofData.spriteData[j].vBottom);

		poofSprite = poofSprite->NextSiblingElement();
		j++;
	}

	float imageWidth, imageHeight;
	poofElement->QueryFloatAttribute("imageWidth", &imageWidth);
	poofElement->QueryFloatAttribute("imageHeight", &imageHeight);

	poofRenderer = new Renderer();
	poofRenderer->init(poofElement->Attribute("src"), totalPoofFrames, imageWidth, imageHeight);

	int k = 0;

	for (j = 0; j < poofData.numSprites; j++)
	{
		poofRenderer->setUTextureLeft(k, poofData.spriteData[j].uLeft);
		poofRenderer->setUTextureRight(k, poofData.spriteData[j].uRight);
		poofRenderer->setVTextureTop(k, poofData.spriteData[j].vTop);
		poofRenderer->setVTextureBottom(k, poofData.spriteData[j].vBottom);

		poofData.spriteData[j].rendererIndex = k;

		k++;
	}
}
Example #11
0
void YafFile::processCameras(TiXmlElement* camerasElement)
{
    char* rootId = (char*)camerasElement->Attribute("initial");
    char* id;
    string testRoot=rootId;
    TiXmlElement* orthoElement = camerasElement->FirstChildElement("ortho");
    TiXmlElement* perspectiveElement = camerasElement->FirstChildElement("perspective");
    CGFcamera* cam;
    float near, far, left, right, top, bottom;
    unsigned int i = 0;
    while(orthoElement != NULL)
    {
        orthoElement->QueryFloatAttribute("near", &near);
        orthoElement->QueryFloatAttribute("far", &far);
        orthoElement->QueryFloatAttribute("left", &left);
        orthoElement->QueryFloatAttribute("right", &right);
        orthoElement->QueryFloatAttribute("top", &top);
        orthoElement->QueryFloatAttribute("bottom", &bottom);
        id=(char*)orthoElement->Attribute("id");
        cam = new OrthoCamera(near, far, left, right, top, bottom,id==rootId);
        sceneCameras.push_back(make_pair(id,cam));
        orthoElement = orthoElement->NextSiblingElement("ortho");
        string test = id;
        if(test==testRoot)
        {
            camera=i;
        }
        else
            i++;
    }

    while(perspectiveElement != NULL)
    {
        float position[3],target[3],angle;
        perspectiveElement->QueryFloatAttribute("near", &near);
        perspectiveElement->QueryFloatAttribute("far", &far);
        perspectiveElement->QueryFloatAttribute("angle", &angle);
        read3Float("pos", perspectiveElement, position[0], position[1], position[2]);
        read3Float("target", perspectiveElement, target[0], target[1], target[2]);
        id=(char*)perspectiveElement->Attribute("id");
        cam = new PerspectiveCamera(id==rootId,near, far, angle, position[0], position[1],
                                    position[2], target[0], target[1], target[2]);
        sceneCameras.push_back(make_pair(id,cam));
        string test = id;
        if(test==testRoot)
        {
            camera=i;
        }
        else
            i++;
        perspectiveElement = perspectiveElement->NextSiblingElement("perspective");
    }
}
Example #12
0
void YafFile::processAnimations(TiXmlElement* animationsElement)
{
    TiXmlElement* element = animationsElement->FirstChildElement("animation");
    while(element!=NULL)
    {
        string id = element->Attribute("id"),type=element->Attribute("type");
        float span;
        element->QueryFloatAttribute("span",&span);
        vector<Point> points;
        Point p;
        TiXmlElement* child = element->FirstChildElement("controlpoint");
        while(child!=NULL)
        {
            child->QueryFloatAttribute("xx", &p.x);
            child->QueryFloatAttribute("yy",&p.y);
            child->QueryFloatAttribute("zz",&p.z);
            points.push_back(p);
            child=child->NextSiblingElement();
        }
        Animation* animation = new Animation(span,type,points);
        animations[id]=animation;
        element=element->NextSiblingElement();
    }
}
Example #13
0
		SCSerror SCSanimation::OpenAnimation (const SCSstring& rsFilename)
		{
			TiXmlDocument kXmlFile(rsFilename);
			TiXmlHandle hkRoot(0);
			TiXmlElement* pkElement;
			TiXmlHandle hkXml(0);
			SCSint iPosX, iPosY;
			SCSint iSizeX, iSizeY;
			SCSint iRepeat;
			SCSfloat fDuration;

			Init();

			if (!kXmlFile.LoadFile()) return scsHandleError(SCS_ERROR_GRAPHICS | SCS_ERROR_OPEN | SCS_ERROR_ANIMATION);
			hkXml = TiXmlHandle(&kXmlFile);
			pkElement = hkXml.FirstChild("animation").Element();
			if (!pkElement) return scsHandleError(SCS_ERROR_GRAPHICS | SCS_ERROR_OPEN | SCS_ERROR_ANIMATION | SCS_ERROR_NULL);
			hkRoot = TiXmlHandle(pkElement);

			SCSstring sTexture = pkElement->Attribute("resource");
			pkElement->QueryIntAttribute("width", &iSizeX);
			pkElement->QueryIntAttribute("height", &iSizeY);
			pkElement->QueryIntAttribute("repeat", &iRepeat);

			m_pkTexture = SCStextures::Singleton()->GetTexture(sTexture);
			if (!m_pkTexture) return scsHandleError(SCS_ERROR_GRAPHICS | SCS_ERROR_GET | SCS_ERROR_TEXTURE | SCS_ERROR_NULL);
			m_kFrameSize = SCSvector2(iSizeX, iSizeY);
			m_iRepeat = iRepeat;

			pkElement = hkRoot.FirstChild("frame").Element();
			while (pkElement) {
				// load frame
				pkElement->QueryIntAttribute("x", &iPosX);
				pkElement->QueryIntAttribute("y", &iPosY);
				pkElement->QueryFloatAttribute("duration", &fDuration);
				AddFrame(SCSvector2(iPosX, iPosY), fDuration);
				// find next element
				pkElement = pkElement->NextSiblingElement("frame");
			}
			return SCS_ERROR_NONE;
		}
bool SimulationData_CudaSystem::loadConfiguration(const char* filename)
{
  TiXmlDocument doc(filename);
  if (doc.LoadFile()){
	TiXmlHandle hDoc(&doc);
	TiXmlElement* elem;
	TiXmlElement* hRoot = doc.FirstChildElement( "Cuda_System_Material" );
        elem=hDoc.FirstChildElement().Element();	
	hRoot->QueryFloatAttribute("visualizationRadius",&this->particleRadius);
	hRoot->QueryFloatAttribute("particle_mass",&this->particleMass);
	hRoot->QueryFloatAttribute("interactionRadius",&this->interactionRadius);
	hRoot->QueryFloatAttribute("spring",&this->spring);
	hRoot->QueryFloatAttribute("damping",&this->damping);
	hRoot->QueryFloatAttribute("shear",&this->shear);
	hRoot->QueryFloatAttribute("attraction",&this->attraction);
	return true;
    }
    else
	return false;
}
	/**
	 * Lee el tag XML multimedia y devuelve el objeto correspondiente
	 * @param pMultFurElement
	 * @return
	 */
	logic::CMultimediaFurniture* CScenariosXmlDao::readMultFur(TiXmlElement* pMultFurElement) {
		TiXmlHandle hMultFur(pMultFurElement);
		TiXmlElement* pPositionElement = hMultFur.FirstChild("position").Element();
		TiXmlElement* pOrientationElement = hMultFur.FirstChild("orientation").Element();
		TiXmlElement* pSkinsElement = hMultFur.FirstChild("skins").Element();

		string id = pMultFurElement->Attribute("id");

		bool reflect = false;
		logic::tRGBAColor color;
		if(pMultFurElement->Attribute("reflect")){
			TiXmlElement* pColorElement = hMultFur.FirstChild("color").Element();
			pColorElement->QueryFloatAttribute("r",&color.r);
			pColorElement->QueryFloatAttribute("g",&color.g);
			pColorElement->QueryFloatAttribute("b",&color.b);
			pColorElement->QueryFloatAttribute("a",&color.a);
			//cout<<"[ScenariosXmlDao::readScenario] Elemento: "<<id<<" REFLEJA!!\n";
			reflect = true;
		}

		float interval = 0;
		pSkinsElement->QueryFloatAttribute("interval", &interval);


		float x=0,y=0,z=0;
		pPositionElement->QueryFloatAttribute("x",&x);
		pPositionElement->QueryFloatAttribute("y",&y);
		pPositionElement->QueryFloatAttribute("z",&z);

		float orientation = 0;
		pOrientationElement->QueryFloatAttribute("value",&orientation);

		vector<string> skinList = readSkins(pSkinsElement);

		logic::CMultimediaFurniture* mult = new logic::CMultimediaFurniture(id, x, y, z, orientation, true, 1.0);
		mult->setInterval(interval);
		mult->setSkinList(skinList);
		mult->setReflection(reflect);
		mult->setColor(color);
		return mult;
	}
Example #16
0
bool ETHEntityProperties::ReadFromXMLFile(TiXmlElement *pElement)
{
	pElement->QueryIntAttribute(GS_L("type"), (int*)&type);

	int nStaticEntity = static_cast<int>(staticEntity);
	pElement->QueryIntAttribute(GS_L("static"), &nStaticEntity);
	staticEntity = static_cast<ETH_BOOL>(nStaticEntity);

	int nApplyLight = static_cast<int>(applyLight);
	pElement->QueryIntAttribute(GS_L("applyLight"), &nApplyLight);
	applyLight = static_cast<ETH_BOOL>(nApplyLight);

	int nCastShadow = static_cast<int>(castShadow);
	pElement->QueryIntAttribute(GS_L("castShadow"), &nCastShadow);
	castShadow = static_cast<ETH_BOOL>(nCastShadow);

	int nHideFromSceneEditor = static_cast<int>(hideFromSceneEditor);
	pElement->QueryIntAttribute(GS_L("hideFromSceneEditor"), &nHideFromSceneEditor);
	hideFromSceneEditor = static_cast<ETH_BOOL>(nHideFromSceneEditor);

	pElement->QueryIntAttribute(GS_L("shape"), (int*)&shape);
	pElement->QueryIntAttribute(GS_L("blendMode"), (int*)&blendMode);
	pElement->QueryFloatAttribute(GS_L("layerDepth"), &layerDepth);
	pElement->QueryFloatAttribute(GS_L("soundVolume"), &soundVolume);
	pElement->QueryFloatAttribute(GS_L("parallaxIntensity"), &parallaxIntensity);

	if (applyLight)
	{
		pElement->QueryFloatAttribute(GS_L("specularPower"), &specularPower);
		pElement->QueryFloatAttribute(GS_L("specularBrightness"), &specularBrightness);
	}

	if (castShadow)
	{
		pElement->QueryFloatAttribute(GS_L("shadowScale"), &shadowScale);
		pElement->QueryFloatAttribute(GS_L("shadowLengthScale"), &shadowLengthScale);
		pElement->QueryFloatAttribute(GS_L("shadowOpacity"), &shadowOpacity);
	}

	if (shape != BS_NONE)
	{
		int nSensor = static_cast<int>(sensor);
		pElement->QueryIntAttribute(GS_L("sensor"), &nSensor);
		sensor = static_cast<ETH_BOOL>(nSensor);

		int nFixedRotation = static_cast<int>(fixedRotation);
		pElement->QueryIntAttribute(GS_L("fixedRotation"), &nFixedRotation);
		fixedRotation = static_cast<ETH_BOOL>(nFixedRotation);

		int nBullet = static_cast<int>(bullet);
		pElement->QueryIntAttribute(GS_L("bullet"), &nBullet);
		bullet = static_cast<ETH_BOOL>(nBullet);

		pElement->QueryFloatAttribute(GS_L("friction"), &friction);
		pElement->QueryFloatAttribute(GS_L("density"), &density);
		pElement->QueryFloatAttribute(GS_L("gravityScale"), &gravityScale);
		pElement->QueryFloatAttribute(GS_L("restitution"), &restitution);
	}

	TiXmlElement *pIter;
	TiXmlNode *pNode;

	pNode = pElement->FirstChild(GS_L("EmissiveColor"));
	if (pNode)
	{
		pIter = pNode->ToElement();
		if (pIter)
		{
			pIter->QueryFloatAttribute(GS_L("r"), &emissiveColor.x);
			pIter->QueryFloatAttribute(GS_L("g"), &emissiveColor.y);
			pIter->QueryFloatAttribute(GS_L("b"), &emissiveColor.z);
			pIter->QueryFloatAttribute(GS_L("a"), &emissiveColor.w);
		}
	}

	pNode = pElement->FirstChild(GS_L("SpriteCut"));
	if (pNode)
	{
		pIter = pNode->ToElement();
		if (pIter)
		{
			pIter->QueryIntAttribute(GS_L("x"), &spriteCut.x);
			pIter->QueryIntAttribute(GS_L("y"), &spriteCut.y);
		}
	}

	pNode = pElement->FirstChild(GS_L("Scale"));
	if (pNode)
	{
		pIter = pNode->ToElement();
		if (pIter)
		{
			pIter->QueryFloatAttribute(GS_L("x"), &scale.x);
			pIter->QueryFloatAttribute(GS_L("y"), &scale.y);
		}
	}

	pNode = pElement->FirstChild(GS_L("PivotAdjust"));
	if (pNode)
	{
		pIter = pNode->ToElement();
		if (pIter)
		{
			pIter->QueryFloatAttribute(GS_L("x"), &pivotAdjust.x);
			pIter->QueryFloatAttribute(GS_L("y"), &pivotAdjust.y);
		}
	}

	pNode = pElement->FirstChild(GS_L("Sprite"));
	if (pNode)
	{
		pIter = pNode->ToElement();
		if (pIter)
		{
			spriteFile = pIter->GetText();
		}
	}

	pNode = pElement->FirstChild(GS_L("Normal"));
	if (pNode)
	{
		pIter = pNode->ToElement();
		if (pIter)
		{
			normalFile = pIter->GetText();
		}
	}

	pNode = pElement->FirstChild(GS_L("Gloss"));
	if (pNode)
	{
		pIter = pNode->ToElement();
		if (pIter)
		{
			glossFile = pIter->GetText();
		}
	}

	pNode = pElement->FirstChild(GS_L("Particles"));
	if (pNode)
	{
		TiXmlElement *pParticles = pNode->ToElement();
		if (pParticles)
		{
			pNode = pParticles->FirstChild(GS_L("ParticleSystem"));
			if (pNode)
			{
				TiXmlElement *pParticleIter = pNode->ToElement();
				if (pParticleIter)
				{
					// TODO: use unlimited amount of systems 
					for (std::size_t t = 0; t < ETH_MAX_PARTICLE_SYS_PER_ENTITY; t++)
					{
						if (pParticleIter)
						{
							boost::shared_ptr<ETHParticleSystem> newSystem = boost::shared_ptr<ETHParticleSystem>(new ETHParticleSystem);
							newSystem->ReadFromXMLFile(pParticleIter);
							if (newSystem->nParticles > 0)
							{
								particleSystems.push_back(newSystem);
							}
							pParticleIter = pParticleIter->NextSiblingElement();
						}
					}
				}
			}
		}
	}

	pNode = pElement->FirstChild(GS_L("Light"));
	if (pNode)
	{
		TiXmlElement *pLight = pNode->ToElement();
		if (pLight)
		{
			boost::shared_ptr<ETHLight> newLight = boost::shared_ptr<ETHLight>(new ETHLight(true));
			newLight->ReadFromXMLFile(pLight);
			if (newLight->IsActive() && newLight->range > 0.0f)
			{
				light = newLight;
				// forces the light 'static' flag to be the same as its owner's
				light->staticLight = staticEntity;
			}
		}
	}

	{
		int nCollidable = 1;
		const int r = pElement->QueryIntAttribute(GS_L("collidable"), &nCollidable);
		if (nCollidable || r == TIXML_NO_ATTRIBUTE)
		{
			pNode = pElement->FirstChild(GS_L("Collision"));
			if (pNode)
			{
				collision = boost::shared_ptr<ETHCollisionBox>(new ETHCollisionBox);
				TiXmlElement *pCollision = pNode->ToElement();
				if (pCollision)
				{
					collision->ReadFromXMLFile(pCollision);
				}

				// if it's a legacy entity, it may have a collision body in its XML even though it is not collidable
				if (collision->size == Vector3(0, 0, 0))
				{
					collision.reset();
				}
				
				{
					TiXmlNode *pPolygonNode = pNode->FirstChild(GS_L("Polygon"));
					if (pPolygonNode)
					{
						pIter = pPolygonNode->ToElement();
						if (pIter)
						{
							polygon = ETHPolygonPtr(new ETHPolygon(pIter->GetText()));
						}
					}
					else
					{
						TiXmlNode *pCompoundNode = pNode->FirstChild(GS_L("Compound"));
						if (pCompoundNode)
						{
							pIter = pCompoundNode->ToElement();
							if (pIter)
							{
								compoundShape = ETHCompoundShapePtr(new ETHCompoundShape(pIter->GetText()));
							}
						}
					}
				}
				{
					TiXmlNode *pJointsNode = pNode->FirstChild(GS_L("Joints"));
					if (pJointsNode)
					{
						pIter = pJointsNode->ToElement();
						if (pIter)
						{
							enmlJointDefinitions = pIter->GetText();
						}
					}

				}
			}
		}
	}
	ReadDataFromXMLFile(pElement);
	return true;
}
Example #17
0
bool ETHEntity::ReadFromXMLFile(TiXmlElement *pElement)
{
	pElement->QueryIntAttribute(GS_L("id"), &m_id);
	pElement->QueryFloatAttribute(GS_L("shadowZ"), &m_shadowZ);

	int nHide = 0;
	pElement->QueryIntAttribute(GS_L("hide"), &nHide);
	m_hide = (!nHide) ? ETH_FALSE : ETH_TRUE;

	int signedSpriteFrame = 0;
	pElement->QueryIntAttribute(GS_L("spriteFrame"), &signedSpriteFrame);
	m_spriteFrame = static_cast<unsigned int>(signedSpriteFrame);

	TiXmlNode *pNode;
	TiXmlElement *pStringElement;

	pNode = pElement->FirstChild(GS_L("EntityName"));
	if (pNode)
	{
		pStringElement = pNode->ToElement();
		if (pStringElement)
		{
			m_properties.entityName = pStringElement->GetText();
		}
	}

	TiXmlElement *pIter;
	pNode = pElement->FirstChild(GS_L("Color"));
	if (pNode)
	{
		pIter = pNode->ToElement();
		if (pIter)
		{
			pIter->QueryFloatAttribute(GS_L("r"), &m_v4Color.x);
			pIter->QueryFloatAttribute(GS_L("g"), &m_v4Color.y);
			pIter->QueryFloatAttribute(GS_L("b"), &m_v4Color.z);
			pIter->QueryFloatAttribute(GS_L("a"), &m_v4Color.w);
		}
	}

	pNode = pElement->FirstChild(GS_L("Position"));
	if (pNode)
	{
		pIter = pNode->ToElement();
		if (pIter)
		{
			Vector3 pos; float angle = 0.0f;
			pIter->QueryFloatAttribute(GS_L("x"), &pos.x);
			pIter->QueryFloatAttribute(GS_L("y"), &pos.y);
			pIter->QueryFloatAttribute(GS_L("z"), &pos.z);
			pIter->QueryFloatAttribute(GS_L("angle"), &angle);
			m_controller->SetPos(pos);
			m_controller->SetAngle(angle);
		}
	}

	pNode = pElement->FirstChild(GS_L("Entity"));
	if (pNode)
	{
		m_properties.ReadFromXMLFile(pNode->ToElement());
	}
	return true;
}
	bool UIElement::Load(TiXmlNode* x_RootNode){
		//Check it has a base
		TiXmlNode* xNode;
		TiXmlElement * xInfoElement;
		TiXmlNode* xBase = x_RootNode->FirstChild("base");
		if (!xBase){
			Logger::Log("Could not find 'info' Node. \n");
			return false;
		}
		xInfoElement = xBase->ToElement();

	//Define all the BASE variables
		char* buffer;
		buffer = (char*)xInfoElement->Attribute("location");

		if (std::strcmp(buffer,"TOP_LEFT") == 0){
			lPivot = Location::TOP_LEFT;
		}else if (std::strcmp(buffer,"TOP_CENTER") == 0){
			lPivot = Location::TOP_CENTER;
		}else if (std::strcmp(buffer,"TOP_RIGHT") == 0){
			lPivot = Location::TOP_RIGHT;
		}else if (std::strcmp(buffer,"CENTER_LEFT") == 0){
			lPivot = Location::CENTER_LEFT;
		}else if (std::strcmp(buffer,"CENTER_CENTER") == 0){
			lPivot = Location::CENTER_CENTER;
		}else if (std::strcmp(buffer,"CENTER_RIGHT") == 0){
			lPivot = Location::CENTER_RIGHT;
		}else if (std::strcmp(buffer,"BOTTOM_LEFT") == 0){
			lPivot = Location::BOTTOM_LEFT;
		}else if (std::strcmp(buffer,"BOTTOM_CENTER") == 0){
			lPivot = Location::BOTTOM_CENTER;
		}else if (std::strcmp(buffer,"BOTTOM_RIGHT") == 0){
			lPivot = Location::BOTTOM_RIGHT;
		}

		xNode = xBase->FirstChild("Colour");
		if (!xNode){Logger::Log("Could not find 'Colour' Node. \n");return false;}
		xInfoElement = xNode->ToElement();
		glm::vec4 Colour(0);
		xInfoElement->QueryFloatAttribute("r",&Colour.r);
		xInfoElement->QueryFloatAttribute("g",&Colour.g);
		xInfoElement->QueryFloatAttribute("b",&Colour.b);
		xInfoElement->QueryFloatAttribute("a",&Colour.a);
		setColour(Colour);

		xNode = xBase->FirstChild("Position");
		if (!xNode){Logger::Log("Could not find 'Position' Node. \n");return false;}
		xInfoElement = xNode->ToElement();
		glm::vec3 Position(0);
		float Offset = 0;
		xInfoElement->QueryFloatAttribute("x",&Position.x);
		xInfoElement->QueryFloatAttribute("y",&Position.y);
		xInfoElement->QueryFloatAttribute("z",&Position.z);
		xInfoElement->QueryFloatAttribute("o",&Offset);
		setOffset(Offset);
		setTranslate(Position);

		xNode = xBase->FirstChild("Rotation");
		if (!xNode){Logger::Log("Could not find 'Rotation' Node. \n");return false;}
		xInfoElement = xNode->ToElement();
		float Rotation;
		xInfoElement->QueryFloatAttribute("r",&Rotation);
		setRotation(Rotation);

		xNode = xBase->FirstChild("Scale");
		if (!xNode){Logger::Log("Could not find 'Scale' Node. \n");return false;}
		xInfoElement = xNode->ToElement();
		glm::vec2 Scale(0);
		xInfoElement->QueryFloatAttribute("x",&Scale.x);
		xInfoElement->QueryFloatAttribute("y",&Scale.y);
		setScale(Scale);

		xNode = xBase->FirstChild("Size");
		if (!xNode){Logger::Log("Could not find 'Size' Node. \n");return false;}
		xInfoElement = xNode->ToElement();
		glm::vec2 Size(0);
		xInfoElement->QueryFloatAttribute("x",&Size.x);
		xInfoElement->QueryFloatAttribute("y",&Size.y);
		setScale(Size);

		return true;
	}
Example #19
0
bool SceneLoader::loadMaterial()
{
	string id = materialElement->Attribute("id");
	float r, g, b, a, shininess;

	Material* mat = new Material(id);
	materiais.push_back(mat);

	cout<<"\tMaterial ID: "<<id<<endl;

	TiXmlElement* child = materialElement->FirstChildElement();
	while(child != NULL)
	{
		if(strcmp(child->Value(), "emission")==0)
		{
			if(child->QueryFloatAttribute("r", &r) == TIXML_SUCCESS &&
				child->QueryFloatAttribute("g", &g) == TIXML_SUCCESS &&
				child->QueryFloatAttribute("b", &b) == TIXML_SUCCESS &&
				child->QueryFloatAttribute("a", &a) == TIXML_SUCCESS)
			{
				materiais.back()->emission[0] = r;
				materiais.back()->emission[1] = g;
				materiais.back()->emission[2] = b;
				materiais.back()->emission[3] = a;
				cout<<"\t\tEmission R, G, B, A: "<<r<<", "<<g<<", "<<b<<", "<<a<<endl;
			} 
			else
			{
				cout<<"Erro parsing emission de material\n";
				system("pause");
				return false;
			}
		}
		else if(strcmp(child->Value(), "ambient")==0)
		{
			if(child->QueryFloatAttribute("r", &r) == TIXML_SUCCESS &&
				child->QueryFloatAttribute("g", &g) == TIXML_SUCCESS &&
				child->QueryFloatAttribute("b", &b) == TIXML_SUCCESS &&
				child->QueryFloatAttribute("a", &a) == TIXML_SUCCESS)
			{
				materiais.back()->ambient[0] = r;
				materiais.back()->ambient[1] = g;
				materiais.back()->ambient[2] = b;
				materiais.back()->ambient[3] = a;
				cout<<"\t\tAmbient R, G, B, A: "<<r<<", "<<g<<", "<<b<<", "<<a<<endl;
			} 
			else
			{
				cout<<"Erro parsing ambient de material\n";
				system("pause");
				return false;
			}
		}
		else if(strcmp(child->Value(), "diffuse")==0)
		{
			if(child->QueryFloatAttribute("r", &r) == TIXML_SUCCESS &&
				child->QueryFloatAttribute("g", &g) == TIXML_SUCCESS &&
				child->QueryFloatAttribute("b", &b) == TIXML_SUCCESS &&
				child->QueryFloatAttribute("a", &a) == TIXML_SUCCESS)
			{
				materiais.back()->diffuse[0] = r;
				materiais.back()->diffuse[1] = g;
				materiais.back()->diffuse[2] = b;
				materiais.back()->diffuse[3] = a;
				cout<<"\t\tDiffuse R, G, B, A: "<<r<<", "<<g<<", "<<b<<", "<<a<<endl;
			} 
			else
			{
				cout<<"Erro parsing diffuse de material\n";
				system("pause");
				return false;
			}
		}
		else if(strcmp(child->Value(), "specular")==0)
		{
			if(child->QueryFloatAttribute("r", &r) == TIXML_SUCCESS &&
				child->QueryFloatAttribute("g", &g) == TIXML_SUCCESS &&
				child->QueryFloatAttribute("b", &b) == TIXML_SUCCESS &&
				child->QueryFloatAttribute("a", &a) == TIXML_SUCCESS)
			{
				materiais.back()->specular[0] = r;
				materiais.back()->specular[1] = g;
				materiais.back()->specular[2] = b;
				materiais.back()->specular[3] = a;
				cout<<"\t\tSpecular R, G, B, A: "<<r<<", "<<g<<", "<<b<<", "<<a<<endl;
			} 
			else
			{
				cout<<"Erro parsing specular de material\n";
				system("pause");
				return false;
			}
		}
		else if(strcmp(child->Value(), "shininess")==0)
		{
			if(child->QueryFloatAttribute("value", &shininess) == TIXML_SUCCESS)
			{
				materiais.back()->shininess[0] = shininess;
				cout<<"\t\tShininess: "<<shininess<<endl;
			}
			else
			{
				cout<<"Erro parsing shininess de material\n";
				system("pause");
				return false;
			}
		}
		else
		{
			cout<<"Erro parsing material\n";
			system("pause");
			return false;
		}
		child=child->NextSiblingElement();
	}
	return true;
}
Example #20
0
bool SceneLoader::loadLight()
{
	int i_enabled;
	bool enabled;
	string id = lightsElement->Attribute("id");
	lightsElement->QueryIntAttribute("enabled", &i_enabled);
	float r, g, b, a, x, y, z, w;

	if(i_enabled==1)
		enabled=true;
	else if(i_enabled==0)
		enabled=false;
	else
	{
		cout<<"enabled deve ser um valor boleano!\n";
		system("pause");
		return false;
	}

	Light* light = new Light(id, enabled);
	lights.push_back(light);

	cout<<"\tLight ID: "<<id<<", Enabled: ";
	if(enabled)
		cout<<"Sim"<<endl;
	else
		cout<<"Nao"<<endl;


	TiXmlElement* child = lightsElement->FirstChildElement("position");

	while(child)
	{
		if(strcmp(child->Value(), "ambient")==0)
		{
			if(child->QueryFloatAttribute("r", &r) == TIXML_SUCCESS &&
				child->QueryFloatAttribute("g", &g) == TIXML_SUCCESS &&
				child->QueryFloatAttribute("b", &b) == TIXML_SUCCESS &&
				child->QueryFloatAttribute("a", &a) == TIXML_SUCCESS)
			{
				lights.back()->ambient[0] = r;
				lights.back()->ambient[1] = g;
				lights.back()->ambient[2] = b;
				lights.back()->ambient[3] = a;
				cout<<"\t\tAmbient R, G, B, A: "<<r<<", "<<g<<", "<<b<<", "<<a<<endl;
			} 
			else
			{
				cout<<"erro na definicao ambient de "<<id<<endl;
				system("pause");
				return false;
			}
		}
		else if(strcmp(child->Value(), "diffuse")==0)
		{
			if(child->QueryFloatAttribute("r", &r) == TIXML_SUCCESS &&
				child->QueryFloatAttribute("g", &g) == TIXML_SUCCESS &&
				child->QueryFloatAttribute("b", &b) == TIXML_SUCCESS &&
				child->QueryFloatAttribute("a", &a) == TIXML_SUCCESS)
			{
				lights.back()->diffuse[0] = r;
				lights.back()->diffuse[1] = g;
				lights.back()->diffuse[2] = b;
				lights.back()->diffuse[3] = a;
				cout<<"\t\tDiffuse R, G, B, A: "<<r<<", "<<g<<", "<<b<<", "<<a<<endl;
			} 
			else
			{
				cout<<"erro na definicao diffuse de "<<id<<endl;
				system("pause");
				return false;
			}
		}
		else if(strcmp(child->Value(), "specular")==0)
		{
			if(child->QueryFloatAttribute("r", &r) == TIXML_SUCCESS &&
				child->QueryFloatAttribute("g", &g) == TIXML_SUCCESS &&
				child->QueryFloatAttribute("b", &b) == TIXML_SUCCESS &&
				child->QueryFloatAttribute("a", &a) == TIXML_SUCCESS)
			{
				lights.back()->specular[0] = r;
				lights.back()->specular[1] = g;
				lights.back()->specular[2] = b;
				lights.back()->specular[3] = a;
				cout<<"\t\tSpecular R, G, B, A: "<<r<<", "<<g<<", "<<b<<", "<<a<<endl;
			} 
			else
			{
				cout<<"erro na definicao specular de "<<id<<endl;
				system("pause");
				return false;
			}
		}
		else if(strcmp(child->Value(), "position")==0)
		{
			if(child->QueryFloatAttribute("x", &x) == TIXML_SUCCESS &&
				child->QueryFloatAttribute("y", &y) == TIXML_SUCCESS &&
				child->QueryFloatAttribute("z", &z) == TIXML_SUCCESS &&
				child->QueryFloatAttribute("w", &w) == TIXML_SUCCESS)
			{
				lights.back()->position[0] = x;
				lights.back()->position[1] = y;
				lights.back()->position[2] = z;
				lights.back()->position[3] = w;
				cout<<"\t\tPosition X, Y, Z, W: "<<x<<", "<<y<<", "<<z<<", "<<w<<endl;
			} 
			else
			{
				cout<<"erro na definicao position de "<<id<<endl;
				system("pause");
				return false;
			}
		}
		else
		{
			cout<<"Erro parsing light id: "<<id<<endl;
			system("pause");
			return false;
		}
		child=child->NextSiblingElement();
	}
	return true;
}
// A font is specified by two files: a TGA file with the rendered 
// chars for the font, and a XML file which contains global info 
// about the font and the texture coordinates and width of each char
// The parameter fontName is the filename without extension. 
// It is assumed that the files are "fontName.xml" and "fontName.tga"
bool
VSFontLib::load(std::string fontName) 
{
	// Test if image file exists
	FILE *fp;
	std::string s;
	errno_t err = -1;

	s = fontName + ".tga";
	err = fopen_s(&fp, s.c_str(), "r");
	if (fp == NULL || err == -1)
	{
		printf("Unable to find font texture: %s", s.c_str());
		return false;
	}
	
	mFontTex = loadRGBATexture(s, true, false, GL_LINEAR, GL_REPEAT);

	s = fontName + ".xml";
	TiXmlDocument doc(s.c_str());
	bool loadOK = doc.LoadFile();

	if (!loadOK) {
		printf("Problem reading the XML font definition file: %s", s.c_str());
		return false;
	}
	TiXmlHandle hDoc(&doc);
	TiXmlHandle hRoot(0);
	TiXmlElement *pElem;

	pElem = hDoc.FirstChildElement().Element();
	if (0 == pElem)
		return false;

	hRoot = TiXmlHandle(pElem);
	
	pElem->QueryIntAttribute("numchars",&mNumChars);

	if (mNumChars == 0)
		return false;

	hRoot = hRoot.FirstChild("characters");
	pElem = hRoot.FirstChild("chardata").Element();
	if (pElem)
		pElem->QueryIntAttribute("hgt",&mHeight);
	VSFLChar aChar;
	int charCode, numChars = 0;
	for(; 0 != pElem; pElem = pElem->NextSiblingElement(), ++numChars) {

		pElem->QueryIntAttribute("char",&charCode);
		pElem->QueryIntAttribute("wid",&(aChar.width));
		pElem->QueryFloatAttribute("X1", &(aChar.x1));
		pElem->QueryFloatAttribute("X2", &(aChar.x2));
		pElem->QueryFloatAttribute("Y1", &(aChar.y1));
		pElem->QueryFloatAttribute("Y2", &(aChar.y2));
		pElem->QueryIntAttribute("A", &(aChar.A));
		pElem->QueryIntAttribute("C", &(aChar.C));
		mChars[(unsigned char)charCode] = aChar;
	}
	printf("Font has %d chars", numChars);
	return true;
}
Example #22
0
bool CGUIWindow::Load(CXBMCTinyXML &xmlDoc)
{
  TiXmlElement* pRootElement = xmlDoc.RootElement();
  if (strcmpi(pRootElement->Value(), "window"))
  {
    CLog::Log(LOGERROR, "file : XML file doesnt contain <window>");
    return false;
  }

  // set the scaling resolution so that any control creation or initialisation can
  // be done with respect to the correct aspect ratio
  g_graphicsContext.SetScalingResolution(m_coordsRes, m_needsScaling);

  // Resolve any includes that may be present
  g_SkinInfo->ResolveIncludes(pRootElement);
  // now load in the skin file
  SetDefaults();

  CGUIControlFactory::GetInfoColor(pRootElement, "backgroundcolor", m_clearBackground, GetID());
  CGUIControlFactory::GetActions(pRootElement, "onload", m_loadActions);
  CGUIControlFactory::GetActions(pRootElement, "onunload", m_unloadActions);
  CGUIControlFactory::GetHitRect(pRootElement, m_hitRect);

  TiXmlElement *pChild = pRootElement->FirstChildElement();
  while (pChild)
  {
    CStdString strValue = pChild->Value();
    if (strValue == "type" && pChild->FirstChild())
    {
      // if we have are a window type (ie not a dialog), and we have <type>dialog</type>
      // then make this window act like a dialog
      if (!IsDialog() && strcmpi(pChild->FirstChild()->Value(), "dialog") == 0)
        m_isDialog = true;
    }
    else if (strValue == "previouswindow" && pChild->FirstChild())
    {
      m_previousWindow = CButtonTranslator::TranslateWindow(pChild->FirstChild()->Value());
    }
    else if (strValue == "defaultcontrol" && pChild->FirstChild())
    {
      const char *always = pChild->Attribute("always");
      if (always && strcmpi(always, "true") == 0)
        m_defaultAlways = true;
      m_defaultControl = atoi(pChild->FirstChild()->Value());
    }
    else if (strValue == "visible" && pChild->FirstChild())
    {
      CStdString condition;
      CGUIControlFactory::GetConditionalVisibility(pRootElement, condition);
      m_visibleCondition = g_infoManager.Register(condition, GetID());
    }
    else if (strValue == "animation" && pChild->FirstChild())
    {
      CRect rect(0, 0, (float)m_coordsRes.iWidth, (float)m_coordsRes.iHeight);
      CAnimation anim;
      anim.Create(pChild, rect, GetID());
      m_animations.push_back(anim);
    }
    else if (strValue == "zorder" && pChild->FirstChild())
    {
      m_renderOrder = atoi(pChild->FirstChild()->Value());
    }
    else if (strValue == "coordinates")
    {
      XMLUtils::GetFloat(pChild, "posx", m_posX);
      XMLUtils::GetFloat(pChild, "posy", m_posY);

      TiXmlElement *originElement = pChild->FirstChildElement("origin");
      while (originElement)
      {
        COrigin origin;
        originElement->QueryFloatAttribute("x", &origin.x);
        originElement->QueryFloatAttribute("y", &origin.y);
        if (originElement->FirstChild())
          origin.condition = g_infoManager.Register(originElement->FirstChild()->Value(), GetID());
        m_origins.push_back(origin);
        originElement = originElement->NextSiblingElement("origin");
      }
    }
    else if (strValue == "camera")
    { // z is fixed
      pChild->QueryFloatAttribute("x", &m_camera.x);
      pChild->QueryFloatAttribute("y", &m_camera.y);
      m_hasCamera = true;
    }
    else if (strValue == "controls")
    {
      TiXmlElement *pControl = pChild->FirstChildElement();
      while (pControl)
      {
        if (strcmpi(pControl->Value(), "control") == 0)
        {
          LoadControl(pControl, NULL);
        }
        pControl = pControl->NextSiblingElement();
      }
    }
    else if (strValue == "allowoverlay")
    {
      bool overlay = false;
      if (XMLUtils::GetBoolean(pRootElement, "allowoverlay", overlay))
        m_overlayState = overlay ? OVERLAY_STATE_SHOWN : OVERLAY_STATE_HIDDEN;
    }

    pChild = pChild->NextSiblingElement();
  }
  LoadAdditionalTags(pRootElement);

  m_windowLoaded = true;
  OnWindowLoaded();
  return true;
}
TKeyFrameAnimationGroup2D* TAnimationManager::GetAnimation(const std::string& fileName, const std::string& animationName)
{
	for(size_t j=0;j<mAnimationGroups.size();++j)
	{
		if( mAnimationGroups[j]->mFileName == fileName && mAnimationGroups[j]->mAnimationGroupName == animationName )
		{
			return mAnimationGroups[j]->mAnimationGroup;
		}
	}

	const std::string & root = TGremlinsFramework::GetInstance()->GetAssetRoot();
    const std::string & dir = (root + "media/");
	
	TSpriteSheetLoader *loader = TSpriteSheetLoader::GetInstance();
	TSpriteSheet* mSpriteSheet = loader->LoadSpriteSheet("MathLand.xml", dir.c_str());
	
	TiXmlDocument doc;
	doc.LoadFile(fileName.c_str());

	TiXmlElement * rootElement = doc.FirstChildElement("KeyFrameAnimationGroup2Ds");
	assert( rootElement );

	TiXmlElement * group = rootElement->FirstChildElement("KeyFrameAnimationGroup2D");
	assert( group );
	for(;group;group=group->NextSiblingElement("KeyFrameAnimationGroup2D"))
	{
		const char* name = group->Attribute("name");
		assert( name );
		TKeyFrameAnimationGroup2D* animationGroup = new TKeyFrameAnimationGroup2D();
		animationGroup->SetName(std::string(name));
		
		TAnimationItem * animationItem = new TAnimationItem(fileName, animationGroup->GetName(), animationGroup);

		// add to the array
		mAnimationGroups.push_back(animationItem);

		TiXmlElement* animationElement = group->FirstChildElement("KeyFrameAnimation2D");
		for(;animationElement;animationElement=animationElement->NextSiblingElement("KeyFrameAnimation2D"))
		{
			const char* spriteName = animationElement->Attribute("sprite");
			assert(spriteName);
			TKeyFrameAnimation2D* animation = new TKeyFrameAnimation2D();
			animationGroup->AddAnimation(animation);
			TSprite* sprite = mSpriteSheet->GetSprite(spriteName);
			animation->SetSprite(sprite);

			// add the key frames to the animation
			TiXmlElement* keyFrameElement = animationElement->FirstChildElement("Frame");
			for(;keyFrameElement;keyFrameElement=keyFrameElement->NextSiblingElement("Frame"))
			{
				TKeyFrame keyFrame;
				int time = keyFrameElement->QueryFloatAttribute("time", &keyFrame.time);
				assert( time == TIXML_SUCCESS );
				keyFrameElement->QueryFloatAttribute("x", &keyFrame.x);
				keyFrameElement->QueryFloatAttribute("y", &keyFrame.y);
				keyFrameElement->QueryFloatAttribute("scalex", &keyFrame.scaleX);
				keyFrameElement->QueryFloatAttribute("scaley", &keyFrame.scaleY);
			
				keyFrameElement->QueryFloatAttribute("rotation", &keyFrame.rotation);
				keyFrame.rotation = Math::ToRadian(keyFrame.rotation);

				keyFrameElement->QueryFloatAttribute("r", &keyFrame.color.r);
				keyFrameElement->QueryFloatAttribute("g", &keyFrame.color.g);
				keyFrameElement->QueryFloatAttribute("b", &keyFrame.color.b);
				keyFrameElement->QueryFloatAttribute("a", &keyFrame.color.a);
				animation->AddKeyFrame(keyFrame);
			}
		}
	}	

	for(size_t j=0;j<mAnimationGroups.size();++j)
	{
		if( mAnimationGroups[j]->mFileName == fileName && mAnimationGroups[j]->mAnimationGroupName == animationName )
		{
			return mAnimationGroups[j]->mAnimationGroup;
		}
	}

	return NULL;
}
Example #24
0
void YafFile::processGraph(TiXmlElement* graphElement)
{
    string rootid=graphElement->Attribute("rootid");
    TiXmlElement* nodeElement = graphElement->FirstChildElement("node");
    sceneGraph = new Graph();
    sceneGraph->setRootId(rootid);
    while(nodeElement!=NULL)
    {
        Node* node = new Node(nodeElement->Attribute("id"));
        bool displaylist=false;
        nodeElement->QueryBoolAttribute("displaylist",&displaylist);
        if(displaylist!=NULL)
            node->setDisplayList(displaylist);

        string animID;
        TiXmlElement* animationsN = nodeElement->FirstChildElement("animationref");
        if(animationsN!=NULL)
            animID=animationsN->Attribute("id");


        TiXmlElement* transformations = nodeElement->FirstChildElement("transforms");
        TiXmlElement* transformation=transformations->FirstChildElement();

        while(transformation!=NULL)
        {
            if(transformation->Attribute("axis")!=NULL)
            {
                string axis=transformation->Attribute("axis");
                float angle;
                transformation->QueryFloatAttribute("angle",&angle);
                Transformation* rot = new Rotation(axis,angle);
                node->addTransformation(rot);
            }
            else if (transformation->Attribute("to")!=NULL)
            {
                float translation[3];
                read3Float("to",transformation,translation[0],translation[1],translation[2]);
                Transformation* translationElement = new Translation(translation[0],translation[1],translation[2]);
                node->addTransformation(translationElement);
            }

            else if (transformation->Attribute("factor")!=NULL)
            {
                float factor[3];
                read3Float("factor",transformation,factor[0],factor[1],factor[2]);
                Transformation* scaling = new Scaling(factor[0],factor[1],factor[2]);
                node->addTransformation(scaling);
            }

            transformation = transformation->NextSiblingElement();
        }

        TiXmlElement* appearanceRef = nodeElement->FirstChildElement("appearanceref");
        if(appearanceRef!=NULL)
        {

            node->setNodeAppearance(make_pair(appearanceRef->Attribute("id"),appearances[appearanceRef->Attribute("id")]));
        }
        else
        {
            node->setNodeAppearance(make_pair("",new Appearance()));
        }
        TiXmlElement* children = nodeElement->FirstChildElement("children");
        TiXmlElement* childrenAnalyzer = children->FirstChildElement();
        while(childrenAnalyzer!=NULL)
        {
            if(childrenAnalyzer->Attribute("xy1")!=NULL)
            {
                float xy1[2],xy2[2];
                read2Float("xy1",childrenAnalyzer,xy1[0],xy1[1]);
                read2Float("xy2",childrenAnalyzer,xy2[0],xy2[1]);
                SceneObject* rectangle = new SceneRectangle(xy1[0],xy1[1],xy2[0],xy2[1]);
                node->addObject(rectangle);
            }

            else if(childrenAnalyzer->Attribute("xyz1")!=NULL)
            {
                float xyz1[3],xyz2[3],xyz3[3];
                read3Float("xyz1",childrenAnalyzer,xyz1[0],xyz1[1],xyz1[2]);
                read3Float("xyz2",childrenAnalyzer,xyz2[0],xyz2[1],xyz2[2]);
                read3Float("xyz3",childrenAnalyzer,xyz3[0],xyz3[1],xyz3[2]);
                SceneObject* triangle = new SceneTriangle(xyz1,xyz2,xyz3);
                node->addObject(triangle);
            }

            else if(childrenAnalyzer->Attribute("base")!=NULL)
            {
                float base,top,height;
                int slices,stacks;
                childrenAnalyzer->QueryFloatAttribute("base",&base);
                childrenAnalyzer->QueryFloatAttribute("top",&top);
                childrenAnalyzer->QueryFloatAttribute("height",&height);
                childrenAnalyzer->QueryIntAttribute("slices",&slices);
                childrenAnalyzer->QueryIntAttribute("stacks",&stacks);
                SceneObject* cylinder = new SceneCylinder(base,top,height,slices,stacks);
                node->addObject(cylinder);
            }
            else if(childrenAnalyzer->Attribute("radius")!=NULL)
            {
                float radius;
                int slices,stacks;
                childrenAnalyzer->QueryFloatAttribute("radius",&radius);
                childrenAnalyzer->QueryIntAttribute("slices",&slices);
                childrenAnalyzer->QueryIntAttribute("stacks",&stacks);
                SceneObject* sphere = new SceneSphere(radius,slices,stacks);
                node->addObject(sphere);
            }
            else if(childrenAnalyzer->Attribute("inner")!=NULL)
            {
                float inner,outer;
                int slices,loops;
                childrenAnalyzer->QueryFloatAttribute("inner",&inner);
                childrenAnalyzer->QueryFloatAttribute("outer",&outer);
                childrenAnalyzer->QueryIntAttribute("slices",&slices);
                childrenAnalyzer->QueryIntAttribute("loops",&loops);
                SceneObject* thorus = new SceneTorus(inner,outer,slices,loops);
                node->addObject(thorus);
            }
            else if(childrenAnalyzer->Attribute("parts")!=NULL)
            {
                int parts;
                childrenAnalyzer->QueryIntAttribute("parts",&parts);
                SceneObject* plane = new ScenePlane(parts);
                node->addObject(plane);
            }
            else if(strcmp(childrenAnalyzer->Value(),"patch")==0)
            {
                int order,partsU,partsV;
                float x,y,z;
                string compute;

                childrenAnalyzer->QueryIntAttribute("order",&order);
                childrenAnalyzer->QueryIntAttribute("partsU",&partsU);
                childrenAnalyzer->QueryIntAttribute("partsV",&partsV);
                compute=childrenAnalyzer->Attribute("compute");

                ScenePatch* patch = new ScenePatch(order,partsU,partsV,compute);

                TiXmlElement* points = childrenAnalyzer->FirstChildElement("controlpoint");

                while(points!=NULL)
                {
                    points->QueryFloatAttribute("x",&x);
                    points->QueryFloatAttribute("y",&y);
                    points->QueryFloatAttribute("z",&z);

                    cout<<x<<","<<y<<","<<z<<endl;
                    patch->addCntrPoint(x,y,z);

                    points = points->NextSiblingElement("controlpoint");
                }
                node->addObject(patch);

            }

            else if(strcmp(childrenAnalyzer->Value(),"vehicle")==0)
            {
                SceneObject* vehicle = new SceneVehicle();
                node->addObject(vehicle);
            }

            else if(childrenAnalyzer->Attribute("heightmap")!=NULL)
            {
                string heightMap,textureMap,fragmentShader,vertexShader;
                heightMap=childrenAnalyzer->Attribute("heightmap");
                textureMap=childrenAnalyzer->Attribute("texturemap");
                fragmentShader=childrenAnalyzer->Attribute("fragmentshader");
                vertexShader=childrenAnalyzer->Attribute("vertexshader");

                SceneObject* shader = new SceneShader(heightMap,textureMap,fragmentShader,vertexShader);
                node->addObject(shader);
            }


            else if (childrenAnalyzer->Attribute("id")!=NULL)
            {
                node->addchildId(childrenAnalyzer->Attribute("id"));
            }
            childrenAnalyzer=childrenAnalyzer->NextSiblingElement();
        }
        //set animation
        Animation* anime=animations[animID];

        if(anime!=NULL)
        {
            node->setAnimation(anime);
        }
        sceneGraph->addNode(node);
        nodeElement=nodeElement->NextSiblingElement("node");
    }
    sceneGraph->createSonNodes();
}
Example #25
0
bool JAnimator::Load(const char* scriptFile)
{

    JFileSystem *fileSystem = JFileSystem::GetInstance();
    if (fileSystem == NULL) return false;

    if (!fileSystem->OpenFile(scriptFile)) return false;

    int size = fileSystem->GetFileSize();
    char *xmlBuffer = new char[size];
    fileSystem->ReadFile(xmlBuffer, size);

    TiXmlDocument doc;
    doc.Parse(xmlBuffer);

    TiXmlNode* script = 0;
    TiXmlNode* frame = 0;
    TiXmlNode* obj = 0;
    TiXmlNode* param = 0;
    TiXmlElement* element = 0;

    float defaultTime = 0.033f;

    script = doc.FirstChild("script");
    if (script)
    {
        element = script->ToElement();
        printf("---- Loading %s:%s\n", element->Value(), element->Attribute("name"));

        char *type[] =
        {
            "ANIMATION_TYPE_LOOPING",
            "ANIMATION_TYPE_ONCE_AND_STAY",
            "ANIMATION_TYPE_ONCE_AND_BACK",
            "ANIMATION_TYPE_ONCE_AND_GONE",
            "ANIMATION_TYPE_PINGPONG"
        };

        const char* aniType = element->Attribute("type");
        for (int i=0; i<5; i++)
            if (strcmp(type[i], aniType)==0)
            {
                SetAnimationType(i);
                break;
            }

        float fps;
        if (element->QueryFloatAttribute("framerate", &fps) != TIXML_SUCCESS)
            fps = 30.0f;

        defaultTime = 1/fps;

        for (frame = script->FirstChild("frame"); frame; frame = frame->NextSibling())
        {
            JAnimatorFrame *aniFrame = new JAnimatorFrame(this);

            float duration;
            element = frame->ToElement();
            if (element->QueryFloatAttribute("time", &duration) != TIXML_SUCCESS)
                duration = defaultTime;
            aniFrame->SetFrameTime(duration);

            for (obj = frame->FirstChild(); obj; obj = obj->NextSibling())
            {
                for (param = obj->FirstChild(); param; param = param->NextSibling())
                {

                    element = param->ToElement();
                    if (element != NULL)
                    {
                        if (strcmp(element->Value(), "settings")==0)
                        {
                            const char* quadName = element->Attribute("quad");
                            JQuad* quad = mResource->GetQuad(quadName);

                            float x, y;
                            float vsize, hsize;
                            float angle;
                            int a, r, g, b;
                            int value;
                            bool flipped = false;

                            if (element->QueryFloatAttribute("x", &x) != TIXML_SUCCESS)
                                x = 0.0f;

                            if (element->QueryFloatAttribute("y", &y) != TIXML_SUCCESS)
                                y = 0.0f;

                            if (element->QueryFloatAttribute("hsize", &hsize) != TIXML_SUCCESS)
                                hsize = 1.0f;

                            if (element->QueryFloatAttribute("vsize", &vsize) != TIXML_SUCCESS)
                                vsize = 1.0f;

                            if (element->QueryFloatAttribute("rotation", &angle) != TIXML_SUCCESS)
                                angle = 0.0f;

                            if (element->QueryIntAttribute("a", &a) != TIXML_SUCCESS)
                                a = 255;

                            if (element->QueryIntAttribute("r", &r) != TIXML_SUCCESS)
                                r = 255;

                            if (element->QueryIntAttribute("g", &g) != TIXML_SUCCESS)
                                g = 255;

                            if (element->QueryIntAttribute("b", &b) != TIXML_SUCCESS)
                                b = 255;

                            if (element->QueryIntAttribute("flip", &value) == TIXML_SUCCESS)
                                flipped = (value==1);


                            JAnimatorObject *object = new JAnimatorObject();
                            object->SetQuad(quad);
                            object->SetPosition(x, y);
                            object->SetHScale(hsize);
                            object->SetVScale(vsize);
                            object->SetRotation(angle);
                            object->SetColor(ARGB(a,r,g,b));
                            object->SetFlip(flipped);

                            aniFrame->AddObject(object);

                        }
                    }
                }

            }

            mFrames.push_back(aniFrame);
        }

    }

    fileSystem->CloseFile();
    delete[] xmlBuffer;

    return true;

}
Example #26
0
/**
 *	@method PigManager::init()
 *	@desc   initializes the pig renderer and stores the properties of all possible types of pigs like the UV coordinates of the sprite states and physics properties
 */
void PigManager::init(TiXmlElement* pigsElement, TiXmlElement* poofElement)
{
	numPigs = 0;
	totalPossiblePigs = 0;
	int totalSpriteCount = 0;

	TiXmlElement* pigElement = pigsElement->FirstChildElement();
	while (pigElement != NULL)
	{
		totalPossiblePigs++;
		pigElement = pigElement->NextSiblingElement();
	}

	allPigsData = (ObjectData *)malloc(totalPossiblePigs * sizeof(ObjectData));
	pigElement = pigsElement->FirstChildElement();
	int i = 0, j = 0;
	while (pigElement != NULL)
	{
		allPigsData[i].objectType = pigElement->Attribute("type");

		TiXmlElement* physicsElement = pigElement->FirstChildElement();
		physicsElement->QueryFloatAttribute("density", &allPigsData[i].density);
		physicsElement->QueryFloatAttribute("restitution", &allPigsData[i].restitution);
		physicsElement->QueryFloatAttribute("friction", &allPigsData[i].friction);
		physicsElement->QueryIntAttribute("health", &allPigsData[i].health);

		TiXmlElement* spritesParentElement = physicsElement->NextSiblingElement();
		int spriteStateCount = 0;
		TiXmlElement* spriteElement = spritesParentElement->FirstChildElement();
		while (spriteElement != NULL)
		{
			spriteStateCount++;
			spriteElement = spriteElement->NextSiblingElement();
		}

		totalSpriteCount += spriteStateCount;

		allPigsData[i].spriteData = (SpriteStateData *)malloc(spriteStateCount * sizeof(SpriteStateData));
		allPigsData[i].numSprites = spriteStateCount;
		j = 0;
		spriteElement = spritesParentElement->FirstChildElement();
		while (spriteElement != NULL)
		{
			allPigsData[i].spriteData[j].spriteState = spriteElement->Attribute("state");
			spriteElement->QueryFloatAttribute("xPosLeft", &allPigsData[i].spriteData[j].uLeft);
			spriteElement->QueryFloatAttribute("xPosRight", &allPigsData[i].spriteData[j].uRight);
			spriteElement->QueryFloatAttribute("yPosTop", &allPigsData[i].spriteData[j].vTop);
			spriteElement->QueryFloatAttribute("yPosBottom", &allPigsData[i].spriteData[j].vBottom);

			spriteElement = spriteElement->NextSiblingElement();
			j++;
		}

		pigElement = pigElement->NextSiblingElement();
		i++;
	}

	/**************************/

	int totalPoofFrames = 0;
	TiXmlElement* poofSprite = poofElement->FirstChildElement()->FirstChildElement();
	while (poofSprite != NULL)
	{
		poofSprite = poofSprite->NextSiblingElement();
		totalPoofFrames++;
	}

	poofData.numSprites = totalPoofFrames;
	poofData.spriteData = (SpriteStateData *)malloc(poofData.numSprites * sizeof(SpriteStateData));

	j = 0;
	poofSprite = poofElement->FirstChildElement()->FirstChildElement();
	while (poofSprite != NULL)
	{
		poofData.spriteData[j].spriteState = poofSprite->Attribute("state");
		poofSprite->QueryFloatAttribute("xPosLeft", &poofData.spriteData[j].uLeft);
		poofSprite->QueryFloatAttribute("xPosRight", &poofData.spriteData[j].uRight);
		poofSprite->QueryFloatAttribute("yPosTop", &poofData.spriteData[j].vTop);
		poofSprite->QueryFloatAttribute("yPosBottom", &poofData.spriteData[j].vBottom);

		//pigRenderer->setUTextureLeft(k, poofData.spriteData[j].uLeft);
		//pigRenderer->setUTextureRight(k, poofData.spriteData[j].uRight);
		//pigRenderer->setVTextureTop(k, poofData.spriteData[j].vTop);
		//pigRenderer->setVTextureBottom(k, poofData.spriteData[j].vBottom);

		//poofData.spriteData[j].rendererIndex = k;

		//k++;

		poofSprite = poofSprite->NextSiblingElement();
		j++;
	}

	totalSpriteCount += totalPoofFrames;
	
	/*************************/

	float imageWidth, imageHeight;
	pigsElement->QueryFloatAttribute("imageWidth", &imageWidth);
	pigsElement->QueryFloatAttribute("imageHeight", &imageHeight);

	pigRenderer = new Renderer();
	pigRenderer->init(pigsElement->Attribute("src"), totalSpriteCount, imageWidth, imageHeight);

	int k = 0;

	for (i = 0; i < totalPossiblePigs; i++)
	{
		for (j = 0; j < allPigsData[i].numSprites; j++)
		{
			pigRenderer->setUTextureLeft(k, allPigsData[i].spriteData[j].uLeft);
			pigRenderer->setUTextureRight(k, allPigsData[i].spriteData[j].uRight);
			pigRenderer->setVTextureTop(k, allPigsData[i].spriteData[j].vTop);
			pigRenderer->setVTextureBottom(k, allPigsData[i].spriteData[j].vBottom);

			allPigsData[i].spriteData[j].rendererIndex = k;

			k++;
		}
	}

	/********Poofing*********/
	j = 0;
	poofSprite = poofElement->FirstChildElement()->FirstChildElement();
	while (poofSprite != NULL)
	{
		pigRenderer->setUTextureLeft(k, poofData.spriteData[j].uLeft);
		pigRenderer->setUTextureRight(k, poofData.spriteData[j].uRight);
		pigRenderer->setVTextureTop(k, poofData.spriteData[j].vTop);
		pigRenderer->setVTextureBottom(k, poofData.spriteData[j].vBottom);

		poofData.spriteData[j].rendererIndex = k;

		k++;

		poofSprite = poofSprite->NextSiblingElement();
		j++;
	}

}
int WindowParams::LoadParamsFromXML(char fileName[])
{		
	TiXmlDocument doc(fileName);
	if (!doc.LoadFile()) return -1;

	TiXmlHandle hDoc(&doc);
	TiXmlElement* pElem;
	TiXmlHandle hRoot(0);
	
	pElem = hDoc.FirstChildElement().Element();
	if (!pElem) return -1;
	hRoot = TiXmlHandle(pElem);	
	
	pElem = hRoot.FirstChild("HOGParams").Element();
	if (pElem)
	{
		pElem->QueryIntAttribute("cell_width", &m_DetectionParams.m_HOG_Params.m_cell.width);
		pElem->QueryIntAttribute("cell_height", &m_DetectionParams.m_HOG_Params.m_cell.height);
		pElem->QueryIntAttribute("block_width", &m_DetectionParams.m_HOG_Params.m_block.width);
		pElem->QueryIntAttribute("block_height", &m_DetectionParams.m_HOG_Params.m_block.height);
		pElem->QueryIntAttribute("total_bin", &m_DetectionParams.m_HOG_Params.m_inBin);
		pElem->QueryFloatAttribute("overlap", &m_DetectionParams.m_HOG_Params.m_fStepOverlap);
	}
		
	pElem = hRoot.FirstChild("SVMParams").Element();
	if (pElem)
	{
		pElem->QueryFloatAttribute("confidence_score", &m_DetectionParams.m_SVM_Params.m_fConfidenceScore);
	}
	
	pElem = hRoot.FirstChild("GaussianParams").Element();
	if (pElem)
	{		
		pElem->QueryFloatAttribute("threshold", &m_DetectionParams.m_Gaussian_Params.m_fThreshold);
	}

	pElem = hRoot.FirstChild("HeadParams").Element();
	if (pElem)
	{		
		pElem->QueryIntAttribute("min_area", &m_DetectionParams.m_Head_Params.m_iMinHeadArea);
		pElem->QueryIntAttribute("max_area", &m_DetectionParams.m_Head_Params.m_iMaxHeadArea);
		pElem->QueryIntAttribute("relative_width_height", &m_DetectionParams.m_Head_Params.m_iRelative_Width_Height);
		pElem->QueryIntAttribute("relative_height_width", &m_DetectionParams.m_Head_Params.m_iRelative_Height_Width);
		pElem->QueryIntAttribute("max_width", &m_DetectionParams.m_Head_Params.m_iMaxWidth);
		pElem->QueryIntAttribute("min_width", &m_DetectionParams.m_Head_Params.m_iMinWidth);
		pElem->QueryIntAttribute("max_head_area_top", &m_DetectionParams.m_Head_Params.m_iMaxHeadAreaTop);
		pElem->QueryIntAttribute("min_head_area_bottom", &m_DetectionParams.m_Head_Params.m_iMinHeadAreaBottom);
	}

	const char* tmp;
	pElem = hRoot.FirstChild("ModelSVM").Element();
	if (pElem)
	{		
		tmp = pElem->GetText();
		m_modelSVMPath = new char[strlen(tmp)];
		strcpy(m_modelSVMPath,pElem->GetText());
	}
	
	pElem = hRoot.FirstChild("ModelGauss").Element();
	if (pElem)
	{	
		tmp = pElem->GetText();
		m_modelGaussPath = new char[strlen(tmp)];
		strcpy( m_modelGaussPath, pElem->GetText());
	}	
	return 0;
}