//Draw the rocks out void drawRocks() { glPushMatrix(); glTranslated(planepos[0], planepos[1], planepos[2]); // change the position of terrain to make it shows infront of camera glRotatef(180, 0, 1, 0); drawplane(); glPopMatrix(); for (int i = 0; i < 9; i++) { glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,'A'); initRock(); if(rocks[i].age > 0){ rocks[i].age -= 1.5; rockpos=(float) (rand() %10 ); glPushMatrix(); rocks[i].pos[2] += speed; glColor3f(rocks[i].color[0], rocks[i].color[1], rocks[i].color[2]); glMaterialfv(GL_FRONT, GL_AMBIENT, colorBlue); glTranslatef(rocks[i].pos[0], rocks[i].pos[1], rocks[i].pos[2]); //rocks[i].pos[0] += rocks[i].velo[0]; //glutSolidCube(10); glutSolidSphere(10, 15, 15); glPopMatrix(); } } }
int main(void) { int height=480,width=640; bool fullscreen=false,freeze=false,up=false,close=false; double camangle=0,camangle2=0,var_r=0; SDL_Init( SDL_INIT_VIDEO ); SDL_WM_SetCaption( "Test 2 - Clipping, Graphics Made By Pawan Harish", NULL ); int nFlags = SDL_OPENGL | SDL_GL_DOUBLEBUFFER | SDL_HWPALETTE | SDL_HWSURFACE | SDL_HWACCEL; SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER,1); SDL_Surface *pSDLSurface = SDL_SetVideoMode(width,height,16, nFlags ); oglViewport(width/4, height/4, width/2, height/2); glViewport(width/4, height/4, width/2, height/2); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); gluOrtho2D ( width/4, width/2, width/4, width/2 ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); GLfloat x = (GLfloat)width / height; double cx=20,cy=150,cz=350; double r=sqrt(pow(cx,2)+pow(cz,2)+pow(cz,2)); double th=double(atan(double(cy)/double(r))*180)/double(PI); double phi=double(atan(double(cx)/double(-cz))*180)/double(PI); oglMLoadIdentity(); oglVLoadIdentity(); oglPLoadIdentity(); bool Done = false; SDL_Event Event; while(!Done) { SDL_PollEvent(&Event); switch(Event.type) { case SDL_QUIT: Done=true; break; case SDL_KEYDOWN: if(Event.key.keysym.sym==SDLK_ESCAPE) Done=true; else if(Event.key.keysym.sym=='s'&&!freeze) { if(!fullscreen) { pSDLSurface=SDL_SetVideoMode(width,height,16, nFlags|SDL_FULLSCREEN); fullscreen=true; } else { pSDLSurface=SDL_SetVideoMode(width,height,16, nFlags); fullscreen=false; } } else if(Event.key.keysym.sym=='f')freeze=true; else if(Event.key.keysym.sym=='r')freeze=false; break; } if(!freeze) { oglClear(0,0,0); //My drawings camangle+=2; if(camangle>360)camangle=0; if(up)camangle2+=0.25; else camangle2-=0.25; if(camangle2>=30)up=false; if(camangle2<=-30)up=true; if(close)var_r+=2; else var_r-=2; if(var_r>=200)close=false; if(var_r<=-200)close=true; oglVLoadIdentity(); // oglOCamera(-x, x, -1.0, 1.0, 4.0, 2000.0); //oglOCamera(-60, 130, -60, 130, -60, 130); oglPCamera(45,x,60,130); oglVTranslate(0,0,-r+var_r); oglVRotate(-camangle2+th,1); oglVRotate(-camangle+phi,2); drawplane(); oglMPushMatrix(); oglMLoadIdentity(); oglMTranslate(0,0,-50); DrawHome(); oglMPopMatrix(); oglShow(); //show everything made up till now in IGL. SDL_GL_SwapBuffers(); } } SDL_Quit(); return 0; }