/*--------------------------------- FINAL PROJECT CECS361 TEAM MEMBERS MANOJ PAVULURI 809618 PINAL SHAH 818994 BHAVIN PATADIYA 818996 INSTRUCTOR : Dr PALANIAPPAN ------------------------------------*/ #include #include #include #include #include #define TRUE 1 #define FALSE 0 #define PI 3.141592653589793238462643 #define TEXTURE_WIDTH 128 #define TEXTURE_HEIGHT 128 #define TEXTURE_COLORS 3 #define MEDIUM 1 #define BEST 2 void Display(void); void CreateEnvironment(void); void MakeGeometry(float,float,float,float,int,float); void MakeLighting(int); void MakeCamera(float,float,float,float,int,int,int); void HandleKeyboard(unsigned char key,int x, int y); void HandleSpecialKeyboard(int key,int x, int y); void HandleMouse(int,int,int,int); void HandleMainMenu(int); void HandleSpeedMenu(int); void HandlecolorMenu(int); void HandlelightMenu(int); void HandleVisibility(int vis); void HandleIdle(void); void DrawTextXY(double,double,double,double,char *); void drawCylinder(int,int,float,float); int spincamera = TRUE; static int ballview,move,lt = 4; static int wiremode=0,count=0; float theta = 90.0,rt = 0.0; double updownrotate = 48.3; int ballbounce = TRUE; double ballspeed = 0.3; float zr=5.5,xr=0.0,yr=0.5,yb = 1.0; int vx,vy,dist =0,WX=700,WY=700; static int sprcolor = 0,ht=0; float cal,cal1; static float angle=180.0; float n=0.0,camx=0.2,camy=2.5,camz = 3.2,sx=1.0,sy=3.0,sz=1.0,ty=0.9; static int first,second; static float tex,tey,tez,textscale; static int k; char *s; char *temp; unsigned char* woodImage = NULL; unsigned char* wallImage = NULL; unsigned char* skyImage = NULL; unsigned char* grassImage = NULL; unsigned char* cloudImage = NULL; typedef struct { float x,y,z,scalex,scaley,scalez; int hit; }pin; static pin pins[10]; static pin ball; static float matAmb[4] = {0.2, 0.2, 0.2, 1.0}; static float matDiff[4] = {0.8, 0.8, 0.8, 1.0}; static float matSpec[4] = {0.4, 0.4, 0.4, 1.0}; static float matEmission[4] = {0.0, 0.0, 0.0, 1.0}; #define REDSPHERE 1 #define GREENSPHERE 2 #define BLUESPHERE 3 #define BROWNSPHERE 4 #define WHITESPHERE 5 #define TEXTID 6 void readTextureImage(unsigned char** textureMemory, char* textureFileName) { FILE *textureFile; int texImageSize; texImageSize = TEXTURE_WIDTH * TEXTURE_HEIGHT * TEXTURE_COLORS; if ( (*textureMemory =(unsigned char *)malloc(sizeof(char) * texImageSize)) == NULL) { fprintf(stderr, "unable to allocate memory in readTextureImage\n"); exit(1); } if ( (textureFile = fopen(textureFileName, "r")) == NULL) { fprintf(stderr, "Unable to open file %s\n", textureFileName); exit(1); } if ( (fread(*textureMemory, sizeof(unsigned char), texImageSize, textureFile)) != texImageSize) { fprintf(stderr, "Error reading texture file\n"); /*exit(1);*/ } fclose(textureFile); } static void drawPlane(int w, int h) { float i, j; glColor3f(0.0,0.1,0.0); glNormal3f(0.0, 1.0, 0.0); for (j = -h; j < h; j = j+1) { /*glColor3f(-i/10,-i/10,-j/10);*/ if(wiremode) glBegin(GL_LINE_LOOP); else glBegin(GL_TRIANGLE_STRIP); for (i = -w; i <= w; i = i+1) { /* glColor3f(-j/10,-j/10,i/10);*/ glVertex3f(i, 0.0,(j + 1)); glVertex3f(i, 0.0,j); } glEnd(); } } static void drawPlane1(int w, int h) { float i, j; glColor3f(0.0,0.1,0.0); glNormal3f(0.0, 1.0, 0.0); for (j = -h; j < h; j = 0.8+j) { glBegin(GL_TRIANGLE_STRIP); for (i = w; i >= -w; i = i-0.8) { glVertex3f(i, 12.0,(j + 1)); glVertex3f(i, 12.0,j); } glEnd(); } } /*void initpins(void) { int i; for(i=0;i<10;i++) { pins[i].hit=0; pins[i].scalex = 1.0; pins[i].scaley = 3.0; pins[i].scalez = 1.0; pins[i].y = 0.9; } pins[0].x = 0.0; pins[0].z = -3.0; pins[1].x = -0.5; pins[1].z = -3.5; pins[2].x = 0.5; pins[2].z = -3.5; for(i=3;i<=5;i++) { pins[i].z = -4.0; } pins[3].x = -1.0; pins[4].x = 0.0; pins[5].x = 1.0; for(i=6;i<=9;i++) { pins[i].z = -4.5; } pins[6].x = -1.5; pins[7].x = -0.5; pins[8].x = 0.5; pins[9].x = 1.5; } */ /*void drawpins(float sx,float sy,float sz,float ty,int ht) { int i; glColor3f(0.0,1.0,1.0); for(i=0;i<10;i++) { pins[i].hit=ht; pins[i].scalex = sx; pins[i].scaley = sy; pins[i].scalez = sz; pins[i].y = ty; } pins[0].x = 0.0; pins[0].z = -3.0; pins[1].x = -0.5; pins[1].z = -3.5; pins[2].x = 0.5; pins[2].z = -3.5; for(i=3;i<=5;i++) { pins[i].z = -4.0; } pins[3].x = -1.0; pins[4].x = 0.0; pins[5].x = 1.0; for(i=6;i<=9;i++) { pins[i].z = -4.5; } pins[6].x = -1.5; pins[7].x = -0.5; pins[8].x = 0.5; pins[9].x = 1.5; for(i=0;i<10;i++) { glPushMatrix(); glTranslatef(pins[i].x,pins[i].y,pins[i].z); glScalef(pins[i].scalex,pins[i].scaley,pins[i].scalez); glutSolidSphere(0.2,8,8); glutSolidCube(0.1); glPopMatrix(); } } */ void drawCylinder(int numMajor, int numMinor, float height, float radius) { double majorStep = height / numMajor; double minorStep = 2.0 * M_PI / numMinor; int i, j; for (i = 0; i < numMajor; ++i) { GLfloat z0 = 0.5 * height - i * majorStep; GLfloat z1 = z0 - majorStep; glBegin(GL_TRIANGLE_STRIP); for (j = 0; j <= numMinor; ++j) { double a = j * minorStep; GLfloat x = radius * cos(a); GLfloat y = radius * sin(a); glNormal3f(x / radius, y / radius, 0.0); glTexCoord2f(j / (GLfloat) numMinor, i / (GLfloat) numMajor); glVertex3f(x, y, z0); glNormal3f(x / radius, y / radius, 0.0); glTexCoord2f(j / (GLfloat) numMinor, (i + 1) / (GLfloat) numMajor); glVertex3f(x, y, z1); } glEnd(); } } int main(int argc,char **argv) { int i,j,depth; int mainmenu,speedmenu,colormenu,lightmenu; /* Set things up and go */ glutInit(&argc,argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(WX,WY); glutInitWindowPosition(100,100); glutCreateWindow("B O W L I N G G A M E "); glutDisplayFunc(Display); glutVisibilityFunc(HandleVisibility); glutKeyboardFunc(HandleKeyboard); glutSpecialFunc(HandleSpecialKeyboard); glutMouseFunc(HandleMouse); CreateEnvironment(); glEnable(GL_LIGHTING); glEnable(GL_NORMALIZE); /*glMaterialfv(GL_FRONT, GL_AMBIENT, matAmb); glMaterialfv(GL_FRONT, GL_DIFFUSE, matDiff); glMaterialfv(GL_FRONT, GL_SPECULAR, matSpec); glMaterialfv(GL_FRONT, GL_EMISSION, matEmission); glMaterialf(GL_FRONT, GL_SHININESS, 10.0);*/ lightmenu = glutCreateMenu(HandlelightMenu); glutAddMenuEntry("Blue",1); glutAddMenuEntry("Yellow",2); glutAddMenuEntry("Both",3); glutAddMenuEntry("OFF All",4); colormenu = glutCreateMenu(HandlecolorMenu); glutAddMenuEntry("Red",1); glutAddMenuEntry("Green",2); glutAddMenuEntry("Blue",3); glutAddMenuEntry("Brown",4); /* Set up some menus */ speedmenu = glutCreateMenu(HandleSpeedMenu); glutAddMenuEntry("WireFrame",1); glutAddMenuEntry("Rendered",2); mainmenu = glutCreateMenu(HandleMainMenu); /*glutAddMenuEntry("Toggle lighting",2);*/ glutAddSubMenu("Select Light",lightmenu); glutAddSubMenu("Select Sphere",colormenu); glutAddSubMenu("Drawing Mode",speedmenu); glutAddMenuEntry("Quit",100); glutAttachMenu(GLUT_RIGHT_BUTTON); glutMainLoop(); return(0); } void CreateEnvironment(void) { glClearColor (0.0, 0.0, 0.0, 0.0); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); /* read in textures */ readTextureImage(&woodImage, "oak.rgb"); readTextureImage(&wallImage, "back.rgb"); readTextureImage(&grassImage, "grass.rgb"); /* readTextureImage(&cloudImage, "clouds.rgb");*/ /* use byte alignment */ /* glPixelStorei(GL_UNPACK_ALIGNMENT, 1);*/ /* clamp texture */ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); /* use nearest pixel */ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); /* use decal mode */ glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); glShadeModel(GL_SMOOTH); glDisable(GL_DITHER); glLineWidth(1.0); glPointSize(1.0); glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); glFrontFace(GL_CW); glDisable(GL_CULL_FACE); glEnable(GL_COLOR_MATERIAL); } static void checkForOpenGLErrors(void) { GLenum error; while ((error = glGetError()) != GL_NO_ERROR) fprintf(stderr, "GL error: %s\n", gluErrorString(error)); } void Display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); MakeCamera(camx,camy,camz,theta,vx,vy,FALSE); MakeLighting(lt); MakeGeometry(xr,zr,rt,yr,dist,yb); drawPlane(17,17); /*drawPlane1(17,16);*/ /*glTranslatef(x,y,z);*/ glPopMatrix(); /* glFlush(); */ glutSwapBuffers(); checkForOpenGLErrors(); } void drawpitch(void) { /*---pitch---*/ if(wiremode) glBegin(GL_LINE_LOOP); else glBegin(GL_POLYGON); /*glMaterialfv(GL_FRONT,GL_AMBIENT,mamb2); glMaterialfv(GL_FRONT,GL_DIFFUSE,mdiff2); glMaterialfv(GL_FRONT,GL_SPECULAR,mspec2); glMaterialfv(GL_FRONT,GL_EMISSION,memission2); glMaterialfv(GL_FRONT,GL_SHININESS,mshin2);*/ glNormal3f( 0.0, 1.0, 0.0); glVertex3f( 2.3, 0.52, 6.5); glVertex3f( 2.3, 0.52,-5.6); glVertex3f(-2.3, 0.52,-5.6); glVertex3f(-2.3, 0.52, 6.5); glEnd(); } void drawpitch1(void) { /*---pitch---*/ if(wiremode) glBegin(GL_LINE_LOOP); else glBegin(GL_POLYGON); /*glMaterialfv(GL_FRONT,GL_AMBIENT,mamb2); glMaterialfv(GL_FRONT,GL_DIFFUSE,mdiff2); glMaterialfv(GL_FRONT,GL_SPECULAR,mspec2); glMaterialfv(GL_FRONT,GL_EMISSION,memission2); glMaterialfv(GL_FRONT,GL_SHININESS,mshin2);*/ glNormal3f( 0.0, 1.0, 0.0); glVertex3f( -2.3, 0.52, 6.5); glVertex3f( 2.3, 0.52,6.5); glVertex3f(2.3, -0.5,6.5); glVertex3f(-2.3, -0.52, 6.5); glEnd(); } void MakeGeometry(float xr,float zr,float rt,float yr,int dist,float yb) { int i; float j; static double theta = 0;int k; /* For the sphere */ GLfloat mamb1[] = {0.17,0.01,0.01,0.55}; GLfloat mdiff1[] = {0.61,0.04,0.04,0.55}; GLfloat mspec1[] = {0.73,0.63,0.63,0.55}; GLfloat memission1[] = {0.0,0.0,0.0,0.0}; GLfloat mshin1[] = {77.0}; GLfloat mamb2[] = {0.23,0.09,0.03,1.00}; GLfloat mdiff2[] = {0.55,0.21,0.07,1.00}; GLfloat mspec2[] = {0.58,0.22,0.07,1.00}; GLfloat memission2[] = {0.0,0.0,0.0,0.0}; GLfloat mshin2[] = {51}; if(!wiremode) { glEnable(GL_TEXTURE_2D); glTexImage2D(GL_TEXTURE_2D, 0, 3, TEXTURE_WIDTH, TEXTURE_HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, woodImage); glBegin(GL_POLYGON); { glNormal3f( 0.0, 1.0, 0.0); glTexCoord2f(0.0, 0.0); glVertex3f(2.3, -1.0, 6.3); glTexCoord2f(0.0, 2.0); glVertex3f(2.3, -1.0,-5.3); glTexCoord2f(2.0, 2.0); glVertex3f(-2.3, -1.0,-5.3); glTexCoord2f(2.0, 0.0); glVertex3f(-2.3, -1.0, 6.3); } glEnd(); gluBuild2DMipmaps(GL_TEXTURE_2D,3,TEXTURE_WIDTH, TEXTURE_HEIGHT,GL_RGB, GL_UNSIGNED_BYTE, wallImage); glBegin(GL_POLYGON); { glNormal3f( 0.0, 0.0, 1.0); glTexCoord2f(0.0, 0.0); glVertex3f(-17.0, 0.0, -15.0); glTexCoord2f(3.0, 0.0); glVertex3f(17.0, 0.0, -15.0); glTexCoord2f(3.0, 3.0); glVertex3f(17.0, 12.0,-15.0); glTexCoord2f(0.0, 3.0); glVertex3f(-17.0, 12.0,-15.0); } glEnd(); gluBuild2DMipmaps(GL_TEXTURE_2D,3,TEXTURE_WIDTH, TEXTURE_HEIGHT,GL_RGB, GL_UNSIGNED_BYTE, wallImage); glBegin(GL_POLYGON); { glNormal3f( 1.0, 0.0, 0.0); glTexCoord2f(0.0, 0.0); glVertex3f(-17.0, 12.0,-15.0); glTexCoord2f(3.0, 0.0); glVertex3f(-17.0, 12.0, 15.0); glTexCoord2f(3.0, 3.0); glVertex3f(-17.0, 0.0, 15.0); glTexCoord2f(0.0, 3.0); glVertex3f(-17.0, 0.0, -15.0); } glEnd(); gluBuild2DMipmaps(GL_TEXTURE_2D,3,TEXTURE_WIDTH, TEXTURE_HEIGHT,GL_RGB, GL_UNSIGNED_BYTE, wallImage); glBegin(GL_POLYGON); { glNormal3f( 1.0, 0.0, 0.0); glTexCoord2f(0.0, 0.0); glVertex3f(16.0, 12.0,-15.0); glTexCoord2f(3.0, 0.0); glVertex3f(16.0, 12.0, 15.0); glTexCoord2f(3.0, 3.0); glVertex3f(16.0, 0.0, 15.0); glTexCoord2f(0.0, 3.0); glVertex3f(16.0, 0.0, -15.0); } glEnd(); gluBuild2DMipmaps(GL_TEXTURE_2D,3,TEXTURE_WIDTH, TEXTURE_HEIGHT,GL_RGB, GL_UNSIGNED_BYTE, wallImage); glBegin(GL_POLYGON); { glNormal3f( 1.0, 0.0, 0.0); glTexCoord2f(0.0, 0.0); glVertex3f(-10.0, 0.0,15.0); glTexCoord2f(3.0, 0.0); glVertex3f(-10.0, 12.0,15.0); glTexCoord2f(3.0, 3.0); glVertex3f(17.0, 12.0,15.0); glTexCoord2f(0.0, 3.0); glVertex3f(17.0, 0.0, 15.0); } glEnd(); gluBuild2DMipmaps(GL_TEXTURE_2D,3,TEXTURE_WIDTH, TEXTURE_HEIGHT,GL_RGB, GL_UNSIGNED_BYTE, grassImage); glBegin(GL_POLYGON); { glNormal3f( 0.0, 1.0, 0.0); glTexCoord2f(0.0, 0.0); glVertex3f(-50.0, -1.1,-50.0); glTexCoord2f(20.0, 0.0); glVertex3f(-17.0, -1.1, -50.0); glTexCoord2f(20.0, 20.0); glVertex3f(-17.0, -1.1, 50.0); glTexCoord2f(0.0, 20.0); glVertex3f(-50.0, -1.1, 50.0); } glEnd(); gluBuild2DMipmaps(GL_TEXTURE_2D,3,TEXTURE_WIDTH, TEXTURE_HEIGHT,GL_RGB, GL_UNSIGNED_BYTE, grassImage); glBegin(GL_POLYGON); { glNormal3f( 0.0, 1.0, 0.0); glTexCoord2f(0.0, 0.0); glVertex3f(17.0, -1.1,-50.0); glTexCoord2f(20.0, 0.0); glVertex3f(50.0, -1.1, -50.0); glTexCoord2f(20.0, 20.0); glVertex3f(50.0, -1.1, 50.0); glTexCoord2f(0.0, 20.0); glVertex3f(17.0, -1.1, 50.0); } glEnd(); gluBuild2DMipmaps(GL_TEXTURE_2D,3,TEXTURE_WIDTH, TEXTURE_HEIGHT,GL_RGB, GL_UNSIGNED_BYTE, grassImage); glBegin(GL_POLYGON); { glNormal3f( 0.0, 1.0, 0.0); glTexCoord2f(0.0, 0.0); glVertex3f(-17.0, -1.1,-50.0); glTexCoord2f(20.0, 0.0); glVertex3f(17.0, -1.1, -50.0); glTexCoord2f(20.0, 20.0); glVertex3f(17.0, -1.1,-15.0); glTexCoord2f(0.0, 20.0); glVertex3f(-17.0, -1.1, -15.0); } glEnd(); gluBuild2DMipmaps(GL_TEXTURE_2D,3,TEXTURE_WIDTH, TEXTURE_HEIGHT,GL_RGB, GL_UNSIGNED_BYTE, grassImage); glBegin(GL_POLYGON); { glNormal3f( 0.0, 1.0, 0.0); glTexCoord2f(0.0, 0.0); glVertex3f(-17.0, -1.1,15.0); glTexCoord2f(20.0, 0.0); glVertex3f(17.0, -1.1, 15.0); glTexCoord2f(20.0, 20.0); glVertex3f(17.0, -1.1,50.0); glTexCoord2f(0.0, 20.0); glVertex3f(-17.0, -1.1, 50.0); } glEnd(); /*gluBuild2DMipmaps(GL_TEXTURE_2D,3,TEXTURE_WIDTH, TEXTURE_HEIGHT,GL_RGB, GL_UNSIGNED_BYTE, cloudImage); glBegin(GL_POLYGON); { glNormal3f( 0.0, 0.0, 1.0); glTexCoord2f(0.0, 0.0); glVertex3f(-50.0, 50.0,-50.0); glTexCoord2f(25.0, 0.0); glVertex3f(50.0, 50.0, -50.0); glTexCoord2f(25.0, 25.0); glVertex3f(50.0, 0.0, -50.0); glTexCoord2f(0.0, 25.0); glVertex3f(-50.0, 0.0,-50.0); } glEnd();*/ glDisable(GL_TEXTURE_2D); } /*pitch*/ glPushMatrix(); glColor3f(0.0,0.0,0.0); glTranslatef(0.0,-2.2,0.4); glScalef(0.62,0.07,1.63); glNormal3f( 0.0, 1.0, 0.0); if(wiremode) glutWireCube(7.3); else glutSolidCube(7.3); glPopMatrix(); /*glPushMatrix(); glColor3f(0.0,0.5,0.0); glTranslatef(0.0,2.2,0.4); drawCylinder(10,10,1.0,0.4); glPopMatrix();*/ if(wiremode) glBegin(GL_LINE_LOOP); else glBegin(GL_POLYGON); glColor3f(0.3,0.3,0.3); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mdiff2); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mamb2); glNormal3f(0.0, 1.0, 0.0); glVertex3f(-2.0, 0.1, 6.3); glVertex3f(-2.0, 0.1,-5.3); glVertex3f(-3.0, 0.1,-5.3); glVertex3f(-3.0, 0.1, 6.3); glEnd(); if(wiremode) glBegin(GL_LINE_LOOP); else glBegin(GL_POLYGON); glColor3f(0.3,0.3,0.3); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mdiff2); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mamb2); glNormal3f( 0.0, 1.0, 0.0); glVertex3f( 2.0, 0.1, 6.3); glVertex3f( 2.0, 0.1,-5.3); glVertex3f( 2.8, 0.1,-5.3); glVertex3f( 2.8, 0.1, 6.3); glEnd(); /*glBegin(GL_POLYGON);---left-white-line-- glColor3f(0.5,0.5,0.5); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mdiff2); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mamb2); glNormal3f( 0.0, 1.0, 0.0); glVertex3f( -2.8, 0.1, 6.3); glVertex3f( -2.8, 0.1,-5.8); glVertex3f(-3.8, 0.1,-5.8); glVertex3f(-3.8, 0.1, 6.3); glEnd();*/ glPushMatrix(); glColor3f(0.5,0.5,0.5); glTranslatef(-3.2,0.2,0.3); glScalef(0.09,0.07,1.67); glNormal3f( 0.0, 1.0, 0.0); if(wiremode) glutWireCube(7.3); else glutSolidCube(7.3); glPopMatrix(); glPushMatrix(); glColor3f(0.5,0.5,0.5); glTranslatef(3.2,0.2,0.3); glScalef(0.09,0.07,1.67); glNormal3f( 0.0, 1.0, 0.0); if(wiremode) glutWireCube(7.3); else glutSolidCube(7.3); glPopMatrix(); if(wiremode) glBegin(GL_LINE_LOOP); else glBegin(GL_POLYGON);/*---right-white-line--*/ glColor3f(0.5,0.5,0.5); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mdiff2); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mamb2); glNormal3f( 0.0, 1.0, 0.0); glVertex3f( 2.8, 0.1, 6.3); glVertex3f( 2.8, 0.1,-5.8); glVertex3f(3.3, 0.1,-5.8); glVertex3f(3.3, 0.1, 6.3); glEnd(); /*glBegin(GL_POLYGON);---right-white-line-- glColor3f(0.3,0.3,0.3); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mdiff2); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mamb2); glNormal3f( 0.0, 1.0, 0.0); glVertex3f( 3.0, 0.1, 6.3); glVertex3f( 3.3, 0.1,-5.8); glVertex3f(4.8, 0.1,-5.8); glVertex3f(4.8, 0.1, 6.3); glEnd();*/ /*---back vertical---*/ /* glBegin(GL_POLYGON); glColor3f(0.5,0.5,0.5); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mdiff2); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mamb2); glNormal3f( 0.0, 0.0, 1.0); glVertex3f(-3.8, 0.0, -5.8); glVertex3f(-3.8, 2.0,-5.8); glVertex3f(3.8, 2.0,-5.8); glVertex3f(3.8, 0.0, -5.8); glEnd();*/ if(wiremode) glBegin(GL_LINE_LOOP); else glBegin(GL_POLYGON); /*--back horizontal--*/ glColor3f(0.3,0.3,0.3); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mdiff2); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mamb2); glNormal3f( 0.0, 1.0, 0.0); glVertex3f(-2.8, 0.1, -5.8); glVertex3f(-2.8, 0.1,-5.3); glVertex3f(2.8, 0.1,-5.3); glVertex3f(2.8, 0.1, -5.8); glEnd(); /*glBegin(GL_POLYGON); --side vertl-- glColor3f(0.3,0.3,0.3); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mdiff2); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mamb2); glNormal3f( 0.0, 1.0, 0.0); glVertex3f(-3.8, 0.0, -5.8); glVertex3f(-3.8, 0.5,-5.8); glVertex3f(-3.8, 0.5,6.3); glVertex3f(-3.8, 0.0, 6.3); glEnd(); if(wiremode) glBegin(GL_LINE_LOOP); else glBegin(GL_POLYGON); --side upper horiztl-- glColor3f(0.4,0.4,0.4); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mdiff2); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mamb2); glNormal3f( 0.0, 0.0, 1.0); glVertex3f(-3.8, 0.5, -5.8); glVertex3f(-4.8, 0.5,-5.8); glVertex3f(-4.8, 0.5,6.3); glVertex3f(-3.8, 0.5, 6.3); glEnd(); glBegin(GL_POLYGON); --side vertl-- glColor3f(0.3,0.3,0.3); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mdiff2); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mamb2); glNormal3f( 0.0, 1.0, 0.0); glVertex3f(3.8, 0.0, -5.8); glVertex3f(3.8, 0.5,-5.8); glVertex3f(3.8, 0.5,6.3); glVertex3f(3.8, 0.0, 6.3); glEnd(); glBegin(GL_POLYGON); --side upper horiztl-- glColor3f(0.4,0.4,0.4); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mdiff2); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mamb2); glNormal3f( 0.0, 0.0, 1.0); glVertex3f(3.8, 0.5, -5.8); glVertex3f(4.8, 0.5,-5.8); glVertex3f(4.8, 0.5,6.3); glVertex3f(3.8, 0.5, 6.3); glEnd(); glBegin(GL_POLYGON); --side vertl-- glColor3f(0.3,0.3,0.3); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mdiff2); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mamb2); glNormal3f( 0.0, 1.0, 0.0); glVertex3f(-4.8, 0.5, -5.8); glVertex3f(-4.8, 1.0,-5.8); glVertex3f(-4.8, 1.0,6.3); glVertex3f(-4.8, 0.5, 6.3); glEnd(); glBegin(GL_POLYGON); --side upper horiztl-- glColor3f(0.4,0.4,0.4); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mdiff2); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mamb2); glNormal3f( 0.0, 0.0, 1.0); glVertex3f(-4.8, 1.0, -5.8); glVertex3f(-5.8, 1.0,-5.8); glVertex3f(-5.8, 1.0,6.3); glVertex3f(-4.8, 1.0, 6.3); glEnd(); glBegin(GL_POLYGON); --side vertl-- glColor3f(0.3,0.3,0.3); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mdiff2); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mamb2); glNormal3f( 0.0, 1.0, 0.0); glVertex3f(4.8, 0.5, -5.8); glVertex3f(4.8, 1.0,-5.8); glVertex3f(4.8, 1.0,6.3); glVertex3f(4.8, 0.5, 6.3); glEnd(); glBegin(GL_POLYGON); --side upper horiztl-- glColor3f(0.4,0.4,0.4); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mdiff2); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mamb2); glNormal3f( 0.0, 0.0, 1.0); glVertex3f(4.8, 1.0, -5.8); glVertex3f(5.8, 1.0,-5.8); glVertex3f(5.8, 1.0,6.3); glVertex3f(4.8, 1.0, 6.3); glEnd(); glBegin(GL_POLYGON); --side vertl-- glColor3f(0.3,0.3,0.3); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mdiff2); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mamb2); glNormal3f( 0.0, 1.0, 0.0); glVertex3f(-5.8, 1.0, -5.8); glVertex3f(-5.8, 1.5,-5.8); glVertex3f(-5.8, 1.5,6.3); glVertex3f(-5.8, 1.0, 6.3); glEnd(); glBegin(GL_POLYGON); --side upper horiztl-- glColor3f(0.4,0.4,0.4); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mdiff2); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mamb2); glNormal3f( 0.0, 0.0, 1.0); glVertex3f(-5.8, 1.5,-5.8); glVertex3f(-6.8, 1.5,-5.8); glVertex3f(-6.8, 1.5,6.3); glVertex3f(-5.8, 1.5,6.3); glEnd(); glBegin(GL_POLYGON); --side vertl-- glColor3f(0.3,0.3,0.3); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mdiff2); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mamb2); glNormal3f( 0.0, 1.0, 0.0); glVertex3f(5.8, 1.0, -5.8); glVertex3f(5.8, 1.5,-5.8); glVertex3f(5.8, 1.5,6.3); glVertex3f(5.8, 1.0, 6.3); glEnd(); glBegin(GL_POLYGON); --side upper horiztl-- glColor3f(0.4,0.4,0.4); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mdiff2); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mamb2); glNormal3f( 0.0, 0.0, 1.0); glVertex3f(5.8, 1.5, -5.8); glVertex3f(6.8, 1.5,-5.8); glVertex3f(6.8, 1.5,6.3); glVertex3f(5.8, 1.5, 6.3); glEnd(); */ /* glBegin(GL_POLYGON); --background horizontal-- glColor3f(0.0,1.0,1.0); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mdiff2); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mamb2); glNormal3f( 0.0, 0.5, 0.0); glVertex3f(-17.0, 0.0, -5.8); glVertex3f(-17.0, 0.0,-15.0); glVertex3f(17.0, 0.0,-15.0); glVertex3f(17.0, 0.0, -5.8); glEnd();*/ /*---background vertical--- if(wiremode) glBegin(GL_LINE_LOOP); glColor3f(0.0,0.0,0.3); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mdiff2); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mamb2); glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,mspec2); glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,memission2); glMaterialfv(GL_FRONT_AND_BACK,GL_SHININESS,mshin2); glNormal3f( 0.0, 0.0, 1.0); glVertex3f(-17.0, 0.0, -15.0); glVertex3f(-17.0, 12.0,-15.0); glVertex3f(17.0, 12.0,-15.0); glVertex3f(17.0, 0.0, -15.0); glEnd();*/ /*if(wiremode) glBegin(GL_LINE_LOOP); glColor3f(1.0,1.0,1.0); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mdiff2); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mamb2); glNormal3f( 0.0, 0.0, 1.0); glVertex3f(-17.0, 0.0, -15.0); glVertex3f(-17.0, 12.0,-15.0); glVertex3f(-17.0, 12.0,15.0); glVertex3f(-17.0, 0.0, 15.0); glVertex3f(-17.0, 0.0, -15.0); glEnd(); if(wiremode) glBegin(GL_LINE_LOOP); glColor3f(0.0,0.5,0.0); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mdiff2); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mamb2); glNormal3f( 0.0, 0.0, -1.0); glVertex3f(17.0, 0.0, -15.0); glVertex3f(17.0, 12.0,-15.0); glVertex3f(17.0, 12.0,15.0); glVertex3f(17.0, 0.0, 15.0); glVertex3f(17.0, 0.0, -15.0); glEnd(); if(wiremode) glBegin(GL_LINE_LOOP); glColor3f(1.0,1.0,1.0); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mdiff2); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mamb2); glNormal3f( 0.0, 0.0, 1.0); glVertex3f(-10.0, 0.0, 15.0); glVertex3f(-10.0, 12.0,15.0); glVertex3f(17.0, 12.0,15.0); glVertex3f(17.0, 0.0, 15.0); glEnd();*/ if(wiremode) glBegin(GL_LINE_LOOP); else glBegin(GL_POLYGON); /*--back steps hz--*/ glColor3f(0.0,1.0,1.0); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mdiff2); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mamb2); glNormal3f( 0.0, 0.5, 0.0); glVertex3f(-17.0, 4.0, 15.0); glVertex3f(-17.0, 4.0,13.0); glVertex3f(-10.0, 4.0,13.0); glVertex3f(-10.0, 4.0, 15.0); glEnd(); if(wiremode) glBegin(GL_LINE_LOOP); else glBegin(GL_POLYGON); /*--back steps hz--*/ glColor3f(0.0,1.0,1.0); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mdiff2); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mamb2); glNormal3f(0.0, 0.5, 0.0); glVertex3f(-17.0, 3.0, 13.0); glVertex3f(-17.0, 3.0,11.0); glVertex3f(-10.0, 3.0,11.0); glVertex3f(-10.0, 3.0, 13.0); glEnd(); if(wiremode) glBegin(GL_LINE_LOOP); else glBegin(GL_POLYGON); /*--back steps hz--*/ glColor3f(0.0,1.0,1.0); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mdiff2); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mamb2); glNormal3f(0.0, 0.5, 0.0); glVertex3f(-17.0, 2.0,11.0); glVertex3f(-17.0, 2.0,9.0); glVertex3f(-10.0, 2.0,9.0); glVertex3f(-10.0, 2.0,11.0); glEnd(); if(wiremode) glBegin(GL_LINE_LOOP); else glBegin(GL_POLYGON); /*--back steps hz--*/ glColor3f(0.0,1.0,1.0); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mdiff2); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mamb2); glNormal3f(0.0, 0.5, 0.0); glVertex3f(-17.0, 1.0,9.0); glVertex3f(-17.0, 1.0,7.0); glVertex3f(-10.0, 1.0,7.0); glVertex3f(-10.0, 1.0,9.0); glEnd(); if(wiremode) glBegin(GL_LINE_LOOP); else glBegin(GL_POLYGON);/*---back steps vtl---*/ glColor3f(0.0,0.5,0.0); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mdiff2); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mamb2); glNormal3f( 0.0, 0.0, 1.0); glVertex3f(-10.0, 4.0, 13.0); glVertex3f(-17.0, 4.0,13.0); glVertex3f(-17.0, 3.0,13.0); glVertex3f(-10.0, 3.0, 13.0); glEnd(); if(wiremode) glBegin(GL_LINE_LOOP); else glBegin(GL_POLYGON);/*---back steps vtl---*/ glColor3f(0.0,0.5,0.0); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mdiff2); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mamb2); glNormal3f( 0.0, 0.0, 1.0); glVertex3f(-10.0, 3.0, 11.0); glVertex3f(-17.0, 3.0,11.0); glVertex3f(-17.0, 2.0,11.0); glVertex3f(-10.0, 2.0, 11.0); glEnd(); if(wiremode) glBegin(GL_LINE_LOOP); else glBegin(GL_POLYGON);/*---back steps vtl---*/ glColor3f(0.0,0.5,0.0); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mdiff2); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mamb2); glNormal3f( 0.0, 0.0, 1.0); glVertex3f(-10.0, 2.0, 9.0); glVertex3f(-17.0, 2.0,9.0); glVertex3f(-17.0, 1.0,9.0); glVertex3f(-10.0, 1.0, 9.0); glEnd(); if(wiremode) glBegin(GL_LINE_LOOP); else glBegin(GL_POLYGON);/*---back steps vtl---*/ glColor3f(0.0,0.5,0.0); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mdiff2); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mamb2); glNormal3f( 0.0, 0.0, 1.0); glVertex3f(-10.0, 1.0, 7.0); glVertex3f(-17.0, 1.0,7.0); glVertex3f(-17.0, 0.0,7.0); glVertex3f(-10.0, 0.0, 7.0); glEnd(); if(wiremode) glBegin(GL_LINE_LOOP); else glBegin(GL_POLYGON);/*---back steps cover vtl---*/ glColor3f(0.6,0.6,0.6); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mdiff2); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mamb2); glNormal3f( 1.0, 0.0, 0.0); glVertex3f(-10.0, 4.0, 15.0); glVertex3f(-10.0, 0.0, 15.0); glVertex3f(-10.0, 0.0, 7.0); glVertex3f(-10.0, 1.0, 7.0); glVertex3f(-10.0, 1.0, 9.0); glVertex3f(-10.0, 2.0, 9.0); glVertex3f(-10.0, 2.0, 11.0); glVertex3f(-10.0, 3.0, 11.0); glVertex3f(-10.0, 3.0, 13.0); glVertex3f(-10.0, 4.0, 13.0); glEnd(); /*glBegin(GL_POLYGON); --floor-- glNormal3f(0.0, 0.5, 0.0); glVertex3f(-17.0, 0.0,-15.0); glVertex3f(17.0, 0.0,-15.0); glVertex3f(17.0, 0.0,15.0); glVertex3f(-17.0, 0.0,15.0); glEnd();*/ if(dist ==0) { /* glColor3f(0.0,1.0,1.0); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mdiff2); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mamb2); for(i= -2;i<3;i++) { glPushMatrix(); glTranslatef(i,0.9,-5.0); glScalef(1.0,3.0,1.0); glutSolidSphere(0.2,8,8); glutSolidCube(0.1); glPopMatrix(); } for(i= -1.5;i<2;i += 1.0) { glPushMatrix(); glTranslatef(i,0.9,-4.5); glScalef(1.0,3.0,1.0); glutSolidSphere(0.2,8,8); glutSolidCube(0.1); glPopMatrix(); } for(i= -1.0;i<2;i += 1.0) { glPushMatrix(); glTranslatef(i,0.9,-4.0); glScalef(1.0,3.0,1.0); glutSolidSphere(0.2,8,8); glutSolidCube(0.1); glPopMatrix(); } for(i= -0.5;i<1.0;i += 1.0) { glPushMatrix(); glTranslatef(i,0.9,-3.5); glScalef(1.0,3.0,1.0); glutSolidSphere(0.2,8,8); glutSolidCube(0.1); glPopMatrix(); } glPushMatrix(); glTranslatef(0.0,0.9,-3.0); glScalef(1.0,3.0,1.0); glutSolidSphere(0.2,8,8); glutSolidCube(0.1); glPopMatrix();*/ for(k=0;k<10;k++) { pins[k].hit=0; pins[k].scalex = 1.0; pins[k].scaley = 3.0; pins[k].scalez = 1.0; pins[k].y = 0.9; } pins[0].x = 0.0; pins[0].z = -3.0; pins[1].x = -0.5; pins[1].z = -3.5; pins[2].x = 0.5; pins[2].z = -3.5; pins[3].z = -4.0; pins[3].x = -1.0; pins[4].z = -4.0; pins[4].x = 0.0; pins[5].z = -4.0; pins[5].x = 1.0; pins[6].z = -4.5; pins[6].x = -1.5; pins[7].x = -0.5; pins[7].z = -4.5; pins[8].z = -4.5; pins[8].x = 0.5; pins[9].x = 1.5; pins[9].z = -4.5; for(i=0;i<10;i++) { glPushMatrix(); glTranslatef(pins[i].x,pins[i].y,pins[i].z); glScalef(pins[i].scalex,pins[i].scaley,pins[i].scalez); if(wiremode) glutWireSphere(0.2,8,8); else glutSolidSphere(0.2,8,8); glPopMatrix(); } } if(dist == 1) /*--left corner--*/ { glColor3f(1.0,1.0,1.0); DrawTextXY(-1.0,5.75,-12.0,0.008,"20"); pins[3].hit = 1; pins[6].hit = 1; pins[7].hit = 1; /*pins[0].x = 0.0; pins[0].z = -3.0; pins[1].x = -0.5; pins[1].z = -3.5; pins[2].x = 0.5; pins[2].z = -3.5; pins[3].z = -4.0; pins[3].x = -1.0; pins[4].z = -4.0; pins[4].x = 0.0; pins[5].z = -4.0; pins[5].x = 1.0; pins[6].z = -4.5; pins[6].x = -1.5; pins[7].x = -0.5; pins[7].z = -4.5; pins[8].z = -4.5; pins[8].x = 0.5; pins[9].x = 1.5; pins[9].z = -4.5;*/ for(i=0;i<10;i++) { glPushMatrix(); if(pins[i].hit==1) { if(first == 0) { pins[i].y = 0.5; pins[i].z = -5.2; pins[i].scalex = 3.0; pins[i].scaley = 1.0; pins[i].scalez = 1.0; } } glTranslatef(pins[i].x,pins[i].y,pins[i].z); glScalef(pins[i].scalex,pins[i].scaley,pins[i].scalez); if(wiremode) glutWireSphere(0.2,8,8); else glutSolidSphere(0.2,8,8); glPopMatrix(); } /* glColor3f(0.0,1.0,1.0); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mdiff2); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mamb2); for(i= -1;i<3;i++) { glPushMatrix(); glTranslatef(i,0.9,-5.0); glScalef(1.0,3.0,1.0); glutSolidSphere(0.2,8,8); glutSolidCube(0.1); glPopMatrix(); } for(i= -0.5;i<2;i += 1.0) { glPushMatrix(); glTranslatef(i,0.9,-4.5); glScalef(1.0,3.0,1.0); glutSolidSphere(0.2,8,8); glutSolidCube(0.1); glPopMatrix(); } for(i= -1.0;i<2;i += 1.0) { glPushMatrix(); glTranslatef(i,0.9,-4.0); glScalef(1.0,3.0,1.0); glutSolidSphere(0.2,8,8); glutSolidCube(0.1); glPopMatrix(); } for(i= -0.5;i<1.0;i += 1.0) { glPushMatrix(); glTranslatef(i,0.9,-3.5); glScalef(1.0,3.0,1.0); glutSolidSphere(0.2,8,8); glutSolidCube(0.1); glPopMatrix(); } glPushMatrix(); glTranslatef(0.0,0.9,-3.0); glScalef(1.0,3.0,1.0); glutSolidSphere(0.2,8,8); glutSolidCube(0.1); glPopMatrix(); glPushMatrix(); glTranslatef(-1.0,0.6,-4.0); glScalef(3.0,1.0,1.0); glutSolidSphere(0.2,8,8); glutSolidCube(0.1); glPopMatrix(); glPushMatrix(); glTranslatef(-2.0,0.6,-3.5); glScalef(1.0,1.0,3.0); glutSolidSphere(0.2,8,8); glutSolidCube(0.1); glPopMatrix();*/ } if(dist == 2) { pins[1].hit =1; pins[4].hit =1; pins[7].hit =1; pins[8].hit =1; pins[3].hit =1; pins[6].hit =1; glColor3f(1.0,1.0,1.0); DrawTextXY(-1.0,5.75,-12.0,0.008,"40"); /*pins[0].x = 0.0; pins[0].z = -3.0; pins[1].x = -0.5; pins[1].z = -3.5; pins[2].x = 0.5; pins[2].z = -3.5; pins[3].z = -4.0; pins[3].x = -1.0; pins[4].z = -4.0; pins[4].x = 0.0; pins[5].z = -4.0; pins[5].x = 1.0; pins[6].z = -4.5; pins[6].x = -1.5; pins[7].x = -0.5; pins[7].z = -4.5; pins[8].z = -4.5; pins[8].x = 0.5; pins[9].x = 1.5; pins[9].z = -4.5;*/ for(i=0;i<10;i++) { glPushMatrix(); if(pins[i].hit==1) { if(first == 0) { pins[i].y = 0.5; pins[i].z = -5.2; pins[i].scalex = 3.0; pins[i].scaley = 1.0; pins[i].scalez = 1.0; } } glTranslatef(pins[i].x,pins[i].y,pins[i].z); glScalef(pins[i].scalex,pins[i].scaley,pins[i].scalez); if(wiremode) glutWireSphere(0.2,8,8); else glutSolidSphere(0.2,8,8); glPopMatrix(); } /*glColor3f(0.0,1.0,1.0); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mdiff2); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mamb2); for(i= 0;i<3;i++) { glPushMatrix(); glTranslatef(i,0.9,-5.0); glScalef(1.0,3.0,1.0); glutSolidSphere(0.2,8,8); glutSolidCube(0.1); glPopMatrix(); } for(i= 0.5;i<2;i += 1.0) { glPushMatrix(); glTranslatef(i,0.9,-4.5); glScalef(1.0,3.0,1.0); glutSolidSphere(0.2,8,8); glutSolidCube(0.1); glPopMatrix(); } for(i= 0;i<2;i += 1.0) { glPushMatrix(); glTranslatef(i,0.9,-4.0); glScalef(1.0,3.0,1.0); glutSolidSphere(0.2,8,8); glutSolidCube(0.1); glPopMatrix(); } glPushMatrix(); glTranslatef(0.5,0.9,-3.5); glScalef(1.0,3.0,1.0); glutSolidSphere(0.2,8,8); glutSolidCube(0.1); glPopMatrix(); glPushMatrix(); glTranslatef(0.0,0.9,-3.0); glScalef(1.0,3.0,1.0); glutSolidSphere(0.2,8,8); glutSolidCube(0.1); glPopMatrix(); glPushMatrix(); glTranslatef(-1.5,0.6,-4.0); glScalef(3.0,1.0,1.0); glutSolidSphere(0.2,8,8); glutSolidCube(0.1); glPopMatrix(); glPushMatrix(); glTranslatef(-2.0,0.6,-3.0); glScalef(3.0,1.0,1.0); glutSolidSphere(0.2,8,8); glutSolidCube(0.1); glPopMatrix(); glPushMatrix(); glTranslatef(-1.0,0.6,-2.5); glScalef(3.0,1.0,1.0); glutSolidSphere(0.2,8,8); glutSolidCube(0.1); glPopMatrix(); glPushMatrix(); glTranslatef(-1.0,0.6,-4.2); glScalef(1.0,1.0,3.0); glutSolidSphere(0.2,8,8); glutSolidCube(0.1); glPopMatrix();*/ } if(dist == 3) { pins[0].hit = 1; pins[1].hit = 1; pins[2].hit = 1; pins[4].hit = 1; pins[7].hit = 1; pins[8].hit = 1; glColor3f(1.0,1.0,1.0); DrawTextXY(-1.0,5.75,-12.0,0.008,"60"); for(i=0;i<10;i++) { glPushMatrix(); if(pins[i].hit == 1) { if(first == 0) { pins[i].y = 0.5; pins[i].z = -5.2; pins[i].scalex = 3.0; pins[i].scaley = 1.0; pins[i].scalez = 1.0; } } glTranslatef(pins[i].x,pins[i].y,pins[i].z); glScalef(pins[i].scalex,pins[i].scaley,pins[i].scalez); if(wiremode) glutWireSphere(0.2,8,8); else glutSolidSphere(0.2,8,8); glPopMatrix(); } /*glColor3f(0.0,1.0,1.0); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mdiff2); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mamb2); for(i= -2;i<3;i += 4) { glPushMatrix(); glTranslatef(i,0.9,-5.0); glScalef(1.0,3.0,1.0); glutSolidSphere(0.2,8,8); glutSolidCube(0.1); glPopMatrix(); } for(i= -1.5;i<2;i += 2.0) { glPushMatrix(); glTranslatef(i,0.9,-4.5); glScalef(1.0,3.0,1.0); glutSolidSphere(0.2,8,8); glutSolidCube(0.1); glPopMatrix(); } glPushMatrix(); glTranslatef(-2.0,0.6,-4.5); glScalef(3.0,1.0,1.0); glutSolidSphere(0.2,8,8); glutSolidCube(0.1); glPopMatrix(); glPushMatrix(); glTranslatef(-0.3,0.6,-3.8); glScalef(1.0,1.0,3.0); glutSolidSphere(0.2,8,8); glutSolidCube(0.1); glPopMatrix(); glPushMatrix(); glTranslatef(1.5,0.6,-3.9); glScalef(3.0,1.0,1.0); glutSolidSphere(0.2,8,8); glutSolidCube(0.1); glPopMatrix(); glPushMatrix(); glTranslatef(1.7,0.6,-4.6); glScalef(3.0,1.0,1.0); glutSolidSphere(0.2,8,8); glutSolidCube(0.1); glPopMatrix(); glPushMatrix(); glTranslatef(0.5,0.6,-5.0); glScalef(1.0,1.0,3.0); glutSolidSphere(0.2,8,8); glutSolidCube(0.1); glPopMatrix(); glPushMatrix(); glTranslatef(-1.4,0.6,-4.2); glScalef(3.0,1.0,1.0); glutSolidSphere(0.2,8,8); glutSolidCube(0.1); glPopMatrix();*/ } if(dist == 4) { pins[5].hit = 1.0; pins[8].hit = 1.0; pins[9].hit = 1.0; /*pins[0].x = 0.0; pins[0].z = -3.0; pins[1].x = -0.5; pins[1].z = -3.5; pins[2].x = 0.5; pins[2].z = -3.5; pins[3].z = -4.0; pins[3].x = -1.0; pins[4].z = -4.0; pins[4].x = 0.0; pins[5].z = -4.0; pins[5].x = 1.0; pins[6].z = -4.5; pins[6].x = -1.5; pins[7].x = -0.5; pins[7].z = -4.5; pins[8].z = -4.5; pins[8].x = 0.5; pins[9].x = 1.5; pins[9].z = -4.5;*/ for(i=0;i<10;i++) { glPushMatrix(); if(pins[i].hit==1) { if(first == 0) { pins[i].y = 0.5; pins[i].z = -5.2; pins[i].scalex = 3.0; pins[i].scaley = 1.0; pins[i].scalez = 1.0; } } glTranslatef(pins[i].x,pins[i].y,pins[i].z); glScalef(pins[i].scalex,pins[i].scaley,pins[i].scalez); if(wiremode) glutWireSphere(0.2,8,8); else glutSolidSphere(0.2,8,8); glPopMatrix(); } /*glColor3f(0.0,1.0,1.0); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mdiff2); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mamb2); for(i= -2;i<2;i++) { glPushMatrix(); glTranslatef(i,0.9,-5.0); glScalef(1.0,3.0,1.0); glutSolidSphere(0.2,8,8); glutSolidCube(0.1); glPopMatrix(); } for(i= -1.5;i<1.5;i += 1.0) { glPushMatrix(); glTranslatef(i,0.9,-4.5); glScalef(1.0,3.0,1.0); glutSolidSphere(0.2,8,8); glutSolidCube(0.1); glPopMatrix(); } for(i= -1.0;i<2;i += 1.0) { glPushMatrix(); glTranslatef(i,0.9,-4.0); glScalef(1.0,3.0,1.0); glutSolidSphere(0.2,8,8); glutSolidCube(0.1); glPopMatrix(); } for(i= -0.5;i<1.0;i += 1.0) { glPushMatrix(); glTranslatef(i,0.9,-3.5); glScalef(1.0,3.0,1.0); glutSolidSphere(0.2,8,8); glutSolidCube(0.1); glPopMatrix(); } glPushMatrix(); glTranslatef(0.0,0.9,-3.0); glScalef(1.0,3.0,1.0); glutSolidSphere(0.2,8,8); glutSolidCube(0.1); glPopMatrix(); glPushMatrix(); glTranslatef(2.5,0.9,-4.1); glScalef(3.0,1.0,1.0); glutSolidSphere(0.2,8,8); glutSolidCube(0.1); glPopMatrix(); glPushMatrix(); glTranslatef(2.0,0.9,-4.5); glScalef(1.0,1.0,3.0); glutSolidSphere(0.2,8,8); glutSolidCube(0.1); glPopMatrix();*/ } if(dist == 5) { pins[2].hit =1; pins[4].hit =1; pins[7].hit =1; pins[8].hit =1; pins[9].hit =1; pins[5].hit =1; /* pins[0].x = 0.0; pins[0].z = -3.0; pins[1].x = -0.5; pins[1].z = -3.5; pins[2].x = 0.5; pins[2].z = -3.5; pins[3].z = -4.0; pins[3].x = -1.0; pins[4].z = -4.0; pins[4].x = 0.0; pins[5].z = -4.0; pins[5].x = 1.0; pins[6].z = -4.5; pins[6].x = -1.5; pins[7].x = -0.5; pins[7].z = -4.5; pins[8].z = -4.5; pins[8].x = 0.5; pins[9].x = 1.5; pins[9].z = -4.5;*/ for(i=0;i<10;i++) { glPushMatrix(); if(pins[i].hit==1) { if(first == 0) { pins[i].y = 0.5; pins[i].z = -5.2; pins[i].scalex = 3.0; pins[i].scaley = 1.0; pins[i].scalez = 1.0; } } glTranslatef(pins[i].x,pins[i].y,pins[i].z); glScalef(pins[i].scalex,pins[i].scaley,pins[i].scalez); if(wiremode) glutWireSphere(0.2,8,8); else glutSolidSphere(0.2,8,8); glPopMatrix(); } /* glColor3f(0.0,1.0,1.0); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mdiff2); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mamb2); for(i= -2;i<1;i++) { glPushMatrix(); glTranslatef(i,0.9,-5.0); glScalef(1.0,3.0,1.0); glutSolidSphere(0.2,8,8); glutSolidCube(0.1); glPopMatrix(); } for(i= -1.5;i<0;i += 1.0) { glPushMatrix(); glTranslatef(i,0.9,-4.5); glScalef(1.0,3.0,1.0); glutSolidSphere(0.2,8,8); glutSolidCube(0.1); glPopMatrix(); } for(i= -1.0;i<1;i += 1.0) { glPushMatrix(); glTranslatef(i,0.9,-4.0); glScalef(1.0,3.0,1.0); glutSolidSphere(0.2,8,8); glutSolidCube(0.1); glPopMatrix(); } glPushMatrix(); glTranslatef(-0.5,0.9,-3.5); glScalef(1.0,3.0,1.0); glutSolidSphere(0.2,8,8); glutSolidCube(0.1); glPopMatrix(); glPushMatrix(); glTranslatef(0.0,0.9,-3.0); glScalef(1.0,3.0,1.0); glutSolidSphere(0.2,8,8); glutSolidCube(0.1); glPopMatrix(); glPushMatrix(); glTranslatef(1.5,0.6,-4.3); glScalef(3.0,1.0,1.0); glutSolidSphere(0.2,8,8); glutSolidCube(0.1); glPopMatrix(); glPushMatrix(); glTranslatef(2.0,0.6,-3.3); glScalef(3.0,1.0,1.0); glutSolidSphere(0.2,8,8); glutSolidCube(0.1); glPopMatrix(); glPushMatrix(); glTranslatef(1.0,0.6,-3.5); glScalef(3.0,1.0,1.0); glutSolidSphere(0.2,8,8); glutSolidCube(0.1); glPopMatrix(); glPushMatrix(); glTranslatef(1.0,0.6,-3.9); glScalef(1.0,1.0,3.0); glutSolidSphere(0.2,8,8); glutSolidCube(0.1); glPopMatrix();*/ } switch(sprcolor) { case 0 : glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(0.3, 0.3, 0.3, 0.7); drawpitch();drawpitch1(); glDisable(GL_BLEND); break; case 1 : glPushMatrix(); glColor3f(1.0,0.0,0.0); glTranslatef(xr,yb-1.0,zr); /*glDisable(GL_NORMALIZE);*/ if(wiremode) glutWireSphere(0.4,30,30); else glutSolidSphere(0.4,30,30); glPopMatrix(); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(0.3, 0.3, 0.3, 0.7); drawpitch();drawpitch1(); glDisable(GL_BLEND); glPushMatrix(); glColor3f(1.0,0.0,0.0); glTranslatef(xr,yb,zr); /*glDisable(GL_NORMALIZE);*/ if(wiremode) glutWireSphere(0.4,30,30); else glutSolidSphere(0.4,30,30); glPopMatrix(); break; case 2 : glPushMatrix(); glColor3f(0.0,0.5,0.0); glTranslatef(xr,yb-1.0,zr); /*glDisable(GL_NORMALIZE);*/ if(wiremode) glutWireSphere(0.4,30,30); else glutSolidSphere(0.4,30,30); glPopMatrix(); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(0.3, 0.3, 0.3, 0.7); drawpitch();drawpitch1(); glDisable(GL_BLEND); glPushMatrix(); glColor3f(0.0,0.5,0.0); glTranslatef(xr,yb,zr); /*glDisable(GL_NORMALIZE);*/ if(wiremode) glutWireSphere(0.4,30,30); else glutSolidSphere(0.4,30,30); glPopMatrix(); break; case 3 : glPushMatrix(); glColor3f(0.0,0.0,0.5); glTranslatef(xr,yb-1.0,zr); /*glDisable(GL_NORMALIZE);*/ if(wiremode) glutWireSphere(0.4,30,30); else glutSolidSphere(0.4,30,30); glPopMatrix(); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(0.3, 0.3, 0.3, 0.7); drawpitch();drawpitch1(); glDisable(GL_BLEND); glPushMatrix(); glColor3f(0.0,0.0,0.5); glTranslatef(xr,yb,zr); /*glDisable(GL_NORMALIZE);*/ if(wiremode) glutWireSphere(0.4,30,30); else glutSolidSphere(0.4,30,30); glPopMatrix(); break; case 4 : glPushMatrix(); glColor3f(0.67,0.31,0.0); glTranslatef(xr,yb-1.0,zr); /*glDisable(GL_NORMALIZE);*/ if(wiremode) glutWireSphere(0.4,30,30); else glutSolidSphere(0.4,30,30); glPopMatrix(); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(0.3, 0.3, 0.3, 0.7); drawpitch();drawpitch1(); glDisable(GL_BLEND); glPushMatrix(); glColor3f(0.67,0.31,0.0); glTranslatef(xr,yb,zr); /*glDisable(GL_NORMALIZE);*/ if(wiremode) glutWireSphere(0.4,30,30); else glutSolidSphere(0.4,30,30); glPopMatrix(); break; } /*--arrow--*/ glPushMatrix(); glColor3f(1.0,0.0,0.0); glTranslatef(xr,yr,0.0); glTranslatef(0.0,0.0,6.0); glRotatef(rt,0.0,1.0,0.0); glTranslatef(0.0,0.0,-6.0); if(wiremode) glBegin(GL_LINE_LOOP); else glBegin(GL_POLYGON); glNormal3f( 0.0, 1.0, 0.0); glVertex3f( 0.0, 0.1, 6.5); glVertex3f(-0.8, 0.1, 6.9); glVertex3f(-0.4, 0.1, 6.9); glVertex3f(-0.4, 0.1, 7.3); glVertex3f(0.4, 0.1, 7.3); glVertex3f(0.4, 0.1, 6.9); glVertex3f(0.8, 0.1, 6.9); glEnd(); glPopMatrix(); /*---pitch wall---*/ glPushMatrix(); glColor3f(0.5,0.5,0.5); glTranslatef(0.5,0.0,-6.8); glScalef(4.0,1.5,0.2); if(wiremode) glutWireCube(2.0); else glutSolidCube(2.0); glPopMatrix(); /*-- box --*/ glPushMatrix(); glColor3f(0.63,0.37,0.3); glTranslatef(4.5,0.5,0.2); glScalef(0.05,0.3,6.8); if(wiremode) glutWireCube(2.0); else glutSolidCube(2.0); glPopMatrix(); /*glPushMatrix(); glColor3f(0.63,0.37,0.3); glTranslatef(3.6,0.5,2.8); glScalef(0.05,0.3,4.2); glutSolidCube(2.0); glPopMatrix();*/ glPushMatrix(); glColor3f(0.63,0.37,0.3); glTranslatef(4.0,0.5,7.0); glScalef(0.45,0.3,0.05); if(wiremode) glutWireCube(2.0); else glutSolidCube(2.0); glPopMatrix(); /*-- table --*/ glPushMatrix(); glColor4f(0.3, 0.0, 0.0, 0.3); glTranslatef(-7.5,1.5,-10.0); glScalef(2.0,0.07,2.5); glNormal3f( 0.0, 1.0, 0.0); if(wiremode) glutWireCube(2.0); else glutSolidCube(2.0); glPopMatrix(); glPushMatrix(); glColor3f(0.67,0.31,0.0); glTranslatef(-6.0,0.5,-10.0); glScalef(0.1,1.05,2.5); if(wiremode) glutWireCube(2.0); else glutSolidCube(2.0); glPopMatrix(); glPushMatrix(); glColor3f(0.67,0.31,0.0); glTranslatef(-9.0,0.5,-10.0); glScalef(0.1,1.05,2.5); if(wiremode) glutWireCube(2.0); else glutSolidCube(2.0); glPopMatrix(); if(sprcolor == 0) { glLoadName(REDSPHERE); glMaterialfv(GL_FRONT,GL_AMBIENT,mamb1); glMaterialfv(GL_FRONT,GL_DIFFUSE,mdiff1); glMaterialfv(GL_FRONT,GL_SPECULAR,mspec1); glMaterialfv(GL_FRONT,GL_EMISSION,memission1); glMaterialfv(GL_FRONT,GL_SHININESS,mshin1); glColor3f(1.0,0.0,0.0); glPushMatrix(); glTranslatef(4.0,0.5,3.5); if(wiremode) glutWireSphere(0.4,30,30); else glutSolidSphere(0.4,30,30); glPopMatrix(); glLoadName(GREENSPHERE); glMaterialfv(GL_FRONT,GL_AMBIENT,mamb1); glMaterialfv(GL_FRONT,GL_DIFFUSE,mdiff1); glMaterialfv(GL_FRONT,GL_SPECULAR,mspec1); glMaterialfv(GL_FRONT,GL_EMISSION,memission1); glMaterialfv(GL_FRONT,GL_SHININESS,mshin1); glColor3f(0.0,0.5,0.0); glPushMatrix(); glTranslatef(4.0,0.5,4.5); if(wiremode) glutWireSphere(0.4,30,30); else glutSolidSphere(0.4,30,30); glPopMatrix(); glLoadName(BLUESPHERE); glMaterialfv(GL_FRONT,GL_AMBIENT,mamb1); glMaterialfv(GL_FRONT,GL_DIFFUSE,mdiff1); glMaterialfv(GL_FRONT,GL_SPECULAR,mspec1); glMaterialfv(GL_FRONT,GL_EMISSION,memission1); glMaterialfv(GL_FRONT,GL_SHININESS,mshin1); glColor3f(0.0,0.0,0.5); glPushMatrix(); glTranslatef(4.0,0.5,5.5); if(wiremode) glutWireSphere(0.4,30,30); else glutSolidSphere(0.4,30,30); glPopMatrix(); glLoadName(BROWNSPHERE); glMaterialfv(GL_FRONT,GL_AMBIENT,mamb1); glMaterialfv(GL_FRONT,GL_DIFFUSE,mdiff1); glMaterialfv(GL_FRONT,GL_SPECULAR,mspec1); glMaterialfv(GL_FRONT,GL_EMISSION,memission1); glMaterialfv(GL_FRONT,GL_SHININESS,mshin1); glColor3f(0.67,0.31,0.0); glPushMatrix(); glTranslatef(4.0,0.5,6.5); if(wiremode) glutWireSphere(0.4,30,30); else glutSolidSphere(0.4,30,30); glPopMatrix(); } if(sprcolor == 1) { /*glLoadName(SPHEREID); glMaterialfv(GL_FRONT,GL_AMBIENT,mamb1); glMaterialfv(GL_FRONT,GL_DIFFUSE,mdiff1); glMaterialfv(GL_FRONT,GL_SPECULAR,mspec1); glMaterialfv(GL_FRONT,GL_EMISSION,memission1); glMaterialfv(GL_FRONT,GL_SHININESS,mshin1); glColor3f(1.0,0.0,0.0); glPushMatrix(); glTranslatef(4.0,0.5,3.5); if(wiremode) glutWireSphere(0.4,30,30); else glutSolidSphere(0.4,30,30); glPopMatrix();*/ glLoadName(GREENSPHERE); glMaterialfv(GL_FRONT,GL_AMBIENT,mamb1); glMaterialfv(GL_FRONT,GL_DIFFUSE,mdiff1); glMaterialfv(GL_FRONT,GL_SPECULAR,mspec1); glMaterialfv(GL_FRONT,GL_EMISSION,memission1); glMaterialfv(GL_FRONT,GL_SHININESS,mshin1); glColor3f(0.0,0.5,0.0); glPushMatrix(); glTranslatef(4.0,0.5,4.5); if(wiremode) glutWireSphere(0.4,30,30); else glutSolidSphere(0.4,30,30); glPopMatrix(); glLoadName(BLUESPHERE); glMaterialfv(GL_FRONT,GL_AMBIENT,mamb1); glMaterialfv(GL_FRONT,GL_DIFFUSE,mdiff1); glMaterialfv(GL_FRONT,GL_SPECULAR,mspec1); glMaterialfv(GL_FRONT,GL_EMISSION,memission1); glMaterialfv(GL_FRONT,GL_SHININESS,mshin1); glColor3f(0.0,0.0,0.5); glPushMatrix(); glTranslatef(4.0,0.5,5.5); if(wiremode) glutWireSphere(0.4,30,30); else glutSolidSphere(0.4,30,30); glPopMatrix(); glLoadName(BROWNSPHERE); glMaterialfv(GL_FRONT,GL_AMBIENT,mamb1); glMaterialfv(GL_FRONT,GL_DIFFUSE,mdiff1); glMaterialfv(GL_FRONT,GL_SPECULAR,mspec1); glMaterialfv(GL_FRONT,GL_EMISSION,memission1); glMaterialfv(GL_FRONT,GL_SHININESS,mshin1); glColor3f(0.67,0.31,0.0); glPushMatrix(); glTranslatef(4.0,0.5,6.5); if(wiremode) glutWireSphere(0.4,30,30); else glutSolidSphere(0.4,30,30); glPopMatrix(); } if(sprcolor == 2) { glLoadName(REDSPHERE); glMaterialfv(GL_FRONT,GL_AMBIENT,mamb1); glMaterialfv(GL_FRONT,GL_DIFFUSE,mdiff1); glMaterialfv(GL_FRONT,GL_SPECULAR,mspec1); glMaterialfv(GL_FRONT,GL_EMISSION,memission1); glMaterialfv(GL_FRONT,GL_SHININESS,mshin1); glColor3f(1.0,0.0,0.0); glPushMatrix(); glTranslatef(4.0,0.5,4.5); if(wiremode) glutWireSphere(0.4,30,30); else glutSolidSphere(0.4,30,30); glPopMatrix(); /*glLoadName(SPHEREID); glMaterialfv(GL_FRONT,GL_AMBIENT,mamb1); glMaterialfv(GL_FRONT,GL_DIFFUSE,mdiff1); glMaterialfv(GL_FRONT,GL_SPECULAR,mspec1); glMaterialfv(GL_FRONT,GL_EMISSION,memission1); glMaterialfv(GL_FRONT,GL_SHININESS,mshin1); glColor3f(0.0,0.5,0.0); glPushMatrix(); glTranslatef(4.0,0.5,4.5); if(wiremode) glutWireSphere(0.4,30,30); else glutSolidSphere(0.4,30,30); glPopMatrix();*/ glLoadName(BLUESPHERE); glMaterialfv(GL_FRONT,GL_AMBIENT,mamb1); glMaterialfv(GL_FRONT,GL_DIFFUSE,mdiff1); glMaterialfv(GL_FRONT,GL_SPECULAR,mspec1); glMaterialfv(GL_FRONT,GL_EMISSION,memission1); glMaterialfv(GL_FRONT,GL_SHININESS,mshin1); glColor3f(0.0,0.0,0.5); glPushMatrix(); glTranslatef(4.0,0.5,5.5); if(wiremode) glutWireSphere(0.4,30,30); else glutSolidSphere(0.4,30,30); glPopMatrix(); glLoadName(BROWNSPHERE); glMaterialfv(GL_FRONT,GL_AMBIENT,mamb1); glMaterialfv(GL_FRONT,GL_DIFFUSE,mdiff1); glMaterialfv(GL_FRONT,GL_SPECULAR,mspec1); glMaterialfv(GL_FRONT,GL_EMISSION,memission1); glMaterialfv(GL_FRONT,GL_SHININESS,mshin1); glColor3f(0.67,0.31,0.0); glPushMatrix(); glTranslatef(4.0,0.5,6.5); if(wiremode) glutWireSphere(0.4,30,30); else glutSolidSphere(0.4,30,30); glPopMatrix(); } if(sprcolor == 3) { glLoadName(REDSPHERE); glMaterialfv(GL_FRONT,GL_AMBIENT,mamb1); glMaterialfv(GL_FRONT,GL_DIFFUSE,mdiff1); glMaterialfv(GL_FRONT,GL_SPECULAR,mspec1); glMaterialfv(GL_FRONT,GL_EMISSION,memission1); glMaterialfv(GL_FRONT,GL_SHININESS,mshin1); glColor3f(1.0,0.0,0.0); glPushMatrix(); glTranslatef(4.0,0.5,4.5); if(wiremode) glutWireSphere(0.4,30,30); else glutSolidSphere(0.4,30,30); glPopMatrix(); glLoadName(GREENSPHERE); glMaterialfv(GL_FRONT,GL_AMBIENT,mamb1); glMaterialfv(GL_FRONT,GL_DIFFUSE,mdiff1); glMaterialfv(GL_FRONT,GL_SPECULAR,mspec1); glMaterialfv(GL_FRONT,GL_EMISSION,memission1); glMaterialfv(GL_FRONT,GL_SHININESS,mshin1); glColor3f(0.0,0.5,0.0); glPushMatrix(); glTranslatef(4.0,0.5,5.5); if(wiremode) glutWireSphere(0.4,30,30); else glutSolidSphere(0.4,30,30); glPopMatrix(); /* glLoadName(SPHEREID); glMaterialfv(GL_FRONT,GL_AMBIENT,mamb1); glMaterialfv(GL_FRONT,GL_DIFFUSE,mdiff1); glMaterialfv(GL_FRONT,GL_SPECULAR,mspec1); glMaterialfv(GL_FRONT,GL_EMISSION,memission1); glMaterialfv(GL_FRONT,GL_SHININESS,mshin1); glColor3f(0.0,0.0,0.4); glPushMatrix(); glTranslatef(4.0,0.5,5.5); if(wiremode) glutWireSphere(0.4,30,30); else glutSolidSphere(0.4,30,30); glPopMatrix();*/ glLoadName(BROWNSPHERE); glMaterialfv(GL_FRONT,GL_AMBIENT,mamb1); glMaterialfv(GL_FRONT,GL_DIFFUSE,mdiff1); glMaterialfv(GL_FRONT,GL_SPECULAR,mspec1); glMaterialfv(GL_FRONT,GL_EMISSION,memission1); glMaterialfv(GL_FRONT,GL_SHININESS,mshin1); glColor3f(0.67,0.31,0.0); glPushMatrix(); glTranslatef(4.0,0.5,6.5); if(wiremode) glutWireSphere(0.4,30,30); else glutSolidSphere(0.4,30,30); glPopMatrix(); } if(sprcolor == 4) { glLoadName(REDSPHERE); glMaterialfv(GL_FRONT,GL_AMBIENT,mamb1); glMaterialfv(GL_FRONT,GL_DIFFUSE,mdiff1); glMaterialfv(GL_FRONT,GL_SPECULAR,mspec1); glMaterialfv(GL_FRONT,GL_EMISSION,memission1); glMaterialfv(GL_FRONT,GL_SHININESS,mshin1); glColor3f(1.0,0.0,0.0); glPushMatrix(); glTranslatef(4.0,0.5,4.5); if(wiremode) glutWireSphere(0.4,30,30); else glutSolidSphere(0.4,30,30); glPopMatrix(); glLoadName(GREENSPHERE); glMaterialfv(GL_FRONT,GL_AMBIENT,mamb1); glMaterialfv(GL_FRONT,GL_DIFFUSE,mdiff1); glMaterialfv(GL_FRONT,GL_SPECULAR,mspec1); glMaterialfv(GL_FRONT,GL_EMISSION,memission1); glMaterialfv(GL_FRONT,GL_SHININESS,mshin1); glColor3f(0.0,0.5,0.0); glPushMatrix(); glTranslatef(4.0,0.5,5.5); if(wiremode) glutWireSphere(0.4,30,30); else glutSolidSphere(0.4,30,30); glPopMatrix(); glLoadName(BLUESPHERE); glMaterialfv(GL_FRONT,GL_AMBIENT,mamb1); glMaterialfv(GL_FRONT,GL_DIFFUSE,mdiff1); glMaterialfv(GL_FRONT,GL_SPECULAR,mspec1); glMaterialfv(GL_FRONT,GL_EMISSION,memission1); glMaterialfv(GL_FRONT,GL_SHININESS,mshin1); glColor3f(0.0,0.0,0.5); glPushMatrix(); glTranslatef(4.0,0.5,6.5); if(wiremode) glutWireSphere(0.4,30,30); else glutSolidSphere(0.4,30,30); glPopMatrix(); /*glLoadName(SPHEREID); glMaterialfv(GL_FRONT,GL_AMBIENT,mamb1); glMaterialfv(GL_FRONT,GL_DIFFUSE,mdiff1); glMaterialfv(GL_FRONT,GL_SPECULAR,mspec1); glMaterialfv(GL_FRONT,GL_EMISSION,memission1); glMaterialfv(GL_FRONT,GL_SHININESS,mshin1); glColor3f(0.67,0.31,0.0); glPushMatrix(); glTranslatef(4.0,0.5,6.5); if(wiremode) glutWireSphere(0.4,30,30); else glutSolidSphere(0.4,30,30); glPopMatrix();*/ } cal=(sin(PI*angle/180)); cal1 = (cal + 2)/4; cal = cal + 0.15; /*--light--*/ /*--force--*/ if(wiremode) glBegin(GL_LINE_LOOP); else glBegin(GL_POLYGON); glColor3f(cal,cal,cal); glNormal3f( 0.0, 1.0, 0.0); glVertex3f( 2.3, 0.1, 8.0); glVertex3f( 2.3, 0.1, 9.0); glVertex3f(-2.3, 0.1, 9.0); glVertex3f(-2.3, 0.1, 8.0); glEnd(); /*glLoadName(PLANEID); glBegin(GL_POLYGON); glColor3f(1.0,1.0,1.0); glPushMatrix(); glTranslatef(xr,0.1,zr); glRotatef(angle,0.0,1.0,0.0); glTranslatef(xr,0.1,zr); glNormal3f( 0.0, 1.0, 0.0); glVertex3f( 0.0, 0.1, 6.5); glVertex3f(-0.8, 0.1, 6.9); glVertex3f(-0.4, 0.1, 6.9); glVertex3f(-0.4, 0.1, 7.3); glVertex3f(0.4, 0.1, 7.3); glVertex3f(0.4, 0.1, 6.9); glVertex3f(0.8, 0.1, 6.9); glEnd(); glPopMatrix();*/ glBegin(GL_POLYGON); glColor3f(0.0,0.0,0.2); glNormal3f( 0.0, 0.0, 1.0); glVertex3f(-2.0, 5.0, -12.2); glVertex3f(-2.0, 7.0, -12.2); glVertex3f(2.0, 7.0, -12.2); glVertex3f(2.0, 5.0, -12.2); glEnd(); /* Write some text */ /*glColor3f(1.0,1.0,1.0); DrawTextXY(-1.0,5.75,-12.0,0.008,"1234");*/ } /* Set up the lighing environment */ void MakeLighting(int lt) { GLfloat modelAmb[] = {0.3,0.3,0.3,1.0}; GLfloat spot_direction[] = {0.0, 0.0, 1.0}; GLfloat pos1[] = {0.0, 0.5, 1.0, 0.0}; /* Light from below */ GLfloat dif1[] = {1.0,1.0,1.0,1.0}; /* Fainter */ GLfloat amb1[] = {1.0,1.0,1.0,1.0}; GLfloat spec1[]= {1.0,1.0,1.0,1.0}; GLfloat pos2[] = {2.0,1.0,-2.0,0.0}; /* Light from below */ GLfloat dif2[] = {0.9,0.9,0.0,1.0}; /* Fainter */ GLfloat amb2[] = {0.2,0.2,0.0,1.0}; GLfloat spec2[]= {0.9,0.9,0.0,1.0}; GLfloat pos3[] = {-2.0,1.0,-2.0,0.0}; /* Light from below */ GLfloat dif3[] = {0.0,0.9,0.9,1.0}; /* Fainter */ GLfloat amb3[] = {0.0,0.2,0.2,1.0}; GLfloat spec3[]= {0.0,0.9,0.9,1.0}; /* Set ambient globally,default ambient for light sources is 0 */ glLightModelfv(GL_LIGHT_MODEL_AMBIENT, modelAmb); glLightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE); glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE); glLightfv(GL_LIGHT1,GL_POSITION,pos1); glLightfv(GL_LIGHT1,GL_DIFFUSE,dif1); glLightfv(GL_LIGHT1,GL_AMBIENT,amb1); glLightfv(GL_LIGHT1,GL_SPECULAR,spec1); glLightfv(GL_LIGHT1,GL_SPOT_DIRECTION,spot_direction); glLightf(GL_LIGHT1,GL_SPOT_EXPONENT,20.0); glLightf(GL_LIGHT1,GL_SPOT_CUTOFF,180.0); glLightf(GL_LIGHT1,GL_CONSTANT_ATTENUATION,0.0); glLightf(GL_LIGHT1,GL_LINEAR_ATTENUATION,0.0); glLightf(GL_LIGHT1,GL_QUADRATIC_ATTENUATION,1.0); glLightfv(GL_LIGHT2,GL_POSITION,pos2); glLightfv(GL_LIGHT2,GL_DIFFUSE,dif2); glLightfv(GL_LIGHT2,GL_AMBIENT,amb2); glLightfv(GL_LIGHT2,GL_SPECULAR,spec2); glLightfv(GL_LIGHT3,GL_POSITION,pos3); glLightfv(GL_LIGHT3,GL_DIFFUSE,dif3); glLightfv(GL_LIGHT3,GL_AMBIENT,amb3); glLightfv(GL_LIGHT3,GL_SPECULAR,spec3); if(lt == 1) { glDisable(GL_LIGHT2); glEnable(GL_LIGHT3); glDisable(GL_LIGHT1);} if(lt == 2) { glDisable(GL_LIGHT1); glEnable(GL_LIGHT2); glDisable(GL_LIGHT3);} if(lt == 3) { glDisable(GL_LIGHT1); glEnable(GL_LIGHT2); glEnable(GL_LIGHT3);} if(lt == 4) { glDisable(GL_LIGHT1); glDisable(GL_LIGHT2); glDisable(GL_LIGHT3);} } void MakeCamera(float camx,float camy,float camz,float theta,int vx,int vy,int pickmode) { GLint viewport[4]; glMatrixMode(GL_PROJECTION); glLoadIdentity(); if (pickmode == TRUE) { glGetIntegerv(GL_VIEWPORT,viewport); /* Get the viewport bounds */ gluPickMatrix(vx,viewport[3]-vy,3.0,3.0,viewport); } gluPerspective(95.0, /*Field of view */ 1.0, /* aspect ratio */ 0.1,50.0); /* near and far */ glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glRotatef(n,0.0,1.0,0.0); /* glTranslatef(camx,camy,camz); */ if(ballview == 0) { gluLookAt(12*cos(theta*PI/180)*sin(updownrotate*PI/180), 12*cos(updownrotate*PI/180), 12*sin(theta*PI/180)*sin(updownrotate*PI/180), 0.0, 1.0, 0.0, 0.0,1.0,0.0); } if(ballview == 1) { gluLookAt(xr, yb+2.0, zr+3, xr, yb, zr-1.0, 0.0,1.0,0.0); } if(ballview == 2) { gluLookAt(camx, camy, camz, camx, camy-0.5, camz-3, 0.0,1.0,0.0); } } void HandleKeyboard(unsigned char key,int x, int y) { float xf,frc;int i; switch (key) { case 27: case 'Q': case 'q': exit(0); break; case 32: if(move == 1) { printf("force = %f\n",10*cal); if(rt == 0.0) { for(zr = 5.9; zr > -5.8;zr -= cal) { yr = -0.2; if(xr < -1.5 && xr >= -2.2 && zr < -3.5 ) {dist =1; first =0; glColor3f(1.0,1.0,1.0); DrawTextXY(-1.0,5.75,-12.0,0.008,"20");} if(xr < -0.2 && xr >= -1.5 && zr < -3.5) {dist =2; first =0; glColor3f(1.0,1.0,1.0); DrawTextXY(-1.0,5.75,-12.0,0.008,"40");} if(xr < 0.5 && xr >= -0.2 && zr < -3.2) {dist =3; first =0; glColor3f(1.0,1.0,1.0); DrawTextXY(-1.0,5.75,-12.0,0.008,"60");} if(xr < 1.5 && xr >= 0.5 && zr < -3.5) { dist =5; first =0; glColor3f(1.0,1.0,1.0); DrawTextXY(-1.0,5.75,-12.0,0.008,"40");} if(xr < 2.5 && xr >= 1.5 && zr < -3.5) {dist =4; first =0; glColor3f(1.0,1.0,1.0); DrawTextXY(-1.0,5.75,-12.0,0.008,"20");} MakeGeometry(xr,zr,rt,yr,dist,yb); Display(); } for(xr = xr;xr < 4.0 ;xr += 0.5) { yb = 0.5; MakeGeometry(xr,zr,rt,yr,dist,yb); Display(); } for(i=0;i<=9;i++) { if(pins[i].hit == 1) { first = 1; pins[i].z = -5.8; pins[i].scalex = 1.0; pins[i].scaley = 3.0; pins[i].scalez = 1.0; pins[i].hit = 0; } } MakeGeometry(xr,zr,rt,yr,dist,yb); Display(); for(zr = -5.0;zr < 3.5 ;zr += 0.5) { xr = 4.0; yb = 0.5; MakeGeometry(xr,zr,rt,yr,dist,yb); Display(); } rt = 0.0; move = 0; count++; if(count == 2) { count = 0; k=0; dist = 0; MakeGeometry(xr,zr,rt,yr,dist,yb); Display(); } } /*-------second condition--------*/ if(rt > 0 && rt < 8) { for(zr = 5.9; zr > -5.8;zr -= cal) { xr -= ballspeed*0.1; if(xr <= -1.5 && xr > -2.2 && zr < -4.0 ) {dist =1; first =0; glColor3f(1.0,1.0,1.0); DrawTextXY(-1.0,5.75,-12.0,0.008,"20");} if(xr < -0.2 && xr >= -1.5 && zr < -3.5) {dist =2; first =0; glColor3f(1.0,1.0,1.0); DrawTextXY(-1.0,5.75,-12.0,0.008,"40");} if(xr < 0.5 && xr >= -0.2 && zr < -3.2) {dist =3; first =0; glColor3f(1.0,1.0,1.0); DrawTextXY(-1.0,5.75,-12.0,0.008,"60");} if(xr < 1.5 && xr >= 0.5 && zr < -3.5) { dist =5; first =0; glColor3f(1.0,1.0,1.0); DrawTextXY(-1.0,5.75,-12.0,0.008,"40");} if(xr < 2.5 && xr >= 1.5 && zr < -3.5) {dist =4; first =0; glColor3f(1.0,1.0,1.0); DrawTextXY(-1.0,5.75,-12.0,0.008,"20");} MakeGeometry(xr,zr,rt,yr,dist,yb); Display(); yr = -0.2; if(xr < -2.5) { yb = 0.5; xr = -2.5; } MakeGeometry(xr,zr,rt,yr,dist,yb); Display(); } /*--------------------------------*/ if(zr < -4.5) { for(xr = xr;xr <= 4.0 ;xr += 0.5) { yb = 0.5; MakeGeometry(xr,zr,rt,yr,dist,yb); Display(); } for(i=0;i<=9;i++) { if(pins[i].hit == 1) { first = 1; pins[i].z = -5.8; pins[i].scalex = 1.0; pins[i].scaley = 3.0; pins[i].scalez = 1.0; pins[i].hit = 0; } } for(zr = -5.0;zr < 3.5 ;zr += 0.5) { xr = 4.0; yb = 0.5; MakeGeometry(xr,zr,rt,yr,dist,yb); Display(); } } /*----------------------------------*/ rt = 0.0; move = 0; count++; if(count == 2) { count = 0; dist = 0; } MakeGeometry(xr,zr,rt,yr,dist,yb); Display(); } /*--end of rotation if----*/ if(rt >= 8 && rt < 16 ) { for(zr = 5.9; zr > -5.8;zr -= cal) { yr = -0.2; xr -= ballspeed*0.2; if(xr <= -1.5 && xr > -2.2 && zr < -4.0 ) {dist =1; first =0; glColor3f(1.0,1.0,1.0); DrawTextXY(-1.0,5.75,-12.0,0.008,"20");} if(xr < -0.2 && xr >= -1.5 && zr < -3.5) {dist =2; first =0; glColor3f(1.0,1.0,1.0); DrawTextXY(-1.0,5.75,-12.0,0.008,"40");} if(xr < 0.5 && xr >= -0.2 && zr < -3.2) {dist =3; first =0; glColor3f(1.0,1.0,1.0); DrawTextXY(-1.0,5.75,-12.0,0.008,"60");} if(xr < 1.5 && xr >= 0.5 && zr < -3.5) { dist =5; first =0; glColor3f(1.0,1.0,1.0); DrawTextXY(-1.0,5.75,-12.0,0.008,"40");} if(xr < 2.5 && xr >= 1.5 && zr < -3.5) {dist =4; first =0; glColor3f(1.0,1.0,1.0); DrawTextXY(-1.0,5.75,-12.0,0.008,"20");} if(xr < -2.5) { yb = 0.5; xr = -2.5; } MakeGeometry(xr,zr,rt,yr,dist,yb); Display(); } if(zr < -4.5) { for(xr = xr;xr <= 4.0 ;xr += 0.5) { yb = 0.5; MakeGeometry(xr,zr,rt,yr,dist,yb); Display(); } for(i=0;i<=9;i++) { if(pins[i].hit == 1) { first = 1; pins[i].z = -5.8; pins[i].scalex = 1.0; pins[i].scaley = 3.0; pins[i].scalez = 1.0; pins[i].hit = 0; } } for(zr = -5.0;zr < 3.5 ;zr += 0.5) { xr = 4.0; yb = 0.5; MakeGeometry(xr,zr,rt,yr,dist,yb); Display(); } } rt = 0.0; move = 0; count++; if(count == 2) { count = 0; dist = 0; } MakeGeometry(xr,zr,rt,yr,dist,yb); Display();} if(rt > 16 && rt < 46) { for(zr = 5.9; zr > -5.8;zr -= cal) { yr = -0.2; xr -= ballspeed*0.3; if(xr <= -1.5 && xr > -2.2 && zr < -4.0 ) {dist =1; first =0; glColor3f(1.0,1.0,1.0); DrawTextXY(-1.0,5.75,-12.0,0.008,"20");} if(xr < -0.2 && xr >= -1.5 && zr < -3.5) {dist =2; first =0; glColor3f(1.0,1.0,1.0); DrawTextXY(-1.0,5.75,-12.0,0.008,"40");} if(xr < 0.5 && xr >= -0.2 && zr < -3.2) {dist =3; first =0; glColor3f(1.0,1.0,1.0); DrawTextXY(-1.0,5.75,-12.0,0.008,"60");} if(xr < 1.5 && xr >= 0.5 && zr < -3.5) { dist =5; first =0; glColor3f(1.0,1.0,1.0); DrawTextXY(-1.0,5.75,-12.0,0.008,"40");} if(xr < 2.5 && xr >= 1.5 && zr < -3.5) {dist =4; first =0; glColor3f(1.0,1.0,1.0); DrawTextXY(-1.0,5.75,-12.0,0.008,"20");} if(xr < -2.5) { yb = 0.25; xr = -2.5; } MakeGeometry(xr,zr,rt,yr,dist,yb); Display(); } if(zr < -4.5) { for(xr = xr;xr <= 4.0 ;xr += 0.5) { yb = 0.5; MakeGeometry(xr,zr,rt,yr,dist,yb); Display(); } for(i=0;i<=9;i++) { if(pins[i].hit == 1) { first = 1; pins[i].z = -5.8; pins[i].scalex = 1.0; pins[i].scaley = 3.0; pins[i].scalez = 1.0; pins[i].hit = 0; } } for(zr = -5.0;zr < 3.5 ;zr += 0.5) { xr = 4.0; yb = 0.5; MakeGeometry(xr,zr,rt,yr,dist,yb); Display(); } } rt = 0.0; move = 0; count++; if(count == 2) { count = 0; dist = 0; } MakeGeometry(xr,zr,rt,yr,dist,yb); Display();} if(rt < 0 && rt >= -8) { for(zr = 5.9; zr > -5.8;zr -= cal) { yr = -0.2; xr += ballspeed*0.1; if(xr <= -1.5 && xr > -2.2 && zr < -4.0 ) {dist =1; first =0; glColor3f(1.0,1.0,1.0); DrawTextXY(-1.0,5.75,-12.0,0.008,"20");} if(xr < -0.2 && xr >= -1.5 && zr < -3.5) {dist =2; first =0; glColor3f(1.0,1.0,1.0); DrawTextXY(-1.0,5.75,-12.0,0.008,"40");} if(xr < 0.5 && xr >= -0.2 && zr < -3.2) {dist =3; first =0; glColor3f(1.0,1.0,1.0); DrawTextXY(-1.0,5.75,-12.0,0.008,"60");} if(xr < 1.5 && xr >= 0.5 && zr < -3.5) { dist =5; first =0; glColor3f(1.0,1.0,1.0); DrawTextXY(-1.0,5.75,-12.0,0.008,"40");} if(xr < 2.5 && xr >= 1.5 && zr < -3.5) {dist =4; first =0; glColor3f(1.0,1.0,1.0); DrawTextXY(-1.0,5.75,-12.0,0.008,"20");} if(xr >= 2.5) {yb = 0.25; xr = 2.5; } MakeGeometry(xr,zr,rt,yr,dist,yb); Display(); } if(zr < -4.5) { for(xr = xr;xr <= 4.0 ;xr += 0.5) { yb = 0.5; MakeGeometry(xr,zr,rt,yr,dist,yb); Display(); } for(i=0;i<=9;i++) { if(pins[i].hit == 1) { first = 1; pins[i].z = -5.8; pins[i].scalex = 1.0; pins[i].scaley = 3.0; pins[i].scalez = 1.0; pins[i].hit = 0; } } for(zr = -5.0;zr < 3.5 ;zr += 0.5) { xr = 4.0; yb = 0.5; MakeGeometry(xr,zr,rt,yr,dist,yb); Display(); } } rt = 0.0; move = 0; count++; if(count == 2) { count = 0; dist = 0; } MakeGeometry(xr,zr,rt,yr,dist,yb); Display();} if(rt < -8 && rt >= -16) { for(zr = 5.9; zr > -5.8;zr -= cal) { yr = -0.2; xr += ballspeed*0.2; if(xr <= -1.5 && xr > -2.2 && zr < -4.0 ) {dist =1; first =0; glColor3f(1.0,1.0,1.0); DrawTextXY(-1.0,5.75,-12.0,0.008,"20");} if(xr < -0.2 && xr >= -1.5 && zr < -3.5) {dist =2; first =0; glColor3f(1.0,1.0,1.0); DrawTextXY(-1.0,5.75,-12.0,0.008,"40");} if(xr < 0.5 && xr >= -0.2 && zr < -3.2) {dist =3; first =0; glColor3f(1.0,1.0,1.0); DrawTextXY(-1.0,5.75,-12.0,0.008,"60");} if(xr < 1.5 && xr >= 0.5 && zr < -3.5) { dist =5; first =0; glColor3f(1.0,1.0,1.0); DrawTextXY(-1.0,5.75,-12.0,0.008,"40");} if(xr < 2.5 && xr >= 1.5 && zr < -3.5) {dist =4; first =0; glColor3f(1.0,1.0,1.0); DrawTextXY(-1.0,5.75,-12.0,0.008,"20");} if(xr >= 2.5) {yb = 0.25; xr = 2.5; } MakeGeometry(xr,zr,rt,yr,dist,yb); Display(); } if(zr < -4.5) { for(xr = xr;xr <= 4.0 ;xr += 0.5) { yb = 0.5; MakeGeometry(xr,zr,rt,yr,dist,yb); Display(); } for(i=0;i<=9;i++) { if(pins[i].hit == 1) { first = 1; pins[i].z = -5.8; pins[i].scalex = 1.0; pins[i].scaley = 3.0; pins[i].scalez = 1.0; pins[i].hit = 0; } } for(zr = -5.0;zr < 3.5 ;zr += 0.5) { xr = 4.0; yb = 0.5; MakeGeometry(xr,zr,rt,yr,dist,yb); Display(); } } rt = 0.0; move = 0; count++; if(count == 2) { count = 0; dist = 0; } MakeGeometry(xr,zr,rt,yr,dist,yb); Display();} if(rt < -16 && rt >= -44) { for(zr = 5.9; zr > -5.8;zr -= cal) { yr = -0.2; xr += ballspeed*0.3; if(xr <= -1.5 && xr > -2.2 && zr < -4.0 ) {dist =1; first =0; glColor3f(1.0,1.0,1.0); DrawTextXY(-1.0,5.75,-12.0,0.008,"20");} if(xr < -0.2 && xr >= -1.5 && zr < -3.5) {dist =2; first =0; glColor3f(1.0,1.0,1.0); DrawTextXY(-1.0,5.75,-12.0,0.008,"40");} if(xr < 0.5 && xr >= -0.2 && zr < -3.2) {dist =3; first =0; glColor3f(1.0,1.0,1.0); DrawTextXY(-1.0,5.75,-12.0,0.008,"60");} if(xr < 1.5 && xr >= 0.5 && zr < -3.5) { dist =5; first =0; glColor3f(1.0,1.0,1.0); DrawTextXY(-1.0,5.75,-12.0,0.008,"40");} if(xr < 2.5 && xr >= 1.5 && zr < -3.5) {dist =4; first =0; glColor3f(1.0,1.0,1.0); DrawTextXY(-1.0,5.75,-12.0,0.008,"20");} if(xr >= 2.5) {yb = 0.25; xr = 2.5; } MakeGeometry(xr,zr,rt,yr,dist,yb); Display(); } if(zr < -4.5) { for(xr = xr;xr <= 4.0 ;xr += 0.5) { yb = 0.5; MakeGeometry(xr,zr,rt,yr,dist,yb); Display(); } for(i=0;i<=9;i++) { if(pins[i].hit == 1) { first = 1; pins[i].z = -5.8; pins[i].scalex = 1.0; pins[i].scaley = 3.0; pins[i].scalez = 1.0; pins[i].hit = 0; } } for(zr = -5.0;zr < 3.5 ;zr += 0.5) { xr = 4.0; yb = 0.5; MakeGeometry(xr,zr,rt,yr,dist,yb); Display(); } } rt = 0.0; move = 0; count++; if(count == 2) { count = 0; dist = 0; } MakeGeometry(xr,zr,rt,yr,dist,yb); Display();} } break; case 't': if(rt < 42.0) { rt += 2.0; MakeGeometry(xr,zr,rt,yr,dist,yb); Display();} break; case 'w': if(rt > -42.0) { rt -= 2.0; MakeGeometry(xr,zr,rt,yr,dist,yb); Display();} break; case 'r': rt = 0.0; if(xr < 2.0) xr += 0.2; Display(); break; case 'e': rt = 0.0; if(xr > -2.0) xr -= 0.2; Display(); break; case 'l': lt = 3; MakeLighting(lt); Display(); break; case 'o': lt = 4; MakeLighting(lt); Display(); break; case 'b': ballview = 0; Display(); Display(); break; case 'B': ballview = 1; Display(); Display(); break; case 'p': ballview = 2; Display(); Display(); break; case 'x': if(camx<30) camx += 0.5; Display(); break; case 'y': if(camy<8) camy += 0.5; Display(); break; case 'z': if(camz<30) camz += 0.5; Display(); break; case 'X': if(camx>-30) camx -= 0.5; Display(); break; case 'Y': if(camy>1.0) camy -= 0.5; Display(); break; case 'Z': if(camz>-13) camz -= 0.5; Display(); break; case 'n': n -= 10.5; Display(); break; case 'N': n += 10.5; Display(); break; } } /* Deal with special key strokes */ void HandleSpecialKeyboard(int key,int x, int y) { switch (key) { case GLUT_KEY_LEFT: if(ballview == 0) { theta -= 2.2; } if(ballview == 2) { camx += 0.5; } break; case GLUT_KEY_RIGHT: if(ballview == 0) { theta += 2.2; } if(ballview == 2) { camx -= 0.5; } break; case GLUT_KEY_UP: if(ballview == 0) {if(updownrotate > 0.3) { updownrotate -= 2; } } if(ballview == 2) { camz += 0.5; } break; case GLUT_KEY_DOWN: if(ballview == 0) {if(updownrotate < 48.3) { updownrotate += 2; } } if(ballview == 2) { camz -= 0.5; } break; } } void HandleMainMenu(int whichone) { switch (whichone) { case 1: spincamera = !spincamera; break; case 2: case 100: exit(0); break; } } void HandleSpeedMenu(int whichone) { switch (whichone) { case 1: wiremode = 1; break; case 2: wiremode = 0; break; } } void HandlecolorMenu(int color) { switch (color) { case 1: sprcolor = 1; move = 1; zr = 5.9; xr = 0.0; yb = 1.0; yr = 0.1; Display(); break; case 2: sprcolor = 2; zr = 5.9; move = 1; xr = 0.0; yb = 1.0; yr = 0.1; Display(); break; case 3: sprcolor = 3; zr = 5.9; move = 1; xr = 0.0; yb = 1.0; yr = 0.1; Display(); break; case 4: sprcolor = 4; zr = 5.9; move = 1; xr = 0.0; yb = 1.0; yr = 0.1; Display(); break; } } void HandlelightMenu(int light) { switch (light) { case 1: lt = 1; Display(); break; case 2: lt = 2; Display(); break; case 3: lt = 3; Display(); break; case 4: lt = 4; Display(); break; } } void HandleMouse(int button,int state,int vx,int vy) { int i,maxselect = 10,nhits = 0; GLuint selectlist[100]; if ((state == GLUT_DOWN) && (button == GLUT_LEFT_BUTTON)) { glSelectBuffer(maxselect,selectlist); glRenderMode(GL_SELECT); glInitNames(); glPushName(-1); glPushMatrix(); MakeCamera(camx,camy,camz,theta,vx,vy,TRUE); MakeGeometry(xr,zr,rt,yr,dist,yb); glPopMatrix(); nhits = glRenderMode(GL_RENDER); if (nhits == -1) fprintf(stderr,"Select buffer overflow\n"); if (nhits > 0) { fprintf(stderr,"\tPicked %d objects: ",nhits); for (i=0;i0) { sprcolor = selectlist[3]; move = 1; zr = 5.9; move = 1; xr = 0.0; yb = 1.0; yr = 0.1; Display(); } } } void HandleVisibility(int visible) { if (visible == GLUT_VISIBLE) glutIdleFunc(HandleIdle); else glutIdleFunc(NULL); } void HandleIdle(void) { angle += 10.0; if(angle > 180) angle -= 180; glutPostRedisplay(); } void DrawTextXY(double tex,double tey,double tez,double textscale,char *s) { int i ,k; glPushMatrix(); glTranslatef(tex,tey,tez); glScalef(textscale,textscale,textscale); for (i=0;i