Changeset cd1cb0f in opengl-game


Ignore:
Timestamp:
Dec 24, 2019, 12:48:49 AM (5 years ago)
Author:
Dmitry Portnoy <dmitry.portnoy@…>
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)
Message:

In VulkanGame, make the ship move when the player holds down the right or left arrow keys

Files:
6 edited

Legend:

Unmodified
Added
Removed
  • game-gui-sdl.cpp

    ra79be34 rcd1cb0f  
    1010
    1111string GameGui_SDL::s_errorMessage;
     12
     13GameGui_SDL::GameGui_SDL() : keyState(SDL_GetKeyboardState(NULL)) {
     14}
    1215
    1316string& GameGui_SDL::getError() {
     
    140143}
    141144
     145bool GameGui_SDL::keyPressed(unsigned int key) {
     146   return keyState[key];
     147}
     148
    142149void GameGui_SDL::refreshWindowSize() {
    143150   SDL_GetWindowSize(window, &windowWidth, &windowHeight);
  • game-gui-sdl.hpp

    ra79be34 rcd1cb0f  
    1414class GameGui_SDL : public GameGui {
    1515   public:
     16      GameGui_SDL();
     17
    1618      string& getError();
    1719
     
    2426      void processEvents();
    2527      int pollEvent(UIEvent* event);
     28      bool keyPressed(unsigned int key);
    2629
    2730      void refreshWindowSize();
     
    3740      SDL_Window* window;
    3841      int windowWidth, windowHeight;
     42      const Uint8* keyState;
    3943
    4044      static string s_errorMessage;
  • game-gui.hpp

    ra79be34 rcd1cb0f  
    7676      virtual void processEvents() = 0;
    7777      virtual int pollEvent(UIEvent* event) = 0;
     78      virtual bool keyPressed(unsigned int key) = 0;
    7879
    7980      virtual void refreshWindowSize() = 0;
  • graphics-pipeline_vulkan.hpp

    ra79be34 rcd1cb0f  
    1010#include <vulkan/vulkan.h>
    1111
     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
    1219#include "vulkan-utils.hpp"
     20
     21using namespace glm;
    1322
    1423// TODO: Maybe change the name of this struct so I can call the list something other than descriptorInfoList
     
    2837   vector<VertexType> vertices;
    2938   vector<uint16_t> indices;
     39
     40   mat4 model_base;
     41   mat4 model_transform;
    3042};
    3143
     
    5466      void createRenderCommands(VkCommandBuffer& commandBuffer, uint32_t currentImage);
    5567
    56       const vector<SceneObject<VertexType>>& getObjects();
     68      vector<SceneObject<VertexType>>& getObjects();
    5769      void addObject(const vector<VertexType>& vertices, vector<uint16_t> indices, VkCommandPool commandPool,
    5870         VkQueue graphicsQueue);
     
    88100      VkDeviceMemory indexBufferMemory;
    89101
    90       // TODO: THe objects vector isn't used at all in this class, except in the method that returns
     102      // TODO: The objects vector isn't used at all in this class, except in the method that returns
    91103      // 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 later
     104      // since I'll be adding other object-specific fields such as transforms to SceneObject later
    93105      vector<SceneObject<VertexType>> objects;
    94106
     
    410422
    411423template<class VertexType>
    412 const vector<SceneObject<VertexType>>& GraphicsPipeline_Vulkan<VertexType>::getObjects() {
     424vector<SceneObject<VertexType>>& GraphicsPipeline_Vulkan<VertexType>::getObjects() {
    413425   return objects;
    414426}
     
    428440      idx += numVertices;
    429441   }
    430    objects.push_back({ vertices, indices });
     442   objects.push_back({ vertices, indices, mat4(1.0f), mat4(1.0f) });
    431443
    432444   VulkanUtils::copyDataToBuffer(device, physicalDevice, commandPool, vertices, vertexBuffer, numVertices,
  • vulkan-game.cpp

    ra79be34 rcd1cb0f  
    508508
    509509   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));
    510514}
    511515
     
    608612      }
    609613
     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
    610622      renderUI();
    611623      renderScene();
     
    623635   float time = chrono::duration<float, chrono::seconds::period>(currentTime - startTime).count();
    624636
     637   // TODO: Will need to change this to go through all objects of all pipelines and update their model mats
     638
    625639   so_Object.model =
    626640      translate(mat4(1.0f), vec3(0.0f, -2.0f, -0.0f)) *
    627641      rotate(mat4(1.0f), time * radians(90.0f), vec3(0.0f, 0.0f, 1.0f));
    628642
    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;
    632644
    633645   VulkanUtils::copyDataToMemory(device, uniformBuffersMemory_scenePipeline[currentImage], object_VP_mats);
  • vulkan-game.hpp

    ra79be34 rcd1cb0f  
    189189      vector<VertexType> centerObject(vector<VertexType> vertices);
    190190
     191      template<class VertexType>
     192      void transformObject(SceneObject<VertexType>& obj, mat4 mat);
     193
    191194      void createBufferSet(VkDeviceSize bufferSize, VkBufferUsageFlags flags,
    192195         vector<VkBuffer>& buffers, vector<VkDeviceMemory>& buffersMemory, vector<VkDescriptorBufferInfo>& bufferInfoList);
     
    269272}
    270273
     274template<class VertexType>
     275void VulkanGame::transformObject(SceneObject<VertexType>& obj, mat4 mat) {
     276   obj.model_transform = mat * obj.model_transform;
     277}
     278
    271279#endif // _VULKAN_GAME_H
Note: See TracChangeset for help on using the changeset viewer.