void display() { auto diff = t2 - t1; auto delta = std::chrono::duration_cast<time_unit>(diff).count(); auto deltaSeconds = delta / 1000.0f; t1 = fast_clock::now(); updateCurrentFrame(); myDefMesh.mySkeleton.updateAnimation(deltaSeconds); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glMultMatrixd(_matrix); //draw terrain //glColor3f(0.5,0.5,0.5); glPushMatrix(); glColor3f(0.7f, 0.7f, 0.7f); glBegin(GL_QUADS); glVertex3f(-3.0f, -0.85f, 3.0f); glVertex3f(3.0f, -0.85f, 3.0f); glVertex3f(3.0f, -0.85f, -3.0f); glVertex3f(-3.0f, -0.85f, -3.0f); glEnd(); glPopMatrix(); glPushMatrix(); myDefMesh.glDraw(meshModel); myDefMesh.resetSkeletonDeltas(); glPopMatrix(); // Drawing reference coord system const int length = 3; const GLfloat r[]{ 1, 0, 0, 1 }; const GLfloat g[]{ 0, 1, 0, 1 }; const GLfloat b[]{ 0, 0, 1, 1 }; glLineWidth(5); glBegin(GL_LINES); glColor4fv(r); glVertex3i(0, 0, 0); glVertex3i(length, 0, 0); glColor4fv(g); glVertex3i(0, 0, 0); glVertex3i(0, length, 0); glColor4fv(b); glVertex3i(0, 0, 0); glVertex3i(0, 0, length); glEnd(); glutSwapBuffers(); t2 = fast_clock::now(); }
void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); GLfloat ambientLight[] = { 0.3f, 0.3f, 0.3f, 1.0f }; GLfloat diffuseLight[] = { 0.7f, 0.7f, 0.7f, 1.0f }; GLfloat lightPos[] = { 20.0f, 20.0f, 50.0f }; changeSize(windowWidth, windowHeight); glEnable(GL_DEPTH_TEST); glFrontFace(GL_CCW); //glEnable(GL_CULL_FACE); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); // Hidden surface removal // Counterclockwise polygons face out // Do not calculate inside of jet // Enable lighting glEnable(GL_LIGHTING); // Set up and enable light 0 glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight); glEnable(GL_LIGHT0); // Enable color tracking glEnable(GL_COLOR_MATERIAL); // Set material properties to follow glColor values glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); glClearColor(0.2f, 0.2f, 0.2f, 3.0f); //Rescale normals to unit length glEnable(GL_NORMALIZE); glLightfv(GL_LIGHT0, GL_POSITION, lightPos); glShadeModel(GL_FLAT); ImguiConf::UpdateImGui(); glLoadIdentity(); glMultMatrixd(_matrix); glColor3f(0.5, 0.5, 0.5); glPushMatrix(); //draw terrain glColor3f(0.7, 0.7, 0.7); glBegin(GL_QUADS); glVertex3f(-3, -0.85, 3); glVertex3f(3, -0.85, 3); glVertex3f(3, -0.85, -3); glVertex3f(-3, -0.85, -3); glEnd(); glPopMatrix(); glPushMatrix(); myDefMesh.mySkeleton.updateSkin(myDefMesh.pmodel); myDefMesh.glDraw(meshModel); glPopMatrix(); if (ImGui::Checkbox("Edition mode", &GLOBALS::editing)) { GLOBALS::frames = 0; } if (GLOBALS::specialFile.empty() && ImGui::Combo("Animation", &GLOBALS::animationNbr, GLOBALS::animationNames, 4)) { if (myDefMesh.mySkeleton.timeline) { myDefMesh.mySkeleton.timeline->save(); myDefMesh.mySkeleton.timeline.release(); myDefMesh.mySkeleton.timeline = nullptr; } myDefMesh.mySkeleton.timeline = std::make_unique<Timeline>(); if (!GLOBALS::animationNbr == 0) { if (!myDefMesh.mySkeleton.timeline->load(GLOBALS::animationNames[GLOBALS::animationNbr])) { std::cerr << "Error loading file : " << GLOBALS::animationNames[GLOBALS::animationNbr] << std::endl; return; } } GLOBALS::frames = 0; } if (GLOBALS::editing) { if (ImGui::InputFloat("Frames", &GLOBALS::frames, 1, 10, 1)) { GLOBALS::frames = floor(GLOBALS::frames); if (GLOBALS::frames < 0) { GLOBALS::frames = 0; } if (myDefMesh.mySkeleton.timeline) myDefMesh.mySkeleton.timeline->createFrame(GLOBALS::frames); } } else { GLOBALS::frames += GLOBALS::speed; ImGui::Text(("Frame : " + std::to_string(GLOBALS::frames)).c_str()); if (GLOBALS::frames < 0 || !myDefMesh.mySkeleton.timeline || !myDefMesh.mySkeleton.timeline->hasFrame(GLOBALS::frames)) { GLOBALS::frames = 0; } ImGui::Combo("Transition type", &GLOBALS::transitionMode, GLOBALS::transitionNames, 4); } myDefMesh.mySkeleton.interpolate(GLOBALS::frames, (InterpolationType)GLOBALS::transitionMode); ImGui::Render(); glutSwapBuffers(); }