void renderScene(void) { if (deltaMove || lstrafe || rstrafe) computePos(deltaMove); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClearColor(102.0/255.0, 204.0/255.0, 1.0f, 1.0f); glLoadIdentity(); gluLookAt( x, 1.0f, z, x+lx, 1.0+ly, z+lz, 0.0f, 1.0f, 0.0f); glColor3f(0.0f, 0.65f, 0.0f); glBegin(GL_QUADS); glVertex3f(-100.0f, 0.0f, -100.0f); glVertex3f(-100.0f, 0.0f, 100.0f); glVertex3f( 100.0f, 0.0f, 100.0f); glVertex3f( 100.0f, 0.0f, -100.0f); glEnd(); int i,j; //Door r = 0.7, g = 0.3, b = 0.3; glPushMatrix(); glTranslatef(29.6,0,30); drawDoorZ(); glPopMatrix(); //Door attached wall r = 0.9, g = 0.9, b = 0.9; glPushMatrix(); glTranslatef(33,0,30.6); drawWallX(10); glPopMatrix(); //Door attached wall glPushMatrix(); glTranslatef(26.6,0,30); drawWallZ(3); glPopMatrix(); //Living room wall glPushMatrix(); glTranslatef(26.6,0,30); drawWallX(-5); glPopMatrix(); //Long living room wall glPushMatrix(); glTranslatef(26.6,0,25); drawWallZ(-30); glPopMatrix(); //Balcony to hall living room connector glPushMatrix(); glTranslatef(-3.4,0,40); drawWallZ(15); glPopMatrix(); //Balcony parapet r = 0.0, g = 0.0, b = 0.0; glPushMatrix(); glTranslatef(-9.6,0,25.65); drawParapetX(14.2); glPopMatrix(); r = 0.9, g = 0.9, b = 0.9; //Balcony wall glPushMatrix(); glTranslatef(-3.4,0,25); drawWallZ(-6); glPopMatrix(); //Balcony wall glPushMatrix(); glTranslatef(-3.4,0,40); drawWallZ(-6); glPopMatrix(); //Balcony slide doors glPushMatrix(); glTranslatef(-3.4,0,25); drawWallX(6); glPopMatrix(); //Balcony slide doors glPushMatrix(); glTranslatef(-3.4,0,34); drawWallX(6); glPopMatrix(); //Shoebox wall glPushMatrix(); glTranslatef(33,0,40); drawWallZ(-6); glPopMatrix(); //Hall wall to bathroom glPushMatrix(); glTranslatef(27,0,40); drawWallX(15); glPopMatrix(); //Hall wall glPushMatrix(); glTranslatef(11.6,0,40); drawWallX(25); glPopMatrix(); //Bathroom Door r = 0.7, g = 0.3, b = 0.3; glPushMatrix(); glTranslatef(27,0,55); drawDoorX(); glPopMatrix(); //Bedroom bathroom separator r = 0.9, g = 0.9, b = 0.9; glPushMatrix(); glTranslatef(27,0,59); drawWallX(1); glPopMatrix(); //Bathroom walls r = 0.0, g = 0.0, b = 0.9; glPushMatrix(); glTranslatef(27.6,0,59); drawWallZ(10); glPopMatrix(); //Bathroom walls glPushMatrix(); glTranslatef(27.6,0,49); drawWallZ(10); glPopMatrix(); //Bathroom walls glPushMatrix(); glTranslatef(37.6,0,59); drawWallX(-10); glPopMatrix(); //Bedroom walls r = 0.9, g = 0.9, b = 0.9; glPushMatrix(); glTranslatef(27.6,0,59.6); drawWallZ(10); glPopMatrix(); //Bedroom walls glPushMatrix(); glTranslatef(37.6,0,59); drawWallX(10); glPopMatrix(); //Bedroom walls glPushMatrix(); glTranslatef(27.6,0,69); drawWallZ(10); glPopMatrix(); //Bedroom walls glPushMatrix(); glTranslatef(27.6,0,69); drawWallX(-4.8); glPopMatrix(); //Bathroom Door r = 0.7, g = 0.3, b = 0.3; glPushMatrix(); glTranslatef(27.6,0,60.2); drawDoorX(); glPopMatrix(); //Bedroom kitchen separator r = 0.9, g = 0.9, b = 0.9; glPushMatrix(); glTranslatef(27.6,0,69); drawWallZ(-5); glPopMatrix(); //Kitchen walls glPushMatrix(); glTranslatef(22.6,0,69); drawWallX(15); glPopMatrix(); //Kitchen walls glPushMatrix(); glTranslatef(22.6,0,84); drawWallZ(-7); glPopMatrix(); //Kitchen walls glPushMatrix(); glTranslatef(15.6,0,84); drawWallX(-15); glPopMatrix(); //Kitchen bedroom separator glPushMatrix(); glTranslatef(15.6,0,69); drawWallZ(-2); glPopMatrix(); //Bedroom 2 walls glPushMatrix(); glTranslatef(13.6,0,69); drawWallX(15); glPopMatrix(); //Bedroom 2 walls glPushMatrix(); glTranslatef(13.6,0,84); drawWallZ(-15); glPopMatrix(); //Bedroom 2 walls glPushMatrix(); glTranslatef(-2.6,0,84); drawWallX(-15); glPopMatrix(); //Bedroom 2 walls glPushMatrix(); glTranslatef(-2.6,0,69); drawWallZ(12); glPopMatrix(); //Bedroom Door r = 0.7, g = 0.3, b = 0.3; glPushMatrix(); glTranslatef(9.6,0,69); drawDoorZ(); glPopMatrix(); //Bathroom 2 walls r = 0.9, g = 0.9, b = 0.9; glPushMatrix(); glTranslatef(5.6,0,65); drawWallZ(-13); glPopMatrix(); //Bathroom 2 walls glPushMatrix(); glTranslatef(-7.4,0,65); drawWallX(-6); glPopMatrix(); //Bathroom 2 walls glPushMatrix(); glTranslatef(-7.4,0,59); drawWallZ(19); glPopMatrix(); //Bathroom 2 walls glPushMatrix(); glTranslatef(9.6,0,65); drawWallZ(2); glPopMatrix(); //Bathroom 2 Door r = 0.7, g = 0.3, b = 0.3; glPushMatrix(); glTranslatef(5.59,0,65); drawDoorZ(); glPopMatrix(); //Bedroom 3 walls r = 0.9, g = 0.9, b = 0.9; glPushMatrix(); glTranslatef(-7.4,0,59); drawWallZ(-6); glPopMatrix(); //Bedroom 3 walls glPushMatrix(); glTranslatef(-13.4,0,59); drawWallX(25); glPopMatrix(); //Bedroom 3 walls glPushMatrix(); glTranslatef(-13.4,0,84); drawWallZ(15); glPopMatrix(); //Bedroom 3 Door r = 0.7, g = 0.3, b = 0.3; glPushMatrix(); glTranslatef(-2.6,0,65); drawDoorX(); glPopMatrix(); glPushMatrix(); glTranslatef(-30,0,-30); watersim(); glPopMatrix(); glutSwapBuffers(); }
void renderScene(void) { if (deltaMove) computePos(deltaMove); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); gluLookAt( x, 1.0f, z, x+lx, 1.0f, z+lz, 0.0f, 1.0f, 0.0f); // Draw ground glColor3f(0.9f, 0.9f, 0.9f); glBegin(GL_QUADS); glVertex3f(-100.0f, 0.0f, -100.0f); glVertex3f(-100.0f, 0.0f, 100.0f); glVertex3f( 100.0f, 0.0f, 100.0f); glVertex3f( 100.0f, 0.0f, -100.0f); glEnd(); // Draw 36 Teapot for(i = -3; i < 3; i++) for(j=-3; j < 3; j++) { glPushMatrix(); glTranslatef(i*10.0,0,j * 10.0); glColor3f(0.7, 0.6, 0.0); glScalef(0.5, 0.5, 0.5); glTranslatef(0, 1.0, 0); glutWireTeapot(1.0); glPopMatrix(); } glutSwapBuffers(); }
// Global idle func void renderSceneAll() { // check for keyboard movement if (deltaMove) computePos(deltaMove); renderScenesw1(); renderScenesw2(); renderScenesw3(); }
void timer(int value){ if (deltaMovex || deltaMovez) computePos(deltaMovex, deltaMovez); if (value != 0){ glutTimerFunc(10, timer, 1); } }
void display() { computePos(deltaForwardMove, deltaSideMove); if(deltaAnglex){ computeDir(deltaAnglex, deltaAngley); } glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); gluLookAt(camx, 1.0f, camz, camx+lx, 1.0+ly, camz+lz, 0.0f, 1.0f, 0.0f); makelighting(); makewalls(); // make balls for (int i = 0; i < numballs; i++) { makeball(balls[i]); } makecubes(); glutSwapBuffers(); }
void renderScene(void) //to do render here.. { if (deltaMove) computePos(deltaMove); // Clear Color and Depth Buffers glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Reset transformations glLoadIdentity(); // Set the camera gluLookAt(x, 200.0f, z, x+lx, 200.0f, z+lz, 0.0f, 1.0f, 0.0f); glScalef(0.2*zoom,0.2*zoom,0.2*zoom); gSceneContext->Draw(); //<<----------draw from library.. glutSwapBuffers(); }
void renderScene(void) { if (deltaMove) computePos(deltaMove); if (deltaAngle) computeDir(deltaAngle); // Clear Color and Depth Buffers glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Reset transformations glLoadIdentity(); // Set the camera gluLookAt( x, 1.0f, z, x+lx, 1.0f, z+lz, 0.0f, 1.0f, 0.0f); // Draw ground glColor3f(0.9f, 0.9f, 0.9f); glBegin(GL_QUADS); glVertex3f(-100.0f, 0.0f, -100.0f); glVertex3f(-100.0f, 0.0f, 100.0f); glVertex3f( 100.0f, 0.0f, 100.0f); glVertex3f( 100.0f, 0.0f, -100.0f); glEnd(); // Draw 36 SnowMen for(int i = -3; i < 3; i++) for(int j=-3; j < 3; j++) { glPushMatrix(); glTranslatef(i*10.0,0,j * 10.0); drawSnowMan(); glPopMatrix(); } glutSwapBuffers(); }
void Computation::traverse(Bone * ptr, int skelNum, double transform[4][4], char c){ if (ptr != NULL) { double Rx[4][4], Ry[4][4], Rz[4][4], M[4][4]; //store rotation matrices. double transformBackUp[4][4]; double translation[4][4]; double C[4][4], Cinv[4][4]; matrix4_copy(transform, transformBackUp); //create homogeneous transformation to next frame. identity(M); identity(translation); identity(Rx); identity(Ry); identity(Rz); // compute C rotationZ(Rz, ptr->axis_z); rotationY(Ry, ptr->axis_y); rotationX(Rx, ptr->axis_x); matrix4_mult(Rz, Ry, C); matrix4_mult(C, Rx, C); // compute M rotationX(Rx, (ptr->rx)); rotationY(Ry, (ptr->ry)); rotationZ(Rz, (ptr->rz)); matrix4_mult(Rz, Ry, M); matrix4_mult(M, Rx, M); M[0][3] += ptr->tx; M[1][3] += ptr->ty; M[2][3] += ptr->tz; matrix4_mult(transform, C, transform); matrix4_mult(transform, M, transform); if(c == 'g') computeCM(ptr, skelNum, transform); if(c == 'h') computePos(ptr, transform); translation[0][3] = ptr->dir[0]*ptr->length; translation[1][3] = ptr->dir[1]*ptr->length; translation[2][3] = ptr->dir[2]*ptr->length; matrix4_mult(transform, translation, transform); matrix4_transpose(C, Cinv); matrix4_mult(transform, Cinv, transform); traverse(ptr->child, skelNum, transform, c); traverse(ptr->sibling, skelNum, transformBackUp, c); } }
// Main drawing function void renderScene(void) { // Compute position if we move forward or left or right if (deltaMove || lstrafe || rstrafe) computePos(deltaMove); // Clear color and set background to blue sky glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClearColor(102.0/255.0, 204.0/255.0, 1.0f, 1.0f); // Sets up viewing // Eye is at recorded position x, y, z // We are looking in the direction vx, vy, vz // The up vector is in y direction glLoadIdentity(); gluLookAt( x, y, z, x+vx, y+vy, z+vz, 0.0f, 1.0f, 0.0f ); // Roll the camera as required by roll amount glTranslatef(x,y,z); glRotatef(rollamount, vx, vy, vz); glTranslatef(-x, -y, -z); // Draw green grass glColor3f(0.0f, 0.65f, 0.0f); glBegin(GL_QUADS); glVertex3f(-100.0f, 0.0f, -100.0f); glVertex3f(-100.0f, 0.0f, 100.0f); glVertex3f( 100.0f, 0.0f, 100.0f); glVertex3f( 100.0f, 0.0f, -100.0f); glEnd(); // Drawing walls and doors //Door r = 0.7, g = 0.3, b = 0.3; glPushMatrix(); glTranslatef(29.6,0,30); drawDoorZ(); glPopMatrix(); //Door attached wall r = 1.0, g = 1.0, b = 1.0; glPushMatrix(); glTranslatef(33,0,30.6); drawWallX(10); glPopMatrix(); //Door attached wall glPushMatrix(); glTranslatef(26.6,0,30); drawWallZ(3); glPopMatrix(); //Living room wall glPushMatrix(); glTranslatef(26.6,0,30); drawWallX(-5); glPopMatrix(); //Long living room wall glPushMatrix(); glTranslatef(26.6,0,25); drawWallZ(-30); glPopMatrix(); //Balcony to hall living room connector glPushMatrix(); glTranslatef(-3.4,0,40); drawWallZ(15); glPopMatrix(); //Balcony parapet r = 0.0, g = 0.0, b = 0.0; glPushMatrix(); glTranslatef(-9.6,0,25.65); drawParapetX(14.2); glPopMatrix(); r = 1.0, g = 1.0, b = 1.0; //Balcony wall glPushMatrix(); glTranslatef(-3.4,0,25); drawWallZ(-6); glPopMatrix(); //Balcony wall glPushMatrix(); glTranslatef(-3.4,0,40); drawWallZ(-6); glPopMatrix(); //Balcony slide doors glPushMatrix(); glTranslatef(-3.4,0,25); drawWallX(6); glPopMatrix(); //Balcony slide doors glPushMatrix(); glTranslatef(-3.4,0,34); drawWallX(6); glPopMatrix(); //Shoebox wall glPushMatrix(); glTranslatef(33,0,40); drawWallZ(-6); glPopMatrix(); //Hall wall to bathroom glPushMatrix(); glTranslatef(27,0,40); drawWallX(15); glPopMatrix(); //Hall wall glPushMatrix(); glTranslatef(11.6,0,40); drawWallX(25); glPopMatrix(); //Bathroom Door r = 0.7, g = 0.3, b = 0.3; glPushMatrix(); glTranslatef(27,0,55); drawDoorX(); glPopMatrix(); //Bedroom bathroom separator r = 1.0, g = 1.0, b = 1.0; glPushMatrix(); glTranslatef(27,0,59); drawWallX(1); glPopMatrix(); //Bathroom walls r = 0.0, g = 0.0, b = 0.9; glPushMatrix(); glTranslatef(27.6,0,59); drawWallZ(10); glPopMatrix(); //Bathroom walls glPushMatrix(); glTranslatef(27.6,0,49); drawWallZ(10); glPopMatrix(); //Bathroom walls glPushMatrix(); glTranslatef(37.6,0,59); drawWallX(-10); glPopMatrix(); //Bedroom walls r = 1.0, g = 1.0, b = 1.0; glPushMatrix(); glTranslatef(27.6,0,59.6); drawWallZ(10); glPopMatrix(); //Bedroom walls glPushMatrix(); glTranslatef(37.6,0,59); drawWallX(10); glPopMatrix(); //Bedroom walls glPushMatrix(); glTranslatef(27.6,0,69); drawWallZ(10); glPopMatrix(); //Bedroom walls glPushMatrix(); glTranslatef(27.6,0,69); drawWallX(-4.8); glPopMatrix(); //Bathroom Door r = 0.7, g = 0.3, b = 0.3; glPushMatrix(); glTranslatef(27.6,0,60.2); drawDoorX(); glPopMatrix(); //Bedroom kitchen separator r = 1.0, g = 1.0, b = 1.0; glPushMatrix(); glTranslatef(27.6,0,69); drawWallZ(-5); glPopMatrix(); //Kitchen walls glPushMatrix(); glTranslatef(22.6,0,69); drawWallX(15); glPopMatrix(); //Kitchen walls glPushMatrix(); glTranslatef(22.6,0,84); drawWallZ(-7); glPopMatrix(); //Kitchen walls glPushMatrix(); glTranslatef(15.6,0,84); drawWallX(-15); glPopMatrix(); //Kitchen bedroom separator glPushMatrix(); glTranslatef(15.6,0,69); drawWallZ(-2); glPopMatrix(); //Bedroom 2 walls glPushMatrix(); glTranslatef(13.6,0,69); drawWallX(15); glPopMatrix(); //Bedroom 2 walls glPushMatrix(); glTranslatef(13.6,0,84); drawWallZ(-15); glPopMatrix(); //Bedroom 2 walls glPushMatrix(); glTranslatef(-2.6,0,84); drawWallX(-15); glPopMatrix(); //Bedroom 2 walls glPushMatrix(); glTranslatef(-2.6,0,69); drawWallZ(12); glPopMatrix(); //Bedroom Door r = 0.7, g = 0.3, b = 0.3; glPushMatrix(); glTranslatef(9.6,0,69); drawDoorZ(); glPopMatrix(); //Bathroom 2 walls r = 1.0, g = 1.0, b = 1.0; glPushMatrix(); glTranslatef(5.6,0,65); drawWallZ(-13); glPopMatrix(); //Bathroom 2 walls glPushMatrix(); glTranslatef(-7.4,0,65); drawWallX(-6); glPopMatrix(); //Bathroom 2 walls glPushMatrix(); glTranslatef(-7.4,0,59); drawWallZ(19); glPopMatrix(); //Bathroom 2 walls glPushMatrix(); glTranslatef(9.6,0,65); drawWallZ(2); glPopMatrix(); //Bathroom 2 Door r = 0.7, g = 0.3, b = 0.3; glPushMatrix(); glTranslatef(5.59,0,65); drawDoorZ(); glPopMatrix(); //Bedroom 3 walls r = 1.0, g = 1.0, b = 1.0; glPushMatrix(); glTranslatef(-7.4,0,59); drawWallZ(-6); glPopMatrix(); //Bedroom 3 walls glPushMatrix(); glTranslatef(-13.4,0,59); drawWallX(25); glPopMatrix(); //Bedroom 3 walls glPushMatrix(); glTranslatef(-13.4,0,84); drawWallZ(15); glPopMatrix(); //Bedroom 3 Door r = 0.7, g = 0.3, b = 0.3; glPushMatrix(); glTranslatef(-2.6,0,65); drawDoorX(); glPopMatrix(); glPushMatrix(); glTranslatef(-30,0,-30); glPopMatrix(); glutSwapBuffers(); }
void renderScene(void) { if (deltaMove) computePos(deltaMove); //if (deltaAngle) // computeDir(deltaAngle); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //Reset Transformations glLoadIdentity(); //Set the camera gluLookAt( x, 1.0f, z, x+lx, 1.0f, z+lz, 0.0f, 1.0f, 0.0f); //glRotatef(angle, 0.0, 0.0, 1.0); //Draw GROUND glColor3f(0.9f,0.9f,0.9f); glBegin(GL_QUADS); glVertex3f(-100.0f, 0.0f, -100.0f); glVertex3f(-100.0f, 0.0f, 100.0f); glVertex3f( 100.0f, 0.0f, 100.0f); glVertex3f( 100.0f, 0.0f, -100.0f); glEnd(); //angle+=0.10f; //Draw 36 Snowmen char number[3]; for(int i=-3;i<3;i++) { for(int j=-3;j<3;j++) { glPushMatrix(); glTranslatef(i*10.0,0,j*10.0); snowman(); sprintf(number,"%d",(i+3)*6+(j+3)); renderStrokeFontString(0.0f, 0.5f, 0.0f, (void *)font ,number); glPopMatrix(); } } // Code to compute frames per second frame++; time=glutGet(GLUT_ELAPSED_TIME); if (time - timebase > 1000) { sprintf(s,"Lighthouse3D - FPS:%4.2f", frame*1000.0/(time-timebase)); timebase = time; frame = 0; } // Code to display a string (fps) with bitmap fonts setOrthographicProjection(); void *font= GLUT_BITMAP_8_BY_13; glPushMatrix(); glLoadIdentity(); renderBitmapString(30,15,0,font,(char *)"GLUT Tutorial @ Lighthouse3D"); renderBitmapString(30,30,0,font,s); renderBitmapString(30,45,0,font,(char *)"F1 - Game Mode 640x480 32 bits"); renderBitmapString(30,60,0,font,(char *)"F2 - Game Mode 800x600 32 bits"); renderBitmapString(30,75,0,font,(char *)"F3 - Game Mode 1024x768 32 bits"); renderBitmapString(30,90,0,font,(char *)"F4 - Game Mode 1280x1024 32 bits"); renderBitmapString(30,105,0,font,(char *)"F5 - Game Mode 1920x1200 32 bits"); renderBitmapString(30,120,0,font,(char *)"F6 - Window Mode"); renderBitmapString(30,135,0,font,(char *)"Esc - Quit"); renderBitmapString(30,150,0,font,currentMode); glPopMatrix(); restorePerspectiveProjection(); glutSwapBuffers(); }
void display(void) { GLfloat no_mat[] = { 0.0, 0.0, 0.0, 1.0 }; GLfloat sun_ambient[] = { 1.0, 1.0, 0.0, 1.0 }; GLfloat mat_ambient_color[] = { 0.8, 0.8, 0.2, 1.0 }; GLfloat sun_diffuse[] = { 0.6, 0.6, 0.0, 1.0 }; GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat no_shininess[] = { 0.0 }; GLfloat low_shininess[] = { 5.0 }; GLfloat sun_shininess[] = { 70.0 }; GLfloat sun_emission[] = {0.3, 0.3, 0.0, 0.0}; GLfloat mercury_ambient[] = { 0.6, 0.1, 0.0, 1.0 }; GLfloat mercury_diffuse[] = { 0.6, 0.1, 0.0, 1.0 }; GLfloat mercury_shininess[] = { 30.0 }; GLfloat mercury_emission[] = {0.2, 0.2, 0.0, 0.0}; GLfloat venus_ambient[] = { 0.6, 0.3, 0.0, 1.0 }; GLfloat venus_diffuse[] = { 0.6, 0.3, 0.0, 1.0 }; GLfloat venus_shininess[] = { 30.0 }; GLfloat venus_emission[] = {0.2, 0.3, 0.0, 0.0}; GLfloat earth_ambient[] = { 0.2, 0.2, 0.55, 1.0 }; GLfloat earth_diffuse[] = { 0.2, 0.2, 0.55, 1.0 }; GLfloat earth_shininess[] = { 40.0 }; GLfloat earth_emission[] = {0.1, 0.1, 0.45, 0.0}; GLfloat mars_ambient[] = { 0.75, 0.2, 0.02, 1.0 }; GLfloat mars_diffuse[] = { 0.75, 0.2, 0.02, 1.0 }; GLfloat mars_shininess[] = { 30.0 }; GLfloat mars_emission[] = {0.3, 0.2, 0.0, 0.0}; GLfloat jupitor_ambient[] = { 0.9, 0.7, 0.3, 1.0 }; GLfloat jupitor_diffuse[] = { 0.9, 0.7, 0.3, 1.0 }; GLfloat jupitor_shininess[] = { 20.0 }; GLfloat jupitor_emission[] = {0.1, 0.1, 0.0, 0.0}; GLfloat saturn_ambient[] = { 0.6, 0.6, 0.4, 1.0 }; GLfloat saturn_diffuse[] = { 0.6, 0.6, 0.4, 1.0 }; GLfloat saturn_shininess[] = { 20.0 }; GLfloat saturn_emission[] = {0.2, 0.2, 0.0, 0.0}; GLfloat uranus_ambient[] = { 0.4, 0.6, 0.8, 1.0 }; GLfloat uranus_diffuse[] = { 0.4, 0.6, 0.8, 1.0 }; GLfloat uranus_shininess[] = { 20.0 }; GLfloat uranus_emission[] = {0.1, 0.2, 0.5, 0.0}; GLfloat neptune_ambient[] = { 0.4, 0.0, 0.6, 1.0 }; GLfloat neptune_diffuse[] = { 0.4, 0.0, 0.6, 1.0 }; GLfloat neptune_shininess[] = { 20.0 }; GLfloat neptune_emission[] = {0.1, 0.1, 0.2, 0.0}; GLfloat pluto_ambient[] = { 0.4, 0.1, 0.7, 1.0 }; GLfloat pluto_diffuse[] = { 0.4, 0.1, 0.7, 1.0 }; GLfloat pluto_shininess[] = { 20.0 }; GLfloat pluto_emission[] = {0.0, 0.2, 0.3, 0.0}; if (deltaMove) computePos(deltaMove); if (deltaAngle) computeDir(deltaAngle); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glColor3f (1.0, 1.0, 1.0); //glRotatef(5.0,1.0,0.0,0.0); glPushMatrix(); gluLookAt( x, 1.0f, z, x+lx, 1.0f, z+lz, 0.0f, 1.0f, 0.0f); glRotatef(rotateScene,1.0,0.0,0.0); if(flag==1) displayPath(); glPushMatrix(); glMaterialfv(GL_FRONT, GL_AMBIENT, sun_ambient); glMaterialfv(GL_FRONT, GL_DIFFUSE, sun_diffuse); //glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); glMaterialfv(GL_FRONT, GL_SHININESS, sun_shininess); glMaterialfv(GL_FRONT, GL_EMISSION, sun_emission); glBindTexture(GL_TEXTURE_2D, texture[0]); gluSphere(sun,1.5,20,20); //glutSolidSphere(1.5, 20, 20); /* draw sun */ glPopMatrix(); glPushMatrix(); glRotatef ((GLfloat) mercuryRot, 0.0, 1.0, 0.0); glRotatef ((GLfloat) day, 0.0, 1.0, 0.0); glPushMatrix(); glMaterialfv(GL_FRONT, GL_AMBIENT, mercury_ambient); glMaterialfv(GL_FRONT, GL_DIFFUSE, mercury_diffuse); glMaterialfv(GL_FRONT, GL_SHININESS, mercury_shininess); glMaterialfv(GL_FRONT, GL_EMISSION, mercury_emission); glTranslatef (2.0, 0.0, 0.0); glBindTexture(GL_TEXTURE_2D, texture[1]); gluSphere(mercury,.2,20,18); glPopMatrix(); if(mercuryRot>=360.0) mercuryRot=0.0; mercuryRot=mercuryRot+1.0 ; glPopMatrix(); glPushMatrix(); glRotatef ((GLfloat) venusRot, 0.0, 1.0, 0.0); glRotatef ((GLfloat) day, 0.0, 1.0, 0.0); glPushMatrix(); glMaterialfv(GL_FRONT, GL_AMBIENT, venus_ambient); glMaterialfv(GL_FRONT, GL_DIFFUSE, venus_diffuse); glMaterialfv(GL_FRONT, GL_SHININESS, venus_shininess); glMaterialfv(GL_FRONT, GL_EMISSION, venus_emission); glTranslatef (4.0, 0.0, 0.0); glBindTexture(GL_TEXTURE_2D, texture[2]); gluSphere(venus,.4,20,18); glPopMatrix(); venusRot=venusRot+.800; if(venusRot>=360.0) venusRot=0.0; glPopMatrix(); glPushMatrix(); glRotatef(rotateAstroid,0.0,1.0,0.0); makeAstroidBelt(); rotateAstroid+=0.3; glPopMatrix(); glPushMatrix(); glRotatef ((GLfloat) earthRot, 0.0, 1.0, 0.0); glRotatef ((GLfloat) day, 0.0, 1.0, 0.0); glPushMatrix(); glMaterialfv(GL_FRONT, GL_AMBIENT, earth_ambient); glMaterialfv(GL_FRONT, GL_DIFFUSE, earth_diffuse); glMaterialfv(GL_FRONT, GL_SHININESS,earth_shininess); glMaterialfv(GL_FRONT, GL_EMISSION, earth_emission); glTranslatef (6.0, 0.0, 0.0); glBindTexture(GL_TEXTURE_2D, texture[3]); //earth gluSphere(earth,.5,20,18); earthRot=earthRot+.5; if(earthRot>=360.0) earthRot=0.0; glPopMatrix(); glPopMatrix(); glPushMatrix(); glRotatef ((GLfloat) marsRot, 0.0, 1.0, 0.0); glRotatef ((GLfloat) day, 0.0, 1.0, 0.0); glPushMatrix(); glMaterialfv(GL_FRONT, GL_AMBIENT, mars_ambient); glMaterialfv(GL_FRONT, GL_DIFFUSE, mars_diffuse); glMaterialfv(GL_FRONT, GL_SHININESS,mars_shininess); glMaterialfv(GL_FRONT, GL_EMISSION, mars_emission); glTranslatef (8.0, 0.0, 0.0); //glutSolidSphere(0.65, 20, 18); //mars glBindTexture(GL_TEXTURE_2D, texture[4]); gluSphere(mars,.65,20,18); marsRot=marsRot+0.53; if(marsRot>=360.0) marsRot=0.0; glPopMatrix(); glPopMatrix(); glPushMatrix(); glRotatef ((GLfloat) jupitorRot, 0.0, 1.0, 0.0); glRotatef ((GLfloat) day, 0.0, 1.0, 0.0); glPushMatrix(); glRotatef (90.0,1.0,0.0,0.0); glMaterialfv(GL_FRONT, GL_AMBIENT, jupitor_ambient); glMaterialfv(GL_FRONT, GL_DIFFUSE, jupitor_diffuse); glMaterialfv(GL_FRONT, GL_SHININESS,jupitor_shininess); glMaterialfv(GL_FRONT, GL_EMISSION, jupitor_emission); glTranslatef (10.0, 0.0, 0.0); //glutSolidSphere(0.8, 20, 18); //jupiter glBindTexture(GL_TEXTURE_2D, texture[5]); gluSphere(jupiter,.9,20,18); jupitorRot=jupitorRot+0.084; if(jupitorRot>=360.0) jupitorRot=0.0; glPopMatrix(); glPopMatrix(); glPushMatrix(); glRotatef ((GLfloat) saturnRot, 0.0, 1.0, 0.0); glRotatef ((GLfloat) day, 0.0, 1.0, 0.0); glPushMatrix(); glMaterialfv(GL_FRONT, GL_AMBIENT, saturn_ambient); glMaterialfv(GL_FRONT, GL_DIFFUSE, saturn_diffuse); glMaterialfv(GL_FRONT, GL_SHININESS,saturn_shininess); glMaterialfv(GL_FRONT, GL_EMISSION, saturn_emission); glTranslatef (12.0, 0.0, 0.0); circle(0.0,0.0,0.0,0.9); circle(0.0,0.0,0.0,0.85); circle(0.0,0.0,0.0,0.95); circle(0.0,0.0,0.0,1.0); circle(0.0,0.0,0.0,1.05); circle(0.0,0.0,0.0,1.10); circle(0.0,0.0,0.0,1.15); //glutSolidSphere(0.7, 20, 18); //saturn glBindTexture(GL_TEXTURE_2D, texture[6]); gluSphere(saturn,.7,20,18); saturnRot= saturnRot+ 0.034; if(saturnRot>=360.0) saturnRot=0.0; glPopMatrix(); glPopMatrix(); glPushMatrix(); glRotatef ((GLfloat) uranusRot, 0.0, 1.0, 0.0); glRotatef ((GLfloat) day, 0.0, 1.0, 0.0); glPushMatrix(); glMaterialfv(GL_FRONT, GL_AMBIENT, uranus_ambient); glMaterialfv(GL_FRONT, GL_DIFFUSE, uranus_diffuse); glMaterialfv(GL_FRONT, GL_SHININESS,uranus_shininess); glMaterialfv(GL_FRONT, GL_EMISSION, uranus_emission); glTranslatef (14.0, 0.0, 0.0); glBindTexture(GL_TEXTURE_2D, texture[7]); gluSphere(uranus,.6,20,18); uranusRot=uranusRot+0.012; if(uranusRot>=360.0) uranusRot=0.0; glPopMatrix(); glPopMatrix(); glPushMatrix(); glRotatef ((GLfloat) neptuneRot, 0.0, 1.0, 0.0); glRotatef ((GLfloat) day, 0.0, 1.0, 0.0); glPushMatrix(); glMaterialfv(GL_FRONT, GL_AMBIENT, neptune_ambient); glMaterialfv(GL_FRONT, GL_DIFFUSE, neptune_diffuse); glMaterialfv(GL_FRONT, GL_SHININESS,neptune_shininess); glMaterialfv(GL_FRONT, GL_EMISSION, neptune_emission); glTranslatef (16.0, 0.0, 0.0); // glutSolidSphere(0.3, 20, 18); //neptune glBindTexture(GL_TEXTURE_2D, texture[8]); gluSphere(neptune,.3,20,18); neptuneRot=neptuneRot+0.007; if(neptuneRot>=360.0) neptuneRot=0.0; glPopMatrix(); glPopMatrix(); glPushMatrix(); glRotatef ((GLfloat) plutoRot, 0.0, 1.0, 0.0); glRotatef ((GLfloat) day, 0.0, 1.0, 0.0); glPushMatrix(); glMaterialfv(GL_FRONT, GL_AMBIENT, pluto_ambient); glMaterialfv(GL_FRONT, GL_DIFFUSE, pluto_diffuse); glMaterialfv(GL_FRONT, GL_SHININESS,pluto_shininess); glMaterialfv(GL_FRONT, GL_EMISSION, pluto_emission); glTranslatef (18.0, 0.0, 0.0); //glutSolidSphere(0.3, 20, 18); //pluto glBindTexture(GL_TEXTURE_2D, texture[9]); gluSphere(pluto,.3,20,18); plutoRot=plutoRot+0.004; if(plutoRot>=360.0) plutoRot=0.0; glPopMatrix(); glPopMatrix(); glFlush(); glPopMatrix(); skyBox(); glutSwapBuffers(); }
//renderizando void renderScene(void) { // se for um movimento, faz o que foi pedido if (deltaMove) computePos(deltaMove); // Limpa buffers glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Reinicia as transformações glLoadIdentity(); // põe a câmera gluLookAt( x, 1.0f, z, x+lx, 1.0f, z+lz, 0.0f, 1.0f, 0.0f); glColor3f(0.2f, 0.7f, 0.3f); glBegin(GL_QUADS); // Desenha o chão glVertex3f(-15,0,-15); glVertex3f(-15,0,15); glVertex3f(15,0,15); glVertex3f(15,0,-15); // Teto glColor3f(0.7f, 0.7f, 0.3f); glVertex3f(-15,10,-15); glVertex3f(15,10,-15); glVertex3f(15,10,15); glVertex3f(-15,10,15); // Paredes glColor3f(0.3f, 0.3f, 0.3f); /*entrada (tá em preto, sem paredes... glVertex3f(-1,-1,1); glVertex3f(1,-1,1); glVertex3f(1,1,1); glVertex3f(-1,1,1); glColor3f(0.3f, 0.3f, 1.0f); */ glVertex3f(-15,-15,-15); glVertex3f(15,-15,-15); glVertex3f(15,15,-15); glVertex3f(-15,15,-15); glVertex3f(15,15,15); glVertex3f(15,-15,15); glVertex3f(15,-15,-15); glVertex3f(15,15,-15); glVertex3f(-15,15,15); glVertex3f(-15,-15,15); glVertex3f(-15,-15,-15); glVertex3f(-15,15,-15); glEnd(); // Desenha a caixa glPushMatrix(); glTranslatef(0.0,0,0.0); desenhaCaixa(); glPopMatrix(); glutSwapBuffers(); }
void display() { /*---------------------------------------Lighting ------------------------------------------------*/ typedef struct materialStruct { float ambient[4]; float diffuse[4]; float specular[4]; float emission[4]; float m_amb[4]; float m_diff[4]; float m_spec[4] ; float shininess; } materialStruct; materialStruct redPlastic = { {0.0, 0.0, 0.3, 1.0}, {0.0, 0.4, 0.1, 1.0}, {0.6, 0.6, 0.8, 1.0}, {0.0, 0.0, 0.0, 0.0}, {0.03, 0.22, 0.03, 1.0}, {0.18, 0.77, 0.1, 1.0}, {0.10, 0.41, 0.29, 1.0}, 50.0 }; // glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0, GL_POSITION, light_pos); //First light point glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLightfv(GL_LIGHT0, GL_AMBIENT, redPlastic.ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, redPlastic.diffuse); glLightfv(GL_LIGHT0, GL_SPECULAR, redPlastic.specular); glEnable(GL_LIGHT1); glLightfv(GL_LIGHT1, GL_POSITION, light_pos1); //Second Light point glLightfv(GL_LIGHT1, GL_AMBIENT, redPlastic.ambient); glLightfv(GL_LIGHT1, GL_DIFFUSE, redPlastic.diffuse); glLightfv(GL_LIGHT1, GL_SPECULAR, redPlastic.specular); typedef struct materialStruct2 { float ambient[4]; float diffuse[4]; float specular[4]; float emission[4]; float m_amb[4]; float m_diff[4]; float m_spec[4] ; float shininess; } materialStruct2; materialStruct2 redPlastic2 = { {0.0, 0.0, 0.3, 1.0}, {0.6, 0.1, 0.1, 1.0}, {0.6, 0.6, 0.8, 1.0}, {0.0, 0.0, 0.0, 0.0}, {0.03, 0.02, 0.33, 1.0}, {0.78, 0.17, 0.21, 1.0}, {0.30, 0.11, 0.19, 1.0}, 50.0 }; glEnable(GL_LIGHT2); glLightfv(GL_LIGHT2, GL_POSITION, light_pos2); //Third Light point glLightfv(GL_LIGHT2, GL_AMBIENT, redPlastic2.ambient); glLightfv(GL_LIGHT2, GL_DIFFUSE, redPlastic2.diffuse); glLightfv(GL_LIGHT2, GL_SPECULAR, redPlastic2.specular); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, redPlastic2.ambient); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, redPlastic2.diffuse); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, redPlastic2.specular); glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, redPlastic2.shininess); //clear the screen glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode (GL_MODELVIEW); glLoadIdentity(); if (deltaMove) computePos(deltaMove); if (deltaAngle) computeDir(deltaAngle); //gluLookAt(0, 30, 70, 0, 0, 0, 0, 1, 0); gluLookAt(eye[0],eye[1],eye[2],eye[0]+point[0],eye[1],eye[2]+point[2],0,1,0); camerapos [0] = eye[0]; camerapos[2] = eye[2]; //optionally draw the axis //glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, "SPACE Helicopter PRO"); //drawAxis(); drawstar(); drawRocks(); glPushMatrix(); /*---------------------------------------Solar system-----------------------------------------*/ //Venus glRotatef(ang/200, 0, 1, 1); glTranslatef(100, 0, 0); glColor3f(1, 0, 0); glScalef(2, 2, 2); drawsphere(); glPopMatrix(); glPushMatrix(); //Earth glRotatef(ang/250, 0, 1, 1); glTranslatef(150, 0, 0); glColor3f(0, 0, 1); glScalef(3, 3, 3); drawsphere(); //moon glRotatef(ang/80, 0, 1, 1); glTranslatef(75, 0, 0); glColor3f(1, .5, .5); glScalef(1, 1, 1); drawsphere(); glPopMatrix(); glPushMatrix(); //Mars glRotatef(ang/500, 0, 1, 0); glTranslatef(200, 0, 0); glColor3f(1, 0, 0); glScalef(5, 5, 5); drawsphere(); glRotatef(ang/800, 0, 1, 1); glTranslatef(-500, 0, 0); glColor3f(.5, .5, .5); glScalef(3, 3, 3); drawsphere(); glPopMatrix(); glRotatef(ang/800, 0, 1, 1); glTranslatef(500, 0, 0); glColor3f(.5, .5, .5); glScalef(3, 3, 3); drawsphere(); glRotatef(ang/550, 0, 1, 1); glTranslatef(-200, 0, 0); //glRotatef(ang, 0, 1, 0); glScalef(5, 5, 5); glPopMatrix(); glPopMatrix(); glPopMatrix(); /*---------------------------------------Draw Light Source-----------------------------------------*/ glPushMatrix(); glTranslated(light_pos2[0], light_pos2[1], light_pos2[2]); glColor3f(1, 1, 0); glPopMatrix(); glutSwapBuffers(); glutPostRedisplay(); }
void updateMovement(void) { if (deltaMove) computePos(deltaMove); }
void updateMovement(void) { if(deltaMove) computePos(deltaMove); if(deltaAngle) computeDir(deltaAngle); }