PDA

View Full Version : terrian generation help



badass
04-29-2010, 08:23 PM
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[10000][24];
int in_pts[12]={-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][0]=x;
points[stack][1]=0;
points[stack][2]=z;
points[stack][3]=x;
points[stack][4]=0;
points[stack][5]=z+zinc;
points[stack][6]=x+xinc;
points[stack][7]=0;
points[stack][8]=z+zinc;
points[stack][9]=x+xinc;
points[stack][10]=0;
points[stack][11]=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][7]+=yoff;
points[i][10]+=yoff;
points[i+1][1]+=yoff;
points[i+1][4]+=yoff;
d2y=(d2y*0.8)+1;
}

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

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

}

void myInit()
{
glClearColor(1.0,1.0,1.0,0.0);
glPointSize(4.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
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][4] >=350 &amp;&amp; points[i][4] =< 400)
// glColor3f(1,0,0);
if (points[i][4] >=300 &amp;&amp; points[i][4] < 350)
glColor3f(0,1,0);
if (points[i][4] >=250 &amp;&amp; points[i][4] < 300)
glColor3f(0,0,1);
if (points[i][4] >=200 &amp;&amp; points[i][4] < 250)
glColor3f(1,1,0);
if (points[i][4] >=150 &amp;&amp; points[i][4] < 200)
glColor3f(0,1,1);
else
glColor3f(0,0,0);
glBegin(GL_LINE_LOOP);
glVertex3i(points[i][0],points[i][1],points[i][2]);
glVertex3i(points[i][3],points[i][4],points[i][5]);
glVertex3i(points[i][6],points[i][7],points[i][8]);
glVertex3i(points[i][9],points[i][10],points[i][11]);
glEnd();
}
axis();




}



void myDisplay()
{
glClear(GL_COLOR_BUFFER_BIT);

draw();
glFlush();

}

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


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


glutMainLoop();
}





thanks
Raza