Jump to content
  • Advertisement

Archived

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

Nibbles

LOL, Rough Terrain!

This topic is 6397 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

Hey! My first poor attempt at a terrain generator

Can anyone point me in the right direction for terrain related stuff? Thanks, Scott

Share this post


Link to post
Share on other sites
Advertisement
prolly not the best.. cause it''s not easy to change the size of the map yet but:

  
int generate_landscape() {
GLfloat x, y;
int i=0;

for (y=-size/2;y<size/2;y+=1.0f)
for (x=-size/2;x<size/2;x+=1.0f) {
p[i].x = x;
p[i].y = y;
i++;
}

for (i=0;i<size*size;i++) {
p[i].z = randFloat(-1.0f, 2.0f);
}


return TRUE;
}

int draw_landscape() {

int i;

glPushMatrix();
for (i=0;i<size*size;i++) {
if (i != 5 && i != 11 && i != 17 && i != 23 && i != 29 && i != 35) {
if (i != 30 && i != 31 && i != 32 && i != 33 && i != 34 && i != 35) {
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 1.0f); glVertex3f(p[i].x, p[i].y, p[i].z);
glTexCoord2f(1.0f, 1.0f); glVertex3f(p[i+1].x, p[i+1].y, p[i+1].z);
glTexCoord2f(1.0f, 0.0f); glVertex3f(p[i+size+1].x, p[i+size+1].y, p[i+size+1].z);
glTexCoord2f(0.0f, 0.0f); glVertex3f(p[i+size].x, p[i+size].y, p[i+size].z);
glEnd();
}
}
}
glPopMatrix();

// water

glPushMatrix();
//glColor3f(0.0f, 0.0f, 1.0f);

glDisable(GL_TEXTURE_2D);

glBegin(GL_QUADS);
glVertex3f(p[0].x, p[0].y, waterheight);
glVertex3f(p[5].x, p[5].y, waterheight);
glVertex3f(p[35].x, p[35].y, waterheight);
glVertex3f(p[30].x, p[30].y, waterheight);
glEnd();
glEnable(GL_TEXTURE_2D);
glPopMatrix();

return TRUE;
}


this code will prolly get garbled, but what can ya do

Scott

Share this post


Link to post
Share on other sites
I finally got it working with different sized maps! yes! a lot easier than i first assumed no wonder it''s hard to find a good tutorial on terrains.. dont need ''em

Scott

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!