void ParticleSystemData::Load(const std::string& aFilePath) { myEmitterData.Init(4); myOrientations.Init(4); myTimeStamps.Init(4); XMLReader xmlDoc; xmlDoc.OpenDocument(aFilePath); XMLElement emitterElement = xmlDoc.FindFirstChild(); emitterElement = emitterElement->FirstChildElement("Emitter"); while (emitterElement != nullptr) { XMLElement dataElement = emitterElement->FirstChildElement("Name"); std::string emitterName = dataElement->GetText(); dataElement = emitterElement->FirstChildElement("Time"); float time; dataElement->QueryFloatText(&time); dataElement = emitterElement->FirstChildElement("Position"); Vector3<float> position; position.x = dataElement->FloatAttribute("x"); position.y = dataElement->FloatAttribute("y"); position.z = dataElement->FloatAttribute("z"); dataElement = emitterElement->FirstChildElement("Rotation"); Vector3<float> rotation; rotation.x = dataElement->FloatAttribute("x"); rotation.y = dataElement->FloatAttribute("y"); rotation.z = dataElement->FloatAttribute("z"); Matrix44<float> orientation; orientation *= Matrix44<float>::CreateRotateAroundX(rotation.x); orientation *= Matrix44<float>::CreateRotateAroundY(rotation.y); orientation *= Matrix44<float>::CreateRotateAroundZ(rotation.z); orientation.SetTranslation(position); myEmitterData.Add(emitterName); myOrientations.Add(orientation); myTimeStamps.Add(time); emitterElement = emitterElement->NextSiblingElement("Emitter"); } }
void VisualComponent::init(XMLElement *componentElement) { XMLElement* textureElement; const char* textureFileLocation; const char* fontFileLocation; std::ostringstream LabelString; ComponentID = componentElement->IntAttribute("ComponentType"); viewType = (ViewType)componentElement->IntAttribute("GameViewId"); XMLElement* colorElement = componentElement->FirstChildElement("Color"); //actorColor = new sf::Color(colorElement->IntAttribute("r"),colorElement->IntAttribute("g"),colorElement->IntAttribute("b"),colorElement->IntAttribute("a")); XMLElement* shapeElement = colorElement->NextSiblingElement("Structure"); shapeID = shapeElement->IntAttribute("ShapeID"); switch(shapeElement->IntAttribute("ShapeID")) { case 1://"Rectangle": actorShape = new ActorShape::Rectangle(); ((ActorShape::Rectangle*)actorShape)->setSize(shapeElement->FloatAttribute("Height"), shapeElement->FloatAttribute("Width")); ((ActorShape::Rectangle*)actorShape)->actorShape.setFillColor((const sf::Color &)actorColor);//(const sf::Color &)actorColor break; case 2://"Circle": actorShape = new ActorShape::Circle(); ((ActorShape::Circle*)actorShape)->setSize(shapeElement->FloatAttribute("Radious")); ((ActorShape::Circle*)actorShape)->actorShape.setFillColor((const sf::Color &)actorColor); break; case 3://"GRID MAP": actorShape = new ActorShape::GridMap(); ((ActorShape::GridMap*)actorShape)->setBlockSize(shapeElement->IntAttribute("BlockHeight"),shapeElement->IntAttribute("BlockWidth")); break; case 5://TextArea textureElement = shapeElement->NextSiblingElement("Texture"); textureFileLocation = textureElement->Attribute("TextureFileName"); actorShape = new ActorShape::GridMap(); ((ActorShape::GridMap*)actorShape)->LoadTexture(textureFileLocation); ((ActorShape::GridMap*)actorShape)->setBlockSize(shapeElement->IntAttribute("BlockHeight"),shapeElement->IntAttribute("BlockWidth")); fontFileLocation = textureElement->Attribute("FontFileName"); ((ActorShape::GridMap*)actorShape)->LoadFont(fontFileLocation); //LabelString << textureElement->Attribute("Text");// put float into string buffer //((ActorShape::GridMap*)actorShape)->SetTextInBox(LabelString, 0, 0); break; default: actorShape = new ActorShape::Circle(); ((ActorShape::Circle*)actorShape)->setSize(10); ((ActorShape::Circle*)actorShape)->actorShape.setFillColor((const sf::Color &)actorColor); break; } isVisible = true; }
void GameObject::LoadProperties( XMLElement & e ) { XMLElement * prop = e.FirstChildElement("Property"); while ( prop ){ g_Log << "Property id is: " << prop->Attribute("id") << "\n"; if ( !prop->Attribute("id") ) throw AttributeMissingException("Property - No id attribute"); if ( !prop->Attribute("type") ) throw AttributeMissingException("Property - No type attribute"); if ( !prop->Attribute("value") ) throw AttributeMissingException("Property - No value attribute"); string type = prop->Attribute("type"); if ( type == "bool" ) AddProperty( prop->Attribute("id"), prop->BoolAttribute("value")); else if ( type == "int" ) AddProperty( prop->Attribute("id"), prop->IntAttribute("value")); else if ( type == "float" ) AddProperty( prop->Attribute("id"), prop->FloatAttribute("value")); else if ( type == "string" ) AddProperty( prop->Attribute("id"), prop->Attribute("value")); else throw InvalidAttributeException("Invalid attribute type defined!"); prop = prop->NextSiblingElement("Property"); } }
bool TransformComponent::VInit(XMLElement* pCompData) { assert(pCompData); Vector3 position = Vector3(0.f, 0.f, 0.f); Vector3 rotation = Vector3(0.f, 0.f, 0.f); Vector3 scale = Vector3(1.f, 1.f, 1.f); XMLElement* pPositionElement = pCompData->FirstChildElement("Position"); if (pPositionElement) { position.x = pPositionElement->FloatAttribute("x"); position.y = pPositionElement->FloatAttribute("y"); position.z = pPositionElement->FloatAttribute("z"); } XMLElement* pRotationElement = pCompData->FirstChildElement("Rotation"); if (pRotationElement) { rotation.x = Deg2Rad(pRotationElement->FloatAttribute("x")); rotation.y = Deg2Rad(pRotationElement->FloatAttribute("y")); rotation.z = Deg2Rad(pRotationElement->FloatAttribute("z")); } XMLElement* pScaleElement = pCompData->FirstChildElement("Scale"); if (pScaleElement) { scale.x = pScaleElement->FloatAttribute("x"); scale.y = pScaleElement->FloatAttribute("y"); scale.z = pScaleElement->FloatAttribute("z"); } Matrix trans; trans= glm::translate(trans, position); Matrix rot; rot = glm::yawPitchRoll(rotation.x, rotation.y, rotation.z); Matrix scaleM; scaleM = glm::scale(scaleM, scale); m_transform = scaleM * rot * trans; return true; }
void Level::loadMap(std::string mapName, Graphics &graphics) { //Parse the .tmx file XMLDocument doc; std::stringstream ss; ss << "maps/" << mapName << ".tmx"; //Pass in Map 1, we get maps/Map 1.tmx doc.LoadFile(ss.str().c_str()); XMLElement* mapNode = doc.FirstChildElement("map"); //Get the width and the height of the whole map and store it in _size int width, height; mapNode->QueryIntAttribute("width", &width); mapNode->QueryIntAttribute("height", &height); this->_size = Vector2(width, height); //Get the width and the height of the tiles and store it in _tileSize int tileWidth, tileHeight; mapNode->QueryIntAttribute("tilewidth", &tileWidth); mapNode->QueryIntAttribute("tileheight", &tileHeight); this->_tileSize = Vector2(tileWidth, tileHeight); //Loading the tilesets XMLElement* pTileset = mapNode->FirstChildElement("tileset"); if (pTileset != NULL) { while (pTileset) { int firstgid; const char* source = pTileset->FirstChildElement("image")->Attribute("source"); char* path; std::stringstream ss; ss << source; pTileset->QueryIntAttribute("firstgid", &firstgid); SDL_Texture* tex = SDL_CreateTextureFromSurface(graphics.getRenderer(), graphics.loadImage(ss.str())); this->_tilesets.push_back(Tileset(tex, firstgid)); pTileset = pTileset->NextSiblingElement("tileset"); } } //Loading the layers XMLElement* pLayer = mapNode->FirstChildElement("layer"); if (pLayer != NULL) { while (pLayer) { //Loading the data element XMLElement* pData = pLayer->FirstChildElement("data"); if (pData != NULL) { while (pData) { //Loading the tile element XMLElement* pTile = pData->FirstChildElement("tile"); if (pTile != NULL) { int tileCounter = 0; while (pTile) { //Build each individual tile here //If gid is 0, no tile should be drawn. Continue loop if (pTile->IntAttribute("gid") == 0) { tileCounter++; if (pTile->NextSiblingElement("tile")) { pTile = pTile->NextSiblingElement("tile"); continue; } else { break; } } //Get the tileset for this specific gid int gid = pTile->IntAttribute("gid"); Tileset tls; for (int i = 0; i < this->_tilesets.size(); i++) { if (this->_tilesets[i].FirstGid <= gid) { //This is the tileset we want tls = this->_tilesets.at(i); break; } } if (tls.FirstGid == -1) { //No tileset was found for this gid tileCounter++; if (pTile->NextSiblingElement("tile")) { pTile = pTile->NextSiblingElement("tile"); continue; } else { break; } } //Get the position of the tile in the level int xx = 0; int yy = 0; xx = tileCounter % width; xx *= tileWidth; yy += tileHeight * (tileCounter / width); Vector2 finalTilePosition = Vector2(xx, yy); //Calculate the position of the tile in the tileset int tilesetWidth, tilesetHeight; SDL_QueryTexture(tls.Texture, NULL, NULL, &tilesetWidth, &tilesetHeight); int tsxx = gid % (tilesetWidth / tileWidth) - 1; tsxx *= tileWidth; int tsyy = 0; int amt = (gid / (tilesetWidth / tileWidth)); tsyy = tileHeight * amt; Vector2 finalTilesetPosition = Vector2(tsxx, tsyy); //Build the actual tile and add it to the level's tile list Tile tile(tls.Texture, Vector2(tileWidth, tileHeight), finalTilesetPosition, finalTilePosition); this->_tileList.push_back(tile); tileCounter++; pTile = pTile->NextSiblingElement("tile"); } } pData = pData->NextSiblingElement("data"); } } pLayer = pLayer->NextSiblingElement("layer"); } } //Parse out the collisions XMLElement* pObjectGroup = mapNode->FirstChildElement("objectgroup"); if (pObjectGroup != NULL) { while (pObjectGroup) { const char* name = pObjectGroup->Attribute("name"); std::stringstream ss; ss << name; if (ss.str() == "collisions") { XMLElement* pObject = pObjectGroup->FirstChildElement("object"); if (pObject != NULL) { while (pObject) { float x, y, width, height; x = pObject->FloatAttribute("x"); y = pObject->FloatAttribute("y"); width = pObject->FloatAttribute("width"); height = pObject->FloatAttribute("height"); this->_collisionRects.push_back(Rectangle( std::ceil(x) * globals::SPRITE_SCALE, std::ceil(y) * globals::SPRITE_SCALE, std::ceil(width) * globals::SPRITE_SCALE, std::ceil(height) * globals::SPRITE_SCALE )); pObject = pObject->NextSiblingElement("object"); } } } //Other objectgroups go here with an else if (ss.str() == "whatever") else if (ss.str() == "slopes") { XMLElement* pObject = pObjectGroup->FirstChildElement("object"); if (pObject != NULL) { while (pObject) { std::vector<Vector2> points; Vector2 p1; p1 = Vector2(std::ceil(pObject->FloatAttribute("x")), std::ceil(pObject->FloatAttribute("y"))); XMLElement* pPolyline = pObject->FirstChildElement("polyline"); if (pPolyline != NULL) { std::vector<std::string> pairs; const char* pointString = pPolyline->Attribute("points"); std::stringstream ss; ss << pointString; Utils::split(ss.str(), pairs, ' '); //Now we have each of the pairs. Loop through the list of pairs //and split them into Vector2s and then store them in our points vector for (int i = 0; i < pairs.size(); i++) { std::vector<std::string> ps; Utils::split(pairs.at(i), ps, ','); points.push_back(Vector2(std::stoi(ps.at(0)), std::stoi(ps.at(1)))); } } for (int i = 0; i < points.size(); i += 2) { this->_slopes.push_back(Slope( Vector2((p1.x + points.at(i < 2 ? i : i - 1).x) * globals::SPRITE_SCALE, (p1.y + points.at(i < 2 ? i : i - 1).y) * globals::SPRITE_SCALE), Vector2((p1.x + points.at(i < 2 ? i + 1 : i).x) * globals::SPRITE_SCALE, (p1.y + points.at(i < 2 ? i + 1 : i).y) * globals::SPRITE_SCALE) )); } pObject = pObject->NextSiblingElement("object"); } } } else if (ss.str() == "spawn points") { XMLElement* pObject = pObjectGroup->FirstChildElement("object"); if (pObject != NULL) { while (pObject) { float x = pObject->FloatAttribute("x"); float y = pObject->FloatAttribute("y"); const char* name = pObject->Attribute("name"); std::stringstream ss; ss << name; if (ss.str() == "player") { this->_spawnPoint = Vector2(std::ceil(x) * globals::SPRITE_SCALE, std::ceil(y) * globals::SPRITE_SCALE); } pObject = pObject->NextSiblingElement("object"); } } } pObjectGroup = pObjectGroup->NextSiblingElement("objectgroup"); } } }
void Level::loadMap(std::string mapName, Graphics &graphics) { //Parse the .tmx file XMLDocument doc; std::stringstream ss; ss << "content/maps/" << mapName << ".tmx"; //"Map 1" = content/maps/Map 1.tmx doc.LoadFile(ss.str().c_str()); XMLElement* mapNode = doc.FirstChildElement("map"); //Get the width and the height of the whole map and store it in _size int height,width; mapNode->QueryIntAttribute("width", &width); mapNode->QueryIntAttribute("height",&height); this->_size = Vector2(width,height); //Get the width and the height of the tiles and store it in _tileSize int tileWidth, tileHeight; mapNode->QueryIntAttribute("tilewidth", &tileWidth); mapNode->QueryIntAttribute("tileheight",&tileHeight); this->_tileSize = Vector2(tileWidth,tileHeight); //load tilesets XMLElement* pTileset = mapNode->FirstChildElement("tileset"); if(pTileset != NULL) { while(pTileset) { int firstgid; const char* source = pTileset->FirstChildElement("image")->Attribute("source"); std::string path(source); path = path.substr(3,path.length()); std::stringstream ss; ss << "content/" << path; pTileset->QueryIntAttribute("firstgid", &firstgid); SDL_Texture* tex = SDL_CreateTextureFromSurface(graphics.getRenderer(), graphics.loadImage(ss.str())); this->_tilesets.push_back(Tileset(tex, firstgid)); pTileset = pTileset->NextSiblingElement("tileset"); } } //Loading the layers XMLElement* pLayer = mapNode->FirstChildElement("layer"); if(pLayer != NULL) { while(pLayer) { //Loading the data element XMLElement* pData = pLayer->FirstChildElement("data"); if(pData != NULL) { while(pData){ //Loading the tile element XMLElement* pTile = pData->FirstChildElement("tile"); if(pTile != NULL) { int tileCounter = 0; while(pTile){ //Build each individual tile here //if gid is 0, no tile should be drawn. Continue loop if(pTile->IntAttribute("gid") == 0){ tileCounter++; if(pTile->NextSiblingElement("tile")){ pTile = pTile->NextSiblingElement("tile"); continue; } else { break; } } //Get the tileset for this specific gid int gid = pTile->IntAttribute("gid"); Tileset tls; for(int i = 0; i < this->_tilesets.size(); i++) { if(this->_tilesets[i].FirstGid <= gid) { //This is the tileset we want tls = this->_tilesets.at(i); break; } } if(tls.FirstGid == -1) { //No tileset was found for this gid tileCounter++; if(pTile->NextSiblingElement("tile")) { pTile = pTile->NextSiblingElement("tile"); continue; } else{ break; } } //Get the position of the tile in the level int xx = 0; int yy = 0; xx = tileCounter % width; xx = xx * tileWidth; yy = yy + (tileHeight * (tileCounter/width)); Vector2 finalTilePosition = Vector2(xx,yy); //Calculate the position of the tile in the tileset int tilesetWidth, tilesetHeight; SDL_QueryTexture(tls.Texture, NULL, NULL, &tilesetWidth, &tilesetHeight); int tsxx = gid % (tilesetWidth / tileWidth) - 1; tsxx = tsxx * tileWidth; int tsyy = 0; int amt = (gid / (tilesetWidth / tileWidth)); tsyy = tileHeight * amt; Vector2 finalTilesetPosition = Vector2(tsxx, tsyy); //Build the actual tile and add it to the level's tile list Tile tile(tls.Texture, Vector2(tileWidth, tileHeight), finalTilesetPosition, finalTilePosition); this->_tileList.push_back(tile); tileCounter++; pTile = pTile->NextSiblingElement("tile"); } } pData = pData->NextSiblingElement("data"); } } pLayer = pLayer->NextSiblingElement("layer"); } } //Parse out the collisions XMLElement* pObjectGroup = mapNode->FirstChildElement("objectgroup"); if(pObjectGroup != NULL){ while(pObjectGroup) { const char* name = pObjectGroup->Attribute("name"); std::stringstream ss; ss << name; if(ss.str() == "collisions") { XMLElement* pObject = pObjectGroup->FirstChildElement("object"); if(pObject != NULL){ while(pObject) { float x, y, width, height; x = pObject->FloatAttribute("x"); y = pObject->FloatAttribute("y"); width = pObject->FloatAttribute("width"); height = pObject->FloatAttribute("height"); this->_collisionRects.push_back(Rectangle( std::ceil(x) * globals::SPRITE_SCALE, std::ceil(y) * globals::SPRITE_SCALE, std::ceil(width) * globals::SPRITE_SCALE, std::ceil(height) * globals::SPRITE_SCALE )); pObject = pObject->NextSiblingElement("object"); } } }else if(ss.str() == "spawn points") { XMLElement* pObject = pObjectGroup->FirstChildElement("object"); if(pObject != NULL) { while(pObject) { float x = pObject->FloatAttribute("x"); float y = pObject->FloatAttribute("y"); const char* name = pObject->Attribute("name"); std::stringstream ss; ss << name; if(ss.str() == "player") { this->_spawnPoint = Vector2(std::ceil(x) * globals::SPRITE_SCALE, std::ceil(y) * globals::SPRITE_SCALE); } pObject = pObject->NextSiblingElement("object"); } } } //Other objectgroups go here with an else if (ss.str() == "whatevs son") { pObjectGroup = pObjectGroup->NextSiblingElement("objectgroup"); } } }
bool Material::ReadShaderChildren(tinyxml2::XMLElement* shaderElement, Material::VariableMap& variableMap) { using namespace tinyxml2; XMLElement* shaderChild = shaderElement->FirstChildElement(); while (shaderChild) { //read all child data for pixel shader std::string _name = shaderChild->Name(); if (_name == "float") { //read float std::string key = shaderChild->Attribute("name"); float val = shaderChild->FloatAttribute("val"); variableMap[key] = new FloatVariable(val); } if (_name == "vec4") { //read vec4 std::string key = shaderChild->Attribute("name"); float x = shaderChild->FloatAttribute("x"); float y = shaderChild->FloatAttribute("y"); float z = shaderChild->FloatAttribute("z"); float w = shaderChild->FloatAttribute("w"); variableMap[key] = new Float4Variable(x, y, z, w); } if (_name == "int") { //read vec4 std::string key = shaderChild->Attribute("name"); float val = shaderChild->FloatAttribute("val"); variableMap[key] = new IntVariable(val); } if (_name == "mat4") { //read vec4 std::string key = shaderChild->Attribute("name"); float a1 = shaderChild->FloatAttribute("a1"); float a2 = shaderChild->FloatAttribute("a2"); float a3 = shaderChild->FloatAttribute("a3"); float a4 = shaderChild->FloatAttribute("a4"); float b1 = shaderChild->FloatAttribute("b1"); float b2 = shaderChild->FloatAttribute("b2"); float b3 = shaderChild->FloatAttribute("b3"); float b4 = shaderChild->FloatAttribute("b4"); float c1 = shaderChild->FloatAttribute("c1"); float c2 = shaderChild->FloatAttribute("c2"); float c3 = shaderChild->FloatAttribute("c3"); float c4 = shaderChild->FloatAttribute("c4"); float d1 = shaderChild->FloatAttribute("d1"); float d2 = shaderChild->FloatAttribute("d2"); float d3 = shaderChild->FloatAttribute("d3"); float d4 = shaderChild->FloatAttribute("d4"); float val[16] = { a1, a1, a3, a4, b1, b2, b3, b4, c1, c2, c3, c4, d1, d2, d3, d4 }; variableMap[key] = new Matrix4FloatVariable(val); } if (_name == "texture") { //read texture std::string key = shaderChild->Attribute("name"); std::string fileName = shaderChild->Attribute("file"); Texture* texture = ResourceManager::OpenTexture(UStringFromCharArray(fileName.c_str())); if (!texture) { return false; } variableMap[key] = new TextureVariable(texture); } shaderChild = shaderChild->NextSiblingElement(); } return true; }
void Level::loadMap(std::string mapName, Graphics &graphics) { //Parse the .tmx file XMLDocument doc; std::stringstream ss; ss << "content/maps/" << mapName << ".tmx"; //Pass in Map1; content/maps/Map1.tmx doc.LoadFile(ss.str().c_str()); XMLElement* mapNode = doc.FirstChildElement("map"); //Get the width and the height of the whole map and store it in _size int width, height; mapNode->QueryIntAttribute("width", &width); mapNode->QueryIntAttribute("height", &height); this->_size = Vector2(width, height); //Get the width and the height of an individual tile and store it in _tileSize int tileWidth, tileHeight; mapNode->QueryIntAttribute("tilewidth", &tileWidth); mapNode->QueryIntAttribute("tileheight", &tileHeight); this->_tileSize = Vector2(tileWidth, tileHeight); //Load the tilesets XMLElement* pTileset = mapNode->FirstChildElement("tileset"); if (pTileset != NULL) { while (pTileset) { int firstgid; const char* source = pTileset->FirstChildElement("image")->Attribute("source"); std::string path = source; path.replace(0, 2, "content"); pTileset->QueryIntAttribute("firstgid", &firstgid); SDL_Texture* tex = SDL_CreateTextureFromSurface(graphics.getRenderer(), graphics.loadImage(path)); this->_tilesets.push_back(Tileset(tex, firstgid)); // Get all the animations for that tileset XMLElement* pTileA = pTileset->FirstChildElement("tile"); if (pTileA != NULL) { while (pTileA) { AnimatedTileInfo ati; ati.StartTileId = pTileA->IntAttribute("id") + firstgid; ati.TilesetsFirstGid = firstgid; XMLElement* pAnimation = pTileA->FirstChildElement("animation"); if (pAnimation != NULL) { while (pAnimation) { XMLElement* pFrame = pAnimation->FirstChildElement("frame"); if (pFrame != NULL) { while (pFrame) { ati.TileIds.push_back(pFrame->IntAttribute("tileid") + firstgid); ati.Duration = pFrame->IntAttribute("duration"); pFrame = pFrame->NextSiblingElement("frame"); } } pAnimation = pAnimation->NextSiblingElement("animation"); } } this->_animatedTileInfos.push_back(ati); pTileA = pTileA->NextSiblingElement("tile"); } } pTileset = pTileset->NextSiblingElement("tileset"); } } //Loading the layers XMLElement* pLayer = mapNode->FirstChildElement("layer"); if (pLayer != NULL) { while (pLayer) { //Loading the data element XMLElement* pData = pLayer->FirstChildElement("data"); if (pData != NULL) { while (pData) { //Loading the tile element XMLElement* pTile = pData->FirstChildElement("tile"); if (pTile != NULL) { int tileCounter = 0; while (pTile) { //Build each individual tile here //If gid is 0, no tile should be drawn. Continue loop. if (pTile->IntAttribute("gid") == 0) { tileCounter++; if (pTile->NextSiblingElement("tile")) { pTile = pTile->NextSiblingElement("tile"); continue; } else { break; } } //Get the tileset for this specific gid int gid = pTile->IntAttribute("gid"); Tileset tls; int closest = 0; for (int i = 0; i < this->_tilesets.size(); i++) { if (this->_tilesets[i].FirstGid <= gid) { if (this->_tilesets[i].FirstGid > closest) { closest = this->_tilesets[i].FirstGid; tls = this->_tilesets.at(i); } } } if (tls.FirstGid == -1) { //No tileset was found for this gid tileCounter++; if (pTile->NextSiblingElement("tile")) { pTile = pTile->NextSiblingElement("tile"); continue; } else { break; } } //Get the position of the tile in the level int xx = 0; int yy = 0; xx = tileCounter % width; xx *= tileWidth; yy += tileHeight * (tileCounter / width); Vector2 finalTilePosition = Vector2(xx, yy); //Calculate the position of the tile in the tileset Vector2 finalTilesetPosition = this->getTilesetPosition(tls, gid, tileWidth, tileHeight); //Build the actual tile and add it to the level's tile list bool isAnimatedTile = false; AnimatedTileInfo ati; for (int i = 0; i < this->_animatedTileInfos.size(); i++) { if (this->_animatedTileInfos.at(i).StartTileId == gid) { ati = this->_animatedTileInfos.at(i); isAnimatedTile = true; break; } } if (isAnimatedTile == true) { std::vector<Vector2> tilesetPositions; for (int i = 0; i < ati.TileIds.size(); i++) { tilesetPositions.push_back(this->getTilesetPosition( tls, ati.TileIds.at(i), tileWidth, tileHeight)); } AnimatedTile tile(tilesetPositions, ati.Duration, tls.Texture, Vector2(tileWidth, tileHeight), finalTilePosition); this->_animatedTileList.push_back(tile); } else { Tile tile(tls.Texture, Vector2(tileWidth, tileHeight), finalTilesetPosition, finalTilePosition); this->_tileList.push_back(tile); } tileCounter++; pTile = pTile->NextSiblingElement("tile"); } } pData = pData->NextSiblingElement("data"); } } pLayer = pLayer->NextSiblingElement("layer"); } } // Parse out the collisions XMLElement* pObjectGroup = mapNode->FirstChildElement("objectgroup"); if (pObjectGroup != NULL) { while (pObjectGroup) { const char* name = pObjectGroup->Attribute("name"); std::stringstream ss; ss << name; if (ss.str() == "collisions") { XMLElement* pObject = pObjectGroup->FirstChildElement("object"); if (pObject != NULL) { while (pObject) { float x, y, width, height; x = pObject->FloatAttribute("x"); y = pObject->FloatAttribute("y"); width = pObject->FloatAttribute("width"); height = pObject->FloatAttribute("height"); this->_collisionRects.push_back(Rectangle( std::ceil(x) * globals::SPRITE_SCALE, std::ceil(y) * globals::SPRITE_SCALE, std::ceil(width) * globals::SPRITE_SCALE, std::ceil(height) * globals::SPRITE_SCALE )); pObject = pObject->NextSiblingElement("object"); } } } // Other object groups go here with an else if (ss.str() == "whatever") else if (ss.str() == "slopes") { XMLElement* pObject = pObjectGroup->FirstChildElement("object"); if (pObject != NULL) { while (pObject) { std::vector<Vector2> points; Vector2 p1; p1 = Vector2(std::ceil(pObject->FloatAttribute("x")), std::ceil(pObject->FloatAttribute("y"))); XMLElement* pPolyline = pObject->FirstChildElement("polyline"); if (pPolyline != NULL) { std::vector<std::string> pairs; const char* pointString = pPolyline->Attribute("points"); std::stringstream ss; ss << pointString; Utils::split(ss.str(), pairs, ' '); // Now we have each of the pairs. Loop through the list of pairs and // split them into Vector2s. Then store them in points vector. for (int i = 0; i < pairs.size(); i++) { std::vector<std::string> ps; Utils::split(pairs.at(i), ps, ','); points.push_back(Vector2( std::stoi(ps.at(0)), std::stoi(ps.at(1)))); } } for (int i = 0; i < points.size(); i += 2) { this->_slopes.push_back(Slope( Vector2( (p1.x + points.at(i < 2 ? i : i - 1).x) * globals::SPRITE_SCALE, (p1.y + points.at(i < 2 ? i : i - 1).y) * globals::SPRITE_SCALE), Vector2( (p1.x + points.at(i < 2 ? i + 1 : i).x) * globals::SPRITE_SCALE, (p1.y + points.at(i < 2 ? i + 1 : i).y) * globals::SPRITE_SCALE) ) ); } pObject = pObject->NextSiblingElement("object"); } } } else if (ss.str() == "spawn points") { XMLElement* pObject = pObjectGroup->FirstChildElement("object"); if (pObject != NULL) { while (pObject) { float x = pObject->FloatAttribute("x"); float y = pObject->FloatAttribute("y"); const char* name = pObject->Attribute("name"); std::stringstream ss; ss << name; if (ss.str() == "player") { this->_spawnPoint = Vector2(std::ceil(x) * globals::SPRITE_SCALE, std::ceil(y) * globals::SPRITE_SCALE); } pObject = pObject->NextSiblingElement("object"); } } } // Parse doors if they exist else if (ss.str() == "doors") { XMLElement* pObject = pObjectGroup->FirstChildElement("object"); if (pObject != NULL) { while (pObject) { float x = pObject->FloatAttribute("x"); float y = pObject->FloatAttribute("y"); float w = pObject->FloatAttribute("width"); float h = pObject->FloatAttribute("height"); Rectangle rect = Rectangle(x, y, w, h); XMLElement* pProperties = pObject->FirstChildElement("properties"); if (pProperties != NULL) { while (pProperties) { XMLElement* pProperty = pProperties->FirstChildElement("property"); if (pProperty != NULL) { while (pProperty) { const char* name = pProperty->Attribute("name"); std::stringstream ss; ss << name; if (ss.str() == "destination") { const char* value = pProperty->Attribute("value"); std::stringstream ss2; ss2 << value; Door door = Door(rect, ss2.str()); this->_doorList.push_back(door); } pProperty = pProperty->NextSiblingElement("property"); } } pProperties = pProperties->NextSiblingElement("properties"); } } pObject = pObject->NextSiblingElement("object"); } } } pObjectGroup = pObjectGroup->NextSiblingElement("objectgroup"); } } }
std::unique_ptr<ensoft::tmx::Map> ensoft::tmx::TmxLoader::loadMap(std::string filename) { Logger logger("TMX Loader"); logger.log("Loading " + filename); XMLDocument doc; XMLError error = doc.LoadFile(filename.c_str()); std::unique_ptr<ensoft::tmx::Map> map; if (error != XMLError::XML_NO_ERROR) { logger.error("Error code: " + std::to_string(error)); } else { // start parsing the TMX map XMLElement *xmap = doc.FirstChildElement("map"); map = std::make_unique<ensoft::tmx::Map>(loadProperties(xmap)); map->version = xmap->Attribute("version"); map->orientation = xmap->Attribute("orientation"); map->width = xmap->IntAttribute("width"); map->height = xmap->IntAttribute("height"); map->tilewidth = xmap->IntAttribute("tilewidth"); map->tileheight = xmap->IntAttribute("tileheight"); map->renderorder = xmap->Attribute("renderorder"); map->properties = loadProperties(xmap); // load all the tilesets XMLElement *xtileset = xmap->FirstChildElement("tileset"); while (xtileset) { auto tileSet = std::make_unique<ensoft::tmx::TileSet>(loadProperties(xtileset)); tileSet->firstgid = xtileset->IntAttribute("firstgid"); tileSet->source = getAttributeString(xtileset, "source"); tileSet->name = getAttributeString(xtileset, "name"); tileSet->tilewidth = xtileset->IntAttribute("tilewidth"); tileSet->tileheight = xtileset->IntAttribute("tileheight"); tileSet->spacing = xtileset->IntAttribute("spacing"); tileSet->margin = xtileset->IntAttribute("margin"); // get the tiles for this tileset XMLElement *xtile = xtileset->FirstChildElement("tile"); while (xtile) { auto tile = make_unique<ensoft::tmx::Tile>(loadProperties(xtile)); tile->id = xtile->IntAttribute("id"); tile->terrain = getAttributeString(xtile, "terrain"); tile->probability = xtile->FloatAttribute("probability"); tile->image = loadImage(xtile); // keep track of all tiles and their global IDs int tileGid = tileSet->firstgid + tile->id; map->allTiles[tileGid] = tile.get(); std::cout << "[TMX Loader] Added: " << tile->image.source << " GID: " << tileGid << " Tileset: " << tileSet->name << std::endl; tileSet->tiles.push_back(std::move(tile)); xtile = xtile->NextSiblingElement("tile"); } map->tilesets.push_back(std::move(tileSet)); // try to find another tileset xtileset = xtileset->NextSiblingElement("tileset"); } XMLElement *xlayer = xmap->FirstChildElement("layer"); while (xlayer) { auto layer = std::make_shared<ensoft::tmx::Layer>(loadProperties(xlayer)); layer->name = xlayer->Attribute("name"); layer->x = xlayer->IntAttribute("x"); layer->y = xlayer->IntAttribute("y"); layer->width = xlayer->IntAttribute("width"); layer->height = xlayer->IntAttribute("height"); layer->opacity = xlayer->FloatAttribute("opacity"); layer->visible = xlayer->BoolAttribute("visible"); // load the data element XMLElement *xdata = xlayer->FirstChildElement("data"); if (xdata) { string data = trim_copy(xdata->GetText()); loadData(*layer, map.get(), data); } map->layers.push_back(layer); xlayer = xlayer->NextSiblingElement("layer"); } XMLElement *ximagelayer = xmap->FirstChildElement("imagelayer"); while (ximagelayer) { auto imageLayer = std::make_unique<ensoft::tmx::ImageLayer>(loadProperties(ximagelayer)); imageLayer->name = ximagelayer->Attribute("name"); imageLayer->x = ximagelayer->IntAttribute("x"); imageLayer->y = ximagelayer->IntAttribute("y"); imageLayer->width = ximagelayer->IntAttribute("width"); imageLayer->height = ximagelayer->IntAttribute("height"); imageLayer->opacity = ximagelayer->FloatAttribute("opacity"); imageLayer->visible = ximagelayer->BoolAttribute("visible"); imageLayer->image = loadImage(ximagelayer); map->imageLayers.push_back(std::move(imageLayer)); ximagelayer = ximagelayer->NextSiblingElement("imagelayer"); } XMLElement *xobjectgroup = xmap->FirstChildElement("objectgroup"); while (xobjectgroup) { auto objectGroup = std::make_unique<ensoft::tmx::ObjectGroup>(loadProperties(xobjectgroup)); objectGroup->name = xobjectgroup->Attribute("name"); objectGroup->x = xobjectgroup->IntAttribute("x"); objectGroup->y = xobjectgroup->IntAttribute("y"); objectGroup->width = xobjectgroup->IntAttribute("width"); objectGroup->height = xobjectgroup->IntAttribute("height"); objectGroup->opacity = xobjectgroup->FloatAttribute("opacity"); objectGroup->visible = xobjectgroup->BoolAttribute("visible"); //grab the objects XMLElement *xobject = xobjectgroup->FirstChildElement("object"); while (xobject) { auto object = std::make_unique<ensoft::tmx::Object>(loadProperties(xobject)); object->id = xobject->Attribute("id"); object->name = getAttributeString(xobject, "name"); object->type = getAttributeString(xobject, "type"); object->x = xobject->IntAttribute("x"); object->y = xobject->IntAttribute("y"); object->width = xobject->IntAttribute("witdth"); object->height = xobject->IntAttribute("height"); object->gid = xobject->IntAttribute("gid"); object->visible = xobject->BoolAttribute("visible"); objectGroup->objects.push_back(std::move(object)); xobject = xobject->NextSiblingElement("object"); } map->objectGroups.push_back(std::move(objectGroup)); xobjectgroup = xobjectgroup->NextSiblingElement("objectgroup"); } } return std::move(map); }
void LevelFileHelper::loadLevel() { XMLDocument doc; // doc.LoadFile(CCFileUtils::sharedFileUtils()->fullPathForFilename("test.xml").c_str()); // const char* content= doc.FirstChildElement( "Hello" )->GetText(); // printf( "Hello,%s\n", content ); _pineapples = CCArray::create(); _pineapples->retain(); _ropes = CCArray::create(); _ropes->retain(); unsigned char* pBuffer = NULL; unsigned long bufferSize = 0; //for android pBuffer = CCFileUtils::sharedFileUtils()->getFileData(_levelFile, "r", &bufferSize); if (pBuffer) { doc.Parse((const char*)pBuffer); } // doc.LoadFile(_levelFile); XMLElement *level = doc.RootElement(); XMLElement *pineaplle = level->FirstChildElement("pineapple"); while (pineaplle) { int id = (int)pineaplle->IntAttribute("id"); float x = pineaplle->FloatAttribute("x"); float y = pineaplle->FloatAttribute("y"); float damping = pineaplle->FloatAttribute("damping"); PineappleModel *pm = new PineappleModel(); pm->id = id; pm->position = ccp(x,y); pm->damping = damping > 0 ? damping : kDefaultDamping; _pineapples->addObject(pm); pm->release(); //CCLOG("id = %d",id); pineaplle = pineaplle->NextSiblingElement("pineapple"); } XMLElement *rope = level->FirstChildElement("rope"); int ropeID = 1; while (rope) { RopeModel *rm = new RopeModel; rm->id = ropeID; //achorA const XMLElement* ropeChild = rope->FirstChildElement(); int bodyAId = ropeChild->IntAttribute("body"); rm->bodyAId = bodyAId; float ax; float ay; if (rm->bodyAId == -1) { ax = ropeChild->FloatAttribute("x"); ay = ropeChild->FloatAttribute("y"); }else{ PineappleModel *pm = this->getPineappleWithID(rm->bodyAId); ax = pm->position.x; ay = pm->position.y; } rm->achorA = ccp(ax,ay); //achorB ropeChild = ropeChild->NextSiblingElement(); int bodyBId = ropeChild->IntAttribute("body"); rm->bodyBId = bodyBId; if (rm->bodyBId == -1) { ax = ropeChild->FloatAttribute("x"); ay = ropeChild->FloatAttribute("y"); }else{ PineappleModel *pm = this->getPineappleWithID(rm->bodyBId); ax = pm->position.x; ay = pm->position.y; } rm->achorB = ccp(ax,ay); float sagity = rope->FloatAttribute("sagity"); if (sagity > 0) { rm->sagity = sagity; } _ropes->addObject(rm); rm->release(); ropeID++; //next rope rope = rope->NextSiblingElement("rope"); } }
Scene* XMLLoader::parseSceneXML(std::string fpath) { tinyxml2::XMLDocument document; XMLError error = document.LoadFile(fpath.c_str()); if (error != XML_SUCCESS) { return NULL; } XMLElement* root = document.RootElement(); XMLElement* sceneElement = root->FirstChildElement(); Scene* scene = new Scene(); while(sceneElement != NULL) { std::string elementType = sceneElement->Name(); if(elementType == "camera") { XMLElement* elementInfo = sceneElement->FirstChildElement(); float xFoV = 60.f; float yFoV = 60.f; float nearClip = 0.1f; float farClip = 1000.f; float width = 800.f; float height = 600.f; XMFLOAT3 up(0.f, 1.f, 0.f); XMFLOAT3 lookAt(0.f, 0.f, -10.f); XMFLOAT3 translate(0.f, 0.f, 0.f); XMFLOAT3 rotateAxis(0.f, 0.f, 1.f); float rotateDegrees = 0.f; while(elementInfo != NULL) { std::string info = elementInfo->Name(); if(info == "perspective") { elementInfo->QueryFloatAttribute("xfov", &xFoV); elementInfo->QueryFloatAttribute("yfov", &yFoV); elementInfo->QueryFloatAttribute("near", &nearClip); elementInfo->QueryFloatAttribute("far", &farClip); elementInfo->QueryFloatAttribute("width", &width); elementInfo->QueryFloatAttribute("height", &height); } else if(info == "lookat") { elementInfo->QueryFloatAttribute("x", &lookAt.x); elementInfo->QueryFloatAttribute("y", &lookAt.y); elementInfo->QueryFloatAttribute("z", &lookAt.z); elementInfo->QueryFloatAttribute("upX", &up.x); elementInfo->QueryFloatAttribute("upY", &up.y); elementInfo->QueryFloatAttribute("upZ", &up.z); } else if(info == "translate") { elementInfo->QueryFloatAttribute("x", &translate.x); elementInfo->QueryFloatAttribute("y", &translate.y); elementInfo->QueryFloatAttribute("z", &translate.z); } else if(info == "rotate") { elementInfo->QueryFloatAttribute("axisX", &rotateAxis.x); elementInfo->QueryFloatAttribute("axisY", &rotateAxis.y); elementInfo->QueryFloatAttribute("axisZ", &rotateAxis.z); elementInfo->QueryFloatAttribute("degrees", &rotateDegrees); } else { std::cout << __LINE__ << " -- boom\n"; } elementInfo = elementInfo->NextSiblingElement(); } //create camera Camera* camera = new Camera(width, height, xFoV, yFoV, nearClip, farClip); camera->setPosition(translate); camera->setTarget(lookAt, up); //set camera in scene scene->setCamera(camera); } else if(elementType == "pointLight") { XMLElement* elementInfo = sceneElement->FirstChildElement(); XMFLOAT3 translate(0.f, 0.f, 0.f); XMFLOAT4 color(1.f, 1.f, 1.f, 1.f); while(elementInfo != NULL) { std::string info = elementInfo->Name(); if(info == "translate") { elementInfo->QueryFloatAttribute("x", &translate.x); elementInfo->QueryFloatAttribute("y", &translate.y); elementInfo->QueryFloatAttribute("z", &translate.z); } else if(info == "color") { elementInfo->QueryFloatAttribute("r", &color.x); elementInfo->QueryFloatAttribute("g", &color.y); elementInfo->QueryFloatAttribute("b", &color.z); } else { std::cout << __LINE__ << " -- boom\n"; } elementInfo = elementInfo->NextSiblingElement(); } //create pointlight PointLight* pointLight = new PointLight(); pointLight->setPosition(translate); pointLight->power = color; //add pointlight to scene scene->addLight(pointLight); } else if(elementType == "areaLight") { XMLElement* elementInfo = sceneElement->FirstChildElement(); float width = sceneElement->FloatAttribute("width"); float height = sceneElement->FloatAttribute("height"); XMFLOAT3 translate(0.f, 0.f, 0.f); XMFLOAT4 color(1.f, 1.f, 1.f, 1.f); XMFLOAT3 target = translate; XMFLOAT3 rotateAxis(0.f, 0.f, 1.f); XMFLOAT3 scale(1.f, 1.f, 1.f); float rotateDegrees = 0.f; while(elementInfo != NULL) { std::string info = elementInfo->Name(); if(info == "translate") { elementInfo->QueryFloatAttribute("x", &translate.x); elementInfo->QueryFloatAttribute("y", &translate.y); elementInfo->QueryFloatAttribute("z", &translate.z); } else if(info == "color") { elementInfo->QueryFloatAttribute("r", &color.x); elementInfo->QueryFloatAttribute("g", &color.y); elementInfo->QueryFloatAttribute("b", &color.z); } else if(info == "target") { elementInfo->QueryFloatAttribute("x", &target.x); elementInfo->QueryFloatAttribute("y", &target.y); elementInfo->QueryFloatAttribute("z", &target.z); } else if(info == "rotate") { elementInfo->QueryFloatAttribute("axisX", &rotateAxis.x); elementInfo->QueryFloatAttribute("axisY", &rotateAxis.y); elementInfo->QueryFloatAttribute("axisZ", &rotateAxis.z); elementInfo->QueryFloatAttribute("degrees", &rotateDegrees); } else if(info == "scale") { elementInfo->QueryFloatAttribute("x", &scale.x); elementInfo->QueryFloatAttribute("y", &scale.y); elementInfo->QueryFloatAttribute("z", &scale.z); } else { std::cout << __LINE__ << " -- boom\n"; } elementInfo = elementInfo->NextSiblingElement(); } //create arealight AreaLight* areaLight = new AreaLight(); areaLight->width = width; areaLight->height = height; areaLight->setPosition(translate); areaLight->setRotation(rotateAxis, rotateDegrees); areaLight->setScale(scale); areaLight->power = color; XMVECTOR pos = XMLoadFloat3(&translate); XMVECTOR tar = XMLoadFloat3(&target); XMStoreFloat3(&areaLight->direction, XMVector3Normalize(tar - pos)); //add arealight to scene scene->addLight(areaLight); } else if(elementType == "sphere") { XMLElement* elementInfo = sceneElement->FirstChildElement(); // get sphere information float radius = sceneElement->FloatAttribute("radius"); XMFLOAT3 translate(0.f, 0.f, 0.f); XMFLOAT3 color(1.f, 1.f, 1.f); XMFLOAT3 scale(1.f, 1.f, 1.f); XMFLOAT3 target = translate; XMFLOAT3 rotateAxis(0.f, 0.f, 1.f); float rotateDegrees = 0.f; while(elementInfo != NULL) { std::string info = elementInfo->Name(); if(info == "translate") { elementInfo->QueryFloatAttribute("x", &translate.x); elementInfo->QueryFloatAttribute("y", &translate.y); elementInfo->QueryFloatAttribute("z", &translate.z); } else if(info == "color") { elementInfo->QueryFloatAttribute("r", &color.x); elementInfo->QueryFloatAttribute("g", &color.y); elementInfo->QueryFloatAttribute("b", &color.z); } else if(info == "rotate") { elementInfo->QueryFloatAttribute("axisX", &rotateAxis.x); elementInfo->QueryFloatAttribute("axisY", &rotateAxis.y); elementInfo->QueryFloatAttribute("axisZ", &rotateAxis.z); elementInfo->QueryFloatAttribute("degrees", &rotateDegrees); } else if(info == "scale") { elementInfo->QueryFloatAttribute("x", &scale.x); elementInfo->QueryFloatAttribute("y", &scale.y); elementInfo->QueryFloatAttribute("z", &scale.z); } else { std::cout << __LINE__ << " -- boom\n"; } elementInfo = elementInfo->NextSiblingElement(); } //create sphere Sphere* sphere = new Sphere(); sphere->SetRadius(radius); sphere->setPosition(translate); sphere->setRotation(rotateAxis, rotateDegrees); sphere->setScale(scale); sphere->color = color; //add sphere to scene scene->addPrimitive(sphere); } else if(elementType == "cube") { XMLElement* elementInfo = sceneElement->FirstChildElement(); float edgelen = sceneElement->FloatAttribute("edgelen"); XMFLOAT3 translate(0.f, 0.f, 0.f); XMFLOAT3 color(1.f, 1.f, 1.f); XMFLOAT3 scale(1.f, 1.f, 1.f); XMFLOAT3 target = translate; XMFLOAT3 rotateAxis(0.f, 0.f, 1.f); float rotateDegrees = 0.f; while(elementInfo != NULL) { std::string info = elementInfo->Name(); if(info == "translate") { elementInfo->QueryFloatAttribute("x", &translate.x); elementInfo->QueryFloatAttribute("y", &translate.y); elementInfo->QueryFloatAttribute("z", &translate.z); } else if(info == "color") { elementInfo->QueryFloatAttribute("r", &color.x); elementInfo->QueryFloatAttribute("g", &color.y); elementInfo->QueryFloatAttribute("b", &color.z); } else if(info == "rotate") { elementInfo->QueryFloatAttribute("axisX", &rotateAxis.x); elementInfo->QueryFloatAttribute("axisY", &rotateAxis.y); elementInfo->QueryFloatAttribute("axisZ", &rotateAxis.z); elementInfo->QueryFloatAttribute("degrees", &rotateDegrees); } else if(info == "scale") { elementInfo->QueryFloatAttribute("x", &scale.x); elementInfo->QueryFloatAttribute("y", &scale.y); elementInfo->QueryFloatAttribute("z", &scale.z); } else { std::cout << __LINE__ << " -- boom\n"; } elementInfo = elementInfo->NextSiblingElement(); } //create cube Cube* cube = new Cube(); cube->SetEdgeLen(edgelen/2.f); cube->setPosition(translate); cube->setRotation(rotateAxis, rotateDegrees); cube->setScale(scale); cube->color = color; //add cube to scene scene->addPrimitive(cube); } else if(elementType == "square") { XMLElement* elementInfo = sceneElement->FirstChildElement(); float edgelen = sceneElement->FloatAttribute("edgelen"); XMFLOAT3 translate(0.f, 0.f, 0.f); XMFLOAT3 color(1.f, 1.f, 1.f); XMFLOAT3 scale(1.f, 1.f, 1.f); XMFLOAT3 target = translate; XMFLOAT3 rotateAxis(0.f, 0.f, 1.f); float rotateDegrees = 0.f; while(elementInfo != NULL) { std::string info = elementInfo->Name(); if(info == "translate") { elementInfo->QueryFloatAttribute("x", &translate.x); elementInfo->QueryFloatAttribute("y", &translate.y); elementInfo->QueryFloatAttribute("z", &translate.z); } else if(info == "color") { elementInfo->QueryFloatAttribute("r", &color.x); elementInfo->QueryFloatAttribute("g", &color.y); elementInfo->QueryFloatAttribute("b", &color.z); } else if(info == "rotate") { elementInfo->QueryFloatAttribute("axisX", &rotateAxis.x); elementInfo->QueryFloatAttribute("axisY", &rotateAxis.y); elementInfo->QueryFloatAttribute("axisZ", &rotateAxis.z); elementInfo->QueryFloatAttribute("degrees", &rotateDegrees); } else if(info == "scale") { elementInfo->QueryFloatAttribute("x", &scale.x); elementInfo->QueryFloatAttribute("y", &scale.y); elementInfo->QueryFloatAttribute("z", &scale.z); } else { std::cout << __LINE__ << " -- boom\n"; } elementInfo = elementInfo->NextSiblingElement(); } //create square Square* square = new Square(); square->SetEdgeLen(edgelen); square->setPosition(translate); square->setRotation(rotateAxis, rotateDegrees); square->setScale(scale); square->color = color; //add square to scene scene->addPrimitive(square); } else { std::cout << __LINE__ << " -- boom\n"; } sceneElement = sceneElement->NextSiblingElement(); } return scene; }