Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ======= add this to main.h ======
- enum ModelType {
- DELPHIN, BRACH, BALLON, FORD, NONE
- } modelType;
- // ======= below goes into main.cpp (context given) =======
- #include <chrono>
- using std::chrono::system_clock;
- system_clock::time_point startTime;
- // ...
- int main(...) {
- startTime = system_clock::now();
- // ...
- }
- // load mesh
- char* filename = "res/Modelle/83ford-gt90.lsa";
- trimesh.loadLSA(filename);
- // save model type
- modelType = FORD; // careful ! need to set accordingly (depengin on file chosen)
- // ...
- // get time passed
- system_clock::duration t = system_clock::now() - startTime;
- // bonus (make objects move)
- switch (modelType) {
- case ModelType::DELPHIN:
- // swim like a delphin
- //glTranslatef(0, sin(val), 0);
- //glTranslatef(0, 0, -5);
- glRotatef(t.count() * 0.00001, 1, 0, 0);
- glTranslatef(0, 2, 5);
- trimesh.draw();
- val += 0.01f;
- break;
- case ModelType::BRACH:
- // appear disappear
- //glTranslatef(sin(t.count() * 0.0000001) * 5, 0, tan(t.count() * 0.0000001) * 2);
- glRotatef(t.count() * 0.00001, 0, 1, 0);
- glTranslatef(0, 0, -5);
- glRotatef(-90, 0, 1, 0);
- glTranslatef(0, 0, 5);
- trimesh.draw();
- break;
- case ModelType::BALLON:
- // fly up, land, fly up again
- glTranslatef(0, 5 + cos(t.count() * 0.0000001) * 5, 0);
- trimesh.draw();
- break;
- case ModelType::FORD:
- // drive around the y-axis
- glPushMatrix();
- glTranslatef(sin(t.count() * 0.00000001) * 5, 3.5f, tan(t.count() * 0.0000001) * 2);
- glRotatef(180, 0, 1, 0); // 3. rotate around y-axis (so that car looks in our direction)
- glRotatef(-90, 1, 0, 0); // 2. rotate around x-axis (so that car stands on wheels)
- glTranslatef(0, 0, 2); // 1. translate to origin
- trimesh.draw();
- glPopMatrix();
- break;
- default:
- //std::cout << "Unknown model type -- do a normal draw() call" << std::endl;
- trimesh.draw();
- break;
- }
- // force rendering
- glutPostRedisplay(); // important !!!!
- // ...
- }
Advertisement
Add Comment
Please, Sign In to add comment