/* Presented by James Madison University Computer Science major Joshua Blake to FALL 2004 CS 480 students on 9/7/2004 Feel free to use and modify as needed. Please send me an email if you find this useful: blakejr@jmu.edu This code generates a 3D terrain using OpenGL */ #include //include gl/glut.h in all GLUT programs #include #include #define M_PI 3.14159265358979323846 #define SIZE 50 float points[SIZE][SIZE]; float xpos, ypos, zpos; float xdir, ydir; float speed; float dxdir, dydir; float dx, dy, dz; int left_down; int mouseStartX, mouseStartY; int mouseCurrentX, mouseCurrentY; void drawVertex(int i, int j) { float x, z; float xmax, zmax, xmin, zmin, xr, zr;; xmax = 5.0; xmin = -5.0; zmax = 5.0; zmin = -5.0; xr = xmax - xmin; zr = zmax - zmin; x = (i/(float)SIZE)*xr + xmin; z = (j/(float)SIZE)*zr + zmin; glVertex3f(x, points[i][j], z); } void drawQuad(int i, int j) { glBegin(GL_QUADS); drawVertex(i , j ); drawVertex(i+1, j ); drawVertex(i+1, j+1); drawVertex(i , j+1); glEnd(); } void drawLines(int i, int j) { glBegin(GL_LINE_STRIP); drawVertex(i , j ); drawVertex(i+1, j ); drawVertex(i+1, j+1); drawVertex(i , j+1); drawVertex(i , j ); glEnd(); } void display(void) { //draws the scene int i, j; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); glRotatef(ydir, 1, 0, 0); glRotatef(xdir, 0, 1, 0); glPushMatrix(); glTranslatef(xpos, zpos, ypos); for (i=0; i