Jump to content
  • Advertisement

Archived

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

Sky

Generating and Drawing Terrain

This topic is 5616 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!