Changeset 4ece3bf in opengl-game
- Timestamp:
- Jan 21, 2020, 6:14:09 PM (5 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 5a1ace0
- Parents:
- 3e8cc8b
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
game-gui-sdl.cpp
r3e8cc8b r4ece3bf 127 127 case SDL_AUDIODEVICEADDED: 128 128 case SDL_AUDIODEVICEREMOVED: 129 case SDL_TEXTINPUT: 129 130 case SDL_TEXTEDITING: // TODO: Research this one later 130 131 event->type = UI_EVENT_UNKNOWN; -
new-game.cpp
r3e8cc8b r4ece3bf 731 731 // temporary code to get around vsync issue in OSX Sierra 732 732 if (elapsedTime < (1.0f / TARGET_FPS)) { 733 continue;733 continue; 734 734 } 735 735 -
shaders/asteroid.vert
r3e8cc8b r4ece3bf 5 5 mat4 model; 6 6 float hp; 7 bool deleted; 7 8 }; 8 9 … … 42 43 light2_position_eye = vec3(ubo.view * vec4(light2_position_world, 1.0)); 43 44 44 gl_Position = ubo.proj * vec4(position_eye, 1.0); 45 if (sbo.objects[obj_index].deleted) { 46 gl_Position = vec4(0.0, 0.0, 2.0, 1.0); 47 } else { 48 gl_Position = ubo.proj * vec4(position_eye, 1.0); 49 } 45 50 } -
vulkan-game.cpp
r3e8cc8b r4ece3bf 98 98 SDL_VERSION(&sdlVersion); 99 99 100 cout << "SDL " << sdlVersion.major << "." << sdlVersion.minor << "." << sdlVersion.patch << endl; 100 cout << "SDL "<< 101 to_string(sdlVersion.major) << "." << 102 to_string(sdlVersion.minor) << "." << 103 to_string(sdlVersion.patch) << endl; 101 104 102 105 font = TTF_OpenFont("assets/fonts/lazy.ttf", 28); … … 600 603 scale(mat4(1.0f), vec3(0.1f, 0.1f, 0.1f)); 601 604 602 //vec3 pos = vec3(getRandomNum(-1.3f, 1.3f), -1.2f, getRandomNum(-5.5f, -4.5f)); 603 vec3 pos = vec3(getRandomNum(-1.3f, 1.3f), -1.2f, -2.0f); 605 // vec3 pos = vec3(getRandomNum(-1.3f, 1.3f), -1.2f, getRandomNum(-5.5f, -4.5f)); 606 // vec3 pos = vec3(getRandomNum(-1.3f, 1.3f), -1.2f, -2.0f); 607 // vec3 pos = vec3(1.0f, -1.2f, -1.0f); 608 vec3 pos = vec3(0.0504826f, -1.2f, 1.0f); 604 609 605 610 asteroidObjects[0].model_base = … … 608 613 scale(mat4(1.0f), vec3(0.1f, 0.1f, 0.1f)); 609 614 asteroidObjects[0].model_transform = mat4(1.0); // Might not be needed 615 616 so_Asteroid.hp = 10.0f; 617 so_Asteroid.deleted = 0; 610 618 } 611 619 … … 655 663 bool quit = false; 656 664 665 curTime = SDL_GetPerformanceCounter(); 666 657 667 while (!quit) { 668 669 prevTime = curTime; 670 curTime = SDL_GetPerformanceCounter(); 671 672 elapsedTime = (double)((curTime - prevTime) * 1000 / (double)SDL_GetPerformanceFrequency()); 673 658 674 gui->processEvents(); 659 675 … … 693 709 694 710 createCommandBuffers(); 711 } else if (e.key.keycode == SDL_SCANCODE_Z) { 712 cout << "Deleting asteroid..." << endl; 713 so_Asteroid.deleted = so_Asteroid.deleted == 0 ? 1 : 0; 695 714 } else { 696 715 cout << "Key event detected" << endl; … … 717 736 // Check which keys are held down 718 737 738 float shipSpeed = 0.0005f; 739 float asteroidSpeed = 0.002f; 740 719 741 if (gui->keyPressed(SDL_SCANCODE_LEFT)) { 720 transformObject(shipObjects[0], translate(mat4(1.0f), vec3(- 0.01f, 0.0f, 0.0f)));742 transformObject(shipObjects[0], translate(mat4(1.0f), vec3(-shipSpeed * elapsedTime, 0.0f, 0.0f))); 721 743 } else if (gui->keyPressed(SDL_SCANCODE_RIGHT)) { 722 transformObject(shipObjects[0], translate(mat4(1.0f), vec3( 0.01f, 0.0f, 0.0f)));744 transformObject(shipObjects[0], translate(mat4(1.0f), vec3(shipSpeed * elapsedTime, 0.0f, 0.0f))); 723 745 } 724 746 725 // this code moves the asteroids 726 transformObject(asteroidObjects[0], translate(mat4(1.0f), vec3(0.0f, 0.0f, 0.04f))); 747 if (gui->keyPressed(SDL_SCANCODE_DOWN)) { 748 transformObject(asteroidObjects[0], translate(mat4(1.0f), vec3(0.0f, 0.0f, asteroidSpeed * elapsedTime))); 749 } 727 750 728 751 renderUI(); … … 750 773 751 774 so_Asteroid.model = asteroidObjects[0].model_transform * asteroidObjects[0].model_base; 752 so_Asteroid.hp = 10.0;753 775 754 776 VulkanUtils::copyDataToMemory(device, uniformBuffersMemory_scenePipeline[currentImage], object_VP_mats); -
vulkan-game.hpp
r3e8cc8b r4ece3bf 70 70 alignas(16) mat4 model; 71 71 alignas(4) float hp; 72 alignas(4) unsigned int deleted; 72 73 }; 73 74 … … 194 195 UBO_VP_mats asteroid_VP_mats; 195 196 SBO_Asteroid so_Asteroid; 197 198 Uint64 curTime, prevTime; 199 double elapsedTime; 196 200 197 201 bool initWindow(int width, int height, unsigned char guiFlags);
Note:
See TracChangeset
for help on using the changeset viewer.