Changeset 15104a8 in opengl-game
- Timestamp:
- Nov 19, 2019, 5:33:49 PM (5 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 1908591
- Parents:
- 5ab1b20
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
vulkan-game.cpp
r5ab1b20 r15104a8 3 3 #define GLM_FORCE_RADIANS 4 4 #define GLM_FORCE_DEPTH_ZERO_TO_ONE 5 6 #include <glm/gtc/matrix_transform.hpp>7 5 8 6 #include <array> … … 17 15 18 16 using namespace std; 19 using namespace glm;20 21 struct UniformBufferObject {22 alignas(16) mat4 model;23 alignas(16) mat4 view;24 alignas(16) mat4 proj;25 };26 17 27 18 VulkanGame::VulkanGame(int maxFramesInFlight) : MAX_FRAMES_IN_FLIGHT(maxFramesInFlight) { … … 34 25 currentFrame = 0; 35 26 framebufferResized = false; 27 28 ubo = {}; 36 29 } 37 30 … … 68 61 69 62 initVulkan(); 63 initMatrices(); 70 64 mainLoop(); 71 65 cleanup(); … … 259 253 260 254 createSyncObjects(); 255 } 256 257 void VulkanGame::initMatrices() { 258 cam_pos = vec3(0.0f, 0.0f, 2.0f); 259 260 float cam_yaw = 0.0f; 261 float cam_pitch = -50.0f; 262 263 mat4 yaw_mat = rotate(mat4(1.0f), radians(-cam_yaw), vec3(0.0f, 1.0f, 0.0f)); 264 mat4 pitch_mat = rotate(mat4(1.0f), radians(-cam_pitch), vec3(1.0f, 0.0f, 0.0f)); 265 266 mat4 R = pitch_mat * yaw_mat; 267 mat4 T = translate(mat4(1.0f), vec3(-cam_pos.x, -cam_pos.y, -cam_pos.z)); 268 269 ubo.view = R * T; 270 271 ubo.proj = perspective(radians(FOV_ANGLE), (float)swapChainExtent.width / (float)swapChainExtent.height, NEAR_CLIP, FAR_CLIP); 272 ubo.proj[1][1] *= -1; // flip the y-axis so that +y is up 261 273 } 262 274 … … 1002 1014 float time = chrono::duration<float, chrono::seconds::period>(currentTime - startTime).count(); 1003 1015 1004 UniformBufferObject ubo = {}; 1005 ubo.model = rotate(mat4(1.0f), time * radians(90.0f), vec3(0.0f, 0.0f, 1.0f)); 1006 ubo.view = lookAt(vec3(0.0f, 2.0f, 2.0f), vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 1.0f, 0.0f)); 1007 ubo.proj = perspective(radians(FOV_ANGLE), (float)swapChainExtent.width / (float)swapChainExtent.height, NEAR_CLIP, FAR_CLIP); 1008 ubo.proj[1][1] *= -1; // flip the y-axis so that +y is up 1016 ubo.model = 1017 translate(mat4(1.0f), vec3(0.0f, -2.0f, -0.0f)) * 1018 rotate(mat4(1.0f), time * radians(90.0f), vec3(0.0f, 0.0f, 1.0f)); 1009 1019 1010 1020 void* data; -
vulkan-game.hpp
r5ab1b20 r15104a8 3 3 4 4 #include <glm/glm.hpp> 5 #include <glm/gtc/matrix_transform.hpp> 5 6 6 7 #include "game-gui-sdl.hpp" … … 8 9 9 10 #include "vulkan-utils.hpp" 11 12 using namespace glm; 10 13 11 14 #ifdef NDEBUG … … 16 19 17 20 struct ModelVertex { 18 glm::vec3 pos;19 glm::vec3 color;20 glm::vec2 texCoord;21 vec3 pos; 22 vec3 color; 23 vec2 texCoord; 21 24 }; 22 25 23 26 struct OverlayVertex { 24 glm::vec3 pos; 25 glm::vec2 texCoord; 27 vec3 pos; 28 vec2 texCoord; 29 }; 30 31 struct UniformBufferObject { 32 alignas(16) mat4 model; 33 alignas(16) mat4 view; 34 alignas(16) mat4 proj; 26 35 }; 27 36 … … 39 48 const float FAR_CLIP = 100.0f; 40 49 const float FOV_ANGLE = 67.0f; 50 51 vec3 cam_pos; 52 53 UniformBufferObject ubo; 41 54 42 55 GameGui* gui; … … 106 119 bool initWindow(int width, int height, unsigned char guiFlags); 107 120 void initVulkan(); 121 void initMatrices(); 108 122 void mainLoop(); 109 123 void renderUI();
Note:
See TracChangeset
for help on using the changeset viewer.