Changeset 15104a8 in opengl-game for vulkan-game.cpp
- Timestamp:
- Nov 19, 2019, 5:33:49 PM (5 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 1908591
- Parents:
- 5ab1b20
- File:
-
- 1 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;
Note:
See TracChangeset
for help on using the changeset viewer.