Esempio n. 1
0
bool cePatchMeshGL20::Initialize (iDevice						*device,
															iVertexBuffer				*vertices, 
															unsigned						numVertexP, 
															unsigned						numVertexQ,
															iVertexDeclaration *vertexDeclaration,
															unsigned						numPatchesP, 
															unsigned						numPatchesQ, 
															float								distance,
															bool								wrapP, 
															bool								wrapQ)
{
	assert (device);
	assert (vertices);
	assert (vertexDeclaration);

	// first initial all private members
  CE_SET(_vertices, vertices);
	_numP = numVertexP;
	_numQ = numVertexQ;
  CE_SET(_vertexDeclaration, vertexDeclaration);

	if (!CreatePatches (device, numPatchesP, numPatchesQ, wrapP, wrapQ)) return false;
	InitializePatches (1);
	if (!UpdatePatchBoundingBoxes (distance)) return false;

	return true;
}
Esempio n. 2
0
void TERRAIN::GenerateRandomTerrain(int numPatches)
{
	try
	{
		Release();

		//Create two heightmaps and multiply them
		m_pHeightMap = new HEIGHTMAP(m_size, 20.0f);
		HEIGHTMAP hm2(m_size, 2.0f);

		m_pHeightMap->CreateRandomHeightMap(rand()%2000, 1.0f, 0.7f, 7);
		hm2.CreateRandomHeightMap(rand()%2000, 2.5f, 0.8f, 3);

		hm2.Cap(hm2.m_maxHeight * 0.4f);

		*m_pHeightMap *= hm2;
		hm2.Release();
		
		//Add objects
		HEIGHTMAP hm3(m_size, 1.0f);
		hm3.CreateRandomHeightMap(rand()%1000, 5.5f, 0.9f, 7);

		for(int y=0;y<m_size.y;y++)
			for(int x=0;x<m_size.x;x++)
			{
				if(m_pHeightMap->GetHeight(x, y) == 0.0f && hm3.GetHeight(x, y) > 0.7f && rand()%6 == 0)
					AddObject(0, INTPOINT(x, y));	//Tree
				else if(m_pHeightMap->GetHeight(x, y) >= 1.0f && hm3.GetHeight(x, y) > 0.9f && rand()%20 == 0)
					AddObject(1, INTPOINT(x, y));	//Stone
			}

		hm3.Release();

		InitPathfinding();
		CreatePatches(numPatches);
		CalculateAlphaMaps();
		CalculateLightMap(false);
	}
	catch(...)
	{
		debug.Print("Error in TERRAIN::GenerateRandomTerrain()");
	}
}
Esempio n. 3
0
void TERRAIN::GenerateRandomTerrain(int numPatches)
{
	try
	{
		Release();

		//Create two heightmaps and multiply them
		m_pHeightMap = new HEIGHTMAP(m_size, 15.0f);
		HEIGHTMAP hm2(m_size, 30.0f);

		m_pHeightMap->CreateRandomHeightMap(rand()%2000, 2.5f, 0.5f, 8);
		hm2.CreateRandomHeightMap(rand()%2000, 2.5f, 0.7f, 3);
		hm2.Cap(hm2.m_maxHeight * 0.4f);

		*m_pHeightMap *= hm2;
		hm2.Release();

		CreatePatches(numPatches);
	}
	catch(...)
	{
		debug.Print("Error in TERRAIN::GenerateRandomTerrain()");
	}
}
Esempio n. 4
0
void TERRAIN::LoadTerrain(char fileName[])
{
	try
	{
		std::ifstream in(fileName, std::ios::binary);		//Binary format

		if(in.good())
		{
			Release();	//Release all terrain resources

			in.read((char*)&m_size, sizeof(INTPOINT));	//read map size
		
			if(m_pMapTiles != NULL)	//Clear old maptiles
				delete [] m_pMapTiles;

			//Create new maptiles
			m_pMapTiles = new MAPTILE[m_size.x * m_size.y];
			memset(m_pMapTiles, 0, sizeof(MAPTILE)*m_size.x*m_size.y);


			//Read the maptile information
			for(int y=0;y<m_size.y;y++)
				for(int x=0;x<m_size.x;x++)
				{
					MAPTILE *tile = GetTile(x, y);
					in.read((char*)&tile->m_type, sizeof(int));			//type
					in.read((char*)&tile->m_height, sizeof(float));		//Height
				}

			//Read number of objects
			int numObjects = 0;
			in.read((char*)&numObjects, sizeof(int));
			for(int i=0;i<numObjects;i++)
			{
				int type = 0;
				INTPOINT mp;
				D3DXVECTOR3 p, r, s;

				in.read((char*)&type, sizeof(int));			//type
				in.read((char*)&mp, sizeof(INTPOINT));		//mappos
				in.read((char*)&p, sizeof(D3DXVECTOR3));	//Pos
				in.read((char*)&r, sizeof(D3DXVECTOR3));	//Rot
				in.read((char*)&s, sizeof(D3DXVECTOR3));	//Sca

				m_objects.push_back(OBJECT(type, mp, p, r, s));
			}

			//Recreate Terrain
			InitPathfinding();
			CreatePatches(3);
			CalculateAlphaMaps();
			CalculateLightMap(true);
		}

		in.close();
	}
	catch(...)
	{
		debug.Print("Error in TERRAIN::LoadTerrain()");
	}
}