D3DXMATRIX ,Random Pos ?

Started by
3 comments, last by jamesss 16 years, 8 months ago
when i trying to get random billboarded grass positions on terrain it will draw random pos without stop continuesly ! how can i solve this here is my render part: int x =rand()%245+10; int z=rand()%255-10; for(int i=0;i<10;i++) { for(int j=0;j<10;j++) { matworld._41=i*x-z; matworld._42=0; matworld._43=j*x-z; m_device->SetTransform(D3DTS_WORLD,&matworld); //Billboard::Animate(); m_device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2); } }
Advertisement
What do you mean "it will draw random pos without stop continuesly"?
hi, i meant it will take new random position over old random positions and so on continuesly ...it will appear and dissappear at mix random positions..u know i just want to keep one random position on terrain.
Quote:Original post by jamesss
hi, i meant it will take new random position over old random positions and so on continuesly ...it will appear and dissappear at mix random positions..u know i just want to keep one random position on terrain.
You mean that each billboards position changes each frame, and you want the positions to only be defined once at the start, and not move each frame?

In that case, you have two options:

  1. Generate the positions once at startup, store them somewhere, and apply those positions each frame

  2. Seed the random number generator (srand()) with the same value before you render your billboards.



It's worth noting that the way you're rendering is sub-optimal. It'd be faster (and possibly easier) to put vertices for all the bilboards into one vertex buffer (instead of the vertices for one) with random positions, and then to render them all in one DrawPrimitive() call.
You are right Steve billboard positions changes every frame,Thank you ,i will try that now..

This topic is closed to new replies.

Advertisement