My program simulates a standard maze. After it runs, you would be asked the maze’s size; by entering an odd integer which signifies the number of rows and columns you would like. You are able to make it any size you wish.
You press the ‘u’, ‘d’, ‘r’, and ‘l’ keys to move the sphere, which is the marker.
My problem is it doesn't leave any open areas on the edges to create an entrance and an exit. I'm not sure how that is done. Can anyone help?
Here is the code:
#include <iostream>
using namespace std;
#include <glut/glut.h>
int m[31][31], n;
static int flag=1;
int X=0, Y=1, Z=0, wire=0;
GLfloat x=0.,y=0.,z=0., spin=0., x1=1., yy1=1., z1=1.;
GLfloat a=0, b=0, c=0, d=0, e=0, f=0;
//notice y1 is a reserved name, so I used yy1 instead
GLfloat mat_ambient[]={.8,.8,.8, 1.0};
GLfloat mat_diffuse[]={1.,.5,.0, 1.0};
GLfloat mat_diffuse2[]={1.,.2,.0,1.0};
GLfloat mat_diffuse3[]={1.,.7,.0,1.0};
GLfloat mat_specular[]={1.,1.,.5, 1.0};
GLfloat mat_shininess[]={128.}; //this needs specular (work together)
GLfloat light0_position[]={1., 1., -5., .0};
void keyboard(unsigned char key, int xx, int yy)
{ switch(key)
{
case '?' : cout<<"\nUse:\n '?' 'x' 'y' 'z' 'a' 'b' 'c' 'w' 's' 'S' ' ' keys for animation\n"<<endl; break;
case 'x' : X=1; Y=Z=0; break;
case 'y' : Y=1; X=Z=0; break;
case 'z' : Z=1; X=Y=0; break;
case 'a' : x+=.01; break;
case 'b' : y+=.01; break;
case 'c' : z+=.01; break;
case 'A' : x-=.01; break;
case 'B' : y-=.01; break;
case 'C' : z-=.01; break;
case 'r' : a+=.055; break;
case 'u' : b+=.055; break;
// case 'f' : c+=.055; break;
case 'l' : a-=.055; break;
case 'd' : b-=.055; break;
// case 'F' : c-=.03; break;
case 'h': x1 += .1; break;
case 'v': yy1 += .1; break;
case 'p': z1 += .1; break;
case 'H': x1 -= .1; break;
case 'V': yy1 -= .1; break;
case 'D': z1 -= .1; break;
case ' ' : spin=x=y=z=.0; break;
case 'w' : wire= ++wire%2; break;
case 's' : glShadeModel(GL_SMOOTH); break;
case 'S' : glShadeModel(GL_FLAT); break;
}
glutPostRedisplay();
}
void mouse(int button, int state, int xx, int yy)
{glutIdleFunc(spinDisplay);
switch(button)
{
case GLUT_LEFT_BUTTON : if(state == GLUT_DOWN) {X=1; Y=Z=0;} break;
case GLUT_RIGHT_BUTTON : if(state == GLUT_UP) glutIdleFunc(NULL);
}
glutPostRedisplay();
}
void reshape(int w, int h)
{ glViewport(0.,0.,900.,900.);
glLoadIdentity();
gluPerspective(80., (GLfloat) w/(GLfloat) h, .1, 190.);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); //important: last line must be glLoadIdentity() for coloring with openGL
//glTranslatef (.0, .0, -1.); //do not translate at all if glLoadIdentity() is used
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize (900, 900); glutInitWindowPosition(0,0);
glutCreateWindow("Symposium Project");
init();
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutKeyboardFunc(keyboard);
glutReshapeFunc(reshape);
glutMainLoop();}