Changeset 15104a8 in opengl-game


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

Files:
2 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;
  • vulkan-game.hpp

    r5ab1b20 r15104a8  
    33
    44#include <glm/glm.hpp>
     5#include <glm/gtc/matrix_transform.hpp>
    56
    67#include "game-gui-sdl.hpp"
     
    89
    910#include "vulkan-utils.hpp"
     11
     12using namespace glm;
    1013
    1114#ifdef NDEBUG
     
    1619
    1720struct ModelVertex {
    18    glm::vec3 pos;
    19    glm::vec3 color;
    20    glm::vec2 texCoord;
     21   vec3 pos;
     22   vec3 color;
     23   vec2 texCoord;
    2124};
    2225
    2326struct OverlayVertex {
    24    glm::vec3 pos;
    25    glm::vec2 texCoord;
     27   vec3 pos;
     28   vec2 texCoord;
     29};
     30
     31struct UniformBufferObject {
     32   alignas(16) mat4 model;
     33   alignas(16) mat4 view;
     34   alignas(16) mat4 proj;
    2635};
    2736
     
    3948      const float FAR_CLIP = 100.0f;
    4049      const float FOV_ANGLE = 67.0f;
     50
     51      vec3 cam_pos;
     52
     53      UniformBufferObject ubo;
    4154
    4255      GameGui* gui;
     
    106119      bool initWindow(int width, int height, unsigned char guiFlags);
    107120      void initVulkan();
     121      void initMatrices();
    108122      void mainLoop();
    109123      void renderUI();
Note: See TracChangeset for help on using the changeset viewer.