Exemple #1
0
QPixmap Ghost::ghostEyesImage(int size)
{
    QPoint eyesOrigin;
    switch (m_direction) {
    case Unit::Up: eyesOrigin = QPoint(21,27);
        break;
    case Unit::Down: eyesOrigin = QPoint(21,49);
        break;
    case Unit::Left: eyesOrigin = QPoint(14,42);
        break;
    case Unit::Right: eyesOrigin = QPoint(28,42);
        break;
    }
    QImage res(":/textures/images/Ghost_Eyes.png");

    QColor eyeColor(0,0,128,255);
    for(int i=0; i<12; i++)
    {
        for(int j=0; j<12; j++)
        {
            res.setPixel(eyesOrigin.x()+i, eyesOrigin.y()+j, eyeColor.rgba());
            res.setPixel(eyesOrigin.x()+i+41, eyesOrigin.y()+j, eyeColor.rgba());
        }
    }
    QSize tmp(size, size);
    if(res.size()!=tmp) res = res.scaled(tmp);

    return QPixmap::fromImage(res);
}
//Called to update the display.
//You should call glutSwapBuffers after all of your rendering to display what you rendered.
//If you need continuous updates of the screen, call glutPostRedisplay() at the end of the function.
void display()
{
   const float epsilon = 0.001f; // necessary for the trackball viewer
   const float period = 10.0;  // repeat time in seconds of movement
   float fElapsedTime = glutGet(GLUT_ELAPSED_TIME) / 1000.0f; // time since programs started in seconds
   float timeParameter = (float) fmodf(fElapsedTime, period)/period; // parameterized time
   //float timeParameter = 0.0f; // no animation - also comment out the glutPostRedisplay() at the bottom of this function

   glClearColor(0.0f, 0.0f, 0.2f, 0.0f); // unshaded objects will show up on this almost-black background
   glClearDepth(1.0f);
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

   // light stuff
   glUniform3f(PhongShade.cameraSpaceLightPosUnif, 0.0, 0.0, 100.0);  // this is a headlight
   glUniform4f(PhongShade.lightIntensityUnif, 1.0f, 1.0f, 1.0f, 1.0f); // light color

   // compute trackball interface (world to camera) transform --------------------------------
   // don't change any of this (unless you can make it better!)
   glm::mat4 camMatrix;
   glm::mat4 cam2Matrix;
   camMatrix = glm::translate(camMatrix, glm::vec3(modelTrans[0], modelTrans[1], modelTrans[2]));
   // in the middle of a left-button drag
   if (trackballMove) {
      // check to make sure axis is not zero vector
      if (!(-epsilon < axis[0] && axis[0] < epsilon && -epsilon < axis[1] && axis[1] < epsilon && -epsilon < axis[2] && axis[2] < epsilon)) {

         cam2Matrix = glm::rotate(cam2Matrix, angle, glm::vec3(axis[0], axis[1], axis[2]));
         cam2Matrix = cam2Matrix * (glm::mat4(trackballXform[0], trackballXform[1], trackballXform[2], trackballXform[3], 
                                              trackballXform[4], trackballXform[5], trackballXform[6], trackballXform[7],
                                              trackballXform[8], trackballXform[9], trackballXform[10], trackballXform[11],
                                              trackballXform[12], trackballXform[13], trackballXform[14], trackballXform[15]));
         glm::mat4 tempM = cam2Matrix;
         // copy current transform back into trackball matrix
         for (int i=0; i<4; i++) {
            for (int j=0; j<4; j++) 
               trackballXform[i*4 + j] = tempM[i][j];
         }
      }
   }
   camMatrix = camMatrix * (glm::mat4(objectXformPtr[0], objectXformPtr[1], objectXformPtr[2], objectXformPtr[3], 
                                      objectXformPtr[4], objectXformPtr[5], objectXformPtr[6], objectXformPtr[7],
                                      objectXformPtr[8], objectXformPtr[9], objectXformPtr[10], objectXformPtr[11],
                                      objectXformPtr[12], objectXformPtr[13], objectXformPtr[14], objectXformPtr[15]));
   // end of world to camera transform -----------------------------------------------

   // pass it on to the shaders
   glUniformMatrix4fv(PhongShade.worldToCameraMatrixUnif, 1, GL_FALSE, glm::value_ptr(camMatrix));

   // draw objects - pass in the transform matrix to use
   glm::mat4 modelMatrix;  //starts with identity

   drawFirstSphere(modelMatrix); // modelMatrix is not modified by the draw functions
   drawTopSphere(modelMatrix, sqrColor(timeParameter), timeParameter);
   drawMiddleSphere(modelMatrix, linearColor(timeParameter), timeParameter);
   drawMiddleSphere2(modelMatrix, linearColor(timeParameter), timeParameter);
   eyeRight(modelMatrix, eyeColor(timeParameter), timeParameter);
   eyeLeft(modelMatrix, eyeColor(timeParameter), timeParameter);
   drawMouth(modelMatrix, linearColor(timeParameter), timeParameter);
   
   drawBottomSphere(modelMatrix, sineColor(timeParameter), timeParameter);
   drawThirdSphere(modelMatrix);

   glutSwapBuffers();
   glutPostRedisplay();
}