static void key_callback(GLFWwindow *window, int key, int scancode, int action, int mods) { if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) glfwSetWindowShouldClose(window, GL_TRUE); if (action == GLFW_PRESS || action == GLFW_REPEAT) { switch (key) { case GLFW_KEY_W: moveCamera(1.f, 0.f, 0.f); break; case GLFW_KEY_S: moveCamera(-1.f, 0.f, 0.f); break; case GLFW_KEY_A: moveCamera(0.f, -1.f, 0.f); break; case GLFW_KEY_D: moveCamera(0.f, 1.f, 0.f); break; case GLFW_KEY_Z: moveCameraGlobal(0.f, 0.f, -1.f); break; case GLFW_KEY_Q: moveCameraGlobal(0.f, 0.f, 1.f); break; case GLFW_KEY_I: turnCamera(1.f, 0.f, 0.f); break; case GLFW_KEY_K: turnCamera(-1.f, 0.f, 0.f); break; case GLFW_KEY_L: turnCamera(0.f, -1.f, 0.f); break; case GLFW_KEY_J: turnCamera(0.f, 1.f, 0.f); break; case GLFW_KEY_T: changeFOV(-1.f); break; case GLFW_KEY_Y: changeFOV(1.f); break; case GLFW_KEY_M: light = camera_pos; break; case GLFW_KEY_P: nextRenderMethod(); break; /*default:*/ } } }
void Engine::checkKeys(void) { if(keys['r']) { initPlayer(); } if(keys['4']) { turnCamera(0.002); } if(keys['5']) { zoomCamera(0.01); } if(keys['6']) { turnCamera(-0.002); } if(keys['8']) { zoomCamera(-0.01); } if(keys[playerKeys->keyUp()]) { moveX(player->GetxyS()); } if(keys[playerKeys->keyDown()]) { moveX(-player->GetxyS()); } if(keys[playerKeys->keyLeft()]) { moveY(player->GetxyS()); } if(keys[playerKeys->keyRight()]){ moveY(-player->GetxyS()); } //if(keys[playerKeys->keyJump()]) { if(state == 0) { index = player->GetZ() + 10; } } //if(index - player->GetZ() > 0.02) //{ player->SetZ(player->GetZ() + player->GetzS()); index-=player->GetzS(); } //else { player->SetZ(player->GetZ() - player->GetzS()); } }
static void cursor_pos_callback(GLFWwindow *window, double xpos, double ypos) { static double last_xpos = 0, last_ypos = 0; xpos -= last_xpos; ypos -= last_ypos; last_xpos += xpos; last_ypos += ypos; if (camera_movement_active) { turnCamera(ypos * cursor_turn_speed, xpos * cursor_turn_speed, 0.f); } }
int main(int argc, char **argv) { glfwSetErrorCallback(error_callback); /* Initialize the library */ if (!glfwInit()){ fprintf(stderr, "Initialization failed.\n"); return 1; } /* Create a windowed mode window and its OpenGL context */ window = glfwCreateWindow(width, height, "Hello World", NULL, NULL); if (!window) { glfwTerminate(); fprintf(stderr, "Error creating window.\n"); return 1; } /* Make the window's context current */ glfwMakeContextCurrent(window); glfwSetInputMode(window, GLFW_STICKY_MOUSE_BUTTONS, 1); glfwSetKeyCallback(window, key_callback); glfwSetMouseButtonCallback(window, mouse_button_callback); glfwSetCursorPosCallback(window, cursor_pos_callback); //**************************** generowanie przykładowych piksli hs_init(&argc, &argv); initOctTree(); hs_exit(); float *piksele = malloc(height*width*3*sizeof(*piksele)); printf("sizeof(OctTreeNode)=%d\n", (int)sizeof(OctTreeNode)); //**************************** init_cl(); turnCamera(0.f,0.f,0.f); // Calculates initial camera direction fflush(stderr); /* Loop until the user closes the window */ while (!glfwWindowShouldClose(window)) { /* Render here */ for (int i = 0; i < height * width * 3; i++) piksele[i] = 0.0; clock_t start = clock(); captureOctTree(camera_pos, camera_target, up, width, height, piksele); clock_t end = clock(); // show render time in window title char title[16]; snprintf(title, 16, "%d ms", (int)((end - start) / (CLOCKS_PER_SEC / 1000))); glfwSetWindowTitle(window, title); /* Swap front and back buffers */ glfwSwapBuffers(window); /* Poll for and process events */ glfwPollEvents(); } if (num_platforms > 0) { clReleaseMemObject(mainOctCL); clReleaseMemObject(image); clReleaseKernel(kernel); clReleaseCommandQueue(queue); } glfwDestroyWindow(window); glfwTerminate(); return 0; }