bekovski

bonus_p1_renderScene

Nov 19th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.31 KB | None | 0 0
  1. void renderScene() {
  2.     // ...
  3.     //trimesh.draw();
  4.    
  5.     // get time passed
  6.     system_clock::duration t = system_clock::now() - startTime;
  7.  
  8.     // bonus (make objects move)
  9.     switch (modelType) {
  10.     case ModelType::DELPHIN:
  11.         // swim like a delphin
  12.         glRotatef(t.count() * 0.00001, 1, 0, 0);
  13.         glTranslatef(0, 2, 5);
  14.         trimesh.draw();
  15.         val += 0.01f;
  16.         break;
  17.     case ModelType::BRACH:
  18.         // swim around the y-axis
  19.         glRotatef(t.count() * 0.00001, 0, 1, 0);
  20.         glTranslatef(0, 0, -5);
  21.         glRotatef(-90, 0, 1, 0);   
  22.         glTranslatef(0, 0, 5);     
  23.         trimesh.draw();
  24.         break;
  25.     case ModelType::BALLON:
  26.         // fly up, land, fly up again
  27.         glTranslatef(0, 5 + cos(t.count() * 0.0000001) * 5, 0);
  28.         trimesh.draw();
  29.         break;
  30.     case ModelType::FORD:
  31.         // appear disappear
  32.         glTranslatef(sin(t.count() * 0.00000001) * 5, 3.5f, tan(t.count() * 0.0000001) * 2);
  33.         glRotatef(180, 0, 1, 0);    // 3. rotate around y-axis (so that car looks in our direction)
  34.         glRotatef(-90, 1, 0, 0);    // 2. rotate around x-axis (so that car stands on wheels)
  35.         glTranslatef(0, 0, 2);      // 1. translate to origin
  36.         trimesh.draw();
  37.         break;
  38.     case NONE:
  39.     default:
  40.         //std::cout << "Unknown model type -- do a normal draw() call" << std::endl;
  41.         trimesh.draw();
  42.         break;
  43.     }
  44.  
  45.   // swap buffers
  46.     glutSwapBuffers();
  47.     // force rendering
  48.     glutPostRedisplay();
  49. }
Advertisement
Add Comment
Please, Sign In to add comment