Esempio n. 1
0
void TerrainTile::saveToXML(TiXmlElement* parentElement)
{
	// Save the terrain land

	f32 x = 0;
	f32 z = 0;

	x = node->getPosition().X;
	z = node->getPosition().Z;

    TiXmlElement* segmentXML = new TiXmlElement("terrainSegment");
    segmentXML->SetDoubleAttribute("x",x);
    segmentXML->SetDoubleAttribute("z",z);

	core::stringc file=TerrainManager::getInstance()->filename;

	segmentXML->SetAttribute("mesh",file.c_str());

	//Saving the vegetation information with the tile
	if (vegetationVector.size()>0)
	{
		for (int i=0 ; i<(int)vegetationVector.size() ; i++)
		{
			TiXmlElement* vertexXML = new TiXmlElement("tree");
			Vegetation * tree = (Vegetation*)vegetationVector[i];

			if (tree!=NULL)
			{
				vector3df treepos=tree->getPosition();
				vertexXML->SetAttribute("v",tree->getType());
				vertexXML->SetDoubleAttribute("tx",tree->getPosition().X);
				vertexXML->SetDoubleAttribute("ty",tree->getPosition().Y);
				vertexXML->SetDoubleAttribute("tz",tree->getPosition().Z);
				vertexXML->SetDoubleAttribute("tr",tree->getNode()->getRotation().Y);
				vertexXML->SetDoubleAttribute("ts",tree->getNode()->getScale().X);
			}
			segmentXML->LinkEndChild(vertexXML);
		}

	}

	parentElement->LinkEndChild(segmentXML);
}
Esempio n. 2
0
TerrainTile::~TerrainTile()
{
	for (int i=0 ; i<(int)vegetationVector.size() ; i++)
    {
    	Vegetation* temp = (Vegetation*)vegetationVector[i];
		if (temp->getNode())
			temp->getNode()->remove();

		//if (temp)
		//	delete temp;
    }
    vegetationVector.clear();

	if (selector)
		selector->drop();

	if (node)
	{
		node->remove();
	}

}
Esempio n. 3
0
//Reposition the vegetation (trees) to touch the ground
void TerrainTile::resetVegetationHeight()
{
	for (int i=0 ; i<(int)vegetationVector.size() ; i++)
    {
    	Vegetation* temp = (Vegetation*)vegetationVector[i];
		f32 newpos = this->getHeightAt(temp->getPosition(),4000.0f);
		if (newpos<-200.0f) //Remove the tree if it's too low (underwater)
		{
			temp->getNode()->remove();
			vegetationVector.erase(vegetationVector.begin()+i);
		}
		else
		temp->setPosition(vector3df(temp->getPosition().X,newpos-3.0f,temp->getPosition().Z)); //little offset of 3 units.
    }
}