 # terrian generation help

im trying to generate a terrian… i dont know where to go from here…below is my code… plz run this code and lemme know what to do from here or any suggestions…

i know the code is messy with the global variables and stuff… this is just for testing…

``````
#include <iostream>
#include <stdlib.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <ctime>
int points;
int in_pts={-200,-200,-200,-200,-100,-200,-170,-100,-200,-170,-200,-200};
int minx=-400,maxx=400,minz=-400,maxz=400,xinc=20,zinc=20;
int stack=0;

using namespace std;

void initialize()
{
int x=minx,z=minz;
for(z=minz;z<=maxz;z+=zinc) {
for(int x=minx;x<=maxx;x+=xinc) {
points[stack]=x;
points[stack]=0;
points[stack]=z;
points[stack]=x;
points[stack]=0;
points[stack]=z+zinc;
points[stack]=x+xinc;
points[stack]=0;
points[stack]=z+zinc;
points[stack]=x+xinc;
points[stack]=0;
points[stack]=z;
stack++;

}
}
}

void elevate()
{
int yoff,d2y=300;

srand((unsigned)time(0));

for(int i=800;i<810;i++) {
yoff=+(rand()%d2y)+1;
points[i]+=yoff;
points[i]+=yoff;
points[i+1]+=yoff;
points[i+1]+=yoff;
d2y=(d2y*0.8)+1;
}

for(int i=500;i<510;i++) {
d2y=250;
yoff=+(rand()%d2y)+1;
points[i]+=yoff;
points[i]+=yoff;
points[i+1]+=yoff;
points[i+1]+=yoff;
d2y=(d2y*0.8)+1;
}

for(int i=300;i<310;i++) {
d2y=200;
yoff=+(rand()%d2y)+1;
points[i]+=yoff;
points[i]+=yoff;
points[i+1]+=yoff;
points[i+1]+=yoff;
d2y=(d2y*0.8)+1;
}

}

void myInit()
{
glClearColor(1.0,1.0,1.0,0.0);
glPointSize(4.0);
glMatrixMode(GL_MODELVIEW);
gluLookAt(00,250,-450.0,0.0,0.0,-400.0,0.0,1.0,0.0);
glMatrixMode(GL_PROJECTION);
glFrustum(-400.0,400.0,-400.0,400.0,100.0,450.0);
}

void axis()
{
glBegin(GL_LINES);
glColor3f(1,0,0); // x-axis red
glVertex3i(-400,0,0);
glVertex3i(400,0,0);
glColor3f(0,1,0); // y-axis green
glVertex3i(0,-400,0);
glVertex3i(0,400,0);
glColor3f(0,0,0); // z-axis black
glVertex3i(0,0,-400);
glVertex3i(0,0,400);
glEnd();
}
void draw()
{

for(int i=0;i<stack;i++){
//		if (points[i] >=350 && points[i] =< 400)
//			glColor3f(1,0,0);
if (points[i] >=300 && points[i] < 350)
glColor3f(0,1,0);
if (points[i] >=250 && points[i] < 300)
glColor3f(0,0,1);
if (points[i] >=200 && points[i] < 250)
glColor3f(1,1,0);
if (points[i] >=150 && points[i] < 200)
glColor3f(0,1,1);
else
glColor3f(0,0,0);
glBegin(GL_LINE_LOOP);
glVertex3i(points[i],points[i],points[i]);
glVertex3i(points[i],points[i],points[i]);
glVertex3i(points[i],points[i],points[i]);
glVertex3i(points[i],points[i],points[i]);
glEnd();
}
axis();

}

void myDisplay()
{
glClear(GL_COLOR_BUFFER_BIT);

draw();
glFlush();

}

void main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(600,600);
glutInitWindowPosition(50,50);
glutCreateWindow("3D Viewing System");
myInit();
initialize();
elevate();

cout << "
Stack = " << stack;
glutDisplayFunc(myDisplay);

glutMainLoop();
}

``````

thanks
Raza