/* fractalLandscape.cpp // Program to draw a Brownian Fractal landscape /* Programmed by Olac Fuentes Last modified October 28, 2009 CS3370 */ #include "stdafx.h" #include #include #include "glut.h" #include using namespace std; // Define a constant for the value of PI, from [2] #define GL_PI 3.1415926535f // Rotation amounts, from [2] static GLfloat xRot =25.0; static GLfloat yRot =-205.0; GLfloat nRange = 100.0f; // display window size int winWidth=600; int winHeight=600; float water_level =0; int randSeed; float h=3; float colorLimit[] = {1.,.7,.4,0}; float frx=winWidth/(2*nRange); float fry=winHeight/(2*nRange); // converts from degrees to radians #define d2r(t) (3.1415926535*t/180) struct wcPt2D { // adapted from [1] GLfloat x, y; }; struct wcPt3D { // adapted from [1] GLfloat x, y, z; }; // vertices counter int vx_c=0; // Modes int op_mode=1; // 0: Points, 1: Polygons int fill_poly=1; // 0: wire, 1: filled float axis_size=70.0; int axis_on=0; int smooth_color_on=0; /**************************************/ // Keyboard Functions void operations(GLubyte sizeFactor, GLint xMouse, GLint yMouse) { switch (sizeFactor) { case ('q' | 'Q') : exit(0); break; case ('/') : h -= .1; break; case ('*') : h += .1; break; case ('+') : water_level+=.1; break; case ('-') : water_level-=.1; break; case ('w' | 'W'): colorLimit[1] -=.02; colorLimit[2] -=.02; break; case ('s'| 'S'): colorLimit[1] +=.02; colorLimit[2] +=.02; break; default: break; } glutPostRedisplay(); } void getRGBColor(float intensity, float colorVect[]){ // Compute altitude-derived colors float colorRef[4][3]={{1,1,1},{.5,.4,0},{.1,.3,.1},{0,0.1,0}}; float frac; int i, index; intensity += 0.12*(1.*rand()/RAND_MAX-.5); if (intensity>1.) intensity=1.; if (intensity<0.) intensity=0.; for(i=0;i<3;i++) if (intensity <= colorLimit[i]) index =i; frac = (intensity - colorLimit[index+1])/(colorLimit[index]-colorLimit[index+1]); for (i=0;i<3;i++){ colorVect[i] = colorRef[index][i]*frac + colorRef[index+1][i]*(1.-frac); } } void brownianFractal(float h){ int rows =200; int cols =200; wcPt3D v[200][200]; int i,j; float intensity; float minXZ = -150; float maxXZ = 150; float colorVect[3]; float maxY= 0; float minY= 0; float range = maxXZ-minXZ; //Build Grid for(i=0;imaxY) maxY=v[i][j].y; else if(v[i][j].y