Jump to content
  • Advertisement
Sign in to follow this  
jamesss

"Ati Grass demo" Need help on Billboarding.

This topic is 3686 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i need help applying billboarding on this code.i tried few ways but i got strange results. any help appreciated. thanks all.

bool CGrass::Initialize(std::string texture,int MaxGrass,float x,float y)	
{	
	m_MaxGrass = MaxGrass;

	GrassVertex vertexdata[]=
	{
		//  x   y     z    tu1   tv1   tu2   tv2
		{ -x,  0.0f, 0.0f, 1.0f,  1.0f, 0.0f, 0.0f},
		{  x,  0.0f, 0.0f, 0.01f, 1.0f, 0.0f, 0.0f},
		{  x, -y,    0.0f, 0.01f, 0.01f,0.0f, 0.0f},
		{ -x,  0.0f, 0.0f, 1.0f,  1.0f ,0.0f, 0.0f},
		{  x, -y,    0.0f, 0.01f, 0.01f,0.0f, 0.0f},
		{ -x, -y,    0.0f, 1.0f,  0.01f,0.0f, 0.0f},
	};

	Renderer->device->CreateVertexBuffer(sizeof(GrassVertex)*m_MaxGrass*6,
		              D3DUSAGE_WRITEONLY,GrassVertex::FVF,
		              D3DPOOL_DEFAULT,&m_GrassVb,0);
	GrassVertex* vertexptr;
	m_GrassVb->Lock(0,6*m_MaxGrass*sizeof(GrassVertex),(void**)vertexptr,0);
	
	for (int j=0; j < m_MaxGrass; j++)
	{
		// Generate each quad at random position, orientation, height
		
		D3DXMATRIX mat;
		D3DXMatrixIdentity( &matRandom);

	
		const int Area=Terrain->GetMapSize()*Terrain->GetMapScale();
		d.x =GetRandom(0,(Area))*4;
		d.z =GetRandom(0,(Area))*4;		
		hy = Terrain->GetTerrainHeight(d.x,d.z);		
		d.y = hy;
		float heightScale = ((float)rand()/RAND_MAX - 0.5f)/2.0f + 1.0f;

		D3DXMatrixRotationX( &mat, D3DX_PI);		
		D3DXMatrixMultiply( &matRandom, &matRandom, &mat );
		D3DXMatrixTranslation( &mat, d.x,d.y, d.z);
		D3DXMatrixMultiply( &matRandom, &matRandom, &mat );
		D3DXMatrixScaling( &mat, 1.0f, 1.0f, 1.0f);
		D3DXMatrixMultiply( &matRandom, &matRandom, &mat );
		
		float sin = sinf(rand()%50);
		float cos = cosf(rand()%10);

		for(int i=0; i < 6; i++)
		{
			D3DXVECTOR4 pos, outPos;
			pos.x = vertexdata.x;
			pos.y = vertexdata.y;
			pos.z = vertexdata.z;
			D3DXVec3Transform(&outPos,&(const struct D3DXVECTOR3pos, &(CONST D3DXMATRIX)matRandom);
			Renderer->device->SetTransform(D3DTS_WORLD,&matRandom);

			DWORD index = j * 6 + i;
			vertexptr[index].x = outPos.x;
			vertexptr[index].y = outPos.y;
			vertexptr[index].z = outPos.z;
			vertexptr[index].tu = vertexdata.tu;
			vertexptr[index].tv = vertexdata.tv;
			vertexptr[index].tu2 =sin; 
			vertexptr[index].tv2 =cos; 
		}
	}m_GrassVb->Unlock();
D3DXCreateTextureFromFile(Renderer->device,texture.c_str),&m_GrassTexture);
D3DXCreateEffectFromFile(Renderer>device,"GameData/Shaders/Grass.fx",0,0,0,0,&GrassEffect,0);
	
	return true;
};




Share this post


Link to post
Share on other sites
Advertisement
Help us to help you - you got "strange results"... er, right... any details? Do you get bright pink elephants dancing across your screen, your computer catch fire or just something more boring like a blank screen? Any indication on how or why you get strange results? Any hypothesis as to what might be wrong? Any reference code that you're using (e.g. ATI sample) and how is yours different from it?


Cheers,
Jack

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!