Changeset 809ce16 in opengl-game for new-game.cpp
- Timestamp:
- Jun 10, 2018, 10:34:19 PM (6 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 81f28c0
- Parents:
- 5c403fe
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
new-game.cpp
r5c403fe r809ce16 475 475 float cam_speed = 1.0f; 476 476 float cam_yaw_speed = 60.0f*ONE_DEG_IN_RAD; 477 float cam_pitch_speed = 60.0f*ONE_DEG_IN_RAD; 477 478 478 479 // glm::lookAt can create the view matrix … … 481 482 cam_pos = vec3(0.0f, 0.0f, 2.0f); 482 483 float cam_yaw = 0.0f * 2.0f * 3.14159f / 360.0f; 484 float cam_pitch = 0.0f * 2.0f * 3.14159f / 360.0f; 483 485 484 486 mat4 T = translate(mat4(), vec3(-cam_pos.x, -cam_pos.y, -cam_pos.z)); … … 636 638 float dist = cam_speed * elapsed_seconds; 637 639 if (glfwGetKey(window, GLFW_KEY_A)) { 638 cam_pos.x -= cos(cam_yaw)*dist;639 cam_pos .z += sin(cam_yaw)*dist;640 vec3 dir = (inverse(R) * vec4(-1.0f, 0.0f, 0.0f, 1.0f)).xyz(); 641 cam_pos += dir * dist; 640 642 641 643 cam_moved = true; 642 644 } 643 645 if (glfwGetKey(window, GLFW_KEY_D)) { 644 cam_pos.x += cos(cam_yaw)*dist;645 cam_pos .z -= sin(cam_yaw)*dist;646 vec3 dir = (inverse(R) * vec4(1.0f, 0.0f, 0.0f, 1.0f)).xyz(); 647 cam_pos += dir * dist; 646 648 647 649 cam_moved = true; 648 650 } 649 651 if (glfwGetKey(window, GLFW_KEY_W)) { 650 cam_pos.x -= sin(cam_yaw)*dist;651 cam_pos .z -= cos(cam_yaw)*dist;652 vec3 dir = (inverse(R) * vec4(0.0f, 0.0f, -1.0f, 1.0f)).xyz(); 653 cam_pos += dir * dist; 652 654 653 655 cam_moved = true; 654 656 } 655 657 if (glfwGetKey(window, GLFW_KEY_S)) { 656 cam_pos.x += sin(cam_yaw)*dist;657 cam_pos .z += cos(cam_yaw)*dist;658 vec3 dir = (inverse(R) * vec4(0.0f, 0.0f, 1.0f, 1.0f)).xyz(); 659 cam_pos += dir * dist; 658 660 659 661 cam_moved = true; … … 667 669 cam_moved = true; 668 670 } 671 if (glfwGetKey(window, GLFW_KEY_UP)) { 672 cam_pitch += cam_pitch_speed * elapsed_seconds; 673 cam_moved = true; 674 } 675 if (glfwGetKey(window, GLFW_KEY_DOWN)) { 676 cam_pitch -= cam_pitch_speed * elapsed_seconds; 677 cam_moved = true; 678 } 669 679 if (cam_moved) { 670 680 T = translate(mat4(), vec3(-cam_pos.x, -cam_pos.y, -cam_pos.z)); 671 R = rotate(mat4(), -cam_yaw, vec3(0.0f, 1.0f, 0.0f)); 681 682 mat4 yaw_mat = rotate(mat4(), -cam_yaw, vec3(0.0f, 1.0f, 0.0f)); 683 mat4 pitch_mat = rotate(mat4(), -cam_pitch, vec3(1.0f, 0.0f, 0.0f)); 684 R = pitch_mat * yaw_mat; 672 685 673 686 view_mat = R*T; 687 688 printVector("cam pos", cam_pos); 674 689 675 690 glUseProgram(color_sp);
Note:
See TracChangeset
for help on using the changeset viewer.