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.
Here is the code that I used to try to place the boxes in a random position.
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();
}
This causes it to not display the boxes at all. I’m pretty sure I’m making a stupid mistake but I can’t see it. Need more help