Do boning and animation properly
[opengl.git] / main.cpp
index fd6159dcd3cf665ff0a822f52137646ed6b8c275..15599b078cd64aa72465777a7dbf71659fb84005 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -20,6 +20,7 @@
 #include "program.hpp"
 #include "skybox.hpp"
 #include "image.hpp"
+#include "util.hpp"
 
 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
 
@@ -115,6 +116,9 @@ void display() {
 
        float d = (float)glutGet(GLUT_ELAPSED_TIME) * 0.001f;
 
+       glUseProgram(getUtilProg()->progId);
+       setProjectionAndViewUniforms(getUtilProg()->progId);
+
        glUseProgram(pbrProg->progId);
        setProjectionAndViewUniforms(pbrProg->progId);
 
@@ -144,7 +148,8 @@ void display() {
        glUniform3fv(glGetUniformLocation(pbrProg->progId, "lightPositions"), 6, glm::value_ptr(lightPositions[0]));
        glUniform3fv(glGetUniformLocation(pbrProg->progId, "lightColors"), 6, glm::value_ptr(lightColors[0]));
 
-       /* pbr->getRoot()->model = glm::rotate(glm::mat4(1.f), glm::radians(d * 10), glm::vec3(0, 1, 0)); */
+       /* sceneModel->find("Top Bone")->transform = glm::rotate(glm::mat4(1), d / 5.f, { 1, 0, 0}); */
+       /* sceneModel->find("Bottom Bone")->transform = glm::rotate(glm::mat4(1), d / 3.f, { 1, 0, 0}); */
        sceneModel->draw(skyboxes[activeSkybox], d * 1000);
 
        for (Light &light: lights) drawLight(light);
@@ -193,6 +198,8 @@ int findNodeTrans(struct aiNode *n, const struct aiString name, glm::mat4 *dest)
 }
 
 void init() {
+       initUtilProg();
+
        plainProg = new Program("plainvertex.glsl", "plainfrag.glsl");
        glUseProgram(plainProg->progId);
        setupLightBuffers(plainProg->progId);
@@ -205,7 +212,8 @@ void init() {
        pbrProg = new Program("pbrvert.glsl", "pbrfrag.glsl");
        glUseProgram(pbrProg->progId);
 
-       const aiScene *scene = importer.ReadFile("models/newtonsCradle.glb", aiProcess_Triangulate | aiProcess_CalcTangentSpace | aiProcess_GenNormals | aiProcess_FlipUVs);
+       const std::string scenePath = "models/ik.glb";
+       const aiScene *scene = importer.ReadFile(scenePath, aiProcess_Triangulate | aiProcess_CalcTangentSpace | aiProcess_GenNormals | aiProcess_FlipUVs);
        if (!scene) {
                std::cerr << importer.GetErrorString() << std::endl;
                exit(1);
@@ -256,7 +264,10 @@ void keyboardUp(unsigned char key, int x, int y) {
        keyStates[key] = false;
 }
 
+#define ENABLE_MOVEMENT
+
 void timer(int _) {
+#ifdef ENABLE_MOVEMENT
        float xSpeed = 0.f, ySpeed = 0.f, zSpeed = 0.f;
        if (keyStates['w'])
                zSpeed = 0.1f;
@@ -281,6 +292,7 @@ void timer(int _) {
        camPos.x += xSpeed * sin(yaw) + zSpeed * cos(yaw);
        camPos.y += ySpeed;
        camPos.z += zSpeed * sin(yaw) - xSpeed * cos(yaw);
+#endif
        glutPostRedisplay();
        glutTimerFunc(16, timer, 0);
 }
@@ -289,6 +301,7 @@ int prevMouseX, prevMouseY;
 bool firstMouse = true;
 
 void motion(int x, int y) {
+#ifdef ENABLE_MOVEMENT
        if (firstMouse) {
                prevMouseX = x;
                prevMouseY = y;
@@ -314,6 +327,7 @@ void motion(int x, int y) {
        } else {
                camUp = glm::vec3(0, 1, 0);
        }
+#endif
 }
 
 void mouse(int button, int state, int x, int y) {