Sign in to follow this  
jamesss

D3DXMATRIX ,Random Pos ?

Recommended Posts

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); } }

Share this post


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

Share this post


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

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