Sign in to follow this  

"Ati Grass demo" Need help on Billboarding.

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},

	GrassVertex* vertexptr;
	for (int j=0; j < m_MaxGrass; j++)
		// Generate each quad at random position, orientation, height
		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[i].x;
			pos.y = vertexdata[i].y;
			pos.z = vertexdata[i].z;
			D3DXVec3Transform(&outPos,&(const struct D3DXVECTOR3pos, &(CONST D3DXMATRIX)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[i].tu;
			vertexptr[index].tv = vertexdata[i].tv;
			vertexptr[index].tu2 =sin; 
			vertexptr[index].tv2 =cos; 
	return true;

Share this post

Link to post
Share on other sites
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?


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this