+ void mouse(int button, int state, int x, int y) override {
+ if (isPanelFocused(controlWindow))
+ return;
+
+ if (button == GLUT_LEFT_BUTTON && state == GLUT_UP) {
+ if (closestVertex.distance < closestVertexThreshold) {
+ VertIdx idx = { closestVertex.meshIdx, closestVertex.vertIdx };
+ if (manipulators.count(idx) <= 0)
+ manipulators[idx] = closestVertex.pos;
+ curManipulator = idx;
+ }
+ }
+ }
+};
+
+Mode *curMode;
+
+
+void display() {
+ glClearColor(0.5, 0.5, 0.5, 1);
+ glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
+ glViewport(0, 0, windowWidth * 2, windowHeight * 2);
+
+ float d = (float)glutGet(GLUT_ELAPSED_TIME) * 0.001f;
+
+ glUseProgram(getUtilProg()->progId);
+ setProjectionAndViewUniforms(getUtilProg()->progId);
+
+ glUseProgram(pbrProg->progId);
+ setProjectionAndViewUniforms(pbrProg->progId);
+
+ std::vector<Light> lights = curMode->getLights(d);
+ glm::vec3 lightPositions[numLights], lightColors[numLights];
+ for (int i = 0; i < lights.size(); i++) {
+ lightPositions[i] = glm::vec3(lights[i].trans[3]);
+ lightColors[i] = lights[i].color;
+ }
+
+
+ glUniform1ui(glGetUniformLocation(pbrProg->progId, "numLights"), numLights);
+ glUniform3fv(glGetUniformLocation(pbrProg->progId, "lightPositions"), numLights, glm::value_ptr(lightPositions[0]));
+ glUniform3fv(glGetUniformLocation(pbrProg->progId, "lightColors"), numLights, glm::value_ptr(lightColors[0]));
+
+#ifdef COWEDBOY_IK
+ {
+ glm::vec3 targetPos(sin(d) * 2 + 3, -2, 1);
+ Light targetLight = { glm::translate(glm::mat4(1), targetPos), {0.5, 1, 1} };
+ drawLight(targetLight);
+ inverseKinematics(*sceneModel->find("Shoulder.L"), *sceneModel->find("Finger.L"), targetPos);
+
+ targetPos = { sin(d * 2) * 2 - 5, 2.5, 0 };
+ targetLight = { glm::translate(glm::mat4(1), targetPos), {1, 1, 0.5} };
+ drawLight(targetLight);
+ inverseKinematics(*sceneModel->find("Shoulder.R"), *sceneModel->find("Finger.R"), targetPos);
+ }
+#endif
+
+ curMode->display(d);
+
+ // TODO: restore
+ /* if (discoLights) { */
+ /* for (int i = numLights - 3; i < numLights; i++) { */
+ /* Light l = { lightPositions[i], lightColors[i] }; */
+ /* drawLight(l); */
+ /* } */
+ /* } */
+
+ skyboxes[activeSkybox].draw(projMat(), viewMat());