bekovski

bonus_p1

Nov 19th, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.97 KB | None | 0 0
  1. // ======= add this to main.h ======
  2.  
  3. enum ModelType {
  4.     DELPHIN, BRACH, BALLON, FORD, NONE
  5. } modelType;
  6.  
  7.  
  8. // ======= below goes into main.cpp (context given) =======
  9.     #include <chrono>
  10.     using std::chrono::system_clock;
  11.     system_clock::time_point startTime;
  12.  
  13.     // ...
  14.     int main(...) {
  15.         startTime = system_clock::now();
  16.         // ...
  17.     }
  18.  
  19.     // load mesh
  20.     char* filename = "res/Modelle/83ford-gt90.lsa";
  21.     trimesh.loadLSA(filename);
  22.     // save model type
  23.     modelType = FORD;       // careful ! need to set accordingly (depengin on file chosen)
  24.  
  25.     // ...
  26.  
  27.     // get time passed
  28.     system_clock::duration t = system_clock::now() - startTime;
  29.  
  30.     // bonus (make objects move)
  31.     switch (modelType) {
  32.     case ModelType::DELPHIN:
  33.         // swim like a delphin
  34.         //glTranslatef(0, sin(val), 0);
  35.         //glTranslatef(0, 0, -5);
  36.         glRotatef(t.count() * 0.00001, 1, 0, 0);
  37.         glTranslatef(0, 2, 5);
  38.         trimesh.draw();
  39.         val += 0.01f;
  40.         break;
  41.     case ModelType::BRACH:
  42.         // appear disappear
  43.         //glTranslatef(sin(t.count() * 0.0000001) * 5, 0, tan(t.count() * 0.0000001) * 2);
  44.         glRotatef(t.count() * 0.00001, 0, 1, 0);
  45.         glTranslatef(0, 0, -5);
  46.         glRotatef(-90, 0, 1, 0);
  47.         glTranslatef(0, 0, 5);
  48.         trimesh.draw();
  49.         break;
  50.     case ModelType::BALLON:
  51.         // fly up, land, fly up again
  52.         glTranslatef(0, 5 + cos(t.count() * 0.0000001) * 5, 0);
  53.         trimesh.draw();
  54.         break;
  55.     case ModelType::FORD:
  56.         // drive around the y-axis
  57.         glPushMatrix();
  58.         glTranslatef(sin(t.count() * 0.00000001) * 5, 3.5f, tan(t.count() * 0.0000001) * 2);
  59.             glRotatef(180, 0, 1, 0);    // 3. rotate around y-axis (so that car looks in our direction)
  60.             glRotatef(-90, 1, 0, 0);    // 2. rotate around x-axis (so that car stands on wheels)
  61.             glTranslatef(0, 0, 2);      // 1. translate to origin
  62.             trimesh.draw();
  63.         glPopMatrix();
  64.         break;
  65.     default:
  66.         //std::cout << "Unknown model type -- do a normal draw() call" << std::endl;
  67.         trimesh.draw();
  68.         break;
  69.     }
  70.  
  71.     // force rendering
  72.     glutPostRedisplay();    // important !!!!
  73.  
  74.     // ...
  75.     }
Advertisement
Add Comment
Please, Sign In to add comment