Archived

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

Sky

Generating and Drawing Terrain

Recommended Posts


      
  line1[0] = rand()%100/100;
  line2[0] = rand()%100/100;
  for (int a = 1; a < 20; a ++) {
    line1[a] = line1[a-1] + (rand()%10)/10;
    line2[a] = line2[a-1] + (rand()%10)/10;
  }

  for (int a = 0; a < 20; a++) 
    for (int b = 0; b < 20; b++) 
      array[a][b] = (line1[a] + line2[b])/2;
      
This is my initialization of the array...
  
  glBegin(GL_QUADS);
  glColor3f(0,0,1);
  for (int tx = 0; tx < 20; tx ++) {
    for (int ty = 0; ty < 20; ty++) {
      glVertex3f(tx  -10,array[tx][ty]-5,     ty -10);
      glVertex3f(tx  -10,array[tx+1][ty]-5,   ty+1-10);
      glVertex3f(tx+1-10,array[tx][ty+1]-5,   ty+1-10);  
      glVertex3f(tx+1-10,array[tx+1][ty+1]-5, ty -10);  
    }
  }
  glEnd();
       
That's where I render it... But its not being a nice rolling terrain.... Its just flat, and then at the very edge some of it just juts up... Any idea whats wrong? [edited by - Sky on March 1, 2003 5:48:50 PM] [edited by - Sky on March 1, 2003 5:49:09 PM]

Share this post


Link to post
Share on other sites
I have a feeling that (rand()%10)/10 is being worked as an integer caculation, which will always get 0 as a result... try changing it to float(rand()%10)/10.0f

| - Project-X - my mega project.. yup, still cracking along - | - adDeath - an ad blocker I made - | - email me - |

Share this post


Link to post
Share on other sites
Ok, now two things...



  
glBegin(GL_TRIANGLE_STRIP);
glColor3f(0,1,0);
for (int ty = 0; ty < 20; ty ++) {
glVertex3f(-10.0f,array[0][ty]-5.0f,ty-10.0f);
glVertex3f(-10.0f,array[0][ty+1]-5.0f,ty-9.0f);
for (int tx = 1; tx < 20; tx++) {
glVertex3f(tx-10.0f,array[tx+1][ty]-5, ty -10.0f);
glVertex3f(tx-10.0f,array[tx+1][ty+1]-5, ty-9.0f);
}
}
glEnd();


There''s my rendering code again, and here''s my initializing:


  
line1[0] = float(rand()%100)/100.0f;
line2[0] = float(rand()%100)/100.0f;
for (int a = 1; a < 20; a ++) {
line1[a] = line1[a-1] + float(rand()%10)/10.0f;
line2[a] = line2[a-1] + float(rand()%10)/10.0f;
}

for (int a = 0; a < 20; a++)
for (int b = 0; b < 20; b++)
array[a][b] = (line1[a] + line2[b])/2;


Now it''s really strange, most of it works fine, and renders fine, but in some parts it like flips.... and looks really wierd... Its just really wierd...

And secondly how do I enable shading or lighting or something so that i can see the curves in the texture more clearly?

Share this post


Link to post
Share on other sites