Archived

This topic is now archived and is closed to further replies.

jon723

Random placement on a grid??

Recommended Posts

jon723    168
Hello. I was wondering if someone could tell me how I would go about placeing objects in a random position on a grid. Actually this is what I did. I created a display list that contained the points for a cube. Then, inside another function I created a grid of points on the xz plane. Now the problem I have is that I want to take a specific number of the box I created and randomly place them on different points on the grid. When I tried doing this it showed me the boxes moving around the different points. Is there a way to stop this so that they remain in a fixed location??? Someone please help me out. Thanx, Jon

Share this post


Link to post
Share on other sites
TerranFury    142
You should generate the points once, store them in some fashion (array, list, something else), and then use those stored points.

It is possible, however, to guarantee the same series of random points each frame. This would achieve the same effect. To do this, seed the random number generator immediately before placing your cubes or whatever on the grid with a constant number. Assuming you''re using the stdlib, then you would call srand(some_constant) to do this.

Share this post


Link to post
Share on other sites
jon723    168
Hey, I seeded the random number generator with a variable equal to 6. I then created two "GLfloat" numbers and inside a "for loop" which ran 4 times (just to test it) I added the following code:

for(int r = 0; r <= 3; r++)
{
pointx = rand(); // make float number a random number
pointz = rand(); // make float number a random number

glTranslatef(pointx, 0.0f, pointz);
Addbox();
}



Now it won''t even display the boxes at all. I''m pretty sure I''m making a stupid mistake but I can''t see it. Need more help

Thanx, Jon.

Share this post


Link to post
Share on other sites
TerranFury    142
My only guess is that your cubes are outside the FOV. If I were you, I''d temporarily disable lighting, texturing, vertex colors, and backface culling, and add code to rotate and move the "camera." This way you should be able to figure out where your cubes are really being placed. I''m afraid I can''t offer too much advice beyond that.

Share this post


Link to post
Share on other sites