Changeset 15104a8 in opengl-game for vulkan-game.cpp


Ignore:
Timestamp:
Nov 19, 2019, 5:33:49 PM (5 years ago)
Author:
Dmitry Portnoy <dmitry.portnoy@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
1908591
Parents:
5ab1b20
Message:

In vulkangame, nitialize the view and projection metrices to what they were in the original OpenGL game

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vulkan-game.cpp

    r5ab1b20 r15104a8  
    33#define GLM_FORCE_RADIANS
    44#define GLM_FORCE_DEPTH_ZERO_TO_ONE
    5 
    6 #include <glm/gtc/matrix_transform.hpp>
    75
    86#include <array>
     
    1715
    1816using 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 };
    2617
    2718VulkanGame::VulkanGame(int maxFramesInFlight) : MAX_FRAMES_IN_FLIGHT(maxFramesInFlight) {
     
    3425   currentFrame = 0;
    3526   framebufferResized = false;
     27
     28   ubo = {};
    3629}
    3730
     
    6861
    6962   initVulkan();
     63   initMatrices();
    7064   mainLoop();
    7165   cleanup();
     
    259253
    260254   createSyncObjects();
     255}
     256
     257void 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
    261273}
    262274
     
    10021014   float time = chrono::duration<float, chrono::seconds::period>(currentTime - startTime).count();
    10031015
    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));
    10091019
    10101020   void* data;
Note: See TracChangeset for help on using the changeset viewer.