/* Focntion de dessin */ void DrawGLScene() { // Effacement du buffer de couleur et de profondeur glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); gluLookAt(cam_pos_x,10.0,cam_pos_z,cam_look_x,5.0,cam_look_z,0.0,1.0,0.0); // Dessin de la grille glPushMatrix(); Draw3DSGrid(); glPopMatrix(); ////////////////////////////////////////////////// // Dessin de la sphere //.. ////////////////////////////////////////////////// // Permutation des buffers glutPostRedisplay(); glutSwapBuffers(); }
############################################################################################################################ */ void display(void) { /* **************************************************************************************************************************** */ /* Effacement du buffer de couleur et de profondeur */ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* **************************************************************************************************************************** */ /* Positionnement du point de vue initial */ SetGlobalView(WindowWidth, WindowHeight); /* **************************************************************************************************************************** */ /* Dessin du squelette */ DrawSkelet(); /* **************************************************************************************************************************** */ /* Dessin de la grille */ Draw3DSGrid(); /* **************************************************************************************************************************** */ /* Dessin des axes */ glCallList(AxesList); /* **************************************************************************************************************************** */ /* Dessin de l'orientation de l'effecteur final */ DrawEEOrientation(); /* **************************************************************************************************************************** */ /* Permutation des buffers et mise-à-jour */ glFlush(); glutSwapBuffers();
void RenderScene() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer glLoadIdentity(); // Reset The matrix gluLookAt(0, 35, 75, 0, 25, 0, 0, 1, 0); // We want the model to rotate around the axis so we give it a rotation // value, then increase/decrease it. You can rotate right of left with the arrow keys. glRotatef(g_RotateX, 0, 1.0f, 0); // Rotate the object around the Y-Axis g_RotateX += g_RotationSpeed; // Increase the speed of rotation //////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** //////////////////// // Here we draw a grid to give us a better representation of the model and it's size Draw3DSGrid(); // Below, we need to increase the frame, but first we put a delay between // each increase so that it doesn't go super fast. I believe the average frame speed // is ~~ 16 milliseconds in 3D Studio Max. You can change this to what ever you want. // When ever Delay() returns true it is time to increase to the next frame of animation. // Check if we can increase to the next frame of animation yet if(Delay(16)) { // Increase the frame count but mod it by the total amount of frames g_3DModel.currentFrame = (g_3DModel.currentFrame) % (g_3DModel.numberOfFrames) + 1; } // * IMPORTANT * // // We do NOT want to animation frame 0 of the animation because it screws // up the animation sometimes. If you have rotations in your model in frame 0 // it will store that rotation in the animation, which messes it up because // when you save the model, the vertices already reflect that rotation. SO, we just // ignore frame 0. If you need frame 0 for some reason, refer to the Quick Notes // for more information on how to make it work (Hint, Reset The Transforms for the object). // Make sure we skip frame 0 of the animation if(g_3DModel.currentFrame == 0) g_3DModel.currentFrame = 1; //////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** //////////////////// // Since we know how many objects our model has, go through each of them. for(int i = 0; i < g_3DModel.numOfObjects; i++) { // Make sure we have valid objects just in case. (size() is in the vector class) if(g_3DModel.pObject.size() <= 0) break; // Get the current object that we are displaying t3DObject *pObject = &g_3DModel.pObject[i]; //////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** //////////////////// // Push on a new matrix for every object so we don't translate/rotate/scale for another glPushMatrix(); // Animated the model with the scale, rotation and translation AnimateModel(&g_3DModel, pObject); //////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** //////////////////// // Check to see if this object has a texture map, if so bind the texture to it. if(pObject->bHasTexture) { // Turn on texture mapping and turn off color glEnable(GL_TEXTURE_2D); // Reset the color to normal again glColor3ub(255, 255, 255); // Bind the texture map to the object by it's materialID glBindTexture(GL_TEXTURE_2D, g_Texture[pObject->materialID]); } else { // Turn off texture mapping and turn on color glDisable(GL_TEXTURE_2D); // Reset the color to normal again glColor3ub(255, 255, 255); } // This determines if we are in wireframe or normal mode glBegin(g_ViewMode); // Begin drawing with our selected mode (triangles or lines) // Go through all of the faces (polygons) of the object and draw them for(int j = 0; j < pObject->numOfFaces; j++) { // Go through each corner of the triangle and draw it. for(int whichVertex = 0; whichVertex < 3; whichVertex++) { // Get the index for each point of the face int index = pObject->pFaces[j].vertIndex[whichVertex]; // Make sure the normals were calculated if(pObject->pNormals) { // Give OpenGL the normal for this vertex. glNormal3f(pObject->pNormals[ index ].x, pObject->pNormals[ index ].y, pObject->pNormals[ index ].z); } // If the object has a texture associated with it, give it a texture coordinate. if(pObject->bHasTexture) { // Make sure there was a UVW map applied to the object or else it won't have tex coords. if(pObject->pTexVerts) { glTexCoord2f(pObject->pTexVerts[ index ].x, pObject->pTexVerts[ index ].y); } } else { // Make sure there is a valid material/color assigned to this object. // You should always at least assign a material color to an object, // but just in case we want to check the size of the material list. // if the size is at least one, and the material ID != -1, // then we have a valid material. if(g_3DModel.pMaterials.size() && pObject->materialID >= 0) { // Get and set the color that the object is, since it must not have a texture BYTE *pColor = g_3DModel.pMaterials[pObject->materialID].color; // Assign the current color to this model glColor3ub(pColor[0], pColor[1], pColor[2]); } } // Make sure we have valid vertices if(pObject->pVerts) { // Pass in the current vertex of the object (Corner of current face) glVertex3f(pObject->pVerts[ index ].x, pObject->pVerts[ index ].y, pObject->pVerts[ index ].z); } } } glEnd(); // End the drawing //////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** //////////////////// // Pop the current matrix and start fresh for another object glPopMatrix(); //////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** //////////////////// } SwapBuffers(g_hDC); // Swap the backbuffers to the foreground }
/* Focntion de dessin */ void DrawGLScene() { // Effacement du buffer de couleur et de profondeur glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); gluLookAt(cam_pos_x,50.0,cam_pos_z,cam_look_x,5.0,cam_look_z,0.0,1.0,0.0); //////////////////////////////////////////////////////////// // Affichage des sphères SetMaterial(mat_specularGREEN, mat_ambientGREEN, mat_diffuseGREEN, mat_shininessGREEN); int i,j ; // variables d'incrémentation for (i = 0; i < N_S ; i++){ glPushMatrix(); if (i == 0){ SetMaterial(mat_specularYELLOW, mat_ambientYELLOW, mat_diffuseYELLOW, mat_shininessYELLOW); } if (i == 1){ SetMaterial(mat_specularGRAY, mat_ambientGRAY, mat_diffuseGRAY, mat_shininessGRAY); } if (i == 2){ SetMaterial(mat_specularRED, mat_ambientRED, mat_diffuseRED, mat_shininessRED); } glTranslatef(sphere_p[0][i], sphere_p[1][i], sphere_p[2][i]); glutSolidSphere (R, 50, 50); glPopMatrix(); } // Dessin de la table SetMaterial(mat_specularTAB, mat_ambientTAB, mat_diffuseTAB, mat_shininessTAB); glPushMatrix(); Draw3DTable(); glPopMatrix(); // Dessin de la grille glPushMatrix(); Draw3DSGrid(); glPopMatrix(); // Dessin de la queue glPushMatrix(); glTranslatef(queue_p[0] , queue_p[1], queue_p[2]); glRotatef(QueueRot,0.0,1.0,0.0); GLUquadricObj *p; p = gluNewQuadric(); gluCylinder(p, 0.09, 0.09,20.0, 30, 30); glPopMatrix(); glPopMatrix(); // Affichage de la puissance de frappe de la queue char strMsg[45] = {0}; char strMsgArg[] = "%"; Pourcentage = (Puiss_incr / Puissance_max) * 100.0; glPushMatrix(); glLoadIdentity(); glRasterPos3f(-0.4f,-0.4f,-1.); sprintf ( strMsg, "Puissance de la queue %d %s", Pourcentage, strMsgArg); unsigned int k; for ( k=0;k<strlen(strMsg);k++) glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,*(strMsg+k)); glPopMatrix(); //////////////////////////////////////////////////////////// // Permutation des buffers glutPostRedisplay(); glutSwapBuffers(); }