Changeset cd1cb0f in opengl-game
- Timestamp:
- Dec 24, 2019, 12:48:49 AM (5 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 0fe8433
- Parents:
- a79be34
- git-author:
- Dmitry Portnoy <dmitry.portnoy@…> (12/22/19 03:45:12)
- git-committer:
- Dmitry Portnoy <dmitry.portnoy@…> (12/24/19 00:48:49)
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
game-gui-sdl.cpp
ra79be34 rcd1cb0f 10 10 11 11 string GameGui_SDL::s_errorMessage; 12 13 GameGui_SDL::GameGui_SDL() : keyState(SDL_GetKeyboardState(NULL)) { 14 } 12 15 13 16 string& GameGui_SDL::getError() { … … 140 143 } 141 144 145 bool GameGui_SDL::keyPressed(unsigned int key) { 146 return keyState[key]; 147 } 148 142 149 void GameGui_SDL::refreshWindowSize() { 143 150 SDL_GetWindowSize(window, &windowWidth, &windowHeight); -
game-gui-sdl.hpp
ra79be34 rcd1cb0f 14 14 class GameGui_SDL : public GameGui { 15 15 public: 16 GameGui_SDL(); 17 16 18 string& getError(); 17 19 … … 24 26 void processEvents(); 25 27 int pollEvent(UIEvent* event); 28 bool keyPressed(unsigned int key); 26 29 27 30 void refreshWindowSize(); … … 37 40 SDL_Window* window; 38 41 int windowWidth, windowHeight; 42 const Uint8* keyState; 39 43 40 44 static string s_errorMessage; -
game-gui.hpp
ra79be34 rcd1cb0f 76 76 virtual void processEvents() = 0; 77 77 virtual int pollEvent(UIEvent* event) = 0; 78 virtual bool keyPressed(unsigned int key) = 0; 78 79 79 80 virtual void refreshWindowSize() = 0; -
graphics-pipeline_vulkan.hpp
ra79be34 rcd1cb0f 10 10 #include <vulkan/vulkan.h> 11 11 12 #define GLM_FORCE_RADIANS 13 #define GLM_FORCE_DEPTH_ZERO_TO_ONE // Since, in Vulkan, the depth range is 0 to 1 instead of -1 to 1 14 #define GLM_FORCE_RIGHT_HANDED 15 16 #include <glm/glm.hpp> 17 #include <glm/gtc/matrix_transform.hpp> 18 12 19 #include "vulkan-utils.hpp" 20 21 using namespace glm; 13 22 14 23 // TODO: Maybe change the name of this struct so I can call the list something other than descriptorInfoList … … 28 37 vector<VertexType> vertices; 29 38 vector<uint16_t> indices; 39 40 mat4 model_base; 41 mat4 model_transform; 30 42 }; 31 43 … … 54 66 void createRenderCommands(VkCommandBuffer& commandBuffer, uint32_t currentImage); 55 67 56 constvector<SceneObject<VertexType>>& getObjects();68 vector<SceneObject<VertexType>>& getObjects(); 57 69 void addObject(const vector<VertexType>& vertices, vector<uint16_t> indices, VkCommandPool commandPool, 58 70 VkQueue graphicsQueue); … … 88 100 VkDeviceMemory indexBufferMemory; 89 101 90 // TODO: T He objects vector isn't used at all in this class, except in the method that returns102 // TODO: The objects vector isn't used at all in this class, except in the method that returns 91 103 // the number of objects. Move this vector and the SceneObject declaration into VulkanGame, esp. 92 // since I'll be adding other // object-specific fields sich as transforms to SceneObject later104 // since I'll be adding other object-specific fields such as transforms to SceneObject later 93 105 vector<SceneObject<VertexType>> objects; 94 106 … … 410 422 411 423 template<class VertexType> 412 constvector<SceneObject<VertexType>>& GraphicsPipeline_Vulkan<VertexType>::getObjects() {424 vector<SceneObject<VertexType>>& GraphicsPipeline_Vulkan<VertexType>::getObjects() { 413 425 return objects; 414 426 } … … 428 440 idx += numVertices; 429 441 } 430 objects.push_back({ vertices, indices });442 objects.push_back({ vertices, indices, mat4(1.0f), mat4(1.0f) }); 431 443 432 444 VulkanUtils::copyDataToBuffer(device, physicalDevice, commandPool, vertices, vertexBuffer, numVertices, -
vulkan-game.cpp
ra79be34 rcd1cb0f 508 508 509 509 createSyncObjects(); 510 511 shipPipeline.getObjects()[0].model_base = 512 translate(mat4(1.0f), vec3(0.0f, -1.2f, 1.65f)) * 513 scale(mat4(1.0f), vec3(0.1f, 0.1f, 0.1f)); 510 514 } 511 515 … … 608 612 } 609 613 614 // Check which keys are held down 615 616 if (gui->keyPressed(SDL_SCANCODE_LEFT)) { 617 transformObject(shipPipeline.getObjects()[0], translate(mat4(1.0f), vec3(-0.01f, 0.0f, 0.0f))); 618 } else if (gui->keyPressed(SDL_SCANCODE_RIGHT)) { 619 transformObject(shipPipeline.getObjects()[0], translate(mat4(1.0f), vec3(0.01f, 0.0f, 0.0f))); 620 } 621 610 622 renderUI(); 611 623 renderScene(); … … 623 635 float time = chrono::duration<float, chrono::seconds::period>(currentTime - startTime).count(); 624 636 637 // TODO: Will need to change this to go through all objects of all pipelines and update their model mats 638 625 639 so_Object.model = 626 640 translate(mat4(1.0f), vec3(0.0f, -2.0f, -0.0f)) * 627 641 rotate(mat4(1.0f), time * radians(90.0f), vec3(0.0f, 0.0f, 1.0f)); 628 642 629 so_Ship.model = 630 translate(mat4(1.0f), vec3(0.0f, -1.2f, 1.65f)) * 631 scale(mat4(1.0f), vec3(0.1f, 0.1f, 0.1f)); 643 so_Ship.model = shipPipeline.getObjects()[0].model_transform * shipPipeline.getObjects()[0].model_base; 632 644 633 645 VulkanUtils::copyDataToMemory(device, uniformBuffersMemory_scenePipeline[currentImage], object_VP_mats); -
vulkan-game.hpp
ra79be34 rcd1cb0f 189 189 vector<VertexType> centerObject(vector<VertexType> vertices); 190 190 191 template<class VertexType> 192 void transformObject(SceneObject<VertexType>& obj, mat4 mat); 193 191 194 void createBufferSet(VkDeviceSize bufferSize, VkBufferUsageFlags flags, 192 195 vector<VkBuffer>& buffers, vector<VkDeviceMemory>& buffersMemory, vector<VkDescriptorBufferInfo>& bufferInfoList); … … 269 272 } 270 273 274 template<class VertexType> 275 void VulkanGame::transformObject(SceneObject<VertexType>& obj, mat4 mat) { 276 obj.model_transform = mat * obj.model_transform; 277 } 278 271 279 #endif // _VULKAN_GAME_H
Note:
See TracChangeset
for help on using the changeset viewer.