当前位置: 首页>>代码示例>>C++>>正文


C++ XMLElement::FloatAttribute方法代码示例

本文整理汇总了C++中XMLElement::FloatAttribute方法的典型用法代码示例。如果您正苦于以下问题:C++ XMLElement::FloatAttribute方法的具体用法?C++ XMLElement::FloatAttribute怎么用?C++ XMLElement::FloatAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在XMLElement的用法示例。


在下文中一共展示了XMLElement::FloatAttribute方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Load

	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");
		}
	}
开发者ID:ebithril,项目名称:ModelViewer,代码行数:55,代码来源:ParticleSystemData.cpp

示例2: init

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;
}
开发者ID:proywm,项目名称:Gravitate,代码行数:49,代码来源:VisualComponent.cpp

示例3: if

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");
  }
}
开发者ID:Caennalla,项目名称:sdlcoursetasks,代码行数:20,代码来源:GameObject.cpp

示例4: VInit

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;
}
开发者ID:ljkd,项目名称:SAGE,代码行数:45,代码来源:TransformComponent.cpp

示例5: loadMap


//.........这里部分代码省略.........
							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
开发者ID:RandallJEllis,项目名称:cavestory-development,代码行数:67,代码来源:level.cpp

示例6: loadMap


//.........这里部分代码省略.........
									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");
		}
	}
}
开发者ID:torchedplatypi,项目名称:remake_cavestory,代码行数:101,代码来源:level.cpp

示例7: ReadShaderChildren

	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;
	}
开发者ID:ritgraphics,项目名称:VixenEngine,代码行数:85,代码来源:vix_material.cpp

示例8: loadMap


//.........这里部分代码省略.........
											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;
开发者ID:jwl,项目名称:mycavestory,代码行数:67,代码来源:level.cpp

示例9: logger

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");

//.........这里部分代码省略.........
开发者ID:nickenchev,项目名称:boiler,代码行数:101,代码来源:tmxloader.cpp

示例10: loadLevel

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();
//.........这里部分代码省略.........
开发者ID:4nakin,项目名称:CutTheRope-x,代码行数:101,代码来源:LevelFileHandler.cpp

示例11: parseSceneXML

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);
//.........这里部分代码省略.........
开发者ID:Joey4s6l,项目名称:instant-radiosity,代码行数:101,代码来源:xmlLoader.cpp


注:本文中的XMLElement::FloatAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。